postgkyl.mask¶
- postgkyl.mask(data, mask_data=None, *, lower=None, upper=None, inplace=False, tag=None, label=None)¶
Mask out values using a mask dataset or numeric thresholds.
Returns a dataset whose values are a
numpy.mamasked array. Exactly one of the masking modes is applied, withmask_datataking precedence:mask_data: mask cells where the mask dataset’s field is negative, repeated acrossdata’s components. Load the mask field yourself (e.g.pg.load(mask_path)) – this verb takes data, never a file path (operationsnever touchesio).lowerandupper: mask values outside the closed range[lower, upper].loweronly: mask values belowlower.upperonly: mask values aboveupper.
- Parameters:
data – the dataset to mask; must contain point values.
mask_data – an already-loaded dataset whose field selects the mask (negative -> masked); it must have exactly one component – the mask is broadcast across every component of
datavianp.repeat(mask_data.values, data.num_comps, axis=-1), which only produces a shape matchingdata.valueswhenmask_datais single-component. A multi-componentmask_dataraises from the subsequentnp.ma.masked_wherebroadcast, not from an explicit check here.lower – lower threshold. Combined with
uppermasks outside the range; alone masks values below it.upper – upper threshold. Combined with
lowermasks outside the range; alone masks values above it.inplace – mutate and return
datainstead of a new dataset.tag – optional tag for the returned dataset.
label – optional label for the returned dataset.
- Returns:
A dataset whose values are a masked array.
- Raises:
ValueError – if
datais unevaluated modal coefficients, or if none ofmask_data,lower, orupperis provided.IndexError – if
mask_datahas more than one component – the repeated mask no longer matchesdata.values’s shape andnp.ma.masked_whererejects the mismatched condition array.