Serializing PowerSystem Data

Originally Contributed by: Clayton Barrows

Introduction

PowerSystems.jl supports serializing/deserializing data with JSON. This provides an example of how to write and read a System to/from disk.

Dependencies

Let's use a dataset from the tabular data parsing tutorial:

julia> using PowerSystems
julia> file_dir = joinpath(pkgdir(PowerSystems), "docs", "src", "tutorials", "tutorials_data"); #hide
julia> sys = System(joinpath(file_dir, "case5_re.m"))┌ Error: Matlab parser skipping line number 85 consisting of: │ }; └ @ PowerSystems ~/work/PowerSystems.jl/PowerSystems.jl/src/parsers/im_io/matlab.jl:64 [ Info: Correcting vm in bus 1 to 1.07762 to match generator set-point [ Info: Correcting vm in bus 3 to 1.1 to match generator set-point [ Info: Correcting vm in bus 4 to 1.06414 to match generator set-point [ Info: Correcting vm in bus 10 to 1.06907 to match generator set-point [ Info: extending matpower format with data: areas 1x3 [ Info: extending matpower format with data: gen_name 7x4 [ Info: extending matpower format by appending matrix "gen_name" in to "gen" [ Info: reversing the orientation of branch 6 (4, 3) to be consistent with other parallel branches [ Info: removing 1 cost terms from generator 4: [4000.0, 0.0] [ Info: removing 1 cost terms from generator 1: [1400.0, 0.0] [ Info: removing 1 cost terms from generator 5: [1000.0, 0.0] [ Info: removing 1 cost terms from generator 2: [1500.0, 0.0] [ Info: removing 3 cost terms from generator 6: Float64[] [ Info: removing 3 cost terms from generator 7: Float64[] [ Info: removing 1 cost terms from generator 3: [3000.0, 0.0] ┌ Info: Constructing System from Power Models │ data["name"] = "nesta_case5_pjm" └ data["source_type"] = "matpower" [ Info: Reading bus data [ Info: Reading Load data in PowerModels dict to populate System ... [ Info: Reading LoadZones data in PowerModels dict to populate System ... [ Info: Reading generator data [ Info: Reading branch data [ Info: Reading branch data [ Info: Reading DC Line data [ Info: Reading storage data System ┌───────────────────┬─────────────┐ │ Property │ Value │ ├───────────────────┼─────────────┤ │ Name │ │ │ Description │ │ │ System Units Base │ SYSTEM_BASE │ │ Base Power │ 100.0 │ │ Base Frequency │ 60.0 │ │ Num Components │ 30 │ └───────────────────┴─────────────┘ Static Components ┌──────────────────────────┬───────┬────────────────────────┬───────────────┐ │ Type │ Count │ Has Static Time Series │ Has Forecasts │ ├──────────────────────────┼───────┼────────────────────────┼───────────────┤ │ ACBus │ 5 │ false │ false │ │ Arc │ 6 │ false │ false │ │ Area │ 1 │ false │ false │ │ Line │ 5 │ false │ false │ │ LoadZone │ 1 │ false │ false │ │ PhaseShiftingTransformer │ 2 │ false │ false │ │ PowerLoad │ 3 │ false │ false │ │ RenewableDispatch │ 2 │ false │ false │ │ ThermalStandard │ 5 │ false │ false │ └──────────────────────────┴───────┴────────────────────────┴───────────────┘

Write data to a temporary directory

julia> folder = mktempdir();
julia> path = joinpath(folder, "system.json")"/tmp/jl_XHqnFe/system.json"
julia> println("Serializing to $path")Serializing to /tmp/jl_XHqnFe/system.json
julia> to_json(sys, path)[ Info: Serialized System to /tmp/jl_XHqnFe/system.json [ Info: Serialized System metadata to /tmp/jl_XHqnFe/system_metadata.json

Read the JSON file and create a new System

julia> sys2 = System(path)System
┌───────────────────┬─────────────┐
│ Property          │ Value       │
├───────────────────┼─────────────┤
│ Name              │             │
│ Description       │             │
│ System Units Base │ SYSTEM_BASE │
│ Base Power        │ 100.0       │
│ Base Frequency    │ 60.0        │
│ Num Components    │ 30          │
└───────────────────┴─────────────┘

Static Components
┌──────────────────────────┬───────┬────────────────────────┬───────────────┐
│ Type                     │ Count │ Has Static Time Series │ Has Forecasts │
├──────────────────────────┼───────┼────────────────────────┼───────────────┤
│ ACBus                    │ 5     │ false                  │ false         │
│ Arc                      │ 6     │ false                  │ false         │
│ Area                     │ 1     │ false                  │ false         │
│ Line                     │ 5     │ false                  │ false         │
│ LoadZone                 │ 1     │ false                  │ false         │
│ PhaseShiftingTransformer │ 2     │ false                  │ false         │
│ PowerLoad                │ 3     │ false                  │ false         │
│ RenewableDispatch        │ 2     │ false                  │ false         │
│ ThermalStandard          │ 5     │ false                  │ false         │
└──────────────────────────┴───────┴────────────────────────┴───────────────┘