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.
SOURCE_TYPES_TS
module-attribute
¶
DataBase
pydantic-model
¶
DataBase(**data: Any)
Bases: ABC, RompyBaseModel
Base class for data objects.
Fields:
-
model_type(Literal['base']) -
id(str)
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:
-
id(str) -
model_type(Literal['data_blob', 'data_link']) -
source(Union[str, Path, AnyPath]) -
link(bool)
Validators:
model_type
pydantic-field
¶
model_type: Literal['data_blob', 'data_link'] = 'data_blob'
Model type discriminator
source
pydantic-field
¶
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
pydantic-field
¶
link: bool = False
Whether to create a symbolic link instead of copying the file
copied_path
property
¶
Return the destination created by the most recent successful get().
validate_link_scheme_compat
pydantic-validator
¶
Validate that link=True only works with file:// scheme.
get
¶
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
¶
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.
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:
-
id(str) -
model_type(Literal['point']) -
source(Union[SOURCE_TYPES_TS]) -
filter(Optional[Filter]) -
variables(Optional[list[str]]) -
coords(Optional[DatasetCoords]) -
crop_data(bool) -
buffer(float) -
time_buffer(list[int])
source
pydantic-field
¶
source: Union[SOURCE_TYPES_TS]
Source reader, must return an xarray timeseries point dataset in the open method
filter
pydantic-field
¶
Optional filter specification to apply to the dataset
variables
pydantic-field
¶
Subset of variables to extract from the dataset
coords
pydantic-field
¶
coords: Optional[DatasetCoords] = DatasetCoords()
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
¶
Number of source data timesteps to buffer the time range if crop_data is True
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 |
None
|
time
|
Optional[TimeRange]
|
The times to filter the data to, only used if |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
outfile |
Path
|
The path to the written file. |
check_for_typos
classmethod
¶
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.
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:
-
id(str) -
filter(Optional[Filter]) -
variables(Optional[list[str]]) -
coords(Optional[DatasetCoords]) -
crop_data(bool) -
buffer(float) -
time_buffer(list[int]) -
model_type(Literal['grid']) -
source(Union[SOURCE_TYPES])
source
pydantic-field
¶
source: Union[SOURCE_TYPES]
Source reader, must return an xarray gridded dataset in the open method
filter
pydantic-field
¶
Optional filter specification to apply to the dataset
variables
pydantic-field
¶
Subset of variables to extract from the dataset
coords
pydantic-field
¶
coords: Optional[DatasetCoords] = DatasetCoords()
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
¶
Number of source data timesteps to buffer the time range if crop_data is True
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
¶
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.
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 |
None
|
time
|
Optional[TimeRange]
|
The times to filter the data to, only used if |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
outfile |
Path
|
The path to the written file. |