osdyn.utils.data.select
Created on Mon Oct 26 21:10:23 2020
@author: valerie
Module Contents
Functions
|
|
|
Mask the elements satisfying the condition. |
|
Select the elements by masking all of those |
|
Apply the filter (defined by flag) on the variables specified in the |
|
Apply the filter (defined by flag) on the variables specified by varnames |
|
Return the command to be applied on a field |
|
Attributes
- osdyn.utils.data.select.modify_where(ds, varnames=None, flag={'POSITION_QC': {'test': '==', 'value': 1}, 'fromds': 'ds'}, outformat='list', **kwargs)[source]
- osdyn.utils.data.select.mask_where(ds, varnames=None, flag={'POSITION_QC': {'test': '==', 'value': 1}, 'fromds': 'ds'}, outformat='list', **kwargs)[source]
Mask the elements satisfying the condition.
As it uses select_where_mask_elsewhere function, the first step is to modify the condition to get its opposite
- Parameters
ds (xarray.Dataset, numpy.ndarray, numpy.array, list (of numpy.array)) – Dataset or arrays containing the fields to be modified.
varnames ([list of] str, optional) – Names of the variables of interest. The default is None, then all the variables of the dataset are treated.
flag (dict, optional) – {“VARNAME”: {“test”: “operator >, ==…”, “value”: X}}. The default is {“POSITION_QC”: {“test”: “==”, “value”: 1}, “fromds”: “ds”}.
outformat (str, optional) – ‘dataset’ or ‘list’. The default is ‘list’.
kwargs (index_condition_field in) – Location (from 0) of the field (in ds) used in the condition. Usefull when processing numpy arrays. The default is None.
- Returns
sel – that contains the masked variables according to the flag.
- Return type
dataset or list of arrays
- osdyn.utils.data.select.select_where_mask_elsewhere(ds, varnames=None, flag={'POSITION_QC': {'test': '==', 'value': 1}, 'fromds': 'ds'}, outformat='list', **kwargs)[source]
Select the elements by masking all of those which to not satisfy the condition.
- Parameters
ds (xarray.Dataset, numpy.ndarray, numpy.array, list (of numpy.array)) – Dataset or arrays containing the fields to be modified.
varnames ([list of] str, optional) – Names of the variables of interest. The default is None, then all the variables of the dataset are treated.
flag (dict, optional) – {“VARNAME”: {“test”: “operator >, ==…”, “value”: X}}. The default is {“POSITION_QC”: {“test”: “==”, “value”: 1}, “fromds”: “ds”}.
outformat (str, optional) – ‘dataset’ or ‘list’. The default is ‘list’.
kwargs (index_condition_field in) – Location (from 0) of the field (in ds) used in the condition. Usefull when processing numpy arrays. The default is None.
- Returns
sel – that contains the masked variables according to the flag.
- Return type
dataset or list of arrays
Todo
add argument ‘other’ (for modify_where function)
- osdyn.utils.data.select.select_where_mask_elsewhere_from_np(npa, flag={'automatic': {'test': '==', 'value': 1}}, index_condition_field=None, **kwargs)[source]
Apply the filter (defined by flag) on the variables specified in the first argument (npa) to keep values where the condition is satisfied (others are set to np.nan).
- Parameters
npa ([list of] np.ndarray) – Fields to be masked or modified.
flag (dict, optional) – for instance {“whatever”: {“test”: “>”, “value”: 111.}. The default is {“automatic”: {“test”: “==”, “value”: 1}}.
index_condition_field (int, optional) – Location (from 0) of the field (in npa) used in the condition. The default is None.
- Returns
sel – that contain the masked variables according to the flag.
- Return type
list of numpy arrays
- osdyn.utils.data.select.select_where_mask_elsewhere_from_ds(ds, varnames=None, flag={'POSITION_QC': {'test': '==', 'value': 1}}, outformat='list')[source]
Apply the filter (defined by flag) on the variables specified by varnames to keep values where the condition is satisfied (others are set to np.nan).
- Parameters
ds (xarray.Dataset) – Content of a dataset.
varnames ([list of] str, optional) – Names of the variables of interest. The default is None, then all the variables are treated.
flag (dict, optional) – {“VARNAME”: {“test”: “operator >, ==…”, “value”: X}}. The default is {“POSITION_QC”: {“test”: “==”, “value”: 1}, “fromds”: “ds”}.
outformat (str, optional) – ‘dataset’ or ‘list’. The default is ‘list’.
- Returns
sel – that contains the masked variables according to the flag.
- Return type
dataset, list
- osdyn.utils.data.select.flag2cmd(flag)[source]
Return the command to be applied on a field
- Parameters
flag (dict) –
dict like {‘POSITION_QC’: {“test”: “==”, “value”: 1}} or {‘POSITION_QC’: 1}
- Returns
comparison command to be applied on data.
- Return type
str
Examples
>>> flag2cmd({"POSITION_QC": {"test": "==", "value": 1}}) >>> flag2cmd({'POSITION_QC': 1, "fromds": "ds"})