va_am.utils package#

Submodules#

va_am.utils.AutoEncoders module#

sampling(args)[source]#

Auxiliar function to perform the VAE sampling

Parameters:

args (list of keras.layer) – A list wich contains the mean layer, standard deviation layer and de dimension of the latent space.

Returns:

The sampled latent space of the VAE.

Return type:

keras.layer

masking(args)[source]#

Auxiliar function to apply a spacial mask to a layer

Parameters:

args (list of keras.layer) – A list wich contains the layer to be masked and the mask to be used.

Returns:

The input layer masked by mask.

Return type:

keras.layer

masking2(args)[source]#

Auxiliar function to apply a spacial conditional mask to a layer

Parameters:

args (list of keras.layer) – A list wich contains the layer to be masked and the mask to be used.

Returns:

The input layer masked by mask.

Return type:

keras.layer

class AE_conv(input_dim, latent_dim, arch=4, in_channels=1, out_channels=1, VAE=False, mask=None)[source]#

Bases: object

Class of AutoEncoders

Parameters:
  • input_dim (list or ndarray) – A 2-array with the dimensions of the image.

  • latent_dim (int) – The dimension of the latent (coded) space.

  • arch (int) – The architecture of AutoEncoder to be used. The default is the arch=4.

  • in_channels (int) – Input channels to be used. That is, if you are using a RGB image as input, it has 3 input channels. Also, if you use a ndarray with differents variables (wind, temperature, pressure, etc.), you could use each variable as a channel.

  • out_channels (int) – Output channels to be computed. In the example of a RBG image as input, you can generate a RGB image (3 output channels) or a gray-scale image (1 output channel).

Returns:

After initialization, it generates an object with the AutoEncoder architecture and methods

Return type:

AE_conv

def_arch_build()[source]#

Easy example of architecture definition. Input have to be divisible by 18 in both dimensions (latitude, longitude).

simple_arch_build()[source]#

A very short architecture. Input have to be divisible by 18 in both dimensions (latitude, longitude).

batched_simetric_build()[source]#

Simetric architecture with batch normalization. Input have to be divisible by 16 in both dimensions (latitude, longitude).

kl_heatwave_arch_build()[source]#

Example of architecture for HW with KL-loss function. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

heatwave_arch_build()[source]#

Example of architecture for HW. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

mask_heatwave_arch_build()[source]#

Example of architecture for HW with masked input. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

simple_heatwave_arch_build()[source]#

Simplified architecture for HW. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

dense_build()[source]#

Example of full-dense architecture.

ae_arch_build()[source]#

Example of Autoencoder architecture for HW. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

ae_relu_arch_build()[source]#

Example of AE architecture for HW with relu activation function. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

mask_ae_relu_arch_build()[source]#

Example of AE architecture for HW with relu and spatial mask. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

very_simple_arch_build()[source]#

Simplified architecture of AE with relu. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

sparse_arch_build()[source]#

Example of Sparse Autoencoder architecture. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

keras_vae_build()[source]#

Keras example architecture. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

vae_relu_arch_build()[source]#

VAE architecture with relu activation function. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

ae_relu_arch_build2()[source]#

Example of AE architecture with relu and BatchNormalization. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

cvae_arch_build()[source]#

VAE architecture with relu activation function. Input have to be divisible by (4,6) respectivelly in dimensions (latitude, longitude).

compile(**kwargs)[source]#

Compilation of the AutoEncoder. Here we specify the method to optimize, the loss function and, if we want, some metrics to show together with the loss.

Parameters:

**kwargs (dict) – all available parameters for fit method at the keras/tensorflow version. If not specified, the default paramaters are optimizer=Adam, loss=mse, metrics=[mae, mape].

Return type:

No output, only compile the model.

fit(x, y, epochs=100, verbose=1, min_delta=3e-06, patience=10, restore_best_weights=True, mask=None, **kwargs)[source]#

Training of the AutoEncoder. Here we specify the parameters for our training.

Parameters:
  • x – input data.

  • y – output data (data to be compared and trained).

  • epochs (int) – number of epochs to train the model.

  • verbose ('auto', 0, 1 or 2.) – differents modes of verbosity when the model is trained.

  • min_delta (int or float) – minimum change in the monitored quantity to qualify as an improvement.

  • patience (int) – number of epochs with no improvement adter wich training will be stoped.

  • restore_best_weigths (bool) – whether to restore model weights from the epoch with the best value of the monitoredquantity

  • **kwargs (dict) – all available parameters for fit method at the keras/tensorflow version, except verbose and epochs

Returns:

  • History

  • A History object. See History.history.

va_am.utils.functions module#

hw_pctl(data: xr.Dataset, years: list[str], pctl: Union[int, float] = 90, window_size: int = 15) xr.Dataset[source]#

This function calculates the heatwave percentile threshold for a given dataset, years and pctl.

Parameters:
  • data (xr.Dataset.) – Temperature Dataset where the percentile threshold should be performed (usually t2m temperature).

  • years (str.) – Period to perform the percentile threshold, given the start and end year (usually [1981, 2010]).

  • pctl (int or float.) – Value (integer or float) wich defines the percentile to perform (default 90).

  • window_size (int) – Size of the rolling window.

Returns:

pctl_th_ds – A xr.Dataset with the percentile threshold (called pctl_th as variable) for the given period.

Return type:

xr.Dataset.

isHW_in_ds(data: Dataset, pctl_th: Dataset, var_name: str = 't2m_dailyMax') Dataset[source]#

This function add a new variable to the dataset with the boolean values of the heatwave index.

Parameters:
  • data (xr.Dataset.) – Temperature Dataset where the identification of HW is performed (usually t2m temperature).

  • pctl_th (xr.Dataset.) – Dataset with the corresponding threshold, based on percentile, that identifies the HW.

Returns:

data – A xr.Dataset with the boolean value (called isHW) thath indicate if HW does or does not exist.

Return type:

xr.Dataset.

Module contents#