PreprocessUnstructured

class spy4cast.spy4cast.PreprocessUnstructured(data_matrix: ndarray[Any, dtype[float32]], time: ndarray[Any, dtype[int32]], coords: ndarray[Any, dtype[float32]], var: str | None = None, order: int | None = None, period: float | None = None, freq: Literal['high', 'low'] = 'high', detrend: bool = False)

Bases: _Procedure

Stores unstructured data (data points not distributed in a grid). Preprocess variables for MCA and Crossvalidation: anomaly and reshaping

Parameters:
  • data_matrix (array) – Data matrix with dimensions (space x time) where each row is a node in the unstructured data and each column corresponds to the time dimension

  • time (array) – Labels each time as integers. For example years

  • coords (array) – Matrix with dimensions (space x 2) where each row is a node from the structured data, the first column corresponds to the latitude and the second to longitude

  • order (optional, int) – If specified as well as period, a butterworth filter with those parameters will be applied

  • period (optional, float) – If specified as well as period, a butterworth filter with those parameters will be applied

  • freq ({'high', 'low'}, default = 'high') – If specified as well as period, a butterworth filter with those parameters will be applied

  • detrend (bool, default = False) – Apply scipy.signal.detrend on the time axis.

Examples

Attributes Summary

VAR_NAMES

coords

Latitude and longitude coordinate of the variable

data

Raw data in the object with nan as in the original dataset.

data_matrix

Data martrix introduced as input

land_data

Data but organised in a land array.

lat

Latitude coordinate of the variable

lon

Longitude coordinate of the variable

region

Region of the data

shape

Shape of the data as a tuple of space x time

time

Time coordinate of the data

var_names

Returns the variables contained in the object (data, time, lat, lon, ...)

Methods Summary

plot([save_fig, show_plot, halt_program, ...])

Plot the unstructured preprocessed data for spy4cast methodologes

Attributes Documentation

VAR_NAMES = ('time', 'coords', 'data', 'var', 'data_matrix')
coords

Latitude and longitude coordinate of the variable

data

Raw data in the object with nan as in the original dataset. It has dimensions of space x time.

data_matrix

Data martrix introduced as input

land_data

Data but organised in a land array. This includes a mask that indicates where the land is in the dataset by masking the nan values. This is useful when handling variables like sea surface temperature

lat

Latitude coordinate of the variable

lon

Longitude coordinate of the variable

region

Region of the data

shape

Shape of the data as a tuple of space x time

time

Time coordinate of the data

var_names

Returns the variables contained in the object (data, time, lat, lon, …)

Methods Documentation

plot(save_fig: bool = False, show_plot: bool = False, halt_program: bool = False, selected_year: int | None = None, cmap: str = 'bwr', folder: str | None = None, name: str | None = None, figsize: Tuple[float, float] | None = None, plot_type: Literal['tricontour', 'scatter'] = 'scatter', levels: ndarray[Any, dtype[float32]] | Sequence[float] | bool | None = None) Tuple[Tuple[Figure], Tuple[Tuple[Axes]]]

Plot the unstructured preprocessed data for spy4cast methodologes

Parameters:
  • save_fig – Saves the fig using folder and name parameters

  • show_plot – Shows the plot

  • halt_program – Only used if show_plot is True. If True shows the plot if plt.show and stops execution. Else uses fig.show and does not halt program

  • cmap – Colormap for the map

  • folder – Directory to save fig if save_fig is True

  • name – Name of the fig saved if save_fig is True

  • figsize – Set figure size. See plt.figure

  • plot_type ({"tricontour", "scatter"}, defaut = "scatter") – Plot type. If tricontour it will use function ax.tricontourf, if scatter ax.scatter.

  • levels – Levels for the map

Examples

Returns:

  • figures (Tuple[plt.Figure]) – Figures objects from matplotlib. In this case just one figure with one axes

  • ax (Tuple[Tuple[plt.Axes]]) – Tuple of axes in figure. In this case just one axes