Skip to content

Data

Data objects fetch or extract input data and write it to the run directory: DataBlob copies files, while DataPoint and DataGrid select data from a source over the model grid and period.

Rompy core data objects.

logger module-attribute

logger = logging.getLogger(__name__)

GRID_TYPES module-attribute

GRID_TYPES = Union[BaseGrid, RegularGrid]

SOURCE_TYPES module-attribute

SOURCE_TYPES = load_entry_points('rompy.source')

SOURCE_TYPES_TS module-attribute

SOURCE_TYPES_TS = load_entry_points(
    "rompy.source", etype="timeseries"
)

DataBase pydantic-model

DataBase(**data: Any)

Bases: ABC, RompyBaseModel

Base class for data objects.

Fields:

model_type pydantic-field

model_type: Literal['base'] = 'base'

Model type discriminator

id pydantic-field

id: str = 'data'

Unique identifier for this data source

get abstractmethod

get(destdir: Union[str, Path], *args, **kwargs) -> Path

Abstract method to get the data.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

DataBlob pydantic-model

DataBlob(**data: Any)

Bases: DataBase

Data source for model ingestion.

Generic data source for files that either need to be copied to the model directory or linked if link is set to True. Supports local/cloud paths, remote HTTP/HTTPS URLs, and oceanum:// storage URIs via the transfer registry. Linking only works with local file paths (file:// scheme).

Examples

from rompy.core.data import DataBlob from pathlib import Path

Local file:

blob = DataBlob(source=Path("/data/input.nc")) blob.get(Path("/output/dir")) # doctest: +ELLIPSIS PosixPath('/output/dir/input.nc')

Remote HTTP file (automatically downloaded):

blob = DataBlob(source="https://example.com/data.nc") blob.get(Path("/output/dir")) # doctest: +ELLIPSIS PosixPath('/output/dir/data.nc')

Remote file with custom name:

blob = DataBlob(source="https://example.com/data.nc") blob.get(Path("/output/dir"), name="custom.nc") # doctest: +ELLIPSIS PosixPath('/output/dir/custom.nc')

Fields:

Validators:

model_type pydantic-field

model_type: Literal['data_blob', 'data_link'] = 'data_blob'

Model type discriminator

source pydantic-field

source: Union[str, Path, AnyPath]

URI of the data source: local file path, cloud storage URI (s3://, gs://), remote HTTP/HTTPS URL, or oceanum:// URL. Sources are handled via the transfer registry.

link: bool = False

Whether to create a symbolic link instead of copying the file

copied_path property

copied_path: Optional[Path]

Return the destination created by the most recent successful get().

id pydantic-field

id: str = 'data'

Unique identifier for this data source

validate_link_scheme_compat()

Validate that link=True only works with file:// scheme.

get

get(
    destdir: Union[str, Path],
    name: Optional[str] = None,
    *args,
    **kwargs,
) -> Path

Copy, download, or link the data source to a new directory.

Uses the transfer registry to dispatch based on URI scheme (file://, http://, https://, oceanum://). For local files, respects the link attribute (symlink vs copy). For remote sources (HTTP, oceanum), always downloads (ignores link flag).

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to copy/download/link the data source to.

required
name str

Override the output filename.

None

Returns:

Type Description
Path

The path to the downloaded/copied file or created symlink.

Notes

HTTP downloads include: - Retry logic with exponential backoff (3 retries by default) - Atomic writes (download to temp file, then rename) - Caching (skip download if file already exists in destination) - 500MB maximum file size limit

Raises:

Type Description
ValueError

If link=True is used with a non-file:// URI.

UnsupportedOperation

If the transfer scheme does not support required operations.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

DataPoint pydantic-model

DataPoint(**data: Any)

Bases: DataBase

Data object for timeseries source data.

Generic data object for xarray datasets that only have time as a dimension and do not need to be cropped to a specific grid.

Fields:

model_type pydantic-field

model_type: Literal['point'] = 'point'

Model type discriminator

source pydantic-field

Source reader, must return an xarray timeseries point dataset in the open method

filter pydantic-field

filter: Optional[Filter]

Optional filter specification to apply to the dataset

variables pydantic-field

variables: Optional[list[str]] = []

Subset of variables to extract from the dataset

coords pydantic-field

Names of the coordinates in the dataset

crop_data pydantic-field

crop_data: bool = True

Update crop filters from Grid and Time objects if passed to get method

buffer pydantic-field

buffer: float = 0.0

Space to buffer the grid bounding box if crop_data is True

time_buffer pydantic-field

time_buffer: list[int] = [0, 0]

Number of source data timesteps to buffer the time range if crop_data is True

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

id pydantic-field

id: str = 'data'

Unique identifier for this data source

get

get(
    destdir: str | Path,
    grid: Optional[GRID_TYPES] = None,
    time: Optional[TimeRange] = None,
) -> Path

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to write the netcdf data to.

required
grid Optional[GRID_TYPES]

The grid to filter the data to, only used if self.crop_data is True.

None
time Optional[TimeRange]

The times to filter the data to, only used if self.crop_data is True.

None

Returns:

Name Type Description
outfile Path

The path to the written file.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

DataGrid pydantic-model

DataGrid(**data: Any)

Bases: DataPoint

Data object for gridded source data.

Generic data object for xarray datasets with gridded spatial dimensions.

Note

When crop_data is True, get crops the data to the bounding box of the grid (plus buffer) and to the time range (plus time_buffer source time steps) passed to it. This is useful for data sources that are not defined on the same grid as the model grid or the same time range as the model run.

Fields:

model_type pydantic-field

model_type: Literal['grid'] = 'grid'

Model type discriminator

source pydantic-field

Source reader, must return an xarray gridded dataset in the open method

id pydantic-field

id: str = 'data'

Unique identifier for this data source

filter pydantic-field

filter: Optional[Filter]

Optional filter specification to apply to the dataset

variables pydantic-field

variables: Optional[list[str]] = []

Subset of variables to extract from the dataset

coords pydantic-field

Names of the coordinates in the dataset

crop_data pydantic-field

crop_data: bool = True

Update crop filters from Grid and Time objects if passed to get method

buffer pydantic-field

buffer: float = 0.0

Space to buffer the grid bounding box if crop_data is True

time_buffer pydantic-field

time_buffer: list[int] = [0, 0]

Number of source data timesteps to buffer the time range if crop_data is True

ds property

ds

Return the xarray dataset for this data source.

outfile property

outfile: str

plot

plot(
    param,
    isel={},
    model_grid=None,
    cmap="turbo",
    figsize=None,
    fscale=10,
    borders=True,
    land=True,
    coastline=True,
    **kwargs,
)

Plot the grid.

check_for_typos classmethod

check_for_typos(data: Any) -> Any

Suggest the closest field name for an unknown input key.

A field can be given by its name or, like in pydantic, by its alias.

dump_inputs_dict

dump_inputs_dict() -> dict

Return the original inputs as a dictionary.

dump_inputs_json

dump_inputs_json() -> str

Return the original inputs as a JSON string.

get

get(
    destdir: str | Path,
    grid: Optional[GRID_TYPES] = None,
    time: Optional[TimeRange] = None,
) -> Path

Write the data source to a new location.

Parameters:

Name Type Description Default
destdir str | Path

The destination directory to write the netcdf data to.

required
grid Optional[GRID_TYPES]

The grid to filter the data to, only used if self.crop_data is True.

None
time Optional[TimeRange]

The times to filter the data to, only used if self.crop_data is True.

None

Returns:

Name Type Description
outfile Path

The path to the written file.