Process and read PLEXOS files

Processing solutions

rplexos is an R package developed to read and analyze PLEXOS solutions. It currently supports the conversion of PLEXOS solution files into SQLite databases and functions to query those databases.

The following sections present the preferred workflow to process PLEXOS solutions with this package. We will use an example database that comes preloaded with the package. This is the location of that database in your system.

location_ST <- location_solution_rplexos('ST')
location_LT <- location_solution_rplexos('LT')
location_ST
#> [1] "C:/Users/DEL535/AppData/Local/Temp/Rtmp8yiJuy/Rinst83941c312587/rplexos/extdata/solution/ST_Solution"
location_LT
#> [1] "C:/Users/DEL535/AppData/Local/Temp/Rtmp8yiJuy/Rinst83941c312587/rplexos/extdata/solution/LT_Solution"

Organize and process solutions

It is recommended to create a folder for each of your scenarios. If a run is divided in different solution files, copy them together in the same folder.

For each folder, run the following command to convert the zip file into a SQLite database.

process_folder(location_ST)

We can also provide a vector of strings with the names of all the folders that need to be processed. For example, let’s load the two scenarios: ST and LT.

process_folder(c(location_ST, location_LT))

Open databases

Once the databases have been processed, we can access them by first opening a connection with plexos_open. Scenarios names can be defined at this point (if not provided, they default to the folder names).

db <- plexos_open(location_ST, "Sc1")

Again, you can provide a vector of folders to open and a vector of scenario names.

db_multi <- plexos_open(c(location_ST, location_LT), name = c("ST", "LT"))

Help queries

We can now use the db object to query and aggregate data using the functions documented in query_master. The list of available properties can be seen with ?query_property.

query_property(db)
#>    phase_id phase is_summary  class_group     class collection               property  unit Sc1
#> 1         4    ST          0     Electric   Battery    Battery             Generation    MW   1
#> 2         4    ST          0     Electric   Battery    Battery                   Load    MW   1
#> 3         4    ST          0     Electric   Battery    Battery         Net Generation    MW   1
#> 4         4    ST          0     Electric   Battery    Battery                    SoC     %   1
#> 5         4    ST          0     Electric Generator  Generator     Capacity Curtailed    MW   1
#> 6         4    ST          0     Electric Generator  Generator             Generation    MW   1
#> 7         4    ST          0     Electric Generator  Generator        Generation Cost     $   1
#> 8         4    ST          0     Electric Generator  Generator         Price Received $/MWh   1
#> 9         4    ST          0     Electric Generator  Generator       Units Generating     -   1
#> 10        4    ST          0 Transmission      Line       Line           Export Limit    MW   1
#> 11        4    ST          0 Transmission      Line       Line                   Flow    MW   1
#> 12        4    ST          0 Transmission      Line       Line           Import Limit    MW   1
#> 13        4    ST          0 Transmission      Node       Node             Generation    MW   1
#> 14        4    ST          0 Transmission      Node       Node                   Load    MW   1
#> 15        4    ST          0 Transmission      Node       Node                  Price $/MWh   1
#> 16        4    ST          0 Transmission    Region     Region           Cost to Load     $   1
#> 17        4    ST          0 Transmission    Region     Region            Dump Energy    MW   1
#> 18        4    ST          0 Transmission    Region     Region             Generation    MW   1
#> 19        4    ST          0 Transmission    Region     Region Generator Pool Revenue     $   1
#> 20        4    ST          0 Transmission    Region     Region                   Load    MW   1
#> 21        4    ST          0 Transmission    Region     Region        Net Interchange    MW   1
#> 22        4    ST          0 Transmission    Region     Region                  Price $/MWh   1
#> 23        4    ST          0 Transmission    Region     Region     Settlement Surplus     $   1
#> 24        4    ST          0 Transmission    Region     Region        Unserved Energy    MW   1
#> 25        4    ST          1     Electric   Battery    Battery             Generation   GWh   1
#> 26        4    ST          1     Electric   Battery    Battery                   Load   GWh   1
#> 27        4    ST          1     Electric   Battery    Battery         Net Generation   GWh   1
#> 28        4    ST          1     Electric   Battery    Battery                    SoC     %   1
#> 29        4    ST          1     Electric Generator  Generator       Energy Curtailed   GWh   1
#> 30        4    ST          1     Electric Generator  Generator             Generation   GWh   1
#> 31        4    ST          1     Electric Generator  Generator        Generation Cost  $000   1
#> 32        4    ST          1 Transmission      Line       Line           Export Limit    MW   1
#> 33        4    ST          1 Transmission      Line       Line                   Flow   GWh   1
#> 34        4    ST          1 Transmission      Line       Line           Import Limit    MW   1
#> 35        4    ST          1 Transmission    Region     Region           Cost to Load  $000   1
#> 36        4    ST          1 Transmission    Region     Region            Dump Energy   GWh   1
#> 37        4    ST          1 Transmission    Region     Region             Generation   GWh   1
#> 38        4    ST          1 Transmission    Region     Region Generator Pool Revenue  $000   1
#> 39        4    ST          1 Transmission    Region     Region                   Load   GWh   1
#> 40        4    ST          1 Transmission    Region     Region        Net Interchange   GWh   1
#> 41        4    ST          1 Transmission    Region     Region                  Price $/MWh   1
#> 42        4    ST          1 Transmission    Region     Region     Settlement Surplus  $000   1
#> 43        4    ST          1 Transmission    Region     Region        Unserved Energy   GWh   1

There are also a number of queries that can be used to explore the contents of the solutions. For example, let’s take a look at the list of generators:

query_generator(db)
#> # A tibble: 3 × 5
#>   scenario position     name     region  zone
#>     <fctr>    <int>    <chr>      <chr> <chr>
#> 1      Sc1        1 Baseload The Region     -
#> 2      Sc1        1   Peaker The Region     -
#> 3      Sc1        1     Wind The Region     -

Query summary data

The following command extract data from the “summary” tables created by PLEXOS. If selected during the solution process in PLEXOS, data is available in daily, weekly, monthly and yearly summaries. rplexos provides a family of functions to access each type of data.

query_day(db, "Generator", "Generation")
#> # A tibble: 3 × 8
#>   scenario collection   property  unit     name parent       time    value
#>     <fctr>      <chr>      <chr> <chr>    <chr>  <chr>     <dttm>    <dbl>
#> 1      Sc1  Generator Generation   GWh Baseload System 2015-03-14 2.409263
#> 2      Sc1  Generator Generation   GWh   Peaker System 2015-03-14 0.073000
#> 3      Sc1  Generator Generation   GWh     Wind System 2015-03-14 0.639000

For convenience, you can also use an asterisk to query all the properties in a collection:

query_day(db, "Region", "*")
#> # A tibble: 9 × 8
#>   scenario collection               property  unit       name parent       time       value
#>     <fctr>      <chr>                  <chr> <chr>      <chr>  <chr>     <dttm>       <dbl>
#> 1      Sc1     Region                   Load   GWh The Region System 2015-03-14 3.166413158
#> 2      Sc1     Region             Generation   GWh The Region System 2015-03-14 3.164263158
#> 3      Sc1     Region        Net Interchange   GWh The Region System 2015-03-14 0.000000000
#> 4      Sc1     Region        Unserved Energy   GWh The Region System 2015-03-14 0.000000000
#> 5      Sc1     Region            Dump Energy   GWh The Region System 2015-03-14 0.000000000
#> 6      Sc1     Region                  Price $/MWh The Region System 2015-03-14 2.543730278
#> 7      Sc1     Region           Cost to Load  $000 The Region System 2015-03-14 7.933894737
#> 8      Sc1     Region Generator Pool Revenue  $000 The Region System 2015-03-14 8.015552632
#> 9      Sc1     Region     Settlement Surplus  $000 The Region System 2015-03-14 0.008868421

Query interval data

You can also query the interval data. This example queries and plots the generation data:

gen <- query_interval(db, "Generator", "Generation")
ggplot(gen, aes(x = time, y = value, fill = name)) +
  geom_area() +
  labs(x = "Time", y = "Generation (MW)", fill = "Generator")

Similary, this example looks at nodal prices:

price <- query_interval(db, "Node", "Price")
ggplot(price, aes(x = time, y = value, color = name)) +
  geom_line() +
  labs(x = "Time", y = "Price ($/MW)", color = "Node")

Finally, this one looks at line flows:

price <- query_interval(db, "Line", "Flow")
ggplot(price, aes(x = time, y = value, color = name)) +
  geom_line() +
  labs(x = "Time", y = "Flow (MW)", color = "Generator")

Using filters in queries

rplexos includes the capability of applying filters to both summary and interval data queries. This can be used to select the part of the data that is of interest, reducing the time it takes to query the database.

For example, the following query is limited to a given time range:

gen.time.filter <- query_interval(db, "Generator", "Generation",
                                  time.range = c("2015-03-14 00:00:00", "2015-03-14 12:00:00"))
ggplot(gen.time.filter, aes(x = time, y = value, fill = name)) +
  geom_area() +
  labs(x = "Time", y = "Generation (MW)", fill = "Generator")

Similarly, the parameter filter can be used to create other filtering conditions. The following code extracts generation data for one or two generators:

gen.gral.filter1 <- query_interval(db, "Generator", "Generation",
                                   filter = list(name = "Baseload"))
ggplot(gen.gral.filter1, aes(x = time, y = value, fill = name)) +
  geom_area() +
  labs(x = "Time", y = "Generation (MW)", fill = "Generator")

gen.gral.filter2 <- query_interval(db, "Generator", "Generation",
                                   filter = list(name = c("Baseload", "Wind")))
ggplot(gen.gral.filter2, aes(x = time, y = value, fill = name)) +
  geom_area() +
  labs(x = "Time", y = "Generation (MW)", fill = "Generator")

Both filtering mechanisms can be combined or used independently.

The previous filters were all positive filters. This means that if you add one item (e.g. list(name = ‘Baseload’)), the return query will only show that one item. Sometimes you would like to do the opposite and drop only one item. Instead of adding all the other items, you can also drop just one item with the dash (‘-’).

gen.gral.filter <- query_interval(db, "Generator", "Generation",
                                   filter = list(name = "-Baseload"))
ggplot(gen.gral.filter, aes(x = time, y = value, fill = name)) +
  geom_area() +
  labs(x = "Time", y = "Generation (MW)", fill = "Generator")

Processing inputs

rplexos also supports converting PLEXOS input databases (which are saved as XML file) into SQLite files. We will use an example database that comes preloaded with the package. This is the location of that database in your system.

location2 <- location_input_rplexos()
location2
#> [1] "C:/Users/DEL535/AppData/Local/Temp/Rtmp8yiJuy/Rinst83941c312587/rplexos/extdata/database"

The input files are processed with the same function that is used for the solutions.

# process_folder(location2)