src.visualisation package

Submodules

src.visualisation.ani module

ani.py - A set of functions to animate particular results.

animate_xr_da - animation for individual xr.DataArray.

animate_prediction - plots inputs and outputs of old model.

src.visualisation.ani.animate_coupling(setup, dpi=200, pac=False, mask_land=False)

Animate coupling.

Parameters
  • setup (ModelSetup) – setup object.

  • dpi (int, optional) – Dots per inch. Defaults to 200.

  • pac (bool, optional) – Whether to only plot the Pacific. Defaults to False.

  • mask_land (bool, optional) – Whether to mask the land in green. Defaults to False.

Return type

None

src.visualisation.ani.animate_ds(ds, file_name, output_dir, dpi=200, front_trim=0, plot_list=None)

Animate the xarray.Dataset.

Parameters
  • ds (xr.Dataset) – xarray.Dataset to animate the variables of.

  • file_name (str) – Name of dataset to be associated with the animations.

  • output_dir (str) – Full path to output directory to put the animations in.

  • dpi (float) – the dots per inch for the figure. Defaults to 200.

  • front_trim (int) – the number of T indices to remove from the front of the xr.DataArray pieces. Defaults to 0.

  • plot_list (Optional[list], optional) – Subset of variables to plot. Defaults to None. Introduced so that I could speed up the test animation, while still covering the function.

Return type

None

src.visualisation.ani.animate_qflx_diff(path_a='/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/ocean/DATA/qflx.nc', path_b='/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/ocean/DATA/qflx-0.nc', video_path='/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/gifs/diff-output.gif', fps=5, dpi=200)

Animate two xr.DataArray and the difference between them.

Parameters
  • path_a (Union[str, pathlib.Path], optional) – Path to qflx. Defaults to os.path.join(OCEAN_DATA_PATH, “qflx.nc”).

  • path_b (Union[str, pathlib.Path], optional) – Path to qflx-0. Defaults to os.path.join(OCEAN_DATA_PATH, “qflx-0.nc”).

  • video_path (str, optional) – path to save video to. Defaults to os.path.join(GIF_PATH, “diff-output.gif”).

  • fps (int, optional) – Frames per second. Defaults to 5.

  • dpi (int, optional) – dots per inch. Defaults to 200.

Return type

None

src.visualisation.ani.animate_xr_da(xr_da, video_path='output.mp4', vcmap=<matplotlib.colors.LinearSegmentedColormap object>, dpi=200)

Animate an xr.DataArray.

Parameters
  • xr_da (xr.DataArray) – input xr.DataArray.

  • video_path (str, optional) – Video path. Defaults to “output.mp4”.

  • vcmap (Union[str, matplotlib.colors.LinearSegmentedColormap], optional) – cmap for variable. Defaults to cmap(“sst”).

  • dpi (float, optional) – dots per inch for plotting. Defaults to 200.

Return type

None

src.visualisation.arrow module

Arrow plots for mechanism.

Figure 2.

TODO: A class structure would probably work best.

TODO: Central plotting base class could work.

TODO: Remove old plot functions.

src.visualisation.arrow.arrow_plot(project='sdat2/ENSOTrend-gamma', save_path=None, show_plots=False)

Make the automated arrow plot on a particular project.

TODO: Add legend with only CMIP5/6 and ECMWF values.

TODO: Add option to plot seager19 values for comparison to CMIP5 plot.

TODO: Add option for SST QFLXing etc. and general extnesiblity to different options.

TODO: Add option to allow matching before subtraction.

TODO: Add option to allow filtering of project to particular input values.

TODO: Add option to allow differnt regions e.g. nino1 to be plotted.

Args:

project (str, optional): Which wandb project to read. Defaults to “sdat2/ENSOTrend-gamma”. save_path (Optional[Union[str, bool]], optional): Where to save plot to.

Defaults to None.

show_plots (bool, optional): Whether to keep plots open for jupyter-notebook. Defaults to False.

Examples:

Example of using function inside a jupyter notebook:

from src.visualisation.arrow import arrow_plot

arrow_plot(project="sdat2/ENSOTrend-gamma", show_plots=True)
arrow_plot(project="sdat2/ENSOTrend-beta", show_plots=True)
arrow_plot(project="sdat2/seager19", show_plots=True)
Return type

None

src.visualisation.arrow.make_results_xr()

Make the results xarray from the dictionary above.

Returns

The results xarray object.

Return type

xr.DataArray

src.visualisation.arrow.origninal_arrow_plot(save_path=None, show_plots=False)

Plot the arrow plot to show that I have reproduced the paper.

Parameters
  • save_path (Optional[str], optional) – Where to save the plot to. Defaults to None. If None will not save.

  • show_plots (bool, optional) – Whether to show plots. Defaults to False.

Return type

None

src.visualisation.arrow.plot_arrow_plot_6(save_path=None, show_plots=False)

Plot the arrow plot to show how it performs in cmip6.

Parameters
  • save_path (Optional[str], optional) – Where to save the plot to. Defaults to None. If None will not save.

  • show_plots (bool, optional) – Whether to show plots. Defaults to False.

Return type

None

src.visualisation.arrow.plot_results_xr()

Plot the RESULTS_XR object, to make a nice plot for AGU.

Return type

None

src.visualisation.bias module

Plot and process biases in trends and means.

src.visualisation.bias.atmos_bias(var='ts', model='S', ending='clim')

Atmospheric bias.

Parameters
  • var (str, optional) – Variable. Defaults to “ts”.

  • model (str, optional) – Model. Defaults to “S”.

  • ending (str, optional) – Ending. Defaults to “clim”.

Return type

xr.DataArray

Get the 60 year trends over the nino3.4 region for differnt members of the nino3.4 ensemble.

Parameters

file_path (Union[str, pathlib.Path], optional) – Defaults to CMIP6_TS_PATH.

Returns

xr trends.

Return type

xr.DataArray

src.visualisation.bias.line_plot(da, ax, **kwargs)
Return type

any

src.visualisation.bias.multi_bias_plot(model='S', vertical=True)

Plot the biases plot.

Parameters

model (str, optional) – Model char. Defaults to “S” for CMIP6.

Example

plot cmip6:

from src.visualisation.bias import multi_bias_plot

multi_bias_plot("S")
Return type

None

src.visualisation.bias.plot_bias(ax, var='ts', ending='trend', model='S', cmap_loc=<matplotlib.colors.LinearSegmentedColormap object>, vmin=-1.5, vmax=1.5, long_name=None, units=None)

Plot an individual bias.

Parameters
  • ax (matplotlib.axes.Axes) – axes.

  • var (str, optional) – Variable. Defaults to “ts”.

  • ending (str, optional) – Ending. Defaults to “trend”.

  • model (str, optional) – Model. Defaults to “S”.

  • cmap_loc (any, optional) – cmap. Defaults to cmap(“delta”).

  • vmin (float, optional) – vmin. Defaults to -1.5.

  • vmax (float, optional) – vmax. Defaults to 1.5.

  • long_name (str, optional) – Long name - label for colormap. Defaults to None.

  • units (str, optional) – Units for colormap. Defaults to None.

src.visualisation.bias.temperature_line_plot(ax)

Temperature line plot.

Parameters

ax (matplotlib.axes.Axes) – which axis to add to.

Return type

None

src.visualisation.bias.trends_from_csv(csv_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/src/data/mmm-trends.csv'))

Get trends csv.

Parameters

csv_path (pathlib.Path, optional) – Defaults to DATA_PATH / “mmm-trends.csv”.

Return type

xr.DataArray

src.visualisation.bias.trends_from_da(da, beginning=2007, finish=2017)

Get 60 year trends over a few years.

Parameters
  • da (xr.DataArray) – Temperature dataarray.

  • beginning (int) – Defaults to 2007.

  • finish (int) – Defaults to 2017.

Returns

Rise dataarray.

Return type

xr.DataArray

src.visualisation.comp_cd module

Comp cd variation for various experiments with varying the inputs to the model.

src.visualisation.comp_cd.plot_comp_cd(mem_d, save_path=None, show_plots=False)

Plot drag coefficient for different inputs.

Parameters
  • mem_d (dict) – dict with different inputs as keys.

  • save_path (Optional[str], optional) – Where to save the plot to. Defaults to None. If None will not save.

  • show_plots (bool, optional) – Whether to show plots. Defaults to False.

Return type

None

src.visualisation.comp_seq module

Comp seq function.

src.visualisation.comp_seq.comp_seq(name, varx, vary, varx_name='psl', vary_name='our code', show_plot=True)

Function to compare two different sequences to see how closely they match

Parameters
  • name (str) – The name of the sequence you’re comparing.

  • varx (np.array) – The name of the target variable.

  • vary (np.array) – The name of the output variable.

  • varx_name (str, optional) – Name of target variable. Defaults to “psl”.

  • vary_name (str, optional) – Name of output variable. Defaults to “our code”.

  • show_plot (bool, optional) – Whether to show the plot. Defaults to True.

Return type

None

src.visualisation.comp_v_seager19 module

Program to automate testing output fields against the paper.

Perhaps this module should be renamed ‘comp_v_seager19’.

src.visualisation.comp_v_seager19.comp_atm_prwnd(setup, num, show_plots=False)

Test to see if atm is right.

Parameters
  • setup (ModelSetup) – The path object.

  • panel (str) – Which panel to test against. E.g. 2d.

Return type

str

src.visualisation.comp_v_seager19.comp_oc_htherm(setup, num, show_plots=False)

Compare the sea surface temperature trend of the final model iteration.

Parameters
  • setup (ModelSetup) – The setup.

  • num (str) – The number e.g. “4b”.

Return type

str

src.visualisation.comp_v_seager19.comp_oc_sst(setup, num, show_plots=False, var='tstrend')

Compare the sea surface temperature trend of the final model iteration.

Parameters
  • setup (ModelSetup) – The setup.

  • num (str) – The number e.g. “2b”.

Return type

str

src.visualisation.comp_v_seager19.comp_plot(ours, papers, default_cmap='delta', diff_cmap='delta', **kwargs)

A comparison plot for two scalar fields.

ours papers ours - papers (ours - papers) / papers

Parameters
  • ours (xr.DataArray) – The output of the model.

  • papers (xr.DataArray) – The paper’s values.

  • default_cmap (str, optional) – The colormap for the field. Defaults to “delta”.

  • diff_cmap (str, optional) – The colormap for the difference between the two fields. Defaults to “delta”.

Return type

None

src.visualisation.comp_v_seager19.comp_prcp_quiver_plot(ours, theirs, vmin=-5e-05, vmax=5e-05, x_pos=0.73, y_pos=-0.15)

Compare the precipitation and windspeeds.

Parameters
  • ours (xr.Dataset) – Our dataset.

  • theirs (xr.Dataset) – Their dataset.

Return type

None

src.visualisation.comp_v_seager19.comp_uc_atm(setup, panel='d', show_plots=False)

Test to see if panel 2d is right.

Parameters
  • setup (ModelSetup) – The path object.

  • panel (str, optional) – Which panel to test against. Defaults to “d”.

Return type

None

src.visualisation.comp_v_seager19.comp_uc_oc(setup, panel='d', show_plots=False)

Test to see if panel 1d is replicated.

Parameters
  • setup (ModelSetup) – The setup object.

  • panel (str, optional) – Which panel to test aginst. Defaults to “d”.

Return type

None

src.visualisation.comp_v_seager19.field_plot()

Plot the different input fields that are varied.

Return type

None

src.visualisation.comp_v_seager19.make_plots_example()

make example plots.

Return type

None

src.visualisation.comp_v_seager19.return_figure_ds(num)

Get the figure dataset.

Parameters

num (str) – The figure number e.g. “2c”.

Returns

the dataset for a particular figure panel with the standard names.

Return type

xr.Dataset

src.visualisation.comp_v_seager19.return_seager19_ds()

Return seager19 data taken from website.

Returns

The dataset for all the figure data.

Return type

xr.Dataset

src.visualisation.comp_v_seager19.return_var_list(num)

Get a list of the variables from each figure.

Args:

num Union[int, str]: The figure number.

Example input: int(4) or “2a”.

Returns:

List[str]: A list of the variable names.

Return type

List[str]

src.visualisation.convergence module

Look at the convergence of the coupling scheme.

src.visualisation.convergence.coupling_frame(setup, pac=False, mask_land=False, close_figure=True)

Create imageio frame function for the variables passed during model coupling.

Parameters
  • setup (ModelSetup) – setup object with path to files.

  • dpi (int, optional) – Dots per inch. Defaults to 200.

  • pac (bool, optional) – Whether to only plot the Pacific. Defaults to False.

  • mask_land (bool, optional) – Whether to mask the land in green. Defaults to False.

  • close_figure (bool, optional) – Wheter to cloe the figure rather than keep it open (only useful for individual plot). Defaults to True.

Returns

make_frame function to create each frame from the index.

Return type

Callable

src.visualisation.convergence.final_coup_plot()

Final coupling panel plot.

Shows how the final set of variables to be passed between the ocean and atmospheric model.

Return type

None

src.visualisation.convergence.metric_conv_plot(metric_name='mean_pac', long_name='Mean Tropical Pacific (pac)', show_plots=False)

Make the convergence plot for a particular metric.

Parameters
  • metric_name (str, optional) – The keyword to extract. Defaults to “mean_pac”.

  • long_name (str, optional) – The long name for the ylabel. Defaults to “Mean Tropical Pacific (pac)”.

src.visualisation.nino module

Store plotting scripts for metrics.py

src.visualisation.nino.get_nino_trend(path_of_run2f, graph_path, nc_path, show_plots=False)

Get nino trend, mean, plot the graph.

Parameters
  • path_of_run2f (str) – path to the main output netcdf.

  • graph_path (str) – path to output plot.

  • nc_path (str) – path to output netcdf

Returns

nino dict.

Return type

dict

src.visualisation.nino.make_plots()

Make sample plots for nino3.4 to check its still working.

Return type

None

src.visualisation.nino.multi_panel_nino(sst_output, graph_path, show_plots=False)

Multi panel nino plot.

Parameters
  • sst_output (xr.DataArray) – sst_output netcdf.

  • graph_path (str) – Graph path.

  • show_plots (bool, optional) – Show plots. Defaults to False.

src.visualisation.nino.plot_nino(ax, legend=False)

Plot all the nino boxes.

Parameters
  • ax (matplotlib.axes.Axes) – axis to plot to.

  • legend (bool, optional) – Whether to include legend. Defaults to False.

Return type

None

src.visualisation.nino.plot_nino_box(ax, reg, color=None)

Plot a nino box.

Parameters
  • ax (matplotlib.axes.Axes) – axis to plot to.

  • reg (str) – region to plot

  • color (Optional[str], optional) – Override color option. Defaults to None.

Example

Add Nino3.4 box to plot:

import matplotlib.pyplot as plt
from src.visualisation.nino import plot_nino_box

ax = plt.gca()
plot_nino_box(
    ax, reg="nino3.4", color=None
)
Return type

None

src.visualisation.pairplot module

A module to contain my pairplot function.

# from scipy.stats import pearsonr

from src.visualisation.pairplot import pairplot

src.visualisation.pairplot.pairplot(df_tmp)

Improved seaborn pairplot from:

https://stackoverflow.com/questions/50832204/show-correlation-values-in-pairplot-using-seaborn-in-python/50835066

Parameters

df_tmp (pd.DataFrame) – A data frame.

Example

Usage with psl indices:

import matplotlib.pyplot as plt
from src.visualisation.pairplot import pairplot
from src.data_loading.psl import get_psl_indices

ds = get_psl_indices()
df = ds.to_dataframe()
df1 = df[["tni", "nino34", "meiv2", "soi"]]
pairplot(df1)
plt.show()
Return type

None

src.visualisation.quiver module

Quiver plots.

src.visualisation.quiver.pqp_part(ax, ads, x_pos=0.65, y_pos=-0.15, **kwargs)

Plot a panel of pqp figure.

Parameters
Return type

None

src.visualisation.quiver.prcp_quiver_plot(setup=<src.models.model_setup.ModelSetup object>, show_plots=False, save_path='/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/report/figures/uv_prcp.png')

prcp wind trends quiver plot.

Parameters
  • setup (ModelSetup, optional) – setup object. Defaults to get_default_setup().

  • show_plots (bool, optional) – Whether to show plots. Defaults to False.

  • save_path ([type], optional) – Path to save fig to. Defaults to str(FIGURE_PATH / “uv_prcp.png”).

Return type

None

src.visualisation.sensitivity module

Find the sensitivity of the coupled omodel.

src.visualisation.sensitivity.cd_heatmaps(show_plots=False)

Return the cd heatmaps

Parameters

show_plots (bool, optional) – Whether or not to show plots or just clear them. Defaults to False.

Return type

None

src.visualisation.sensitivity.cd_plots(show_plots=False)

Generate the cd sensitivity plots.

Return type

None

src.visualisation.sensitivity.eps_heatmaps(show_plots=False)

Return the eps heatmaps

Parameters

show_plots (bool, optional) – Whether or not to show plots or just clear them. Defaults to False.

Return type

None

src.visualisation.sensitivity.eps_plots(show_plots=False)

Generate the eps sensitivity plots.

Currently I’m cutting off all results with more than 2.25 days.

Return type

None

src.visualisation.sensitivity.k_plots(show_plots=False)

Generate the k sensitivity plots.

Return type

None

src.visualisation.sensitivity.nummode_plots(show_plots=False)

Make a plot of the number of modes vs. time taken to run the ocean section.

Return type

None

src.visualisation.trends module

Program to do; plot trends etc.

src.visualisation.trends.up_therm_qnet(setup=<src.models.model_setup.ModelSetup object>, show_plots=False, save_path='/home/docs/checkouts/readthedocs.org/user_builds/seager19/checkouts/latest/report/figures/tuq_trends.png')

up trend qnet trend.

Parameters
  • setup (ModelSetup, optional) – setup object. Defaults to get_default_setup().

  • show_plots (bool, optional) – Whether to show the plots. Defaults to False.

  • save_path ([type], optional) – path to save fig to. Defaults to str(FIGURE_PATH / “tuq_trends.png”).

Return type

None

Module contents