Build accounting models
A model represents a discrete set of calculations and data associations to generate production accounting. There are 2 main types of models in Mangrove: production models, and quantification models.
Building models
Models can be edited by Admin users in the Model Editor using a YAML-based scripting language.
- Open the Model Editor by clicking on Edit/Test besides the model name
The YAML script constructs carbon accounting models using a tree of interconnected nodes, where each node performs a calculation or holds a value. These nodes are organized in a hierarchical structure.
This is the equivalent of writing the following equation:
As a best practice, Validate the model you have built, and check the results in the Console before saving the model.
Editing models
Saving the model updates its version.
New model versions do not affect the calculations of past accounting batches, only new calculations run after the version has been created.
Defining new nodes
Nodes can be added to the model to represent specific variables in the accounting equations. Each node can:
- Receive a value from a data source (data_point_type)
- Use a constant/mapped value from a library, or
- Have its value calculated from child nodes through the defined operator
See Reference below for the full list of parameters that can be defined on each node.
Units
Units are not always required to be defined on nodes, but are very helpful for legibility especially when data is run through operator expressions. Use output_unit
to define the expected result unit:
See Reference below: units have to conform to the supported syntax from the Unitwise library. Mismatched units between inputs on the same tier of nodes can result in errors unless explicitly converted upstream.
Testing models
Models can be tested by running them with a set of inputs to confirm the calculations.
How to test the models:
- Open the Model Editor by clicking on Edit/Test besides the model name
- Switch to Test Model
- Define a time range (this is necessary for certain calculations that consider duration), enter values for the model’s required inputs, and Run Test
- Review the output calculations in the Console
Reference
Below is the full list of fields that can be configured on nodes within a model.
Name of the variable
Unit. We use the Unitwise library to interpret units. Here’s a list of library-supported units.
Specifies whether the values of that node represent a type of GHG calculation. Possible values: co2e
Specifies the node’s order in the parent node’s equation
Defines a new tier of child nodes.
Specifies the datapoint slug that the nodes is associated with, defining the node as either an input node that expects incoming data, or an input node tied to a Static Input.
Operation performed on the child nodes.
Operator | Function |
---|---|
Keisan expressions | Expressions supported by the Keisan Ruby library are acceptable. A list can be found here. |
summation | Sums all child node values |
difference | Subtracts subsequent values from the first. Child nodes have to be set in the right order . |
product | Multiplies all child node values |
quotient | Divides subsequent values from the first. Child nodes have to be set in the right order . |
max | Finds the maximum value across all child node values |
min | Finds the minimum value across all child node values |
average | Finds the average of all child node values |
count | |
duration | Special operator used to convert the time range of the incoming datapoint into a duration |
map | Maps a value from an linked library |
Sets a constant value on the node.
If set to false
, the node’s computation behaviour will change such that it will always return an array in which the computation is applied to each element of the input. If the node is using data points as input, the array will have the same length as the number of data points found for that data flow. If the node is using multiple child nodes as input, the operator is applied piece-wise across each child’s output array to derive one output array.