pyku.downscale#

Downscaling library

class pyku.downscale.Downscaler[source]#

Bases: object

Parent class for downscalers.

The purpose of this class is to gather high-level optimized functions.

groupby_fit_predict(lowres, groupby_type='time.month', progress=False)[source]#

Group, fit and predict

Parameters:
  • ds (xarray.Dataset) – Dataset to downscale.

  • groupby_type (string) – Data grouping. The correction is applied independently to each group. The value of the groupby_type is expected to be ‘time.month’, but could also be set to ‘time.season’

groupby_fit_predict_all_variables(lowres, groupby_type='time.month', progress=False)[source]#

Group, fit and predict

Parameters:
  • ds (xarray.Dataset) – Dataset to downscale.

  • groupby_type (string) – Data grouping. The correction is applied independently to each group. The value of the groupby_type is expected to be ‘time.month’, but could also be set to ‘time.season’

class pyku.downscale.PCA(da, npcs)[source]#

Bases: object

Principal components analysis (PCA) This class is deprecated but kept for now

fit()[source]#

Fit with principal component analysis (PCA)

transform(da)[source]#
Returns:

Transformed data with size

(npcs x ny x nx)

Return type:

xarray.Dataset

class pyku.downscale.SVD(high_res, low_res, max_nsvs=None)[source]#

Bases: object

Singular Value Decomposition (SVD)

eigenvectors()[source]#

Get eigenvectors of the singular value decomposition (SVD)

Returns:

Tuple[xarray.Dataset]. The eigenvectors. One in low

resolution, one in high resolution.

fit()[source]#

Fit with singular value decomposition (SVD)

predict(data)[source]#

Predict with singular value decomposition (SVD)

Parameters:

data (numpy.ndarray) – data to be recomposed with size (ntimes x nsamples).

Returns:

predicted values with shape

(ntimes x nsamples)

Return type:

numpy.ndarray

Notes

Practically the data input have shapes (ntimes x ny*nx) or (ntimes x nvars*ny*nx)

class pyku.downscale.SVDDownscaler(high_res, low_res, max_nsvs)[source]#

Bases: Downscaler

Downscaler with singular value decomposition (SVD).

Note

Using a multivariable SVD was tried. It kinda worked but results were not convincing and was henced removed. The code can still be found in the old clutils repository.

eigenvectors()[source]#

Eigenvectors

Returns:

xarray.Dataset containing the eigenvectors

fit()[source]#

Fit

groupby_fit_predict(lowres, groupby_type='time.month', progress=False)#

Group, fit and predict

Parameters:
  • ds (xarray.Dataset) – Dataset to downscale.

  • groupby_type (string) – Data grouping. The correction is applied independently to each group. The value of the groupby_type is expected to be ‘time.month’, but could also be set to ‘time.season’

groupby_fit_predict_all_variables(lowres, groupby_type='time.month', progress=False)#

Group, fit and predict

Parameters:
  • ds (xarray.Dataset) – Dataset to downscale.

  • groupby_type (string) – Data grouping. The correction is applied independently to each group. The value of the groupby_type is expected to be ‘time.month’, but could also be set to ‘time.season’

predict(data)[source]#

Predict