sup3r.preprocessing.samplers.cc.DualSamplerCC#

class DualSamplerCC(data: Sup3rDataset, sample_shape: tuple | None = None, batch_size: int = 16, s_enhance: int = 1, t_enhance: int = 24, feature_sets: dict | None = None, mode: str = 'lazy')[source]#

Bases: DualSampler

Special sampling of WTK or NSRDB data for climate change applications

Note

This will always give daily / hourly data if t_enhance != 1. The number of days / hours in the samples is determined by t_enhance. For example, if t_enhance = 8 and sample_shape = (..., 24) there will be 3 days in the low res sample: lr_sample_shape = (…, 3). If 1 < t_enhance != 24 reduce_high_res_sub_daily() will be used to reduce a high res sample shape from (..., sample_shape[2] * 24 // t_enhance) to (..., sample_shape[2])

Parameters:
  • data (Sup3rDataset) – See DualSampler for full documentation.

  • sample_shape (tuple) – See DualSampler for full documentation.

  • s_enhance (int) – See DualSampler for full documentation.

  • t_enhance (int) – Temporal enhancement factor. Defaults to 24 for daily data.

  • feature_sets (Optional[dict]) – See DualSampler for full documentation.

  • mode (str) – See DualSampler for full documentation.

See also

DualSampler

Methods

check_feature_consistency()

Make sure features are consistent with the data and with each other.

check_proxy_obs_consistency()

Check that the obs features are configured correctly for proxy observations.

check_shape_consistency()

Make sure container shapes and sample shapes are compatible with enhancement factors.

derive(feature[, strict])

Resolve feature name to a feature in the underlying data.

get_middle_days(high_res, sample_shape)

Get middle chunk of high_res data that will then be reduced to day time steps.

get_sample_index([n_obs])

Get sample index for expanded hourly chunk which will be reduced to the given sample shape.

post_init_log([args_dict])

Log additional arguments after initialization.

preflight()

Perform shape and feature checks.

reduce_high_res_sub_daily(high_res[, csr_ind])

Take an hourly high-res observation and reduce the temporal axis down to lr_sample_shape[2] * t_enhance time steps, using only daylight hours on the middle part of the high res data.

wrap(data)

Return a Sup3rDataset object or tuple of such.

Attributes

timer

data

Return underlying data.

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.

hr_features

List of feature names or patt*erns that the model is shown at high-resolution.

hr_features_ind

Get the high-resolution feature channel indices that should be included for loss calculations.

hr_out_features

List of feature names or patt*erns that should be output by the generative model.

hr_sample_features

List of feature names used in the sample index for the high-resolution training data.

hr_sample_shape

Shape of the data sample to select when __next__() is called.

hr_source_features

Features available natively at high-resolution.

lr_features

List of feature names or patt*erns to use as low-resolution model inputs.

lr_features_ind

Get the low-resolution feature channel indices that should be included for training.

obs_features

List of feature names or patt*erns that should be treated as observations.

obs_features_ind

Get the source feature indices for each obs feature's corresponding base feature (e.g. u_100m for u_100m_obs).

real_obs_features

Obs features that actually exist in the data.

sample_shape

Shape of the data sample to select when __next__() is called.

shape

Get shape of underlying data.

use_proxy_obs

Whether to use proxy observations.

check_shape_consistency()[source]#

Make sure container shapes and sample shapes are compatible with enhancement factors.

reduce_high_res_sub_daily(high_res, csr_ind=0)[source]#

Take an hourly high-res observation and reduce the temporal axis down to lr_sample_shape[2] * t_enhance time steps, using only daylight hours on the middle part of the high res data.

Parameters:
  • high_res (Union[np.ndarray, da.core.Array]) – 5D array with dimensions (n_obs, spatial_1, spatial_2, temporal, n_features) where temporal >= 24 (set by the data handler).

  • csr_ind (int) – Feature index of clearsky_ratio. e.g. self.data[…, csr_ind] -> cs_ratio

Returns:

high_res (Union[np.ndarray, da.core.Array]) – 5D array with dimensions (n_obs, spatial_1, spatial_2, temporal, n_features) where temporal has been reduced down to the integer lr_sample_shape[2] * t_enhance. For example if hr_sample_shape[2] is 9 and t_enhance = 8, 72 hourly time steps will be reduced to 9 using the center daylight 9 hours from the second day.

Note

This only does something when 1 < t_enhance < 24. If t_enhance = 24 there is no need for reduction since every daily time step will have 24 hourly time steps in the high_res batch data. Of course, if t_enhance = 1, we are running for a spatial only model so this routine is unnecessary.

*Needs review from @grantbuster

static get_middle_days(high_res, sample_shape)[source]#

Get middle chunk of high_res data that will then be reduced to day time steps. This has n_time_steps = 24 if sample_shape[-1] <= 24 otherwise n_time_steps = sample_shape[-1].

get_sample_index(n_obs=None)[source]#

Get sample index for expanded hourly chunk which will be reduced to the given sample shape.

check_feature_consistency()#

Make sure features are consistent with the data and with each other.

check_proxy_obs_consistency()#

Check that the obs features are configured correctly for proxy observations.

property data#

Return underlying data.

Returns:

Sup3rDataset

See also

wrap()

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#

Features available natively at high-resolution.

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_100m for u_100m_obs). Used to extract gridded truth for proxy obs generation.

Returns:

list[int] – Indices into hr_sample_features for 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 sample_shape: tuple#

Shape of the data sample to select when __next__() is called.

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_features argument and should have a corresponding source feature in the data features that is used for sampling. For example, an obs feature named temperature_obs would be generated from the gridded ground truth feature named temperature.

wrap(data)#

Return a Sup3rDataset object or tuple of such. This is a tuple when the .data attribute belongs to a Collection object like BatchHandler. Otherwise this is Sup3rDataset object, which is either a wrapped 3-tuple, 2-tuple, or 1-tuple (e.g. len(data) == 3, len(data) == 2 or len(data) == 1). This is a 3-tuple when .data belongs to a container object like DualSamplerWithObs, a 2-tuple when .data belongs to a dual container object like DualSampler, and a 1-tuple otherwise.