pocean package

Subpackages

Submodules

pocean.cf module

class pocean.cf.CFDataset

Bases: EnhancedDataset

ancillary_vars()
axes(name)
data_vars()
default_fill_value = -9999.9
default_time_unit = 'seconds since 1990-01-01 00:00:00Z'
is_valid(*args, **kwargs)
classmethod load(path)

Attempt to load a netCDF file as a CF compatible dataset

Extended description of function.

Parameters:

path – Path to netCDF file

Return type:

CFDataset subclass for your netCDF file

Raises:

ValueError: – If no suitable class is found for your dataset

nc_attributes()
t_axes()
x_axes()
CF X axis will have one of the following:
  • The axis property has the value 'X'

  • Units of longitude (see cf.Units.islongitude for details)

  • The standard_name property is one of 'longitude', 'projection_x_coordinate' or 'grid_longitude'

y_axes()
z_axes()
pocean.cf.cf_safe_name(name)

pocean.dataset module

class pocean.dataset.EnhancedDataset

Bases: Dataset

apply_json(meta, create_vars=True, create_dims=True, create_data=True)

Apply a meta interface object to a netCDF4 compatible object

apply_meta(*args, **kwargs)

Shortcut to the JSON object without writing any data

close()

`close(self)`

Close the Dataset.

filter_by_attrs(*args, **kwargs)
json(return_data=True, fill_data=True)
json_attributes(vfuncs=None)

vfuncs can be any callable that accepts a single argument, the Variable object, and returns a dictionary of new attributes to set. These will overwrite existing attributes

meta(*args, **kwargs)

Shortcut to the JSON object without any data

to_json(*args, **kwargs)
update_attributes(attributes)
vatts(vname)

pocean.meta module

class pocean.meta.MetaInterface(*args, **kwargs)

Bases: Mapping

VALID_KEYS = ['dimensions', 'variables', 'attributes']
classmethod from_jsonfile(jsf)
classmethod from_jsonstr(js)
pocean.meta.ncpyattributes(obj, verbose=True)

Converts any attributes that are not native python types to those types

pocean.meta.safe_attribute_typing(zdtype, value)
pocean.meta.string_to_dtype(type_str)
pocean.meta.untype_attributes(vd)

pocean.utils module

class pocean.utils.JSONEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=False, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, item_sort_key=None, for_json=False, ignore_nan=False, int_as_string_bitcount=None, iterable_as_array=False)

Bases: JSONEncoder

default(obj)

If input object is an ndarray it will be converted into a list

pocean.utils.all_subclasses(cls, skips=None)

Recursively generate of all the subclasses of class cls.

pocean.utils.create_ncvar_from_series(ncd, var_name, dimensions, series, **kwargs)
pocean.utils.dict_update(d, u)
pocean.utils.downcast_dataframe(df)
pocean.utils.generic_masked(arr, attrs=None, minv=None, maxv=None, mask_nan=True)

Returns a masked array with anything outside of values masked. The minv and maxv parameters take precedence over any dict values. The valid_range attribute takes precedence over the valid_min and valid_max attributes.

pocean.utils.get_default_axes(axes=None)
pocean.utils.get_dtype(obj)
pocean.utils.get_fill_value(var)
pocean.utils.get_mapped_axes_variables(ncd, axes=None, skip=None)
pocean.utils.get_masked_datetime_array(t, tvar, mask_nan=True)
pocean.utils.get_ncdata_from_series(series, ncvar, fillna=True)
pocean.utils.is_url(url)
pocean.utils.namedtuple_with_defaults(typename, field_names, default_values=())
pocean.utils.nativize_times(df)
pocean.utils.normalize_array(var)

Returns a normalized data array from a NetCDF4 variable. This is mostly used to normalize string types between py2 and py3 as well as netcdf3 and netcdf4. It has no effect on types other than chars/strings

pocean.utils.normalize_countable_array(cvar, count_if_none=None)
pocean.utils.pyscalar(val)
pocean.utils.safe_attribute_typing(zdtype, value)
pocean.utils.safe_issubdtype(source, goal)
pocean.utils.unique_justseen(iterable, key=None)

List unique elements, preserving order. Remember only the element just seen.