Getting, Setting, and Viewing Data
In this tutorial, we will explore the data in a System
, including looking at a summary of the system and getting both its components and their data. We will also start checking for time-series data, which we will explore more in the tutorial on Working with Time Series Data.
In Create and Explore a Power System
, we created a basic System
with nodes, a transmission line, and a few generators. Let's recreate that system if you don't have it already:
PowerSystems provides functional interfaces to all data. The following examples outline the intended approach to accessing data expressed using PowerSystems.
PowerSystems enforces unique name
fields between components of a particular concrete type. So, in order to retrieve a specific component, the user must specify the type of the component along with the name and system
Accessing components and their data
julia> get_component(ACBus, sys, "nodeA")
ERROR: UndefVarError: `get_component` not defined
julia> get_component(Line, sys, "1")
ERROR: UndefVarError: `get_component` not defined
Similarly, you can access all the components of a particular type: *note: the return type of get_components is a FlattenIteratorWrapper
, so call collect
to get an Array
julia> get_components(ACBus, sys) |> collect
ERROR: UndefVarError: `get_components` not defined
get_components
also works on abstract types:
julia> get_components(Branch, sys) |> collect
ERROR: UndefVarError: `get_components` not defined
The fields within a component can be accessed using the get_*
functions: It's highly recommended that users avoid using the .
to access fields since we make no guarantees on the stability field names and locations. We do however promise to keep the accessor functions stable.
julia> bus1 = get_component(ACBus, sys, "nodeA")
ERROR: UndefVarError: `get_component` not defined
julia> @show get_name(bus1);
ERROR: UndefVarError: `get_name` not defined
julia> @show get_magnitude(bus1);
ERROR: UndefVarError: `get_magnitude` not defined