Draft: Resolve "Make static (network) tariff information available to satellite models"
Description
Adds an initial implementation of network tariff information to be passed into the simulation and on to the satellite models.
Tariff information is encoded as a netCDF file to support multiple tiers of indexing that can be expanded as needed while providing an easy user interface for accessing the data. Extra tariffs can be added as additional DataArray
s in the Dataset
.
For now, the tariff data consists of (semi-)randomly generated values representing hourly volumetric tariffs. These are either 'flat' over the whole year, or are specified more 'detailed', with variance over month and 'day_type', i.e. weekday vs weekend.
Reasons for choosing xarray
- xarray (and by extension the use of hdf5/netcdf file formats) explicitly stores data separate from the indices. Compared to the 'default' of using CSV files, this should prevent a lot of hassle with interpreting the contents to make this distinction for more complex tariff structures
- xarray has good compatibility with pandas and numpy, which should make it relatively easy to create the files
- xarray can bundle multiple DataArrays into a single Dataset. Each DataArray can represent a different tariff, while being addressed similar to a dictionary. Compared to a standard dictionary though, the 'native' bundling feels like a stronger/tighter coupling that keeps the intent clear to the user, while also providing the benefit of re-using the coordinates (indices).
- xarray's
.sel(...)
accessor to select certain data is a clean single point of entry that also explicitly uses the defined coordinates and their names, as opposed to messing with pandas.[i]loc
stuff.
Example
To use the tariff information in OptimizerBiddingStrategy
:
The tariffs are already read in, and are accessible as self.tariffs
.
To retrieve a specific hour of the simple hourly volumetric tariff:
# Select the 'simple' hourly tariffs DataArray
hourly_tariffs = self.tariffs["hourly_volumetric"]
# Get the tariff for 06:00 using `.sel()`, xarray's version of panda's `.loc` so to speak
hourly_tariffs.sel(hour=6) # returns a DataArray that should behave mostly as a numpy array
hourly_tariffs.sel(hour=6).item() # extracts the actual value
For the detailed tariffs, the procedure is similar but with more selection:
# Select the 'detailed' hourly tariffs DataArray
detailed_tariffs = self.tariffs["detailed_hourly_volumetric"]
# Get the tariffs for a weekday in January:
detailed_tariffs.sel(months="January", day_type="weekday") # again, returns a DataArray
detailed_tariffs.sel(months="January", day_type="weekday").values # use .values to extract explicit numpy array
# Get the tariff for a weekend 12:00 in August
detailed_tariffs.sel(months="August", day_type="weekend/holiday", hour=12).item()
Note that the names of the DataArrays in the Dataset are intended to be clear and unique enough to serve as 'top-level' selection, but those,can still be changed if needed.
Related Issues
Issues resolved by this MR:
- fixes #67
Checklist
-
Formatting matches prescribed style -
Tests pass -
Code coverage does not decrease -
New tests have been added for new code -
User-facing changes have been listed in [CHANGELOG.md]