Write, View, and Load Data with a JSON

PowerSystems.jl provides functionality to serialize an entire System to a JSON file and then deserialize it back to a System. The main benefit is that deserializing is significantly faster than reconstructing the System from raw data files.

The sections below show how to write data to a JSON, explore the data while it is in JSON format, and load Data saved in a JSON back into PowerSystems.jl.

Write data to a JSON

You can do this to save your own custom System, but we'll use an existing dataset from PowerSystemCaseBuilder.jl, simply to illustrate the process.

First, load the dependencies and a System from PowerSystemCaseBuilder:

using PowerSystems
using PowerSystemCaseBuilder
sys = build_system(PSISystems, "c_sys5_pjm")
System
Property Value
Name
Description
System Units Base SYSTEM_BASE
Base Power 100.0
Base Frequency 60.0
Num Components 27
Static Components
Type Count
ACBus 5
Arc 6
Line 6
PowerLoad 3
RenewableDispatch 2
ThermalStandard 5
StaticTimeSeries Summary
owner_type owner_category name time_series_type initial_timestamp resolution count time_step_count
String String String String String Dates.CompoundPeriod Int64 Int64
PowerLoad Component max_active_power SingleTimeSeries 2024-01-01T00:00:00 1 hour 3 168
RenewableDispatch Component max_active_power SingleTimeSeries 2024-01-01T00:00:00 1 hour 2 168

Set up your target path, for example in a "mysystems" subfolder:

folder = mkdir("mysystems");
path = joinpath(folder, "system.json")
"mysystems/system.json"

Now write the system to JSON:

to_json(sys, path)
[ Info: Serialized time series data to mysystems/system_time_series_storage.h5.
[ Info: Serialized System to mysystems/system.json
[ Info: Serialized System metadata to mysystems/system_metadata.json

Notice in the Info statements that the serialization process stores 3 files:

  1. System data file (*.json file)
  2. Validation data file (*.json file)
  3. Time Series data file (*.h5 file)

Viewing PowerSystems Data in JSON Format

Some users prefer to view and filter the PowerSystems.jl data while it is in JSON format. There are many tools available to browse JSON data.

Here is an example GUI tool that is available online in a browser.

The command line utility jq offers even more features. Below are some example commands, called from the command line within the "mysystems" subfolder:

View the entire file pretty-printed:

jq . system.json

View the PowerSystems component types:

jq '.data.components | .[] | .__metadata__ | .type' system.json | sort | uniq

View specific components:

jq '.data.components | .[] | select(.__metadata__.type == "ThermalStandard")' system.json

Get the count of a component type:

# There is almost certainly a better way.
jq '.data.components | .[] | select(.__metadata__.type == "ThermalStandard")' system.json | grep -c ThermalStandard

View specific component by name:

jq '.data.components | .[] | select(.__metadata__.type == "ThermalStandard" and .name == "107_CC_1")' system.json

Filter on a field value:

jq '.data.components | .[] | select(.__metadata__.type == "ThermalStandard" and .active_power > 2.3)' system.json

Read the JSON file and create a new System

Finally, you can read the file back in, and verify the new system has the same data as above:

sys2 = System(path)
System
Property Value
Name
Description
System Units Base SYSTEM_BASE
Base Power 100.0
Base Frequency 60.0
Num Components 27
Static Components
Type Count
ACBus 5
Arc 6
Line 6
PowerLoad 3
RenewableDispatch 2
ThermalStandard 5
StaticTimeSeries Summary
owner_type owner_category name time_series_type initial_timestamp resolution count time_step_count
String String String String String Dates.CompoundPeriod Int64 Int64
PowerLoad Component max_active_power SingleTimeSeries 2024-01-01T00:00:00 1 hour 3 168
RenewableDispatch Component max_active_power SingleTimeSeries 2024-01-01T00:00:00 1 hour 2 168
Tip

PowerSystems generates UUIDs for the System and all components in order to have a way to uniquely identify objects. During deserialization it restores the same UUIDs. If you will modify the System or components after deserialization then it is recommended that you set this flag to generate new UUIDs.

system2 = System(path; assign_new_uuids = true)
[ Info: Loaded time series from storage file existing=mysystems/system_time_series_storage.h5 new=/tmp/jl_j9SQSx compression=CompressionSettings(false, CompressionTypes.DEFLATE = 1, 3, true)