OceanDB.ocean_data.ocean_data#

class OceanDB.ocean_data.ocean_data.ColumnField(export_name, python_type, postgres_table_name, postgres_column_name, postgres_type=None, netcdf_unique_name=None, process_from_netcdf=None)#

Bases: OceanDataField

A field retrieved directly from the column of a table.

Parameters:
from_netcdf(ds, rows)#

Read the value of this field from NetCDF

Parameters:
  • ds (Dataset) – NetCDF dataset to read

  • rows (slice) – Slice or index of rows to read

Return type:

ndarray[Any, dtype[Any]]

Returns:

The value corresponding to this field, as type OceanDataField.python_type

sql_expression()#
Return type:

Composable

Returns:

the SQL expression for this field without aliasing.

property netcdf_name: str#
netcdf_unique_name: str | None = None#

Name of the parameter when importing from netcdf. Defaults to same as postgres column name

postgres_column_name: str#

Name of the column containing this field in a database, i.e. name in:

SELECT field AS name FROM ... WHERE ...
                ^
postgres_table_name: str#

Name (or alias) of the source table for this column

postgres_type: str | None = None#

Postgres type of this column (UNUSED)

process_from_netcdf: Callable[[Any, slice], Any] | None = None#

When loading from netcdf, additional post-processing to perform

class OceanDB.ocean_data.ocean_data.DerivedField(export_name, python_type, expression, postgres_type=None)#

Bases: OceanDataField

Projection backed by a custom SQL expression.

Parameters:
sql_expression()#
Return type:

Composable

Returns:

the SQL expression for this field without aliasing.

expression: str#

Expression string for computing this field in postgres, e.g.:

EXTRACT(EPOCH FROM (%(central_date_time)s - along_track.date_time))
postgres_type: str | None = None#

Postgres type of this column (UNUSED)

class OceanDB.ocean_data.ocean_data.OceanDataField(export_name, python_type)#

Bases: ABC

The base dataclass for all ocean fields supported by this library.

Parameters:
  • name – See name

  • python_type (type | None) – See python_type

  • export_name (str)

from_sql_query(values)#

Convert to a NDArray[self.python_type] from a list of values.

Parameters:

values (list[Any]) – List of values to convert

Return type:

Any

Returns:

values, cast to a numpy array of the expected type.

abstractmethod sql_expression()#
Return type:

Composable

Returns:

the SQL expression for this field without aliasing.

to_sql_query()#
Return type:

Composed

Returns:

a SELECT expression for this field with a stable alias.

export_name: str#

Unique name for this field, used in exporting

python_type: type | None#

Numpy dtype to use when casting this field to a numpy array