climate_ref_core.constraints
#
Dataset selection constraints
AddSupplementaryDataset
#
Include e.g. a cell measure or ancillary variable in the selection.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
matching_facets
instance-attribute
#
Facets that must match with datasets in the selection.
optional_matching_facets
instance-attribute
#
Select only the best matching datasets based on similarity with these facets.
supplementary_facets
instance-attribute
#
Facets describing the supplementary dataset.
apply(group, data_catalog)
#
Add a supplementary dataset to the group.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
from_defaults(variable, source_type)
classmethod
#
Include e.g. a cell measure or ancillary variable in the selection.
The constraint is created using the defaults for the source_type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
The name of the variable to add. |
required |
source_type
|
SourceDatasetType
|
The source_type of the variable to add. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A constraint to include a supplementary variable. |
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
GroupConstraint
#
Bases: Protocol
An operation to perform on a group of datasets resulting in a new group of datasets.
This is applied to a group of datasets representing the inputs to a potential diagnostic execution.
If the operation results in an empty group, the constraint is considered not satisfied. The group must satisfy all constraints to be processed.
!! warning
Operations should not mutate the input group, but instead return a new group.
Mutating the input group may result in unexpected behaviour.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
apply(group, data_catalog)
#
Perform an operation on the group of datasets.
A new group of datasets should be returned if modifications are required, and the input group should not be modified. If no modifications are required, return the input group unchanged. If this operation fails, a ConstraintNotSatisfied exception should be raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
DataFrame
|
A group of datasets that is being validated. |
required |
data_catalog
|
DataFrame
|
The data catalog of datasets |
required |
Raises:
| Type | Description |
|---|---|
ConstraintNotSatisfied
|
The operation was not successful |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The updated group of datasets |
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
IgnoreFacets
#
A constraint that ignores certain facet values.
Datasets with these facet values are removed from the selection.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
facets = field(converter=_to_tuple_dict)
class-attribute
instance-attribute
#
The facet values to ignore.
apply(group, data_catalog)
#
Filter out datasets with the ignored facets.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
PartialDateTime
#
A partial datetime object that can be used to compare datetimes.
Only the specified fields are used for comparison.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
RequireContiguousTimerange
#
A constraint that requires datasets to have a contiguous timerange.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
group_by
instance-attribute
#
The fields to group the datasets by. Groups that are not be contiguous in time are removed.
apply(group, data_catalog)
#
Check that all subgroups of the group have a contiguous timerange.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
RequireFacets
#
A constraint that requires datasets to have certain facet values.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
dimension
instance-attribute
#
The name of the facet to filter on.
group_by = field(converter=_to_tuple, default=None)
class-attribute
instance-attribute
#
The facets to group the datasets by.
Each group created by group_by must contain at least one dataset where the
value of the given dimension is in the list of required facet values.
For example, if there are multiple models and variables in the selection,
group_by can be used to make sure that only those models are selected that
provide all required variables.
operator = 'all'
class-attribute
instance-attribute
#
Whether all or any of the required facets must be present.
required_facets = field(converter=_to_tuple)
class-attribute
instance-attribute
#
The required facet values.
apply(group, data_catalog)
#
Filter out groups of datasets that do not provide the required facets
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
RequireOverlappingTimerange
#
A constraint that requires datasets to have an overlapping timerange.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
group_by
instance-attribute
#
The fields to group the datasets by. There must be overlap in time between the groups to fulfill the constraint.
apply(group, data_catalog)
#
Check that all subgroups of the group have an overlapping timerange.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
RequireTimerange
#
A constraint that requires datasets to have a specific timerange.
Specify the start and/or end of the required timerange using a precision that matches the frequency of the datasets.
For example, to ensure that datasets at monthly frequency cover the period from 2000 to 2010, use start=PartialDateTime(year=2000, month=1) and end=PartialDateTime(year=2010, month=12).
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
end = None
class-attribute
instance-attribute
#
The end time of the required timerange. If None, no end time is required.
group_by
instance-attribute
#
The fields to group the datasets by. Groups that do not cover the timerange will be removed.
start = None
class-attribute
instance-attribute
#
The start time of the required timerange. If None, no start time is required.
apply(group, data_catalog)
#
Check that all subgroups of the group have a contiguous timerange.
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
SelectParentExperiment
#
Include a dataset's parent experiment in the selection
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
apply(group, data_catalog)
#
Include a dataset's parent experiment in the selection
Not yet implemented
Source code in packages/climate-ref-core/src/climate_ref_core/constraints.py
apply_constraint(dataframe, constraint, data_catalog)
#
Apply a constraint to a group of datasets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
DataFrame
|
The group of datasets to apply the constraint to. |
required |
constraint
|
GroupConstraint
|
The constraint to apply. |
required |
data_catalog
|
DataFrame
|
The data catalog of all datasets. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame | None
|
The updated group of datasets or None if the constraint was not satisfied |