DataSet

class unifhy.DataSet(files=None, name_mapping=None, select=None)

DataSet is a dictionary-like data structure which maps variable names to Variable objects.

Instantiation

Parameters
files: (sequence of) str, optional

A string or sequence of strings providing the netCDF file names or directory names containing netCDF files from which to read the variables.

Parameter example:

files='tests/data/sciencish_driving_data_daily.nc'

Parameter example:

files=['tests/data/sciencish_driving_data_daily.nc',
       'tests/data/sciencish_ancillary_data.nc']
select: (sequence of) str, optional

A string or sequence of strings providing the identities of the variables to read in the netCDF file. By default, all variables in the netCDF file are read.

Parameter example:

select=['rainfall_flux', 'snowfall_flux']
name_mapping: dict, optional

A dictionary with the Field identities as keys and the desired new name variables as values. If a Field is read from the netCDF file, and its identity is not a key in name_mapping (if provided), its ‘standard_name’ attribute is used instead.

Examples

>>> ds = DataSet()
>>> print(ds)
DataSet{ }
>>> ds = DataSet(
...     files='data/sciencish_driving_data_daily.nc'
... )
>>> print(ds)
DataSet{
    air_temperature(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K
    rainfall_flux(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) kg m-2 s-1
    snowfall_flux(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) kg m-2 s-1
    soil_temperature(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) K
}
>>> ds = DataSet(
...     files='data/sciencish_driving_data_daily.nc',
...     select=['rainfall_flux', 'snowfall_flux'],
...     name_mapping={'rainfall_flux': 'rainfall'}
... )
>>> print(ds)
DataSet{
    rainfall(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) kg m-2 s-1
    snowfall_flux(time(6), atmosphere_hybrid_height_coordinate(1), grid_latitude(10), grid_longitude(9)) kg m-2 s-1
}

Methods

load_from_file

Append to the DataSet the variables that are contained in the file(s) provided.