bluemath_tk.predictor package
Submodules
bluemath_tk.predictor.xwt module
- class bluemath_tk.predictor.xwt.XWT(steps: Dict[str, BlueMathModel])[source]
Bases:
BlueMathModel
,BlueMathPipeline
Xly Weather Types (XWT) class.
This class implements the XWT method to identify and classify weather patterns in a dataset. The XWT method is a combination of Principal Component Analysis (PCA) and K-means clustering (KMA).
- steps
The steps of the XWT method.
- Type:
Dict[str, BlueMathModel]
- num_clusters
The number of clusters.
- Type:
int
- kma_bmus
The KMA best matching units (BMUs).
- Type:
pd.DataFrame
- property clusters_annual_probs_df
- property clusters_monthly_probs_df
- property clusters_perpetual_year_probs_df
- property clusters_probs_df
- property clusters_seasonal_probs_df
- property data: Dataset
- fit(data: Dataset, fit_params: Dict[str, Dict[str, Any]] = {}, variable_to_sort_bmus: str = None) None [source]
Fit the XWT model to the data.
- Parameters:
data (xr.Dataset) – The data to fit the model to. Must be PCA formatted.
fit_params (Dict[str, Dict[str, Any]], optional) – The fitting parameters for the PCA and KMA models. Default is {}.
variable_to_sort_bmus (str, optional) – The variable to sort the BMUs. Default is None.
- Raises:
XWTError – If the data is not PCA formatted.
TODO – Standarize PCs by first PC variance.: pca.pcs_df / pca.pcs.stds.isel(n_component=0).values ??
- property get_conditioned_probabilities
- plot_dwts_probs(vmax: float = 0.15, vmax_seasonality: float = 0.15, plot_text: bool = False) None [source]
Plot Daily Weather Types bmus probabilities.
- Parameters:
vmax (float, optional) – The maximum value of the colorbar. Default is 0.15.
vmax_seasonality (float, optional) – The maximum value of the colorbar for seasonality. Default is 0.15.
plot_text (bool, optional) – Whether to plot the text in each cell. Default is False.
- Raises:
ValueError – If the kma_bmus time sampling is not daily.
- plot_map_features(ax: Axes, land_color: str = array([0.9375, 0.9375, 0.859375])) None [source]
Plot map features on an axis.
- Parameters:
ax (Axes) – The axis to plot the map features on.
land_color (str, optional) – The color of the land. Default is cfeature.COLORS[“land”].
- plot_perpetual_year() Axes [source]
Plot perpetual year bmus probabilities.
- Returns:
The plot with the perpetual year bmus probabilities.
- Return type:
Axes
- plot_xwts(var_to_plot: str, anomaly: bool = False, map_center: tuple = None) Collection [source]
Plot the XWTs for a variable.
- Parameters:
var_to_plot (str) – The variable to plot.
anomaly (bool, optional) – Whether to plot the anomaly of the variable. Default is False.
map_center (tuple, optional) – The center of the map. Default is None.
- Returns:
The grid specification with the XWTs plot.
- Return type:
GridSpec
- exception bluemath_tk.predictor.xwt.XWTError(message='XWT error occurred.')[source]
Bases:
Exception
Custom exception for XWT class.
- bluemath_tk.predictor.xwt.check_model_is_fitted(func)[source]
Decorator to check if the model is fitted.
- bluemath_tk.predictor.xwt.get_dynamic_estela_predictor(data: Dataset, estela: Dataset, check_interpolation: bool = True, verbose: bool = False) Dataset [source]
Transform an xarray dataset of longitude, latitude, and time into one where each longitude, latitude value at each time is replaced by the corresponding time - t, where t is specified in the estela dataset.
Parameters ———-ltimes = estela.where(estela.F >= 0, np.nan).traveltime.astype(int) estela_max_traveltime = estela_traveltimes.max().values for traveltime in range(estela_max_traveltime):
data = data.w
- dataxr.Dataset
The input dataset with dimensions longitude, latitude, and time.
- estelaxr.Dataset
The dataset containing the F values with dimensions longitude and latitude.
- check_interpolationbool, optional
Whether to check if the data is interpolated. Default is True.
- verbosebool, optional
Whether to print verbose output. Default is False. If False, Dask logs are suppressed. If True, Dask logs are shown.
- Returns:
The transformed dataset.
- Return type:
xr.Dataset
Module contents
Project: BlueMath_tk Sub-Module: predictor Author: GeoOcean Research Group, Universidad de Cantabria Repository: https://github.com/GeoOcean/BlueMath_tk.git Status: Under development (Working)
- class bluemath_tk.predictor.XWT(steps: Dict[str, BlueMathModel])[source]
Bases:
BlueMathModel
,BlueMathPipeline
Xly Weather Types (XWT) class.
This class implements the XWT method to identify and classify weather patterns in a dataset. The XWT method is a combination of Principal Component Analysis (PCA) and K-means clustering (KMA).
- steps
The steps of the XWT method.
- Type:
Dict[str, BlueMathModel]
- num_clusters
The number of clusters.
- Type:
int
- kma_bmus
The KMA best matching units (BMUs).
- Type:
pd.DataFrame
- property clusters_annual_probs_df
- property clusters_monthly_probs_df
- property clusters_perpetual_year_probs_df
- property clusters_probs_df
- property clusters_seasonal_probs_df
- property data: Dataset
- fit(data: Dataset, fit_params: Dict[str, Dict[str, Any]] = {}, variable_to_sort_bmus: str = None) None [source]
Fit the XWT model to the data.
- Parameters:
data (xr.Dataset) – The data to fit the model to. Must be PCA formatted.
fit_params (Dict[str, Dict[str, Any]], optional) – The fitting parameters for the PCA and KMA models. Default is {}.
variable_to_sort_bmus (str, optional) – The variable to sort the BMUs. Default is None.
- Raises:
XWTError – If the data is not PCA formatted.
TODO – Standarize PCs by first PC variance.: pca.pcs_df / pca.pcs.stds.isel(n_component=0).values ??
- property get_conditioned_probabilities
- plot_dwts_probs(vmax: float = 0.15, vmax_seasonality: float = 0.15, plot_text: bool = False) None [source]
Plot Daily Weather Types bmus probabilities.
- Parameters:
vmax (float, optional) – The maximum value of the colorbar. Default is 0.15.
vmax_seasonality (float, optional) – The maximum value of the colorbar for seasonality. Default is 0.15.
plot_text (bool, optional) – Whether to plot the text in each cell. Default is False.
- Raises:
ValueError – If the kma_bmus time sampling is not daily.
- plot_map_features(ax: Axes, land_color: str = array([0.9375, 0.9375, 0.859375])) None [source]
Plot map features on an axis.
- Parameters:
ax (Axes) – The axis to plot the map features on.
land_color (str, optional) – The color of the land. Default is cfeature.COLORS[“land”].
- plot_perpetual_year() Axes [source]
Plot perpetual year bmus probabilities.
- Returns:
The plot with the perpetual year bmus probabilities.
- Return type:
Axes
- plot_xwts(var_to_plot: str, anomaly: bool = False, map_center: tuple = None) Collection [source]
Plot the XWTs for a variable.
- Parameters:
var_to_plot (str) – The variable to plot.
anomaly (bool, optional) – Whether to plot the anomaly of the variable. Default is False.
map_center (tuple, optional) – The center of the map. Default is None.
- Returns:
The grid specification with the XWTs plot.
- Return type:
GridSpec