From f6e7e0f309c3bb0c1fc7357654419e4056a0a545 Mon Sep 17 00:00:00 2001 From: James Frost Date: Thu, 23 Nov 2023 16:45:01 +0000 Subject: [PATCH 1/3] Add aggregate operator to documentation Fixes #275 --- docs/source/reference/operators.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/source/reference/operators.rst b/docs/source/reference/operators.rst index 34714d146..2834c4788 100644 --- a/docs/source/reference/operators.rst +++ b/docs/source/reference/operators.rst @@ -5,6 +5,12 @@ This page details the operators contained within CSET. It is automatically generated from the code and its docstrings. Operators should be used via :doc:`/usage/operator-recipes`. +CSET.operators.aggregate +------------------------ + +.. automodule:: CSET.operators.aggregate + :members: + CSET.operators.collapse ----------------------- From 119829433e64b83bb723304bb04e4d1603feae3d Mon Sep 17 00:00:00 2001 From: James Frost Date: Thu, 23 Nov 2023 17:58:06 +0000 Subject: [PATCH 2/3] WIP improved contour plot style --- src/CSET/operators/plot.py | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/CSET/operators/plot.py b/src/CSET/operators/plot.py index 19de19e7a..d3ba680b4 100644 --- a/src/CSET/operators/plot.py +++ b/src/CSET/operators/plot.py @@ -23,7 +23,7 @@ import iris.cube import iris.exceptions import iris.plot as iplt -import iris.quickplot as qplt +import matplotlib as mpl import matplotlib.pyplot as plt from markdown_it import MarkdownIt @@ -49,9 +49,11 @@ def _make_plot_html_page(plot_filename: str) -> None: } .plot-container { width: min(95vw, 95vh); + height: 99vh; } .plot-container>img { width: 100%; + height: 100%; } #description-container { flex: 30ch; @@ -145,12 +147,39 @@ def spatial_contour_plot( TypeError If cube isn't a Cube. """ + title = get_recipe_metadata().get("title", "Untitled") if not filename: - filename = slugify(get_recipe_metadata().get("title", "Untitled")) + filename = slugify(title) filename = Path(filename).with_suffix(".svg") cube = _check_single_cube(cube) - qplt.contourf(cube) - plt.savefig(filename) + + # with mpl.rc_context({"figure.labelsize": 22}): + + # Setup plot details, size, resolution, etc. + # Set label size. + plt.figure(num=1, figsize=(15, 15), facecolor="w", edgecolor="k") + # fig.tight_layout(pad=0) + + # plt.rc('xtick',labelsize=22) + # plt.rc('ytick',labelsize=22) + + # Filled contour plot of the field. + iplt.contourf(cube, cmap=mpl.cm.magma) + + # Add coastlines. + plt.gca().coastlines(resolution="10m") + + # Set plotting limits. + # plt.xlim(points_x) + # plt.ylim(points_y) + + # Add title. + plt.title(title, fontsize=16) + cbar = plt.colorbar() + cbar.set_label(label=f"{cube.name()} ({cube.units})", size=20) + + plt.savefig(filename, bbox_inches="tight") + logging.info("Saved contour plot to %s", filename) _make_plot_html_page(filename) return cube From 10218d77d66deb96ddf679637e4e8c35d6be1a02 Mon Sep 17 00:00:00 2001 From: James Frost Date: Fri, 24 Nov 2023 14:49:17 +0000 Subject: [PATCH 3/3] Remove whitepace from postage-stamp plots --- src/CSET/operators/collapse.py | 5 +++-- src/CSET/operators/plot.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CSET/operators/collapse.py b/src/CSET/operators/collapse.py index 5f65f97e3..723433201 100644 --- a/src/CSET/operators/collapse.py +++ b/src/CSET/operators/collapse.py @@ -39,8 +39,9 @@ def collapse( cube: iris.cube.Cube Cube to collapse and iterate over one dimension coordinate: str | list[str] - Coordinate(s) to collapse over i.e. 'time', 'longitude', 'latitude', - 'model_level_number'. A list of multiple coordinates can be given. + Coordinate(s) to collapse over e.g. 'time', 'longitude', 'latitude', + 'model_level_number', 'realization'. A list of multiple coordinates can + be given. method: str Type of collapse i.e. method: 'MEAN', 'MAX', 'MIN', 'MEDIAN', 'PERCENTILE' getattr creates iris.analysis.MEAN, etc For PERCENTILE diff --git a/src/CSET/operators/plot.py b/src/CSET/operators/plot.py index d3ba680b4..d86bf5b20 100644 --- a/src/CSET/operators/plot.py +++ b/src/CSET/operators/plot.py @@ -23,7 +23,6 @@ import iris.cube import iris.exceptions import iris.plot as iplt -import matplotlib as mpl import matplotlib.pyplot as plt from markdown_it import MarkdownIt @@ -164,7 +163,7 @@ def spatial_contour_plot( # plt.rc('ytick',labelsize=22) # Filled contour plot of the field. - iplt.contourf(cube, cmap=mpl.cm.magma) + iplt.contourf(cube) # Add coastlines. plt.gca().coastlines(resolution="10m") @@ -243,7 +242,7 @@ def postage_stamp_contour_plot( colorbar = plt.colorbar(plot, colorbar_axes, orientation="horizontal") colorbar.set_label(f"{cube.name()} / {cube.units}") - plt.savefig(filename) + plt.savefig(filename, bbox_inches="tight") logging.info("Saved contour postage stamp plot to %s", filename) _make_plot_html_page(filename) return cube