openghg_inversions.postprocessing.utils#
- openghg_inversions.postprocessing.utils.add_suffix(suffix: str)#
Decorator to add suffix to variable names of dataset returned by decorated function.
For example:
@add_suffix("abc") def some_func(): ...
will add “_abc” to the end of all the data variables in the dataset returned by some_func. (So this only works if the output of some_func is an xr.Dataset or xr.DataArray.)
Note: technically, add_suffix creates a new decorator each time it is called. This is the decorate function that is returned. Then the actual “decoration” is done by the decorate function.
So:
@add_suffix("mean") def calc_mean(): pass
is the same as:
temp = add_suffix("mean") # get `decorate` @temp def calc_mean(): pass
- Parameters:
suffix – Suffix to add to variable names.
- openghg_inversions.postprocessing.utils.get_parameters(func: Callable) list[str]#
Return list of parameters for a function.
- Parameters:
func – function to inspect
- Returns:
list of parameters for the given function
- openghg_inversions.postprocessing.utils.make_replace_names_dict(names: list[str], old: str, new: str) dict[str, str]#
Make dictionary for renaming data variables by replacing “old” with “new”.
- Parameters:
names – list of data variable names to update
old – old string to replace
new – replacement string for old
- Returns:
dictionary mapping old names to new names
- openghg_inversions.postprocessing.utils.rename_by_replacement(ds: Dataset, old: str, new: str) Dataset#
Rename data variables by replacing “old” with “new”.
If the string old is contained in a data variable’s name, it is replaced with new.
- Parameters:
ds – dataset whose data variables will be renamed
old – string to replace
new – replacement string
- Returns:
dataset with renamed data variables
- openghg_inversions.postprocessing.utils.update_attrs(prefix: str)#
Decorator to update all attributes of output dataset with prefix.
- Parameters:
prefix – prefix to append to attributes; an underscore will be inserted after this prefix.
- Raises:
ValueError – if the decorated function does not return xr.Dataset