climate_ref.models.metric_value
#
MetricValue
#
Bases: DimensionMixin, CreatedUpdatedMixin, Base
Represents a single metric value
This is a base class for different types of metric values (e.g. scalar, series) which are stored in a single table using single table inheritance.
This value has a number of dimensions which are used to query the diagnostic values. These dimensions describe aspects such as the type of statistic being measured, the region of interest or the model from which the statistic is being measured.
The columns in this table are not known statically because the REF can track an arbitrary
set of dimensions depending on the controlled vocabulary that will be used.
A call to register_cv_dimensions must be made before using this class.
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
type = mapped_column(index=True)
class-attribute
instance-attribute
#
Type of metric value
This value is used to determine how the metric value should be interpreted.
MetricValueType
#
Bases: Enum
Type of metric value
This is used to determine how the metric value should be interpreted.
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
ScalarMetricValue
#
Bases: MetricValue
A scalar value with an associated dimensions
This is a subclass of MetricValue that is used to represent a scalar value.
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
build(*, execution_id, value, dimensions, attributes)
classmethod
#
Build a MetricValue from a collection of dimensions and a value
This is a helper method that validates the dimensions supplied and provides an interface similar to climate_ref_core.metric_values.ScalarMetricValue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution_id
|
int
|
Execution that created the diagnostic value |
required |
value
|
float
|
The value of the diagnostic |
required |
dimensions
|
dict[str, str]
|
Dimensions that describe the diagnostic execution result |
required |
attributes
|
dict[str, Any] | None
|
Optional additional attributes to describe the value, but are not in the controlled vocabulary. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an unknown dimension was supplied. Dimensions must exist in the controlled vocabulary. |
Returns:
| Type | Description |
|---|---|
Newly created MetricValue
|
|
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
SeriesMetricValue
#
Bases: MetricValue
A 1d series with associated dimensions
This is a subclass of MetricValue that is used to represent a series. This can be used to represent time series, vertical profiles or other 1d data.
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
build(*, execution_id, values, index, index_name, dimensions, attributes)
classmethod
#
Build a database object from a series
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
execution_id
|
int
|
Execution that created the diagnostic value |
required |
values
|
list[float | int]
|
1-d array of values |
required |
index
|
list[float | int | str]
|
1-d array of index values |
required |
index_name
|
str
|
Name of the index. Used for presentation purposes |
required |
dimensions
|
dict[str, str]
|
Dimensions that describe the diagnostic execution result |
required |
attributes
|
dict[str, Any] | None
|
Optional additional attributes to describe the value, but are not in the controlled vocabulary. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If an unknown dimension was supplied. Dimensions must exist in the controlled vocabulary. |
ValueError
|
If the length of values and index do not match. |
Returns:
| Type | Description |
|---|---|
Newly created MetricValue
|
|
Source code in packages/climate-ref/src/climate_ref/models/metric_value.py
validate_series_lengths(mapper, connection, target)
#
Validate that values and index have matching lengths
This is done on insert and update to ensure that the database is consistent.