veriflow.datasources.fewsnetcdf#

Read and write NetCDF files in a fews compatible format.

Classes

FewsNetCDF(config)

For reading data from a NetCDF file produced by Delft-FEWS.

FewsNetCDFConfig(*, directory, ...[, ...])

A FEWS NetCDF config element.

class veriflow.datasources.fewsnetcdf.FewsNetCDF(config)[source]#

For reading data from a NetCDF file produced by Delft-FEWS.

Parameters:

config (FewsNetCDFConfig)

kind: str = 'fewsnetcdf'#
config_class#

alias of FewsNetCDFConfig

supported_data_specs: ClassVar[set[tuple[DataType, SpatialType]]] = {(DataType.observed_historical, SpatialType.point), (DataType.simulated_forecast_ensemble, SpatialType.point)}#
config: FewsNetCDFConfig#
property configured_stations: set[str] | None#

Return the internal station identifiers configured for this datasource.

This is needed for standardization of station identifiers across sources.

property configured_variables: set[str] | None#

Return the internal variable identifiers configured for this datasource.

This is needed for standardization of variable identifiers across sources.

property cache: ZarrCache | None#

Return the cache instance if caching is enabled, otherwise None.

clamp_verification_period_on_frt_to_available_period(available)#

Clamp the configured verification period to the source’s currently available period.

Parameters:

available (TimePeriod)

Return type:

None

property configured_variables_internal: set[str] | None#

Return the standardized internal variable identifiers configured for this datasource.

This standardized format is needed for caching across different datasources. If your datasource implementation does not have any configurable variables, return None.

create_cache_request(cached_dataset)#

Get the cache request based on the cached dataset and the config.

Parameters:

cached_dataset (Dataset)

Return type:

CacheRequest

property data_type: DataType#

Whether the instance represents simulations or observations data.

fetch_available_forecast_reference_time_period()#

Return the period actually available from the source right now, if resolvable.

Used to clamp an open-ended/rolling configured verification period (e.g. “up to now”) to what the source can currently serve, so operational runs don’t fail by requesting data that hasn’t been produced (yet) or has fallen outside the source’s retention. Returns None by default, meaning the configured verification period is used as-is.

When implemented, this method is used during caching. In a standard veriflow run, the period for which to fetch data is defined in the configuration. However, the actual available period from the datasource may differ, and this method allows Veriflow to adjust the verification period accordingly. As a result, we never request data outside the source’s actual availability and the cache is only updated with new data if it is available in the datasource.

Return type:

TimePeriod | None

fetch_validate_filter_cache(*, clear_cache=False)#

High-level wrapper to fetch, validate, filter and apply id mapping to the dataset.

Parameters:

clear_cache (bool)

Return type:

Self

filter_dataset(dataset)#

Filter the dataset on lead times and times outside the verification period.

Parameters:

dataset (Dataset)

Return type:

Dataset

classmethod from_config(raw_config)#

Initialize class from config dict.

Parameters:

raw_config (dict[str, Any])

Return type:

Self

static get_cached_data(cached_dataset, datasource)#

Get the dataset from the cache based on the datasource configuration.

Parameters:
Return type:

Dataset

get_data()#

Get data and make use of cache if configured.

Return type:

Self

property spatial_type: SpatialType#

Spatial structure (point/gridded) of the datasource’s data.

standardize_dataset(dataset, data_type)[source]#

Standardize a fetched dataset to the internal datamodel.

Ensures the station dim is indexed by the station id, sets standard dim ordering on each data variable, and ensures each data variable carries a units attribute (filling in "unknown" when missing).

Parameters:
Return type:

Dataset

validate_fetched_data()#

Validate that the dataset is consistent with the config.

Return type:

None

dataset: Dataset#
fetch_data()[source]#

Retrieve fewsnetcdf content as an xarray Dataset.

Return type:

Self

class veriflow.datasources.fewsnetcdf.FewsNetCDFConfig(*, directory, filename_glob, import_adapter, source_id, data_type, spatial_type=SpatialType.point, general, id_mapping=None, netcdf_kind, station_ids=None, parameter_ids=None, filter_stations=True, filter_variables=True, **extra_data)#

A FEWS NetCDF config element.

Parameters:
property lead_times: LeadTimes | None#
property paths: Iterator[Path]#

Return all filepaths as Path objects in a deterministic sorted order.

property verification_period: TimePeriod#
property verification_period_on_frt: TimePeriod#
property verification_period_on_time: TimePeriod#
import_adapter: Literal[DataSourceKind.FEWSNETCDF]#
netcdf_kind: FewsNetCDFKind#
station_ids: Annotated[list[str], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])] | None#
parameter_ids: Annotated[list[str], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])] | None#
filter_stations: bool#
filter_variables: bool#
source_id#
data_type#
spatial_type#
general#
id_mapping#
directory#
filename_glob#