Skip to content

Sources

Sources open datasets for the data objects. Model plugins and other packages add sources under the rompy.source entry point.

Rompy source objects.

logger module-attribute

logger = get_logger(__name__)

SourceBase pydantic-model

SourceBase(**data: Any)

Bases: RompyBaseModel, ABC

Abstract base class for a source dataset.

Fields:

model_type pydantic-field

model_type: Literal['base_source']

Model type discriminator, must be overriden by a subclass

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

open

open(
    variables: list = [], filters: Filter = {}, **kwargs
) -> Dataset

Return the filtered dataset object.

Parameters:

Name Type Description Default
variables list

List of variables to select from the dataset.

[]
filters Filter

Filters to apply to the dataset.

{}
Notes

The kwargs are only a placeholder in case a subclass needs to pass additional arguments to the open method.

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.

SourceFile pydantic-model

SourceFile(**data: Any)

Bases: SourceBase

Source dataset from file to open with xarray.open_dataset.

Config:

  • arbitrary_types_allowed: True

Fields:

model_type pydantic-field

model_type: Literal['file'] = 'file'

Model type discriminator

uri pydantic-field

uri: Union[str, Path]

Path to the dataset

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments to pass to xarray.open_dataset

variable pydantic-field

variable: Optional[str] = None

Variable to select from the dataset

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

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.

open

open(
    variables: list = [], filters: Filter = {}, **kwargs
) -> Dataset

Return the filtered dataset object.

Parameters:

Name Type Description Default
variables list

List of variables to select from the dataset.

[]
filters Filter

Filters to apply to the dataset.

{}
Notes

The kwargs are only a placeholder in case a subclass needs to pass additional arguments to the open method.

SourceIntake pydantic-model

SourceIntake(**data: Any)

Bases: SourceBase

Source dataset from intake catalog.

note

The intake catalog can be prescribed either by the URI of an existing catalog file or by a YAML string defining the catalog. The YAML string can be obtained from calling the yaml() method on an intake dataset instance.

Fields:

Validators:

model_type pydantic-field

model_type: Literal['intake'] = 'intake'

Model type discriminator

dataset_id pydantic-field

dataset_id: str

The id of the dataset to read in the catalog

catalog_uri pydantic-field

catalog_uri: Optional[str | Path] = None

The URI of the catalog to read from

catalog_yaml pydantic-field

catalog_yaml: Optional[str] = None

The YAML string of the catalog to read from

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments to define intake dataset parameters

catalog property

catalog: Catalog

The intake catalog instance.

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

check_catalog pydantic-validator

check_catalog() -> SourceIntake

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.

open

open(
    variables: list = [], filters: Filter = {}, **kwargs
) -> Dataset

Return the filtered dataset object.

Parameters:

Name Type Description Default
variables list

List of variables to select from the dataset.

[]
filters Filter

Filters to apply to the dataset.

{}
Notes

The kwargs are only a placeholder in case a subclass needs to pass additional arguments to the open method.

SourceDatamesh pydantic-model

SourceDatamesh(**data: Any)

Bases: SourceBase

Source dataset from Datamesh.

Datamesh documentation: https://docs.oceanum.io/datamesh/index.html

Fields:

model_type pydantic-field

model_type: Literal['datamesh'] = 'datamesh'

Model type discriminator

datasource pydantic-field

datasource: str

The id of the datasource on Datamesh

token pydantic-field

token: Optional[str] = None

Datamesh API token, taken from the environment if not provided

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments to pass to oceanum.datamesh.Connector

connector cached property

connector: Connector

The Datamesh connector instance.

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

open

open(
    filters: Filter,
    coords: DatasetCoords,
    variables: list = [],
) -> Dataset

Returns the filtered dataset object.

This method is overriden from the base class because the crop filters need to be converted to a geofilter and timefilter for querying Datamesh.

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.

SourceWavespectra pydantic-model

SourceWavespectra(**data: Any)

Bases: SourceBase

Wavespectra dataset from wavespectra reader.

Fields:

model_type pydantic-field

model_type: Literal['wavespectra'] = 'wavespectra'

Model type discriminator

uri pydantic-field

uri: str | Path

Path to the dataset

reader pydantic-field

reader: str

Name of the wavespectra reader to use, e.g., read_swan

kwargs pydantic-field

kwargs: dict = {}

Keyword arguments to pass to the wavespectra reader

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

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.

open

open(
    variables: list = [], filters: Filter = {}, **kwargs
) -> Dataset

Return the filtered dataset object.

Parameters:

Name Type Description Default
variables list

List of variables to select from the dataset.

[]
filters Filter

Filters to apply to the dataset.

{}
Notes

The kwargs are only a placeholder in case a subclass needs to pass additional arguments to the open method.

SourceTimeseriesCSV pydantic-model

SourceTimeseriesCSV(**data: Any)

Bases: SourceBase

Timeseries source class from CSV file.

This class should return a timeseries from a CSV file. The dataset variables are defined from the column headers, therefore the appropriate read_csv kwargs must be passed to allow defining the columns. The time index is defined from column name identified by the tcol field.

Fields:

Validators:

model_type pydantic-field

model_type: Literal['csv'] = 'csv'

Model type discriminator

filename pydantic-field

filename: str | Path

Path to the csv file

tcol pydantic-field

tcol: str = 'time'

Name of the column containing the time data

read_csv_kwargs pydantic-field

read_csv_kwargs: dict = {}

Keyword arguments to pass to pandas.read_csv

coordinates cached property

coordinates: Dataset

Return the coordinates of the datasource.

validate_kwargs pydantic-validator

validate_kwargs() -> SourceTimeseriesCSV

Validate the keyword arguments.

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.

open

open(
    variables: list = [], filters: Filter = {}, **kwargs
) -> Dataset

Return the filtered dataset object.

Parameters:

Name Type Description Default
variables list

List of variables to select from the dataset.

[]
filters Filter

Filters to apply to the dataset.

{}
Notes

The kwargs are only a placeholder in case a subclass needs to pass additional arguments to the open method.

render_datetimes

render_datetimes(dict_obj: dict) -> dict

Convert datetime objects in a dictionary to ISO format strings.

Parameters:

Name Type Description Default
dict_obj dict

The dictionary to process.

required

Returns:

Type Description
dict

The processed dictionary with datetime objects converted to strings.

dict_to_key

dict_to_key(data: dict) -> str

Convert a dictionary to a hashable key string.

This function converts a dictionary uniquely to a string which can be used as a hashable key.

Parameters:

Name Type Description Default
data dict

The dictionary to convert.

required

Returns:

Type Description
str

A string representation of the sorted dictionary items.