Skip to content

Commit

Permalink
Merge branch 'psy4' into jdgk/cost_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Apr 27, 2024
2 parents b0f4f60 + d80e757 commit 39c87fb
Show file tree
Hide file tree
Showing 26 changed files with 468 additions and 160 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LinearAlgebra = "1"
Logging = "1"
PowerFlowData = "^1.5"
PrettyTables = "1, 2"
TimeSeries = "~0.22, 0.23"
TimeSeries = "~0.22, 0.23, 0.24"
YAML = "~0.4"
UUIDs = "1"
Unicode = "1"
Expand Down
14 changes: 6 additions & 8 deletions docs/make_model_library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ using InteractiveUtils
const IS = InfrastructureSystems
const PSY = PowerSystems

IS.strip_module_name

function _check_exception(T, exceptions::Vector)
for type_exception in exceptions
if T <: type_exception
Expand Down Expand Up @@ -37,13 +35,13 @@ function _write_first_level_markdown(c::String)
end

function _write_second_level_markdown(input::DataType, subtypes::Vector{DataType}, exceptions)
c = IS.strip_module_name(input)
c = string(nameof(input))
file_name = "model_library/generated_$(c).md"
open(joinpath("docs/src", file_name), "w") do io
print(io, "# $input\n\n")
for T_ in subtypes
_check_exception(T_, exceptions) && continue
T = IS.strip_module_name(T_)
T = string(nameof(T_))
print(
io,
"""
Expand Down Expand Up @@ -77,11 +75,11 @@ manual_additions = Dict{String, Any}("DynamicInverterComponent" => Any["OuterCon
)
for abstract_type in dyn_categories
@info "Making entries for subtypes of $abstract_type"
abstract_type_string = IS.strip_module_name(abstract_type)
abstract_type_string = string(nameof(abstract_type))
addition = Dict{String, Any}()
internal_index = Any[]
for c_ in subtypes(abstract_type)
c_string = IS.strip_module_name(c_)
c_string = string(nameof(c_))
_check_exception(c_, exceptions) && continue
concretes = IS.get_all_concrete_subtypes(c_)
file_name = _write_second_level_markdown(c_,
Expand Down Expand Up @@ -110,12 +108,12 @@ function make_model_library(;
concrete = IS.get_all_concrete_subtypes(abstract_type)
for c_ in concrete
_check_exception(c_, exceptions) && continue
c = IS.strip_module_name(c_)
c = string(nameof(c_))
file_name = _write_first_level_markdown(c)
push!(internal_index, c => file_name)
end
isempty(internal_index) && continue
model_library[IS.strip_module_name(abstract_type)] = internal_index
model_library[string(nameof(abstract_type))] = internal_index
end

make_dynamics_library!(model_library)
Expand Down
8 changes: 8 additions & 0 deletions docs/src/modeler_guide/parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ RAW_dir = joinpath(file_dir, "ThreeBusNetwork.raw")
DYR_dir = joinpath(file_dir, "TestGENCLS.dyr")
dyn_system = System(RAW_dir, DYR_dir, runchecks = false)
```
### Common Issues

Please note that while PSS/e does not enforce unique bus names, `PowerSystems.jl` does. To reparse bus names to comply with this requirement the `bus_name_formatter` *kwarg can be used in `System()` as shown in the example below:

```@repl raw_dyr_system
dyn_system = System(RAW_dir, DYR_dir; bus_name_formatter = x -> strip(string(x["name"])) * "-" * string(x["index"]))
```
In this example the anonymous function `x -> strip(string(x["name"])) * "-" * string(x["index"])` takes the bus name and index from PSSe and concatenates them to produce the name.

## [PowerSystems Table Data](@id table_data)

Expand Down
54 changes: 50 additions & 4 deletions docs/src/modeler_guide/time_series.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ Example:
DateTime("2020-01-01T01:00:00") => ones(24),
)
forecast = Deterministic(
"max_active_power",
data,
resolution,
scaling_factor_multiplier = get_max_active_power,
"max_active_power",
data,
resolution,
scaling_factor_multiplier = get_max_active_power,
)
```

Expand Down Expand Up @@ -225,6 +225,52 @@ components that share the time series data.
This function stores a single copy of the data. Each component will store a
reference to that data.

Time series data can also be shared on a component level. Suppose a time series array applies to
both the `max_active_power` and `max_reactive_power` attributes of a generator. You can share the
data as shown in this example.

```julia
resolution = Dates.Hour(1)
data = Dict(
DateTime("2020-01-01T00:00:00") => ones(24),
DateTime("2020-01-01T01:00:00") => ones(24),
)
forecast_max_active_power = Deterministic(
"max_active_power",
data,
resolution,
scaling_factor_multiplier = get_max_active_power,
)
add_time_series!(sys, generator, forecast_max_active_power)
forecast_max_reactive_power = Deterministic(
forecast_max_active_power,
"max_reactive_power",
scaling_factor_multiplier = get_max_reactive_power,
)
add_time_series!(sys, generator, forecast_max_reactive_power)
```

### Adding time series in bulk

By default, the call to `add_time_series!` will open the HDF5 file, write the data to the file,
and close the file. Opening and closing the file has overhead. If you will add thousands of time
series arrays, consider using `open_time_series_store!`as shown in the example below. All arrays
will be written with one file handle.

This example assumes that there are arrays of components and time series stored in the variables
`components` and `single_time_series`, respectively.

```julia
open_time_series_store!(sys, "r+") do
for (component, ts) in zip(components, single_time_series)
add_time_series!(sys, component, ts)
end
end
```

You can also use this function to make reads faster. Change the mode from `"r+"` to `"r"` to open
the file read-only.

## Removing time series data

Time series instances can be removed from a system like this:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ get_forecast_initial_times(sys)
We can find the names of all time series attached to a component:

```@repl basics
ts_names = get_time_series_names(Deterministic, loads[1])
show_time_series(loads[1])
```

We can access a specific time series for a specific component:
Expand Down
16 changes: 12 additions & 4 deletions src/PowerSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export Deterministic
export Probabilistic
export SingleTimeSeries
export DeterministicSingleTimeSeries
export StaticTimeSeriesInfo
export ForecastInfo
export Scenarios
export ForecastCache
export StaticTimeSeriesCache
Expand All @@ -274,6 +276,7 @@ export TimeSeriesCounts
export get_dynamic_components

export parse_file
export open_time_series_store!
export add_time_series!
export remove_time_series!
export check_time_series_consistency
Expand Down Expand Up @@ -320,18 +323,18 @@ export has_supplemental_attributes
export iterate_supplemental_attributes
export get_time_series
export get_time_series_array
export get_time_series_resolution
export list_time_series_resolutions
export get_time_series_timestamps
export get_time_series_values
export get_time_series_names
export get_time_series_counts
export get_scenario_count
export get_percentiles
export get_next_time_series_array!
export get_next_time
export get_horizon
export get_forecast_initial_times
export get_forecast_total_period
export list_time_series_info
export show_time_series
export get_resolution
export get_data
export iterate_components
Expand Down Expand Up @@ -427,6 +430,8 @@ export has_component
export get_assigned_subsystems
export has_subsystems
export is_assigned_to_subsystem
export from_subsystem
export filter_components_by_subsystem!

export set_runchecks!
export check
Expand Down Expand Up @@ -474,7 +479,9 @@ import InfrastructureSystems:
Deterministic,
Probabilistic,
SingleTimeSeries,
StaticTimeSeriesInfo,
DeterministicSingleTimeSeries,
ForecastInfo,
Scenarios,
ForecastCache,
StaticTimeSeriesCache,
Expand Down Expand Up @@ -511,7 +518,8 @@ import InfrastructureSystems:
get_time_series_array,
get_time_series_timestamps,
get_time_series_values,
get_time_series_names,
list_time_series_info,
show_time_series,
get_scenario_count, # Scenario Forecast Exports
get_percentiles, # Probabilistic Forecast Exports
get_next_time_series_array!,
Expand Down
Loading

0 comments on commit 39c87fb

Please sign in to comment.