knitr::opts_chunk$set(collapse = T, comment = "#>", fig.height = 3, fig.width = 7)
options(width = 200)
library(rplexos, quietly = TRUE)
library(ggplot2, quietly = TRUE)
theme_set(theme_bw())

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
location_LT

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)

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)

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")

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

query_day(db, "Region", "*")

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

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

# process_folder(location2)


NREL/rplexos documentation built on May 7, 2019, 6:03 p.m.