scmdata.database.backends.netcdf

Database backend for handling local files stored as NetCDF

NetCDFDatabaseBackend

class NetCDFDatabaseBackend(**kwargs)[source]

Bases: BaseDatabaseBackend

Database backend for handling local files stored as NetCDF

delete(key)[source]

Delete a key

Parameters:

key (str) –

get(filters)[source]

Get all matching objects for a given filter

Parameters:

filters (dict of str) – String filters If a level is missing then all values are fetched

Returns:

list of str

get_key(sr)[source]

Get key where the data will be stored

The key is the root directory joined with the other information provided. The filepath is also cleaned to remove spaces and special characters.

Parameters:

sr (scmdata.ScmRun) – Data to save

Raises:
  • ValueError – If non-unique metadata is found for each of self.kwargs["levels"] If any metadata end with ‘.’

  • KeyError – If missing metadata is found for each of self.kwargs["levels"]

Returns:

str – Path in which to save the data without spaces or special characters

load(key)[source]

Load a run using a key

Parameters:

key (str) –

Returns:

scmdata.ScmRun

save(sr)[source]

Save a ScmRun to the database

The dataset should not contain any duplicate metadata for the database levels

Parameters:

sr (scmdata.ScmRun) – Data to save

Raises:
  • ValueError – If duplicate metadata are present for the requested database levels

  • KeyError – If metadata for the requested database levels are not found

Returns:

str – Key where the data is saved