AIModels.UtilPlot module

Auxiliary Plotting routines

Plotting routines for verification of the forecasts.

Functions

AIModels.UtilPlot.Single_Forecast_plots(F, V, field, level, cont, timestart, world_projection='Atlantic', maxtime=3, stride=1, colorbars=True, title='', mainlabel='', arealatz=None, arealonz=None, centlon=0, labfile=None)[source]

Make verification plots for the field field and level level for the dataset F and V. Plots are made in two column of maxtime rows each.

Parameters:
  • F (xarray dataset) -- Dataset with the forecast to be analyzed

  • V (xarray dataset) -- Dataset with the verification field

  • mainlabel (string) -- Main label for the plot

  • field (string) -- Field to be analyzed

  • level (string) -- Level to be analyzed

  • timestart (string) -- Starting date for the plotting

  • maxtime (int) -- Maximum number of time steps to be plotted The number of rows will be determined by this number

  • stride (int) -- Stride for the plotting

  • title (string) -- Title for the plot

  • cont --

    • [cmin,cmax,cinc] fixed increment from cmin to cmax step cinc

    • [ c1,c2, ..., cn] fixed contours at [ c1,c2, ..., cn]

    • n n contours

    • [] automatic choice

  • arealatz (numpy array) -- Latitude limits of the field

  • arealonz (numpy array) -- Longitude limits of the field

  • centlon (float) -- Central longitude

  • labfile (string) -- Name of the file to be written

Return type:

None

AIModels.UtilPlot.many_plots(F, field, level, cont, timestart, world_projection='Pacific', mainlabel='', mode='time', lead=0, ncols=2, nrows=3, arealatz=None, arealonz=None, centlon=0, labfile=None, colorbars=False, suptitle='')[source]

Make many plots for the field field and level level for the dataset F. Plots are made in rows and columns according to ncol and nrows.

Parameters:
  • F (xarray dataset) -- Dataset with the field to be analyzed

  • mainlabel (string) -- Main label for the plot

  • field (string) -- Field to be analyzed

  • level (string) -- Level to be analyzed

  • timestart (string) -- Starting date for the plotting

  • mode (string) -- Mode for the plotting, either 'time' or 'lead'

  • lead (int) -- Lead time for the plotting

  • ncols (int) -- Number of columns for the plotting

  • nrows (int) -- Number of rows for the plotting

  • cont --

    • [cmin,cmax,cinc] fixed increment from cmin to cmax step cinc

    • [ c1,c2, ..., cn] fixed contours at [ c1,c2, ..., cn]

    • n n contours

    • [] automatic choice

  • arealatz (numpy array) -- Latitude limits of the field

  • arealonz (numpy array) -- Longitude limits of the field

  • centlon (float) -- Central longitude

  • labfile (string) -- Name of the file to be written

  • colorbars (bool) -- Whether to add colorbars to each panel or a single colorbar at the bottom

  • suptitle (string) -- General title on top of the plot

Return type:

None

AIModels.UtilPlot.Forecast_plots(F, V, field, level, cont, world_projection='Atlantic', pictimes=None, colorbars=True, title='', mainlabel='', arealatz=None, arealonz=None, centlon=0, labfile=None)[source]

Make verification plots for the field field and level level for the dataset F and V. Plots are made in two column of maxtime rows each.

Parameters:
  • F (xarray dataset) -- Dataset with the forecast to be analyzed

  • V (xarray dataset) -- Dataset with the verification field

  • mainlabel (string) -- Main label for the plot

  • field (string) -- Field to be analyzed

  • level (string) -- Level to be analyzed

  • maxtime (int) -- Maximum number of time steps to be plotted The number of rows will be determined by this number

  • stride (int) -- Stride for the plotting

  • title (string) -- Title for the plot

  • cont --

    • [cmin,cmax,cinc] fixed increment from cmin to cmax step cinc

    • [ c1,c2, ..., cn] fixed contours at [ c1,c2, ..., cn]

    • n n contours

    • [] automatic choice

  • arealatz (numpy array) -- Latitude limits of the field

  • arealonz (numpy array) -- Longitude limits of the field

  • centlon (float) -- Central longitude

  • labfile (string) -- Name of the file to be written

Return type:

None

AIModels.UtilPlot.Three_Forecast_plots(F, V, D, field, level, cont, timestart, pictimes, figsize=(12, 8), world_projection='Atlantic', colorbars=True, maintitle='', picturelabels=None, arealatz=None, arealonz=None, centlon=0, labfile=None)[source]

Make verification plots for the field field and level level for the dataset F and V. Plots are made in two column of maxtime rows each.

Parameters:
  • F (xarray dataset) -- Dataset with the forecast to be analyzed

  • V (xarray dataset) -- Dataset with the verification field

  • D (xarray dataset) -- Dataset with the deterministic forecast

  • figsize (tuple) -- Size of the figure

  • world_projection (string) -- World Projection for the plot

  • maintitle (string) -- Main label for the plot

  • picturelabels (namedtuple) -- List of labels for the pictures

  • field (string) -- Field to be analyzed

  • level (string) -- Level to be analyzed

  • timestart (string) -- Starting date for the plotting

  • column (int) -- Number of columns for the plotting

  • pictimes (list) -- List of times to be plotted

  • cont --

    • [cmin,cmax,cinc] fixed increment from cmin to cmax step cinc

    • [ c1,c2, ..., cn] fixed contours at [ c1,c2, ..., cn]

    • n n contours

    • [] automatic choice

  • arealatz (numpy array) -- Latitude limits of the field

  • arealonz (numpy array) -- Longitude limits of the field

  • centlon (float) -- Central longitude

  • labfile (string) -- Name of the file to be written

Return type:

None

AIModels.UtilPlot.select_months(datetimes, months)[source]

Select the indices corresponding to certain months in a xarray of datetimes64

Parameters:
  • datetimes (xarray of datetimes64) -- Datetimes to be analyzed

  • months (string or list of months) -- Label of months to be selected

Returns:

indices -- Indices of the selected months

Return type:

numpy array

AIModels.UtilPlot.plot_skill(corrresult, persistence, rmsres, rmsper, rmsdyn=None, corrdyn=None, labtit=None, batch=False, savefig=False, data_dict=None, skill='mean', numbers=True, printout=False, labfile='scores', figsize=(10, 10))[source]

Makes plot of the skill scores for forecasts and persistence Optionally add the skill scores for the dynamic forecast

AIModels.UtilPlot.extract_and_merge_csv(input_folder, output_file, selected_rows)[source]

Extract selected rows from multiple CSV files in a folder and merge them into a single CSV.

Parameters:
  • input_folder (str) -- Path to the folder containing CSV files.

  • output_file (str) -- Path to the output merged CSV file.

  • selected_rows (list of int) -- List of row indices to extract from each CSV.

Returns:

Saves the merged CSV file to the specified output path.

Return type:

None

AIModels.UtilPlot.write_skill_to_csv(labfile, skill, Tpredict, sk, ps, corrdyn=None, data_dict=None)[source]

Write skill scores to a CSV file.

Parameters:
  • labfile (str) -- Base name for the output CSV file.

  • skill (str) -- Skill type (e.g., 'mean', 'median').

  • Tpredict (int) -- Number of prediction time steps.

  • sk (array-like) -- Skill scores for the forecast.

  • ps (array-like) -- Skill scores for the persistence.

  • corrdyn (array-like, optional) -- Skill scores for the dynamic forecast, by default None.

Return type:

None

AIModels.UtilPlot.plot_csv(file, figsize=(10, 6), colname='Exp', title='', xlab=None, ylab=None, row_indices=[0, 3, 6, 9, 12], per_indices=None, GCM_indices=None, sort_rows=False, savefile=None, input_axes=None, line06=True, lstyle=None, tstyle=None)[source]

Plot the data in the skill csv file

Parameters:
  • file (str) -- Path to the CSV file

  • figsize (tuple) -- Size of the figure

  • colname (str) -- Column name to be used as labels

  • title (str) -- General title for the plot

  • xlab (str) -- Label for the x-axis

  • ylab (str) -- Label for the y-axis

  • row_indices (list) -- Indices of the rows to be plotted

  • per_indices (list) -- Indices of the persistence forecast

  • GCM_indices (list) -- Indices of the GCM forecast

  • sort_rows (bool) -- Whether to sort the subset by the chosen colname before plotting

  • savefile (str) -- Name of the file to be written (default not saved)

  • input_axes (obj (optinoal)) -- Whether to use input axes for the plot Axes for the plot

  • line06 (bool) -- Whether to plot the 0.6 line

  • lstyle (dict) -- Line style for the plot

  • tstyle (dict) -- Text style for the plot

Return type:

None

AIModels.UtilPlot.boxplot(file, verify_dyn=False, input_axes=None, savefile=False, pltype='ACC')[source]

Make a box plot of the data in a pickle file. It also write a tex files with the description of the plot

Parameters:
  • file (str) -- Path to the pickle file

  • verify_dyn (bool) -- Whether to include the GCM-based forecast

  • input_axes (bool) -- Whether to use input axes for the plot

  • savefile (str) -- Name of the file to be written (default not saved)

  • pltype (str) -- Type of plot to be made (default ACC)

Return type:

None

AIModels.UtilPlot.write_var_excel(name='Y620', varname='best_val_loss', vcases=[1, 2, 3, 4, 5], subcases=[8], filename=None, datain='_corr_data', write_latex=False)[source]

Read several pickle files, extract the requested variable "varname" from each, and write them into a DataFrame with columns = subcases and rows = vcases. Optionally write the DataFrame to an Excel file and also output a LaTeX table.

AIModels.UtilPlot.Two_Forecast_plots(F, V, field, level, cont, timestart, pictimes, figsize=(12, 8), world_projection='Atlantic', colorbars=True, maintitle='', picturelabels=None, arealatz=None, arealonz=None, centlon=0, labfile=None)[source]

Make verification plots for the field field and level level for the dataset F and V. Plots are made in two columns of maxtime rows each.

Parameters:
  • F (xarray dataset) -- Dataset with the forecast to be analyzed

  • V (xarray dataset) -- Dataset with the verification field

  • figsize (tuple) -- Size of the figure

  • world_projection (string) -- World Projection for the plot

  • maintitle (string) -- Main label for the plot

  • picturelabels (namedtuple) -- List of labels for the pictures

  • field (string) -- Field to be analyzed

  • level (string) -- Level to be analyzed

  • timestart (string) -- Starting date for the plotting

  • pictimes (list) -- List of times to be plotted

  • cont --

    • [cmin,cmax,cinc] fixed increment from cmin to cmax step cinc

    • [ c1,c2, ..., cn] fixed contours at [ c1,c2, ..., cn]

    • n n contours

    • [] automatic choice

  • arealatz (numpy array) -- Latitude limits of the field

  • arealonz (numpy array) -- Longitude limits of the field

  • centlon (float) -- Central longitude

  • labfile (string) -- Name of the file to be written

Return type:

None

AIModels.UtilPlot.write_var_table(name='Y620', case='LAGS', subcases=[8, 9], rows=[0, 3, 5, 7, 9, 11], srwox=[1, 2], filename='TableTex', skill=False, stype='mean', mark='max')[source]

Read several csv files, with "name" and several subcases, option for "skill cases", and write a latex table from input "rows", add the single rows in "special rows" and write the table in "filename"

AIModels.UtilPlot.define_defaults_values(lstyle, tstyle)[source]

Define default values for the line and title styles

AIModels.UtilPlot.get_common_dates(Ft, Dt)[source]

Get common dates between two xarray datasets and their indices.

Parameters:
  • Ft (xarray.DataArray) -- First dataset with a time dimension.

  • Dt (xarray.DataArray) -- Second dataset with a time dimension.

Returns:

  • common_dates (numpy.ndarray) -- Array of common dates.

  • Ft_indices (numpy.ndarray) -- Indices of common dates in the first dataset.

  • Dt_indices (numpy.ndarray) -- Indices of common dates in the second dataset.

AIModels.UtilPlot.calculate_significance(corr: DataArray, n, alpha: float = 0.05, two_tailed: bool = True, method: str = 'fisher')[source]

Significance test for correlation coefficients.

Parameters:
  • corr (xr.DataArray Correlation coefficients (−1 < r < 1))

  • n (int or xr.DataArray Sample size(s) (must be > 3))

  • alpha (float Significance level)

  • two_tailed (bool Two‑tailed if True, else one‑tailed)

  • method ({"fisher","t"} Approximate (normal) or exact (t) test)