Anom¶
- class spy4cast.meteo.Anom(ds: Dataset, typ: Literal['map', 'ts'], st: bool = False, group_season: bool = True)¶
Bases:
_ProcedureProcedure to create the anomaly of a spy4cast.dataset.Dataset
- Parameters:
ds (spy4cast.dataset.Dataset) – spy4cast.dataset.Dataset on to which perform the anomaly
type ('map' or 'ts') –
- Perform the anomaly and outputing a map (will result in a series of maps)
or ouputting a timeseries by doing the mean across space.
st (bool, default=False) – Indicates whether to standarise the anomaly
group_season (bool, default=True) – If True, group data points with the same season_id (defined below) and take the average. This creates a new dataset with only time dimension being season_id. This dataset is the one used to calculate anomalies. This is used when regions span multiple months (e.g. JUN-AUG) and you consider the mean during this season the variable. season_id is the common year of the region; or for regions like DEC-FEB that mix years, the year of the end of the region (FEB).
Attributes Summary
Data Matrix
Dataset introduced
Array of latitude values of the dataset passes in initialization if type is map
Array of longitude values of the dataset passes in initialization if type is map
Region applied to the matrix.
Array of years of the time variable
Type of anomaly passed in initialization
Variable name
Returns the variables contained in the object (data, time, lat, lon, ...)
Methods Summary
from_xrarray(array[, st])Function to calculate the anomalies on a xarray DataArray
load(prefix[, folder, zip_file, type])Load an anom object from matrices and type
plot(*[, save_fig, show_plot, halt_program, ...])Plot the anomaly map or time series
Attributes Documentation
- data¶
Data Matrix
- Return type:
xarray.DataArray
- ds¶
Dataset introduced
- lat¶
Array of latitude values of the dataset passes in initialization if type is map
- Return type:
xarray.DataArray
- lon¶
Array of longitude values of the dataset passes in initialization if type is map
- Return type:
xarray.DataArray
- region¶
Region applied to the matrix.
- Return type:
Note
If type is ts and initilization from ds was not run then a default time and region region is returned
Note
If type is map and initilization from ds was not run then a default time region is returned
- time¶
Array of years of the time variable
- Return type:
xarray.DataArray
- var¶
Variable name
- Return type:
str
- var_names¶
Returns the variables contained in the object (data, time, lat, lon, …)
Methods Documentation
- classmethod from_xrarray(array: DataArray, st: bool = False) Anom¶
Function to calculate the anomalies on a xarray DataArray
The anomaly is the time variable minus the mean across all times of a given point
- Parameters:
array (xr.DataArray) – Array to process the anomalies. Must have a dimension called time
st (bool, default=False) – Indicates whether the anomaly should standarized. Divide by the standard deviation
- Raises:
TypeError – If array is not an instance of xr.DataArray
ValueError – If the number of dimension of the array is not either 3 (map) or 1 (time series)
- Returns:
Anom object
- Return type:
See also
npanom
- classmethod load(prefix: str, folder: str = '.', zip_file: str | None = None, *, type: Literal['map', 'ts'] | None = None, **attrs: Any) Anom¶
Load an anom object from matrices and type
- Parameters:
prefix (str) – Prefix of the files containing the information for the object
folder (str) – Directory of the files
zip_file (optional, str) – If provided folder will be searched inside of the zip file, that should conatin all the data.
type ('map' or 'ts') – Type of anomaly
- Return type:
- plot(*, save_fig: bool = False, show_plot: bool = False, halt_program: bool = False, year: int | None = None, timestamp: str | Timestamp | datetime | None = None, cmap: str | None = None, color: Tuple[float, float, float] | None = None, folder: str = '.', name: str = 'anomaly.png', levels: int | ndarray[Any, dtype[float32]] | Sequence[float] | None = None, ticks: ndarray[Any, dtype[float32]] | Sequence[float] | None = None, figsize: Tuple[float, float] | None = None, plot_type: Literal['contour', 'pcolor'] | None = None, central_longitude: float | None = None, xlim: Tuple[float, float] | None = None) Tuple[Tuple[Figure], Tuple[Tuple[Axes]]]¶
Plot the anomaly map or time series
- 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
year – Plot the anomaly map for the last date of the season with this year
timestamp – Plot the date which is closest to the timestamp
cmap – Colormap for the map types
color – Color of the line for ts types
folder – Directory to save fig if save_fig is True
name – Name of the fig saved if save_fig is True
levels – Levels for the anomaly map
ticks – Ticks for the anomaly map
figsize – Set figure size. See plt.figure
plot_type ({"contour", "pcolor"}, defaut = "pcolor") – Plot type for map. If contour it will use function ax.contourf, if pcolor ax.pcolormesh.
central_longitude (float, optional) – Longitude used to center the map
xlim (tuple[float, float], optional) – Xlim lim for the y map passed into ax.set_extent
- Returns:
figures (Tuple[plt.Figure]) – Figures objects from matplotlib. In this case just one figure
ax (Tuple[Tuple[plt.Axes]]) – Tuple of axes in figure. In this case just one axes