Add time series to System

Originally Contributed by: Clayton Barrows

Introduction

An example of how to parse add time series data to a System using PowerSystems.jl

For example, a System created by parsing a MATPOWER file doesn't contain any time series data. So a user may want to add time series to the System.

Dependencies

Let's use the 5-bus dataset we parsed in the MATPOWER example

julia> using PowerSystems
julia> using JSON3
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 │ └──────────────────────────┴───────┴────────────────────────┴───────────────┘

Define pointers to time series files

For example, if we want to add a bunch of time series files, say one for each load and one for each renewable generator, we need to define pointers to each .csv file containing the time series in the following format (PowerSystems.jl also supports a CSV format for this file). We will use Artifacts for the following data.


julia> fname = joinpath(FORECASTS_DIR, "timeseries_pointers_da.json")"/home/runner/.julia/artifacts/2b7013812a985ce5884696ce276ca17b2719a57a/PowerSystemsTestData-2.0/5-Bus/5bus_ts/timeseries_pointers_da.json"
julia> open(fname, "r") do f JSON3.@pretty JSON3.read(f) end[ { "simulation": "DAY_AHEAD", "resolution": 3600, "category": "Generator", "component_name": "SolarBusC", "module": "PowerSystems", "type": "SingleTimeSeries", "name": "max_active_power", "scaling_factor_multiplier": "get_max_active_power", "scaling_factor_multiplier_module": "PowerSystems", "normalization_factor": 1, "data_file": "./gen/Renewable/PV/da_solar5.csv" }, { "simulation": "DAY_AHEAD", "resolution": 3600, "category": "Generator", "component_name": "WindBusA", "module": "PowerSystems", "type": "SingleTimeSeries", "name": "max_active_power", "scaling_factor_multiplier": "get_max_active_power", "scaling_factor_multiplier_module": "PowerSystems", "normalization_factor": 1, "data_file": "./gen/Renewable/WIND/da_wind5.csv" }, { "simulation": "DAY_AHEAD", "resolution": 3600, "category": "ElectricLoad", "component_name": "bus2", "module": "PowerSystems", "type": "SingleTimeSeries", "name": "max_active_power", "scaling_factor_multiplier": "get_max_active_power", "scaling_factor_multiplier_module": "PowerSystems", "normalization_factor": 1, "data_file": "./load/da_load5.csv" }, { "simulation": "DAY_AHEAD", "resolution": 3600, "category": "ElectricLoad", "component_name": "bus3", "module": "PowerSystems", "type": "SingleTimeSeries", "name": "max_active_power", "scaling_factor_multiplier": "get_max_active_power", "scaling_factor_multiplier_module": "PowerSystems", "normalization_factor": 1, "data_file": "./load/da_load5.csv" }, { "simulation": "DAY_AHEAD", "resolution": 3600, "category": "ElectricLoad", "component_name": "bus4", "module": "PowerSystems", "type": "SingleTimeSeries", "name": "max_active_power", "scaling_factor_multiplier": "get_max_active_power", "scaling_factor_multiplier_module": "PowerSystems", "normalization_factor": 1, "data_file": "./load/da_load5.csv" } ]

Read and assign time series to System using these parameters.

julia> add_time_series!(sys, fname)
julia> sysSystem ┌───────────────────┬─────────────┐ │ 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 │ true │ false │ │ RenewableDispatch │ 2 │ true │ false │ │ ThermalStandard │ 5 │ false │ false │ └──────────────────────────┴───────┴────────────────────────┴───────────────┘ Time Series Summary ┌──────────────────────────────────┬────────────┐ │ Property │ Value │ ├──────────────────────────────────┼────────────┤ │ Components with time series data │ 5 │ │ Total StaticTimeSeries │ 5 │ │ Total Forecasts │ 0 │ │ Resolution │ 60 minutes │ └──────────────────────────────────┴────────────┘