Multivariate: fPCA

Import libraries

[1]:
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
import synthia as syn
import pyvinecopulib as pv
from multiprocessing import cpu_count

Define plotting function

[2]:
def plot_profiles(ds, var_name, n_profiles=100):
    _, ax = plt.subplots(figsize=(6, 4))
    for column in np.random.choice(ds.column, n_profiles):
        ds[var_name].sel(column=column).plot(ax=ax, c='#332288', alpha=0.15)
    ax.set_ylabel('Air temperature in K')
    ax.set_xlabel('Atmospheric level')

Plot source data

[3]:
ds_true = syn.util.load_dataset(name='SAF-Synthetic')
plot_profiles(ds_true, 'temperature_fl')
../_images/examples_fpca_6_0.png

Fit the fPCA model using 10 components

[4]:
generator = syn.FPCADataGenerator()
generator.fit(ds_true, n_fpca_components=10)

Generate same number of samples as in the input

[5]:
N_SAMPLES = 100
ds_synth = generator.generate(n_samples=N_SAMPLES)
ds_synth
[5]:
<xarray.Dataset>
Dimensions:         (column: 100, level: 137)
Dimensions without coordinates: column, level
Data variables:
    temperature_fl  (column, level) float32 176.6 188.8 198.1 ... 300.8 301.1

Plot the results

[6]:
plot_profiles(ds_synth, 'temperature_fl')
../_images/examples_fpca_12_0.png
[ ]: