sup3r.models.linear.LinearInterp#

class LinearInterp(lr_features, s_enhance, t_enhance, t_centered=False, input_resolution=None)[source]#

Bases: AbstractInterface

Simple model to do linear interpolation on the spatial and temporal axes

Parameters:
  • lr_features (list) – List of feature names that this model will operate on for both input and output. This must match the feature axis ordering in the array input to generate().

  • s_enhance (int) – Integer factor by which the spatial axes is to be enhanced.

  • t_enhance (int) – Integer factor by which the temporal axes is to be enhanced.

  • t_centered (bool) – Flag to switch time axis from time-beginning (Default, e.g. interpolate 00:00 01:00 to 00:00 00:30 01:00 01:30) to time-centered (e.g. interp 01:00 02:00 to 00:45 01:15 01:45 02:15)

  • input_resolution (dict | None) – Resolution of the input data. e.g. {‘spatial’: ‘30km’, ‘temporal’: ‘60min’}. This is used to determine how to aggregate high-resolution topography data.

Methods

generate(low_res[, norm_in, un_norm_out, ...])

Use the generator model to generate high res data from low res input.

get_s_enhance_from_layers()

Compute factor by which model will enhance spatial resolution from layer attributes.

get_t_enhance_from_layers()

Compute factor by which model will enhance temporal resolution from layer attributes.

load(model_dir[, verbose])

Load the LinearInterp model with its params saved to the model_dir created with LinearInterp.save(model_dir)

save(out_dir)

save_params(out_dir)

seed([s])

Set the random seed for reproducible results.

set_model_params(**kwargs)

Set parameters used for training the model

Attributes

hr_exo_features

Returns an empty list for LinearInterp model

hr_out_features

Get the list of output feature names that the generative model outputs

input_dims

Get dimension of model generator input.

input_resolution

Resolution of input data.

is_4d

Check if model expects spatial only input

is_5d

Check if model expects spatiotemporal input

lr_features

Get the list of input feature names that the generative model was trained on.

meta

Get meta data dictionary that defines the model params

model_params

Model parameters, used to save model to disc

output_resolution

Resolution of output data.

s_enhance

Factor by which model will enhance spatial resolution.

s_enhancements

List of spatial enhancement factors.

smoothed_features

Get the list of smoothed input feature names that the generative model was trained on.

smoothing

Value of smoothing parameter used in gaussian filtering of coarsened high res data.

t_enhance

Factor by which model will enhance temporal resolution.

t_enhancements

List of temporal enhancement factors.

version_record

A record of important versions that this model was built with.

classmethod load(model_dir, verbose=False)[source]#

Load the LinearInterp model with its params saved to the model_dir created with LinearInterp.save(model_dir)

Parameters:
  • model_dir (str) – Directory to load LinearInterp model files from. Must have a model_params.json file containing “meta” key with all of the class init args.

  • verbose (bool) – Flag to log information about the loaded model.

Returns:

out (LinearInterp) – Returns an initialized LinearInterp model

property meta#

Get meta data dictionary that defines the model params

property lr_features#

Get the list of input feature names that the generative model was trained on.

property hr_out_features#

Get the list of output feature names that the generative model outputs

property hr_exo_features#

Returns an empty list for LinearInterp model

save(out_dir)[source]#
Parameters:

out_dir (str) – Directory to save linear model params. This directory will be created if it does not already exist.

generate(low_res, norm_in=False, un_norm_out=False, 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 spatiotemporal input data, a 5D array of shape: (n_obs, spatial_1, spatial_2, temporal, n_features)

  • norm_in (bool) – This doesnt do anything for this LinearInterp, but is kept to keep the same interface as Sup3rGan

  • un_norm_out (bool) – This doesnt do anything for this LinearInterp, but is kept to keep the same interface as Sup3rGan

  • exogenous_data (list) – This doesnt do anything for this LinearInterp, but is kept to keep the same interface as Sup3rGan

Returns:

hi_res (ndarray) – high-resolution spatial output data, a 5D array of shape: (n_obs, spatial_1, spatial_2, temporal, n_features)

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 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 model_params#

Model parameters, used to save model to disc

Returns:

dict

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 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#

A record of important versions that this model was built with.

Returns:

dict