AI4COPSEC AI4COPSEC collekt
  • Home
  • Products
  • CLI
  • Credentials
  • Manifest
  • API reference

On this page

  • Assembler
    • Example
    • Parameters
    • Methods
      • to_netcdf
      • to_numpy
      • to_xarray
      • to_zarr

Assembler

Assembler(result)

Convert a downloaded collection into analysis-ready objects.

Assembler starts from a Result returned by Fetcher.download. By default, it keeps source identity explicit by prefixing variables, coordinates, and dimensions with the configured source name. This avoids collisions when a collection contains several products for the same physical quantity, such as multiple wind sources. Non-native grid policies interpolate NetCDF and GRIB2 sources onto a common overlapping latitude/longitude grid while keeping variable names source-prefixed or explicitly aliased.

Example

from collekt import Assembler

result = fetcher.download()
assembler = Assembler(result)

ds = assembler.to_xarray(
    aliases={"era5_reanalysis__u10": "era5_u10"},
    grid="lowest_resolution",
    time="lowest_resolution",
)
assembler.to_netcdf("merged.nc", grid="lowest_resolution", time="lowest_resolution")
arrays = assembler.to_numpy(grid="lowest_resolution", time="lowest_resolution")

Parameters

Name Type Description Default
result Result Download result returned by Fetcher.download. required

Methods

Name Description
to_netcdf Write assembled data to a NetCDF file.
to_numpy Return assembled data variables as NumPy arrays.
to_xarray Open downloaded dataset files as one xarray dataset.
to_zarr Write assembled data to a Zarr store.

to_netcdf

Assembler.to_netcdf(
    path,
    *,
    aliases=None,
    grid='native',
    spatial_method='linear',
    target_grid=None,
    time='native',
    temporal_method='nearest',
    target_time=None,
    time_tolerance='1h',
    **kwargs,
)

Write assembled data to a NetCDF file.

Parameters

Name Type Description Default
path str | Path Destination NetCDF path. required
aliases Mapping[str, str] | None Optional explicit variable aliases. None
grid GridPolicy Spatial grid policy. 'native'
spatial_method SpatialMethod Spatial interpolation method. 'linear'
target_grid TargetGrid | None Required when grid="custom". None
time TimePolicy Temporal alignment policy. 'native'
temporal_method TemporalMethod Temporal interpolation or aggregation method. 'nearest'
target_time TargetTime | None Required when time="custom". None
time_tolerance str | timedelta | None Maximum nearest-neighbour temporal distance. '1h'
**kwargs Any Extra keyword arguments passed to xarray.Dataset.to_netcdf. {}

Returns

Name Type Description
Path Destination path.

to_numpy

Assembler.to_numpy(
    variables=None,
    *,
    aliases=None,
    grid='native',
    spatial_method='linear',
    target_grid=None,
    time='native',
    temporal_method='nearest',
    target_time=None,
    time_tolerance='1h',
)

Return assembled data variables as NumPy arrays.

Parameters

Name Type Description Default
variables Iterable[str] | None Optional assembled variable names to extract after alias application. If omitted, all data variables are returned. None
aliases Mapping[str, str] | None Optional explicit variable aliases. None
grid GridPolicy Spatial grid policy. 'native'
spatial_method SpatialMethod Spatial interpolation method. 'linear'
target_grid TargetGrid | None Required when grid="custom". None
time TimePolicy Temporal alignment policy. 'native'
temporal_method TemporalMethod Temporal interpolation or aggregation method. 'nearest'
target_time TargetTime | None Required when time="custom". None
time_tolerance str | timedelta | None Maximum nearest-neighbour temporal distance. '1h'

Returns

Name Type Description
dict[str, Any] Mapping from variable name to NumPy array.

to_xarray

Assembler.to_xarray(
    aliases=None,
    grid='native',
    spatial_method='linear',
    target_grid=None,
    time='native',
    temporal_method='nearest',
    target_time=None,
    time_tolerance='1h',
)

Open downloaded dataset files as one xarray dataset.

Parameters

Name Type Description Default
aliases Mapping[str, str] | None Optional explicit mapping from default assembled variable names, such as cmems_glorys__uo, to user-facing names. None
grid GridPolicy Spatial grid policy. "native" keeps each source on its own grid. "lowest_resolution" and "highest_resolution" interpolate sources onto the coarsest or finest overlapping source grid. "custom" interpolates to target_grid. 'native'
spatial_method SpatialMethod xarray interpolation method used when grid is not "native". Supported values are "linear" and "nearest". 'linear'
target_grid TargetGrid | None Required when grid="custom". Mapping with latitude/longitude or lat/lon arrays. None
time TimePolicy Temporal alignment policy. "native" keeps each source on its own time coordinate. "lowest_resolution" and "highest_resolution" align sources onto the coarsest or finest source timestamps. "custom" aligns to target_time. 'native'
temporal_method TemporalMethod Temporal method used when time is not "native". "nearest" uses nearest-neighbour selection with time_tolerance; "linear" uses xarray interpolation; "mean", "max", and "min" aggregate with xarray resampling before aligning to the target timestamps. 'nearest'
target_time TargetTime | None Required when time="custom". Iterable of target datetimes, ISO datetime strings, or NumPy datetime64 values. None
time_tolerance str | timedelta | None Maximum nearest-neighbour temporal distance. Use values such as "30min", "1h", or a datetime.timedelta. Set to None to allow unbounded nearest-neighbour selection. '1h'

Returns

Name Type Description
Any An xarray.Dataset containing all dataset variables that could be
Any opened from downloaded or reused NetCDF/GRIB2 source files.

Raises

Name Type Description
ValueError If no readable dataset files are available, aliases collide, or a requested grid cannot be built.

to_zarr

Assembler.to_zarr(
    path,
    *,
    aliases=None,
    grid='native',
    spatial_method='linear',
    target_grid=None,
    time='native',
    temporal_method='nearest',
    target_time=None,
    time_tolerance='1h',
    **kwargs,
)

Write assembled data to a Zarr store.

Parameters

Name Type Description Default
path str | Path Destination Zarr store path. required
aliases Mapping[str, str] | None Optional explicit variable aliases. None
grid GridPolicy Spatial grid policy. 'native'
spatial_method SpatialMethod Spatial interpolation method. 'linear'
target_grid TargetGrid | None Required when grid="custom". None
time TimePolicy Temporal alignment policy. 'native'
temporal_method TemporalMethod Temporal interpolation or aggregation method. 'nearest'
target_time TargetTime | None Required when time="custom". None
time_tolerance str | timedelta | None Maximum nearest-neighbour temporal distance. '1h'
**kwargs Any Extra keyword arguments passed to xarray.Dataset.to_zarr. {}

Returns

Name Type Description
Path Destination path.

Part of AI4COPSEC.

Built with Quarto.

GitHub