pycontrails.datalib.ecmwf.IFS¶
- class pycontrails.datalib.ecmwf.IFS(time, variables, pressure_levels=-1, paths=None, grid=None, forecast_path=None, forecast_date=None)¶
Bases:
MetDataSource
ECMWF Integrated Forecasting System (IFS) data source.
Warning
This data source is not fully implemented.
- Parameters:
time (
metsource.TimeInput | None
) – The time range for data retrieval, either a single datetime or (start, end) datetime range. Input must be a single datetime-like or tuple of datetime-like (datetime,pandas.Timestamp
,numpy.datetime64
) specifying the (start, end) of the date range, inclusive. If None, all time coordinates will be loaded.variables (
metsource.VariableInput
) – Variable name (i.e. “air_temperature”, [“air_temperature, relative_humidity”]) Seepressure_level_variables
for the list of available variables.pressure_levels (
metsource.PressureLevelInput
, optional) – Pressure level bounds for data (min, max), in hPa (mbar) Set to -1 for to download surface level parameters. Defaults to -1.paths (
str | list[str] | pathlib.Path | list[pathlib.Path] | None
, optional) – UNSUPPORTED FOR IFSforecast_path (
str | pathlib.Path | None
, optional) – Path to local forecast files. Defaults to Noneforecast_date (
DatetimeLike
, optional) – Forecast date to load specific netcdf files. Defaults to None
Notes
This takes an average pressure of the model level to create pressure level dimensions.
- __init__(time, variables, pressure_levels=-1, paths=None, grid=None, forecast_path=None, forecast_date=None)¶
Methods
__init__
(time, variables[, pressure_levels, ...])cache_dataset
(dataset)Cache data from data source.
Return cachepath to local data file based on datetime.
download
(**xr_kwargs)Confirm all data files are downloaded and available locally in the
cachestore
.download_dataset
(times)Download data from data source for input times.
is_datafile_cached
(t, **xr_kwargs)Check datafile defined by datetime for variables and pressure levels in class.
list_timesteps_cached
(**xr_kwargs)Get a list of data files available locally in the
cachestore
.list_timesteps_not_cached
(**xr_kwargs)Get a list of data files not available locally in the
cachestore
.open_dataset
(disk_paths, **xr_kwargs)Open multi-file dataset in xarray.
open_metdataset
([dataset, xr_kwargs])Open MetDataset from data source.
set_metadata
(ds)Set met source metadata on
ds.attrs
.Attributes
Forecast datetime of IFS forecast
Root path of IFS data
Lat / Lon grid spacing
Generate a unique hash for this datasource.
Return True if the datasource is single level data.
Path to local source files to load.
Parameters available from data source.
List of pressure levels.
Parameters available from data source.
IFS does not provide constant pressure levels and instead uses model levels.
IFS parameters available.
List of individual timesteps from data source derived from
time
Useparse_time()
to handleTimeInput
.Return a list of variable short names.
Return a list of variable standard names.
Variables requested from data source Use
parse_variables()
to handleVariableInput
.Cache store for intermediates while processing data source If None, cache is turned off.
- cache_dataset(dataset)¶
Cache data from data source.
- Parameters:
dataset (
xarray.Dataset
) – Dataset loaded from remote API or local files. The dataset must have the same format as the original data source API or files.
- cachestore¶
Cache store for intermediates while processing data source If None, cache is turned off.
- create_cachepath(t)¶
Return cachepath to local data file based on datetime.
- Parameters:
t (
datetime
) – Datetime of datafile- Returns:
str
– Path to cached data file
- download(**xr_kwargs)¶
Confirm all data files are downloaded and available locally in the
cachestore
.- Parameters:
**xr_kwargs – Passed into
xarray.open_dataset()
viais_datafile_cached()
.
- download_dataset(times)¶
Download data from data source for input times.
- Parameters:
times (
list[datetime]
) – List of datetimes to download a store in cache
- forecast_date¶
Forecast datetime of IFS forecast
- forecast_path¶
Root path of IFS data
- grid¶
Lat / Lon grid spacing
- property hash¶
Generate a unique hash for this datasource.
- Returns:
str
– Unique hash for met instance (sha1)
- is_datafile_cached(t, **xr_kwargs)¶
Check datafile defined by datetime for variables and pressure levels in class.
If using a cloud cache store (i.e.
cache.GCPCacheStore
), this is where the datafile will be mirrored to a local file for access.- Parameters:
t (
datetime
) – Datetime of datafile**xr_kwargs (
Any
) – Additional kwargs passed directly toxarray.open_mfdataset()
when opening files. By default, the following values are used if not specified:chunks: {“time”: 1}
engine: “netcdf4”
parallel: False
- Returns:
bool
– True if data file exists for datetime with all variables and pressure levels, False otherwise
- property is_single_level¶
Return True if the datasource is single level data.
Added in version 0.50.0.
- list_timesteps_cached(**xr_kwargs)¶
Get a list of data files available locally in the
cachestore
.- Parameters:
**xr_kwargs – Passed into
xarray.open_dataset()
viais_datafile_cached()
.
- list_timesteps_not_cached(**xr_kwargs)¶
Get a list of data files not available locally in the
cachestore
.- Parameters:
**xr_kwargs – Passed into
xarray.open_dataset()
viais_datafile_cached()
.
- open_dataset(disk_paths, **xr_kwargs)¶
Open multi-file dataset in xarray.
- Parameters:
disk_paths (
str | list[str] | pathlib.Path | list[pathlib.Path]
) – list of string paths to local files to open**xr_kwargs (
Any
) – Additional kwargs passed directly toxarray.open_mfdataset()
when opening files. By default, the following values are used if not specified:chunks: {“time”: 1}
engine: “netcdf4”
parallel: False
lock: False
- Returns:
xarray.Dataset
– Open xarray dataset
- open_metdataset(dataset=None, xr_kwargs=None, **kwargs)¶
Open MetDataset from data source.
This method should download / load any required datafiles and returns a MetDataset of the multi-file dataset opened by xarray.
- Parameters:
dataset (
xr.Dataset | None
, optional) – Inputxr.Dataset
loaded manually. The dataset must have the same format as the original data source API or files.xr_kwargs (
dict[str
,Any] | None
, optional) – Dictionary of keyword arguments passed intoxarray.open_mfdataset()
when opening files. Examples include “chunks”, “engine”, “parallel”, etc. Ignored ifdataset
is input.**kwargs (
Any
) – Keyword arguments passed through directly intoMetDataset
constructor.
- Returns:
MetDataset
– Meteorology dataset
See also
- paths¶
Path to local source files to load. Set to the paths of files cached in
cachestore
if nopaths
input is provided on init.
- property pressure_level_variables¶
Parameters available from data source.
- Returns:
list[MetVariable] | None
– List of MetVariable available in datasource
- pressure_levels¶
List of pressure levels. Set to [-1] for data without level coordinate. Use
parse_pressure_levels()
to handlePressureLevelInput
.
- set_metadata(ds)¶
Set met source metadata on
ds.attrs
.This is called within the
open_metdataset()
method to set metadata on the returnedMetDataset
instance.- Parameters:
ds (
xr.Dataset | MetDataset
) – Dataset to set metadata on. Mutated in place.
- property single_level_variables¶
Parameters available from data source.
- Returns:
list[MetVariable] | None
– List of MetVariable available in datasource
- property supported_pressure_levels¶
IFS does not provide constant pressure levels and instead uses model levels.
- Returns:
list[int]
- property supported_variables¶
IFS parameters available.
- Returns:
list[MetVariable] | None
– List of MetVariable available in datasource
- timesteps¶
List of individual timesteps from data source derived from
time
Useparse_time()
to handleTimeInput
.
- property variable_shortnames¶
Return a list of variable short names.
- Returns:
list[str]
– Lst of variable short names.
- property variable_standardnames¶
Return a list of variable standard names.
- Returns:
list[str]
– Lst of variable standard names.
- variables¶
Variables requested from data source Use
parse_variables()
to handleVariableInput
.