NREL-Sienna / InfrastructureSystems.jl

Utility package for Sienna's simulation infrastructure
https://nrel-sienna.github.io/InfrastructureSystems.jl/
BSD 3-Clause "New" or "Revised" License
39 stars 20 forks source link

Erroring showing `System` after forecasts added via `transform_single_time_series!` #211

Closed nickrobinson251 closed 3 years ago

nickrobinson251 commented 3 years ago

I'm trying to update some private code from PowerSystems.jl v0.28 to v1

Below is using PowerSystems v1.3.0 and InfrastructureSystems v1.3.6

I'm testing with a 3 bus system, which should have SingleTimeSeries for each of the PowerLoad and ThermalStandard

julia> sys
System
======
System Units Base: SYSTEM_BASE
Base Power: 100.0
Base Frequency: 60.0

Components
==========
Num components: 26

8×3 DataFrame
 Row │ ConcreteType                   SuperTypes                         Count
     │ String                         String                             Int64
─────┼─────────────────────────────────────────────────────────────────────────
   1 │ Arc                            Topology <: Component <: Infrast…      3
   2 │ Bus                            Topology <: Component <: Infrast…      3
   3 │ Line                           ACBranch <: Branch <: Device <: …      3
   4 │ PhaseShiftingTransformer       ACBranch <: Branch <: Device <: …      1
   5 │ PowerLoad                      StaticLoad <: ElectricLoad <: St…      2
   6 │ StaticReserveGroup{ReserveUp}  Service <: Component <: Infrastr…      3
   7 │ ThermalStandard                ThermalGen <: Generator <: Stati…      2
   8 │ VariableReserve{ReserveUp}     Reserve{ReserveUp} <: Service <:…      9

TimeSeriesContainer
===================
Components with time series data: 4
Total StaticTimeSeries: 4
Total Forecasts: 0
Resolution: 60 minutes

I convert these time-series to forecasts, with transform_single_time_series!, and that seems to work (no error or other output is shown)

julia> transform_single_time_series!(sys, 24, Hour(1))

but when I then see an error upon trying to show the resulting system:

julia> sys
System
======
System Units Base: SYSTEM_BASE
Base Power: 100.0
Base Frequency: 60.0

Components
==========
Num components: 26

8×3 DataFrame
 Row │ ConcreteType                   SuperTypes                         Count
     │ String                         String                             Int64
─────┼─────────────────────────────────────────────────────────────────────────
   1 │ Arc                            Topology <: Component <: Infrast…      3
   2 │ Bus                            Topology <: Component <: Infrast…      3
   3 │ Line                           ACBranch <: Branch <: Device <: …      3
   4 │ PhaseShiftingTransformer       ACBranch <: Branch <: Device <: …      1
   5 │ PowerLoad                      StaticLoad <: ElectricLoad <: St…      2
   6 │ StaticReserveGroup{ReserveUp}  Service <: Component <: Infrastr…      3
   7 │ ThermalStandard                ThermalGen <: Generator <: Stati…      2
   8 │ VariableReserve{ReserveUp}     Reserve{ReserveUp} <: Service <:…      9

TimeSeriesContainer
===================
Components with time series data: 4
Total StaticTimeSeries: 4
Total Forecasts: 4
Resolution: 60 minutes
Error showing value of type System:
ERROR: AssertionError: 1 hour == 0 seconds
Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/InfrastructureSystems/v75Hd/src/utils/assert_op.jl:34 [inlined]
  [2] get_initial_times(initial_timestamp::DateTime, count::Int64, interval::Hour)
    @ InfrastructureSystems ~/.julia/packages/InfrastructureSystems/v75Hd/src/utils/utils.jl:404
  [3] get_forecast_initial_times(params::InfrastructureSystems.ForecastParameters)
    @ InfrastructureSystems ~/.julia/packages/InfrastructureSystems/v75Hd/src/time_series_parameters.jl:67
  [4] get_forecast_initial_times
    @ ~/.julia/packages/InfrastructureSystems/v75Hd/src/time_series_parameters.jl:232 [inlined]
  [5] get_forecast_initial_times
    @ ~/.julia/packages/InfrastructureSystems/v75Hd/src/system_data.jl:601 [inlined]
  [6] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, data::InfrastructureSystems.SystemData)
    @ InfrastructureSystems ~/.julia/packages/InfrastructureSystems/v75Hd/src/utils/print.jl:93
  [7] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, sys::System)
    @ PowerSystems ~/.julia/packages/PowerSystems/yTZiA/src/utils/print.jl:18
  [8] (::REPL.var"#38#39"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)

Seemingly from an AssertionError in get_forecast_initial_times(sys)

jd-lara commented 3 years ago

@daniel-thom seems that the transform isn't setting the interval correctly

nickrobinson251 commented 3 years ago

In case it's helpful, the code i'm trying to update (from PSys v0.28 -> v1) looks roughly like

     for load in get_components(PowerLoad, system)
-        add_forecast!(
+        add_time_series!(
             system,
             load,
-            Deterministic(
-                "get_max_active_power",
-                TimeArray(datetimes, values),
+            SingleTimeSeries(
+                name="max_active_power",
+                data=TimeArray(datetimes, values),
+                scaling_factor_multiplier=get_max_active_power,
             )
         )

where datetimes = initial_time:Hour(1):(initial_time + Hour(23)) and in the updated version we call transform_single_time_series!(sys, 24, Hour(1)) once the system is constructed