Global Functions
Overview
The database, functions and modules defined in ENERGY 2100's Julia project, EnergyModel are available to use in Julia script files or the Julia REPL.
To use the structures, you need to import what you want to use. You can see many of these structures imported at the top of each Julia file For example:
|
import ...EnergyModel: ReadDisk,WriteDisk,Select import ...EnergyModel: HisTime,ITime,MaxTime,First,Future,Final,Yr import ...EnergyModel: @finite_math import ...EnergyModel: DB |
Model Database Path
|
Command |
Description |
|
DB |
The absolute path to the active model HDF5 database. Defined as: DB = abspath(joinpath(E2020Folder, "database.hdf5")) |
Database Read Functions
|
Command |
Description |
|
ReadDisk(db, name) |
Reads the entire dataset name from the HDF5 database at path db and returns it as a raw array. Throws HDF5DataSetNotFoundException if the dataset is not found. Example: xPkSav = ReadDisk(DB,"RInput/xPkSav") |
|
ReadDisk(db, name, year) |
Reads a single year slice from a dataset. The dataset must have Year as its last dimension. Example: ReadDisk(DB,"RInput/xPkSav",Yr(2030)) |
|
ReadDisk(DataFrame, db, name) |
Opens an interactive fuzzy-search menu to select a variable from the database, then returns it as a DataFrame. |
|
ReadDiskAndSets(db, name) |
Reads a variable and all of its associated sets from the database in a single call. Returns a named tuple containing the variable array and each of its set arrays by name. Use named tuple destructuring to assign them. Example: (;xPkSav,Enduse,EC,Area,Year) = ReadDiskAndSets(DB,"IInput/xPkSav") |
|
ReadSets(db, name) |
Reads only the set arrays associated with a variable, without reading the variable itself. Returns a named tuple of set arrays. |
Database Write Functions
|
Command |
Description |
|
WriteDisk(db, name, value) |
Writes value to the dataset named name in the HDF5 database at db. Preserves existing dataset attributes. Throws HDF5DataSetNotFoundException if the dataset does not exist. Example: WriteDisk(DB, "RInput/xPkSav", xPkSav) |
|
WriteDisk(db, name, year, value) |
Writes value to a specific year slice of a dataset. The dataset must have Year as its last dimension. Example: WriteDisk(DB, "RInput/xPkSav", Yr(2030), xPkSav) |
|
WriteDisk(db, data) |
Writes an entire HDF5GroupDatabase data struct to the database. All fields of the struct are written to their corresponding dataset locations. |
|
ModifyDisk(func, db, names...) |
Reads one or more datasets, applies a user-defined function func to modify them in place, then writes the results back to the database. Useful for making targeted changes without loading and re-saving variables manually. |
|
ModifyDiskAndSets(func, db, name) |
Reads a variable and its sets into a named tuple, applies func to the named tuple, then writes the modified variable back to the database. |
Database Utility Functions
|
Command |
Description |
|
data_attrs(db, name) |
Returns a dictionary of metadata attributes for the specified dataset, including: "dims" (set names), "doc" (documentation string), "units", "ndims" (number of dimensions), "size" (array dimensions), and "type" ("variable", "set", or "scalar"). Example: data_attrs(DB, "IInput/xPkSav") |
|
data_names(db) |
Returns a vector of all dataset names stored in the HDF5 database. Useful for exploring what variables are available. |
Set Selection Functions
|
Command |
Description |
|
Select(Set, key) |
Returns the index or indices within Set corresponding to a single key string or a vector of key strings. Used to filter a set to specific elements before looping or subsetting arrays. Example: ecs = Select(EC, ["PulpPaperMills", "IronSteel"]) |
|
HasValues(setSelection) |
Returns true if the set selection is non-empty, false if it is empty. Used to guard against looping over empty selections. |
Other Custom Functions
|
Command |
Description |
|
ReadSetFromCSV() |
Reads and returns the set keys or set descriptors from a specified .csv file stored in \Database\Sets. Example of its use: Area = ReadSetFromCSV("Area","Key") Year = ReadSetFromCSV("Year","Key") |
|
Yr(year) |
Converts a calendar year to the model's internal year index. Defined as year - ITime + 1. Example: Yr(2030) returns the index corresponding to 2030. Used when reading or writing a specific year slice: ReadDisk(DB, "RInput/xPkSav", Yr(2030)) |