sup3r.models.multi_step.SolarMultiStepGan#
- class SolarMultiStepGan(spatial_solar_models, spatial_wind_models, temporal_solar_models, t_enhance=None)[source]#
Bases:
MultiStepGan
Special multi step model for solar clearsky ratio super resolution.
This model takes in two parallel models for wind-only and solar-only spatial super resolutions, then combines them into a 3-channel high-spatial-resolution input (clearsky_ratio, u_200m, v_200m) for a solar temporal super resolution model.
- Parameters:
spatial_solar_models (MultiStepGan) – A loaded MultiStepGan object representing the one or more spatial super resolution steps in this composite MultiStepGan model that inputs and outputs clearsky_ratio
spatial_wind_models (MultiStepGan) – A loaded MultiStepGan object representing the one or more spatial super resolution steps in this composite MultiStepGan model that inputs and outputs wind u/v features and must include u_200m + v_200m as output features.
temporal_solar_models (MultiStepGan) – A loaded MultiStepGan object representing the one or more (spatio)temporal super resolution steps in this composite SolarMultiStepGan model. This is the final step in the custom solar downscaling methodology.
t_enhance (int | None) – Optional argument to fix or update the temporal enhancement of the model. This can be used to manipulate the output shape to match whatever padded shape the sup3r forward pass module expects. If this differs from the t_enhance value based on model layers the output will be padded so that the output shape matches low_res * t_enhance for the time dimension.
Methods
generate
(low_res[, norm_in, un_norm_out, ...])Use the generator model to generate high res data from low res input.
Compute factor by which model will enhance spatial resolution from layer attributes.
Compute factor by which model will enhance temporal resolution from layer attributes.
load
(spatial_solar_model_dirs, ...[, ...])Load the GANs with its sub-networks from a previously saved-to output directory.
Run some preflight checks to make sure the loaded models can work together.
save_params
(out_dir)seed
([s])Set the random seed for reproducible results.
set_model_params
(**kwargs)Set parameters used for training the model
temporal_pad
(low_res, hi_res[, mode])Optionally add temporal padding to the 5D generated output array
Attributes
Get list of high-resolution exogenous filter names the model uses.
Get the list of output feature names that the last solar spatiotemporal generative model in this SolarMultiStepGan outputs.
Get an array of feature indices for the subset of features required for the spatial_solar_models.
Get an array of feature indices for the subset of features required for the spatial_wind_models.
Get an array of spatial_wind_models output feature indices that are required for input to the temporal_solar_models.
Get dimension of model generator input.
Resolution of input data.
Check if model expects spatial only input
Check if model expects spatiotemporal input
Get a list of low-resolution features input to the generative model.
Get the data normalization mean values.
Get a tuple of meta data dictionaries for all models
Get a tuple of model parameters for all models
Get an ordered tuple of the Sup3rGan models that are part of this MultiStepGan
Resolution of output data.
Factor by which model will enhance spatial resolution.
List of spatial enhancement factors.
Get the list of smoothed input feature names that the generative model was trained on.
Value of smoothing parameter used in gaussian filtering of coarsened high res data.
Get the MultiStepGan object for the spatial-only solar model(s)
Get the MultiStepGan object for the spatial-only wind model(s)
Get the data normalization standard deviation values.
Factor by which model will enhance temporal resolution.
List of temporal enhancement factors.
Get the MultiStepGan object for the (spatio)temporal model(s)
Get a tuple of version records from all models
- property spatial_solar_models#
Get the MultiStepGan object for the spatial-only solar model(s)
- Returns:
MultiStepGan
- property spatial_wind_models#
Get the MultiStepGan object for the spatial-only wind model(s)
- Returns:
MultiStepGan
- property temporal_solar_models#
Get the MultiStepGan object for the (spatio)temporal model(s)
- Returns:
MultiStepGan
- property meta#
Get a tuple of meta data dictionaries for all models
- Returns:
tuple
- property lr_features#
Get a list of low-resolution features input to the generative model. This includes low-resolution features that might be supplied exogenously at inference time but that were in the low-res batches during training
- property hr_out_features#
Get the list of output feature names that the last solar spatiotemporal generative model in this SolarMultiStepGan outputs.
- property idf_wind#
Get an array of feature indices for the subset of features required for the spatial_wind_models. This excludes topography which is assumed to be provided as exogenous_data.
- property idf_wind_out#
Get an array of spatial_wind_models output feature indices that are required for input to the temporal_solar_models. Typically this is the indices of u_200m + v_200m from the output features of spatial_wind_models
- property idf_solar#
Get an array of feature indices for the subset of features required for the spatial_solar_models. This excludes topography which is assumed to be provided as exogenous_data.
- generate(low_res, norm_in=True, un_norm_out=True, exogenous_data=None)[source]#
Use the generator model to generate high res data from low res input. This is the public generate function.
- Parameters:
low_res (np.ndarray) – Low-resolution input data to the 1st step spatial GAN, which is a 4D array of shape: (temporal, spatial_1, spatial_2, n_features). This should include all of the
self.lr_features
which is a concatenation of both the solar and wind spatial model features. The topography feature might be removed from this input and present in the exogenous_data input.norm_in (bool) – Flag to normalize low_res input data if the self.means, self.stdevs attributes are available. The generator should always received normalized data with mean=0 stdev=1.
un_norm_out (bool) – Flag to un-normalize synthetically generated output data to physical units
exogenous_data (ExoData | dict) –
ExoData
object (or dict that will be cast to ExoData) with data arrays for each exogenous data step. Each array has 3D or 4D shape:(spatial_1, spatial_2, n_features) (temporal, spatial_1, spatial_2, n_features) It’s assumed that the spatial_solar_models do not require exogenous_data and only use clearsky_ratio.
- Returns:
hi_res (ndarray) – Synthetically generated high-resolution data output from the 2nd step (spatio)temporal GAN with a 5D array shape: (1, spatial_1, spatial_2, n_temporal, n_features)
- temporal_pad(low_res, hi_res, mode='reflect')[source]#
Optionally add temporal padding to the 5D generated output array
- Parameters:
low_res (np.ndarray) – Low-resolution input data to the 1st step spatial GAN, which is a 4D array of shape: (temporal, spatial_1, spatial_2, n_features).
hi_res (ndarray) – Synthetically generated high-resolution data output from the 2nd step (spatio)temporal GAN with a 5D array shape: (1, spatial_1, spatial_2, n_temporal, n_features)
mode (str) – Padding mode for np.pad()
- Returns:
hi_res (ndarray) – Synthetically generated high-resolution data output from the 2nd step (spatio)temporal GAN with a 5D array shape: (1, spatial_1, spatial_2, n_temporal, n_features) With the temporal axis padded with self._temporal_pad on either side.
- classmethod load(spatial_solar_model_dirs, spatial_wind_model_dirs, temporal_solar_model_dirs, t_enhance=None, verbose=True)[source]#
Load the GANs with its sub-networks from a previously saved-to output directory.
- Parameters:
spatial_solar_model_dirs (str | list | tuple) – An ordered list/tuple of one or more directories containing trained + saved Sup3rGan models created using the Sup3rGan.save() method. This must contain only spatial solar models that input/output 4D tensors.
spatial_wind_model_dirs (str | list | tuple) – An ordered list/tuple of one or more directories containing trained + saved Sup3rGan models created using the Sup3rGan.save() method. This must contain only spatial wind models that input/output 4D tensors.
temporal_solar_model_dirs (str | list | tuple) – An ordered list/tuple of one or more directories containing trained + saved Sup3rGan models created using the Sup3rGan.save() method. This must contain only (spatio)temporal solar models that input/output 5D tensors that are the concatenated output of the spatial_solar_models and the spatial_wind_models.
t_enhance (int | None) – Optional argument to fix or update the temporal enhancement of the model. This can be used to manipulate the output shape to match whatever padded shape the sup3r forward pass module expects. If this differs from the t_enhance value based on model layers the output will be padded so that the output shape matches low_res * t_enhance for the time dimension.
verbose (bool) – Flag to log information about the loaded model.
- Returns:
out (SolarMultiStepGan) – Returns a pretrained gan model that was previously saved to model_dirs
- get_s_enhance_from_layers()#
Compute factor by which model will enhance spatial resolution from layer attributes. Used in model training during high res coarsening
- get_t_enhance_from_layers()#
Compute factor by which model will enhance temporal resolution from layer attributes. Used in model training during high res coarsening
- property hr_exo_features#
Get list of high-resolution exogenous filter names the model uses. For the multi-step model, each entry in this list corresponds to one of the single-step models and is itself a list of hr_exo_features for that model.
- property input_dims#
Get dimension of model generator input. This is usually 4D for spatial models and 5D for spatiotemporal models. This gives the input to the first step if the model is multi-step. Returns 5 for linear models.
- Returns:
int
- property input_resolution#
Resolution of input data. Given as a dictionary
{'spatial': '...km', 'temporal': '...min'}
. The numbers are required to be integers in the units specified. The units are not strict as long as the resolution of the exogenous data, when extracting exogenous data, is specified in the same units.
- property is_4d#
Check if model expects spatial only input
- property is_5d#
Check if model expects spatiotemporal input
- property means#
Get the data normalization mean values. This is a tuple of means from all models.
- Returns:
tuple | np.ndarray
- property model_params#
Get a tuple of model parameters for all models
- Returns:
tuple
- property models#
Get an ordered tuple of the Sup3rGan models that are part of this MultiStepGan
- property output_resolution#
Resolution of output data. Given as a dictionary {‘spatial’: ‘…km’, ‘temporal’: ‘…min’}. This is computed from the input resolution and the enhancement factors.
- property s_enhance#
Factor by which model will enhance spatial resolution. Used in model training during high res coarsening and also in forward pass routine to determine shape of needed exogenous data
- property s_enhancements#
List of spatial enhancement factors. In the case of a single step model this is just
[self.s_enhance]
. This is used to determine shapes of needed exogenous data in forward pass routine
- save_params(out_dir)#
- Parameters:
out_dir (str) – Directory to save linear model params. This directory will be created if it does not already exist.
- static seed(s=0)#
Set the random seed for reproducible results.
- Parameters:
s (int) – Random seed
- set_model_params(**kwargs)#
Set parameters used for training the model
- Parameters:
kwargs (dict) – Keyword arguments including ‘input_resolution’, ‘lr_features’, ‘hr_exo_features’, ‘hr_out_features’, ‘smoothed_features’, ‘s_enhance’, ‘t_enhance’, ‘smoothing’
- property smoothed_features#
Get the list of smoothed input feature names that the generative model was trained on.
- property smoothing#
Value of smoothing parameter used in gaussian filtering of coarsened high res data.
- property stdevs#
Get the data normalization standard deviation values. This is a tuple of stdevs from all models.
- Returns:
tuple | np.ndarray
- property t_enhance#
Factor by which model will enhance temporal resolution. Used in model training during high res coarsening and also in forward pass routine to determine shape of needed exogenous data
- property t_enhancements#
List of temporal enhancement factors. In the case of a single step model this is just
[self.t_enhance]
. This is used to determine shapes of needed exogenous data in forward pass routine
- property version_record#
Get a tuple of version records from all models
- Returns:
tuple