pycontrails.Model¶
- class pycontrails.Model(met=None, params=None, **params_kwargs)¶
Bases:
ABC
Base class for physical models.
Implementing classes must implement the
eval()
method- __init__(met=None, params=None, **params_kwargs)¶
Methods
__init__
([met, params])eval
([source])Abstract method to handle evaluation.
get_source_param
(key[, default, set_attr])Get source data with default set by parameter key.
Ensure that
met
is a MetDataset.require_source_type
(type_)Ensure that
source
istype_
.set_source
([source])Attach original or copy of input
source
tosource
.set_source_met
([optional, variable])Ensure or interpolate each required
met_variables
onsource
.transfer_met_source_attrs
([source])Transfer met source metadata from
met
tosource
.update_params
([params])Update model parameters on
params
.Attributes
Instantiated model parameters, in dictionary form
Meteorology data
Data evaluated in model
Generate a unique hash for model instance.
Shortcut to create interpolation arguments from
params
.Get long name descriptor, annotated on
xr.DataArray
outputs.Require meteorology is not None on __init__()
class`Flight`.
Required meteorology pressure level variables.
Set of required parameters if processing already complete on
met
input.Optional meteorology variables
- default_params¶
alias of
ModelParams
- downselect_met()¶
Downselect
met
domain to the max/min bounds ofsource
.Override this method if special handling is needed in met down-selection.
source
must be defined before callingdownselect_met()
.This method copies and re-assigns
met
usingmet.copy()
to avoid side-effects.
- Raises:
ValueError – Raised if
source
is not defined. Raised ifsource
is not aGeoVectorDataset
.TypeError – Raised if
met
is not aMetDataset
.
- abstract eval(source=None, **params)¶
Abstract method to handle evaluation.
Implementing classes should override call signature to overload
source
inputs and model outputs.- Parameters:
source (
ModelInput
, optional) – Dataset defining coordinates to evaluate model. Defined by implementing class, but must be a subset of ModelInput. If None,met
is assumed to be evaluation points.**params (
Any
) – Overwrite model parameters before evaluation.
- Returns:
ModelOutput
– Return type depends on implementing model
- get_source_param(key, default=<object object>, *, set_attr=True)¶
Get source data with default set by parameter key.
Retrieves data with the following hierarchy:
source.data[key]
. Returnsnp.ndarray | xr.DataArray
.source.attrs[key]
params[key]
default
In case 3., the value of
params[key]
is attached tosource.attrs[key]
.- Parameters:
- Returns:
Any
– Value(s) found for key in source data, source attrs, or model params- Raises:
KeyError – Raises KeyError if key is not found in any location and
default
is not provided.
See also
-
- property hash¶
Generate a unique hash for model instance.
- Returns:
str
– Unique hash for model instance (sha1)
- property interp_kwargs¶
Shortcut to create interpolation arguments from
params
.The output of this is useful for passing to
interpolate_met()
.- Returns:
dict[str
,Any]
– Dictionary with keys”method”
”bounds_error”
”fill_value”
”localize”
”use_indices”
”q_method”
as determined by
params
.
- abstract property long_name¶
Get long name descriptor, annotated on
xr.DataArray
outputs.
- met¶
Meteorology data
- met_required = False¶
Require meteorology is not None on __init__()
- met_variables¶
Required meteorology pressure level variables. Each element in the list is a
MetVariable
or atuple[MetVariable]
. If element is atuple[MetVariable]
, the variable depends on the data source. Only one variable in the tuple is required.
- abstract property name¶
class`Flight`.
- Type:
Get model name for use as a data key in
xr.DataArray
or
- optional_met_variables¶
Optional meteorology variables
- params¶
Instantiated model parameters, in dictionary form
- processed_met_variables¶
Set of required parameters if processing already complete on
met
input.
- require_met()¶
Ensure that
met
is a MetDataset.- Returns:
MetDataset
– Returns reference tomet
. This is helpful for type narrowingmet
when meteorology is required.- Raises:
ValueError – Raises when
met
is None.
- require_source_type(type_)¶
Ensure that
source
istype_
.- Returns:
_Source
– Returns reference tosource
. This is helpful for type narrowingsource
to specific type(s).- Raises:
ValueError – Raises when
source
is not_type_
.
- set_source(source=None)¶
Attach original or copy of input
source
tosource
.- Parameters:
source (
MetDataset | GeoVectorDataset | Flight | Iterable[Flight] | None
) – Parametersource
passed ineval()
. If None, an empty MetDataset with coordinates likemet
is set tosource
.
See also
-
meth:eval
- set_source_met(optional=False, variable=None)¶
Ensure or interpolate each required
met_variables
onsource
.For each variable in
met_variables
, checksource
for data variable with the same name.For
GeoVectorDataset
sources, try to interpolatemet
if variable does not exist.For
MetDataset
sources, try to get data frommet
if variable does not exist.- Parameters:
optional (
bool
, optional) – Includeoptional_met_variables
variable (
MetVariable | Sequence[MetVariable] | None
, optional) – MetVariable to set, frommet_variables
. If None, set all variables inmet_variables
andoptional_met_variables
ifoptional
is True.
- Raises:
ValueError – Variable does not exist and
source
is a MetDataset.
- source¶
Data evaluated in model