{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Add time series to `System`"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"**Originally Contributed by**: Clayton Barrows"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## Introduction"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"An example of how to parse add time series data to a `System` using [PowerSystems.jl](github.com/NREL-SIIP/PowerSystems.jl)\n",
"\n",
"For example, a `System` created by [parsing a MATPOWER file](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/2_PowerSystems_examples/parse_matpower.ipynb)\n",
"doesn't contain any time series data. So a user may want to add time series to the `System`\n",
"### Dependencies\n",
"Let's use the 5-bus dataset we parsed in the MATPOWER example"
],
"metadata": {}
},
{
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ Info: Correcting vm in bus 1 to 1.07762 to match generator set-point\n",
"[ Info: Correcting vm in bus 3 to 1.1 to match generator set-point\n",
"[ Info: Correcting vm in bus 4 to 1.06414 to match generator set-point\n",
"[ Info: Correcting vm in bus 10 to 1.06907 to match generator set-point\n",
"[ Info: Correcting vm in bus 3 to 1.0 to match generator set-point\n",
"┌ Error: Generator voltage set-points for bus 3 are inconsistent. This can lead to unexpected results\n",
"└ @ PowerSystems ~/.julia/packages/PowerSystems/gGFFl/src/parsers/pm_io/matpower.jl:245\n",
"[ Info: Correcting vm in bus 10 to 1.0 to match generator set-point\n",
"┌ Error: Generator voltage set-points for bus 10 are inconsistent. This can lead to unexpected results\n",
"└ @ PowerSystems ~/.julia/packages/PowerSystems/gGFFl/src/parsers/pm_io/matpower.jl:245\n",
"[ Info: extending matpower format with data: areas 1x3\n",
"[ Info: extending matpower format with data: gen_name 7x4\n",
"[ Info: extending matpower format by appending matrix \"gen_name\" in to \"gen\"\n",
"[ Info: reversing the orientation of branch 6 (4, 3) to be consistent with other parallel branches\n",
"[ Info: the voltage setpoint on generator 6 does not match the value at bus 3\n",
"[ Info: the voltage setpoint on generator 7 does not match the value at bus 10\n",
"[ Info: removing 1 cost terms from generator 4: [4000.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 1: [1400.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 5: [1000.0, 0.0]\n",
"[ Info: removing 1 cost terms from generator 2: [1500.0, 0.0]\n",
"[ Info: removing 3 cost terms from generator 6: Float64[]\n",
"[ Info: removing 3 cost terms from generator 7: Float64[]\n",
"[ Info: removing 1 cost terms from generator 3: [3000.0, 0.0]\n",
"┌ Info: Constructing System from Power Models\n",
"│ data[\"name\"] = \"nesta_case5_pjm\"\n",
"└ data[\"source_type\"] = \"matpower\"\n",
"[ Info: Reading bus data\n",
"[ Info: Reading generator data\n",
"[ Info: Reading branch data\n",
"[ Info: Reading branch data\n",
"[ Info: Reading DC Line data\n",
"[ Info: Reading storage data\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": "System\n┌───────────────────┬─────────────┐\n│ Property │ Value │\n├───────────────────┼─────────────┤\n│ System Units Base │ SYSTEM_BASE │\n│ Base Power │ 100.0 │\n│ Base Frequency │ 60.0 │\n│ Num Components │ 30 │\n└───────────────────┴─────────────┘\n\nStatic Components\n┌──────────────────────────┬───────┬────────────────────────┬───────────────┐\n│ Type │ Count │ Has Static Time Series │ Has Forecasts │\n├──────────────────────────┼───────┼────────────────────────┼───────────────┤\n│ Arc │ 6 │ false │ false │\n│ Area │ 1 │ false │ false │\n│ Bus │ 5 │ false │ false │\n│ Line │ 5 │ false │ false │\n│ LoadZone │ 1 │ false │ false │\n│ PhaseShiftingTransformer │ 2 │ false │ false │\n│ PowerLoad │ 3 │ false │ false │\n│ RenewableDispatch │ 2 │ false │ false │\n│ ThermalStandard │ 5 │ false │ false │\n└──────────────────────────┴───────┴────────────────────────┴───────────────┘\n\n",
"text/html": [
"\n",
"\n",
"\n",
"\n",
"
\n",
"\n",
" System\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" System Units Base | \n",
" SYSTEM_BASE | \n",
"
\n",
" \n",
" Base Power | \n",
" 100.0 | \n",
"
\n",
" \n",
" Base Frequency | \n",
" 60.0 | \n",
"
\n",
" \n",
" Num Components | \n",
" 30 | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" Static Components\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Arc | \n",
" 6 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Area | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Bus | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Line | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" LoadZone | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PhaseShiftingTransformer | \n",
" 2 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PowerLoad | \n",
" 3 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" RenewableDispatch | \n",
" 2 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" ThermalStandard | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n"
]
},
"metadata": {},
"execution_count": 1
}
],
"cell_type": "code",
"source": [
"using SIIPExamples\n",
"using PowerSystems\n",
"using JSON3\n",
"\n",
"pkgpath = dirname(dirname(pathof(SIIPExamples)))\n",
"include(joinpath(pkgpath, \"test\", \"2_PowerSystems_examples\", \"02_parse_matpower.jl\"))"
],
"metadata": {},
"execution_count": 1
},
{
"cell_type": "markdown",
"source": [
"### Define pointers to time series files\n",
"For example, if we want to add a bunch of time series files, say one for each load and\n",
"one for each renewable generator, we need to define pointers to each .csv file containing\n",
"the time series in the following format (PowerSystems.jl also supports a CSV format for this file)"
],
"metadata": {}
},
{
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" {\n",
" \"simulation\": \"DAY_AHEAD\",\n",
" \"resolution\": 3600,\n",
" \"category\": \"Generator\",\n",
" \"component_name\": \"SolarBusC\",\n",
" \"module\": \"PowerSystems\",\n",
" \"type\": \"SingleTimeSeries\",\n",
" \"name\": \"max_active_power\",\n",
" \"scaling_factor_multiplier\": \"get_max_active_power\",\n",
" \"scaling_factor_multiplier_module\": \"PowerSystems\",\n",
" \"normalization_factor\": 1,\n",
" \"data_file\": \"./gen/Renewable/PV/da_solar5.csv\"\n",
" },\n",
" {\n",
" \"simulation\": \"DAY_AHEAD\",\n",
" \"resolution\": 3600,\n",
" \"category\": \"Generator\",\n",
" \"component_name\": \"WindBusA\",\n",
" \"module\": \"PowerSystems\",\n",
" \"type\": \"SingleTimeSeries\",\n",
" \"name\": \"max_active_power\",\n",
" \"scaling_factor_multiplier\": \"get_max_active_power\",\n",
" \"scaling_factor_multiplier_module\": \"PowerSystems\",\n",
" \"normalization_factor\": 1,\n",
" \"data_file\": \"./gen/Renewable/WIND/da_wind5.csv\"\n",
" },\n",
" {\n",
" \"simulation\": \"DAY_AHEAD\",\n",
" \"resolution\": 3600,\n",
" \"category\": \"ElectricLoad\",\n",
" \"component_name\": \"bus2\",\n",
" \"module\": \"PowerSystems\",\n",
" \"type\": \"SingleTimeSeries\",\n",
" \"name\": \"max_active_power\",\n",
" \"scaling_factor_multiplier\": \"get_max_active_power\",\n",
" \"scaling_factor_multiplier_module\": \"PowerSystems\",\n",
" \"normalization_factor\": 1,\n",
" \"data_file\": \"./load/da_load5.csv\"\n",
" },\n",
" {\n",
" \"simulation\": \"DAY_AHEAD\",\n",
" \"resolution\": 3600,\n",
" \"category\": \"ElectricLoad\",\n",
" \"component_name\": \"bus3\",\n",
" \"module\": \"PowerSystems\",\n",
" \"type\": \"SingleTimeSeries\",\n",
" \"name\": \"max_active_power\",\n",
" \"scaling_factor_multiplier\": \"get_max_active_power\",\n",
" \"scaling_factor_multiplier_module\": \"PowerSystems\",\n",
" \"normalization_factor\": 1,\n",
" \"data_file\": \"./load/da_load5.csv\"\n",
" },\n",
" {\n",
" \"simulation\": \"DAY_AHEAD\",\n",
" \"resolution\": 3600,\n",
" \"category\": \"ElectricLoad\",\n",
" \"component_name\": \"bus4\",\n",
" \"module\": \"PowerSystems\",\n",
" \"type\": \"SingleTimeSeries\",\n",
" \"name\": \"max_active_power\",\n",
" \"scaling_factor_multiplier\": \"get_max_active_power\",\n",
" \"scaling_factor_multiplier_module\": \"PowerSystems\",\n",
" \"normalization_factor\": 1,\n",
" \"data_file\": \"./load/da_load5.csv\"\n",
" }\n",
"]"
]
}
],
"cell_type": "code",
"source": [
"FORECASTS_DIR = joinpath(base_dir, \"forecasts\", \"5bus_ts\")\n",
"fname = joinpath(FORECASTS_DIR, \"timeseries_pointers_da.json\")\n",
"open(fname, \"r\") do f\n",
" JSON3.@pretty JSON3.read(f)\n",
"end"
],
"metadata": {},
"execution_count": 2
},
{
"cell_type": "markdown",
"source": [
"### Read and assign time series to `System` using these parameters."
],
"metadata": {}
},
{
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "System\n┌───────────────────┬─────────────┐\n│ Property │ Value │\n├───────────────────┼─────────────┤\n│ System Units Base │ SYSTEM_BASE │\n│ Base Power │ 100.0 │\n│ Base Frequency │ 60.0 │\n│ Num Components │ 30 │\n└───────────────────┴─────────────┘\n\nStatic Components\n┌──────────────────────────┬───────┬────────────────────────┬───────────────┐\n│ Type │ Count │ Has Static Time Series │ Has Forecasts │\n├──────────────────────────┼───────┼────────────────────────┼───────────────┤\n│ Arc │ 6 │ false │ false │\n│ Area │ 1 │ false │ false │\n│ Bus │ 5 │ false │ false │\n│ Line │ 5 │ false │ false │\n│ LoadZone │ 1 │ false │ false │\n│ PhaseShiftingTransformer │ 2 │ false │ false │\n│ PowerLoad │ 3 │ true │ false │\n│ RenewableDispatch │ 2 │ true │ false │\n│ ThermalStandard │ 5 │ false │ false │\n└──────────────────────────┴───────┴────────────────────────┴───────────────┘\n\nTime Series Summary\n┌──────────────────────────────────┬────────────┐\n│ Property │ Value │\n├──────────────────────────────────┼────────────┤\n│ Components with time series data │ 5 │\n│ Total StaticTimeSeries │ 5 │\n│ Total Forecasts │ 0 │\n│ Resolution │ 60 minutes │\n└──────────────────────────────────┴────────────┘\n",
"text/html": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" System\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" System Units Base | \n",
" SYSTEM_BASE | \n",
"
\n",
" \n",
" Base Power | \n",
" 100.0 | \n",
"
\n",
" \n",
" Base Frequency | \n",
" 60.0 | \n",
"
\n",
" \n",
" Num Components | \n",
" 30 | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" Static Components\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Arc | \n",
" 6 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Area | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Bus | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" Line | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" LoadZone | \n",
" 1 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PhaseShiftingTransformer | \n",
" 2 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
" PowerLoad | \n",
" 3 | \n",
" true | \n",
" false | \n",
"
\n",
" \n",
" RenewableDispatch | \n",
" 2 | \n",
" true | \n",
" false | \n",
"
\n",
" \n",
" ThermalStandard | \n",
" 5 | \n",
" false | \n",
" false | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" Time Series Summary\n",
" \n",
" \n",
" \n",
" \n",
" \n",
" Components with time series data | \n",
" 5 | \n",
"
\n",
" \n",
" Total StaticTimeSeries | \n",
" 5 | \n",
"
\n",
" \n",
" Total Forecasts | \n",
" 0 | \n",
"
\n",
" \n",
" Resolution | \n",
" 60 minutes | \n",
"
\n",
" \n",
"
\n",
"\n",
"\n"
]
},
"metadata": {},
"execution_count": 3
}
],
"cell_type": "code",
"source": [
"add_time_series!(sys, fname)\n",
"sys"
],
"metadata": {},
"execution_count": 3
},
{
"cell_type": "markdown",
"source": [
"---\n",
"\n",
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*"
],
"metadata": {}
}
],
"nbformat_minor": 3,
"metadata": {
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.2"
},
"kernelspec": {
"name": "julia-1.7",
"display_name": "Julia 1.7.2",
"language": "julia"
}
},
"nbformat": 4
}