pywatershed.parameters.PrmsParameters#
- class pywatershed.parameters.PrmsParameters(dims=None, coords=None, data_vars=None, metadata=None, encoding=None, validate=True, copy=True)[source]#
A parameter class with methods for native PRMS files.
See also
- __init__(dims=None, coords=None, data_vars=None, metadata=None, encoding=None, validate=True, copy=True)[source]#
Methods
__init__
([dims, coords, data_vars, ...])drop_var
(var_names)Drop variables
from_dict
(dict_in[, copy])Return this class from a passed dictionary. :type dict_in: :param dict_in: a dictionary from which to create an instance of this class :type copy: :param copy: boolean if the passed dictionary should be deep copied.
from_ds
(ds)Get this class from a dataset (nc4 or xarray).
from_netcdf
(nc_file[, use_xr, encoding])Load this class from a netcdf file.
get_dim_values
([keys])Get the values of the dimensions by keys.
get_param_values
([keys])Get the values of the parameters (coords or data_vars) by keys
load
(parameter_file)Load parameters from a PRMS parameter file
load_from_json
(json_filename)Load parameters from a json file.
merge
(*args[, copy, del_global_src])Merge Parameter classes
parameters_to_json
(json_filename)write the parameters dictionary out to a json file
rename_dim
(name_maps[, in_place])Rename dimensions.
rename_var
(name_maps[, in_place])Rename variables.
subset
(keys[, copy, keep_global, ...])Subset a DatasetDict to keys in data_vars or coordinates
subset_on_coord
(coord_name, where)Subset DatasetDict to a np.where along a named coordinate in-place
to_dd
([copy])Export Parameters to a DatasetDict (for editing).
to_nc4_ds
(filename)Export Parameters to a netcdf4 dataset
to_netcdf
(filename[, use_xr])Write PrmsParameters to a netcdf file
to_xr_dd
()Export to an xarray DatasetDict (xr.Dataset.to_dict()).
to_xr_ds
()Export Parameters to an xarray dataset
validate
()Check that a DatasetDict is internally consistent.
Attributes
Return the coordinates
dims, coords, data_vars, metadata, encoding
Return the data_vars.
Get the dimensions from the parameters
Return the dimensions
Return the encoding
Return the metadata
Return the spatial coordinate names.
Return coords and data_vars together
- property data: dict#
dims, coords, data_vars, metadata, encoding
- Parameters:
copy – boolean if a deepcopy is desired
- Returns:
A dict of dicts containing all the data
- Type:
Return a dict of dicts
- property dimensions: dict#
Get the dimensions from the parameters
- Returns:
dimensions in the PRMS parameter dictionary
- drop_var(var_names)#
Drop variables
- classmethod from_dict(dict_in, copy=False)#
Return this class from a passed dictionary. :type dict_in: :param dict_in: a dictionary from which to create an instance of this
class
- Parameters:
copy – boolean if the passed dictionary should be deep copied
- Returns:
A object of this class.
- classmethod from_ds(ds)#
Get this class from a dataset (nc4 or xarray).
- classmethod from_netcdf(nc_file, use_xr=False, encoding=False)#
Load this class from a netcdf file.
- Return type:
- get_dim_values(keys=None)#
Get the values of the dimensions by keys.
- get_param_values(keys=None)#
Get the values of the parameters (coords or data_vars) by keys
- Also see:
subset() method is a Parameter object is desired.
- static load(parameter_file)[source]#
Load parameters from a PRMS parameter file
- Parameters:
- Return type:
- Returns:
PrmsParameters – full PRMS parameter dictionary
- static load_from_json(json_filename)[source]#
Load parameters from a json file. :type json_filename:
Union
[str
,Path
] :param json_filename: json file path- Return type:
- classmethod merge(*args, copy=True, del_global_src=True)#
Merge Parameter classes
- Parameters:
*args – several Parameters objects as individual objects.
copy – bool if the args should be copied?
del_golbal_src – bool delete the file source attribute to avoid meaningless merge conflicts?
- parameters_to_json(json_filename)[source]#
write the parameters dictionary out to a json file
- Return type:
- rename_dim(name_maps, in_place=True)#
Rename dimensions.
- rename_var(name_maps, in_place=True)#
Rename variables.
- property spatial_coord_names: dict#
Return the spatial coordinate names. :param None:
- Returns:
Dictionary of spatial coordinates with names.
- subset(keys, copy=False, keep_global=False, keep_global_metadata=None, keep_global_encoding=None, strict=False)#
Subset a DatasetDict to keys in data_vars or coordinates
- Parameters:
keys (
Iterable
) – Iterable to subset oncopy (
bool
) – bool to copy the input or edit itkeep_global (
bool
) – bool that sets both keep_global_metadata and keep_global_encodingkeep_global_metadata (
Optional
[bool
]) – bool retain the global metadata in the subsetkeep_global_encoding (
Optional
[bool
]) – bool retain the global encoding in the subset
- Return type:
- Returns:
A subset Parameter object on the passed keys.
- subset_on_coord(coord_name, where)#
Subset DatasetDict to a np.where along a named coordinate in-place
- to_dd(copy=True)#
Export Parameters to a DatasetDict (for editing).
Parameters can NOT be edited, but DatasetDicts can. To convert back
pws.Parameters(**dataset_dict.data)
.- Parameters:
copy – return a copy or a reference?
- Return type:
- to_nc4_ds(filename)#
Export Parameters to a netcdf4 dataset