sup3r.preprocessing.samplers.dc.SamplerDC#
- class SamplerDC(data: Sup3rX | Sup3rDataset, sample_shape: tuple | None = None, batch_size: int = 16, feature_sets: dict | None = None, mode: str = 'lazy', spatial_weights: ndarray | Array | list | None = None, temporal_weights: ndarray | Array | list | None = None)[source]#
Bases:
SamplerDataCentric Sampler class used for sampling based on weights which can be updated during training.
- Parameters:
data (Union[Sup3rX, Sup3rDataset],) – See
Samplerfor full documentation.sample_shape (tuple) – See
Samplerfor full documentation.batch_size (int) – See
Samplerfor full documentation.feature_sets (Optional[dict]) – See
Samplerfor full documentation.mode (str) – See
Samplerfor full documentation.spatial_weights (Union[np.ndarray, da.core.Array] | List | None) – Set of weights used to initialize the spatial sampling. e.g. If we want to start off sampling across 2 spatial bins evenly this should be [0.5, 0.5]. During training these weights will be updated based only performance across the bins associated with these weights.
temporal_weights (Union[np.ndarray, da.core.Array] | List | None) – Set of weights used to initialize the temporal sampling. e.g. If we want to start off sampling only the first season of the year this should be [1, 0, 0, 0]. During training these weights will be updated based only performance across the bins associated with these weights.
Methods
Check that the feature sets are consistent with each other and the obs features are configured correctly.
Check that the obs features are configured correctly for proxy observations.
derive(feature[, strict])Resolve feature name to a feature in the underlying data.
get_sample_index([n_obs])Randomly gets weighted spatial sample and time sample indices
post_init_log([args_dict])Log additional arguments after initialization.
Perform shape and feature checks.
update_weights(spatial_weights, temporal_weights)Update spatial and temporal sampling weights.
wrap(data)Return a
Sup3rDatasetobject or tuple of such.Attributes
timerReturn underlying data.
Get a list of exogenous high-resolution features that are only used for training e.g., mid-network high-res topo injection.
List of feature names or patt*erns that the model is shown at high-resolution.
Get the high-resolution feature channel indices that should be included for loss calculations.
List of feature names or patt*erns that should be output by the generative model.
List of feature names used in the sample index for the high-resolution training data.
Shape of the data sample to select when __next__() is called.
List of feature names or patt*erns that should be available natively as high-resolution.
List of feature names or patt*erns to use as low-resolution model inputs.
Get the low-resolution feature channel indices that should be included for training.
List of feature names or patt*erns that should be treated as observations.
Get the source feature indices for each obs feature's corresponding base feature (e.g.
u_100mforu_100m_obs).Obs features that actually exist in the data.
Shape of the data sample to select when
__next__()is called.Get shape of underlying data.
Whether to use proxy observations.
- update_weights(spatial_weights, temporal_weights)[source]#
Update spatial and temporal sampling weights.
- get_sample_index(n_obs=None)[source]#
Randomly gets weighted spatial sample and time sample indices
- Returns:
observation_index (tuple) – Tuple of sampled spatial grid, time slice, and features indices. Used to get single observation like self.data[observation_index]
- check_feature_consistency()#
Check that the feature sets are consistent with each other and the obs features are configured correctly.
- check_proxy_obs_consistency()#
Check that the obs features are configured correctly for proxy observations.
- property data#
Return underlying data.
- Returns:
See also
- derive(feature, strict=True)#
Resolve feature name to a feature in the underlying data. This is used for handling feature aliases and for deriving new features from existing ones.
- property hr_exo_features#
Get a list of exogenous high-resolution features that are only used for training e.g., mid-network high-res topo injection. These must come at the end of the high-res feature set. These can also be input to the model as low-res features.
- property hr_features#
List of feature names or patt*erns that the model is shown at high-resolution. This does not include features that are only shown to the model after coarsening. Thus, this includes hr_out_features and and hr_exo_features but not lr_features.
- property hr_features_ind#
Get the high-resolution feature channel indices that should be included for loss calculations. This includes hr_out_features and hr_exo_features, Any high-resolution features that are only included in the data handler to be coarsened for the low-res input are removed.
- property hr_out_features#
List of feature names or patt*erns that should be output by the generative model. If no entry is provided then all features in hr_features will be used.
- property hr_sample_features#
List of feature names used in the sample index for the high-resolution training data. When using proxy obs, obs features that are not present in the raw data are excluded from sampling (they will be generated as proxy obs). Obs features that ARE in the data are included so they get sampled.
- property hr_sample_shape: tuple#
Shape of the data sample to select when __next__() is called. Same as sample_shape
- property hr_source_features#
List of feature names or patt*erns that should be available natively as high-resolution. For a non-dual sampler this is all features, since even features only provided to the model as low-resolution still need to be coarsened from the high-resolution data. This is in contrast to dual samplers (
DualSampler), where there are separate high-resolution and low-resolution data members.
- property lr_features#
List of feature names or patt*erns to use as low-resolution model inputs. If no entry is provided then all available features from the data will be used.
- property lr_features_ind#
Get the low-resolution feature channel indices that should be included for training. This includes lr_features.
- property obs_features#
List of feature names or patt*erns that should be treated as observations. These features will be included in the high-res data but not the low-res data and won’t necessarily be expected to be output by the generative model. These are different from other hr_exo_features in that they are intended to be used as observation features with NaN values where observations are not available.
- property obs_features_ind#
Get the source feature indices for each obs feature’s corresponding base feature (e.g.
u_100mforu_100m_obs). Used to extract gridded truth for proxy obs generation.- Returns:
list[int] – Indices into
hr_sample_featuresfor each obs base feature.
- post_init_log(args_dict=None)#
Log additional arguments after initialization.
- preflight()#
Perform shape and feature checks.
- property real_obs_features#
Obs features that actually exist in the data. In contrast to proxy obs, which are generated by masking the gridded data, these features are present in the raw data and are sampled directly. These are a subset of obs_features.
- property shape#
Get shape of underlying data.
- property use_proxy_obs#
Whether to use proxy observations. When True, proxy observation features are generated by masking the corresponding gridded ground truth data and are appended to the samples. The obs features are specified by the
obs_featuresargument and should have a corresponding source feature in the data features that is used for sampling. For example, an obs feature namedtemperature_obswould be generated from the gridded ground truth feature namedtemperature.
- wrap(data)#
Return a
Sup3rDatasetobject or tuple of such. This is a tuple when the.dataattribute belongs to aCollectionobject likeBatchHandler. Otherwise this isSup3rDatasetobject, which is either a wrapped 3-tuple, 2-tuple, or 1-tuple (e.g.len(data) == 3,len(data) == 2orlen(data) == 1). This is a 3-tuple when.databelongs to a container object likeDualSamplerWithObs, a 2-tuple when.databelongs to a dual container object likeDualSampler, and a 1-tuple otherwise.