Skip to content

Commit

Permalink
Merge branch 'main' of github.com:NCAS-CMS/cf-python into ugrid-0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhassell committed Sep 5, 2023
2 parents 87ffa9b + ed9e4c8 commit 2c70d98
Show file tree
Hide file tree
Showing 3,897 changed files with 90,423 additions and 11,179 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
8 changes: 8 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
version 3.15.3
--------------

**2023-08-31**

* Prevent unlimited dimensions from being written to CFA-netCDF files
(https://github.com/NCAS-CMS/cf-python/issues/689)

version 3.15.2
--------------

Expand Down
3 changes: 3 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
sphinxcontrib-spelling==4.3.0
* The `.py` files to generate recipes are stored in `docs/source/recipes/`.
* The netCDF and PP files for generation of the same are available to download at:
https://drive.google.com/drive/folders/1gaMHbV0A37hzQHH_C5oMBWOoxgoQPdCT?usp=sharing
* For every new added recipe, `docs/source/recipes/recipe_list.txt` has to be
edited to include the newly added recipe with its corresponding filters in the
Expand Down
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@
https://github.com/NCAS-CMS/cf-python/releases

* Upload the new release to Zenodo: https://zenodo.org/record/3961353

* Copy the archive docs to https://github.com/NCAS-CMS/cf-python-docs
6 changes: 3 additions & 3 deletions cf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
"""

__Conventions__ = "CF-1.10"
__date__ = "2023-07-21"
__version__ = "3.15.2"
__date__ = "2023-08-31"
__version__ = "3.15.3"

_requires = (
"numpy",
Expand Down Expand Up @@ -193,7 +193,7 @@
)

# Check the version of cfdm
_minimum_vn = "1.10.1.1"
_minimum_vn = "1.10.1.2"
_maximum_vn = "1.10.2.0"
_cfdm_version = Version(cfdm.__version__)
if not Version(_minimum_vn) <= _cfdm_version < Version(_maximum_vn):
Expand Down
26 changes: 26 additions & 0 deletions cf/read_write/netcdf/netcdfwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,32 @@ def __new__(cls, *args, **kwargs):
instance._NetCDFRead = NetCDFRead
return instance

def _unlimited(self, field, axis):
"""Whether an axis is unlimited.
If a CFA-netCDF file is being written then no axis can be
unlimited, i.e. `False` is always returned.
.. versionadded:: 3.15.3
:Parameters:
field: `Field` or `Domain`
axis: `str`
Domain axis construct identifier,
e.g. ``'domainaxis1'``.
:Returns:
`bool`
"""
if self.write_vars["cfa"]:
return False

return super()._unlimited(field, axis)

def _write_as_cfa(self, cfvar, construct_type, domain_axes):
"""Whether or not to write as a CFA variable.
Expand Down
18 changes: 16 additions & 2 deletions cf/test/test_CFA.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,6 @@ def test_CFA_PP(self):

def test_CFA_multiple_files(self):
"""Test storing multiple CFA frgament locations."""
tmpfile1 = "delme1.nc"
tmpfile2 = "delme2.nc"
f = cf.example_field(0)
cf.write(f, tmpfile1)
f = cf.read(tmpfile1)[0]
Expand All @@ -451,6 +449,22 @@ def test_CFA_multiple_files(self):
self.assertEqual(len(g.data.get_filenames()), 2)
self.assertEqual(len(g.get_filenames()), 3)

def test_CFA_unlimited_dimension(self):
"""Test CFA with unlimited dimensions"""
# Create a CFA file from a field that has an unlimited
# dimension and no metadata constructs spanning that dimension
f = cf.example_field(0)
d = f.domain_axis("X")
d.nc_set_unlimited(True)
f.del_construct("X")
cf.write(f, tmpfile1)
g = cf.read(tmpfile1)
cf.write(g, tmpfile2, cfa=True)

# Check that the CFA file can be read
h = cf.read(tmpfile2)
self.assertEqual(len(h), 1)


if __name__ == "__main__":
print("Run date:", datetime.datetime.now())
Expand Down
8 changes: 6 additions & 2 deletions docs/2_to_3_changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<script src="_static/copybutton.js"></script>
<script src="_static/toggleprompt.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="shortcut icon" href="_static/favicon.ico"/>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />

Expand All @@ -37,10 +38,13 @@

<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="index.html">
<img class="logo" src="_static/logo.svg" alt="Logo"/>
</a></p>



<h1 class="logo"><a href="index.html">cf 3.15.2</a></h1>
<h1 class="logo"><a href="index.html">cf 3.15.3</a></h1>



Expand Down Expand Up @@ -487,7 +491,7 @@ <h2>Changes to the API of existing methods<a class="headerlink" href="#changes-
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2023, NCAS | Page built on 2023-07-21.
&copy;2023, NCAS | Page built on 2023-08-31.

|
Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.5</a>
Expand Down
457 changes: 234 additions & 223 deletions docs/Changelog.html

Large diffs are not rendered by default.

Binary file modified docs/_downloads/cf_tutorial_files.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_downloads/plot_01_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_02_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_03_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_04_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_05_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_06_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_07_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_08_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_09_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_10_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_11_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/_downloads/plot_12_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"9. Now plot both the AOD from `high-quality` retrieval and all other retrievals \nusing [cfplot.con](http://ajheaps.github.io/cf-plot/con.html). Here:\n\n- [cfplot.gopen](http://ajheaps.github.io/cf-plot/gopen.html) is used to \n define the parts of the plot area, specifying that the figure should have \n 1 row and 2 columns, which is closed by \n [cfplot.gclose](http://ajheaps.github.io/cf-plot/gclose.html);\n- [plt.suptitle](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.suptitle.html)\n is used to add a title for the whole figure;\n- the subplots for plotting are selected using \n [cfplot.gpos](https://ajheaps.github.io/cf-plot/gpos.html) after which \n [cfplot.mapset](https://ajheaps.github.io/cf-plot/mapset.html) is used to \n set the map limits and resolution for the subplots; \n- and as cf-plot stores the plot in a plot object with the name \n ``cfp.plotvars.plot``, country borders are added using normal \n [Cartopy operations](https://scitools.org.uk/cartopy/docs/latest/reference/index.html) \n on the ``cfp.plotvars.mymap`` object:\n\n"
"9. Now plot both the AOD from `high-quality` retrieval and all other retrievals\nusing [cfplot.con](http://ajheaps.github.io/cf-plot/con.html). Here:\n\n- [cfplot.gopen](http://ajheaps.github.io/cf-plot/gopen.html) is used to\n define the parts of the plot area, specifying that the figure should have\n 1 row and 2 columns, which is closed by\n [cfplot.gclose](http://ajheaps.github.io/cf-plot/gclose.html);\n- [plt.suptitle](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.suptitle.html)\n is used to add a title for the whole figure;\n- the subplots for plotting are selected using\n [cfplot.gpos](https://ajheaps.github.io/cf-plot/gpos.html) after which\n [cfplot.mapset](https://ajheaps.github.io/cf-plot/mapset.html) is used to\n set the map limits and resolution for the subplots;\n- and as cf-plot stores the plot in a plot object with the name\n ``cfp.plotvars.plot``, country borders are added using normal\n [Cartopy operations](https://scitools.org.uk/cartopy/docs/latest/reference/index.html)\n on the ``cfp.plotvars.mymap`` object:\n\n"
]
},
{
Expand Down Expand Up @@ -197,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
22 changes: 11 additions & 11 deletions docs/_downloads/plot_12_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@
high = aod.where(mask, cf.masked)

# %%
# 9. Now plot both the AOD from `high-quality` retrieval and all other retrievals
# 9. Now plot both the AOD from `high-quality` retrieval and all other retrievals
# using `cfplot.con <http://ajheaps.github.io/cf-plot/con.html>`_. Here:
#
# - `cfplot.gopen <http://ajheaps.github.io/cf-plot/gopen.html>`_ is used to
# define the parts of the plot area, specifying that the figure should have
# 1 row and 2 columns, which is closed by
# - `cfplot.gopen <http://ajheaps.github.io/cf-plot/gopen.html>`_ is used to
# define the parts of the plot area, specifying that the figure should have
# 1 row and 2 columns, which is closed by
# `cfplot.gclose <http://ajheaps.github.io/cf-plot/gclose.html>`_;
# - `plt.suptitle <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.suptitle.html>`_
# is used to add a title for the whole figure;
# - the subplots for plotting are selected using
# `cfplot.gpos <https://ajheaps.github.io/cf-plot/gpos.html>`_ after which
# `cfplot.mapset <https://ajheaps.github.io/cf-plot/mapset.html>`_ is used to
# set the map limits and resolution for the subplots;
# - and as cf-plot stores the plot in a plot object with the name
# ``cfp.plotvars.plot``, country borders are added using normal
# `Cartopy operations <https://scitools.org.uk/cartopy/docs/latest/reference/index.html>`_
# - the subplots for plotting are selected using
# `cfplot.gpos <https://ajheaps.github.io/cf-plot/gpos.html>`_ after which
# `cfplot.mapset <https://ajheaps.github.io/cf-plot/mapset.html>`_ is used to
# set the map limits and resolution for the subplots;
# - and as cf-plot stores the plot in a plot object with the name
# ``cfp.plotvars.plot``, country borders are added using normal
# `Cartopy operations <https://scitools.org.uk/cartopy/docs/latest/reference/index.html>`_
# on the ``cfp.plotvars.mymap`` object:
import cartopy.feature as cfeature

Expand Down
6 changes: 3 additions & 3 deletions docs/_downloads/plot_13_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"8. The line for variable ``nino34_anomaly`` calculates the standardized\nanomaly for each time step in the ``nino34_index`` data. It subtracts the\n``climatology`` from the ``nino34_index`` and then divides by the ``std_dev``.\nThe resulting ``nino34_anomaly`` data represents how much the SST in the Ni\u00f1o \n3.4 region deviates from the 1961-1990 average, in units of standard \ndeviations. This is a common way to quantify climate anomalies like El Ni\u00f1o \nand La Ni\u00f1a events:\n\n"
"8. The line for variable ``nino34_anomaly`` calculates the standardized\nanomaly for each time step in the ``nino34_index`` data. It subtracts the\n``climatology`` from the ``nino34_index`` and then divides by the ``std_dev``.\nThe resulting ``nino34_anomaly`` data represents how much the SST in the Ni\u00f1o\n3.4 region deviates from the 1961-1990 average, in units of standard\ndeviations. This is a common way to quantify climate anomalies like El Ni\u00f1o\nand La Ni\u00f1a events:\n\n"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
},
"outputs": [],
"source": [
"elnino = nino34_rolling >= 0.4\nlanina = nino34_rolling <= -0.4\n\ncfp.gset(xmin='1940-1-1', xmax='2022-12-31', ymin=-3, ymax=3)\n\ncfp.gopen(figsize=(10, 6))\ncfp.lineplot(\n nino34_rolling,\n color=\"black\",\n title=\"SST Anomaly in Ni\u00f1o 3.4 Region (5N-5S, 120-170W)\",\n ylabel=\"Temperature anomaly ($\\degree C$)\",\n xlabel=\"Year\",\n)\ncfp.plotvars.plot.axhline(\n 0.4, color=\"red\", linestyle=\"--\", label=\"El Ni\u00f1o Threshold\"\n)\ncfp.plotvars.plot.axhline(\n -0.4, color=\"blue\", linestyle=\"--\", label=\"La Ni\u00f1a Threshold\"\n)\ncfp.plotvars.plot.axhline(0, color=\"black\", linestyle=\"-\", linewidth=1)\ncfp.plotvars.plot.fill_between(\n nino34_rolling.coordinate(\"T\").array,\n 0.4,\n nino34_rolling.array.squeeze(),\n where=elnino.squeeze(),\n color=\"red\",\n alpha=0.3,\n)\ncfp.plotvars.plot.fill_between(\n nino34_rolling.coordinate(\"T\").array,\n -0.4,\n nino34_rolling.array.squeeze(),\n where=lanina.squeeze(),\n color=\"blue\",\n alpha=0.3,\n)\ncfp.plotvars.plot.legend(frameon=False, loc=\"lower center\", ncol=2)\ncfp.gclose()"
"elnino = nino34_rolling >= 0.4\nlanina = nino34_rolling <= -0.4\n\ncfp.gset(xmin=\"1940-1-1\", xmax=\"2022-12-31\", ymin=-3, ymax=3)\n\ncfp.gopen(figsize=(10, 6))\ncfp.lineplot(\n nino34_rolling,\n color=\"black\",\n title=\"SST Anomaly in Ni\u00f1o 3.4 Region (5N-5S, 120-170W)\",\n ylabel=\"Temperature anomaly ($\\degree C$)\",\n xlabel=\"Year\",\n)\ncfp.plotvars.plot.axhline(\n 0.4, color=\"red\", linestyle=\"--\", label=\"El Ni\u00f1o Threshold\"\n)\ncfp.plotvars.plot.axhline(\n -0.4, color=\"blue\", linestyle=\"--\", label=\"La Ni\u00f1a Threshold\"\n)\ncfp.plotvars.plot.axhline(0, color=\"black\", linestyle=\"-\", linewidth=1)\ncfp.plotvars.plot.fill_between(\n nino34_rolling.coordinate(\"T\").array,\n 0.4,\n nino34_rolling.array.squeeze(),\n where=elnino.squeeze(),\n color=\"red\",\n alpha=0.3,\n)\ncfp.plotvars.plot.fill_between(\n nino34_rolling.coordinate(\"T\").array,\n -0.4,\n nino34_rolling.array.squeeze(),\n where=lanina.squeeze(),\n color=\"blue\",\n alpha=0.3,\n)\ncfp.plotvars.plot.legend(frameon=False, loc=\"lower center\", ncol=2)\ncfp.gclose()"
]
}
],
Expand All @@ -215,7 +215,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions docs/_downloads/plot_13_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@
# 8. The line for variable ``nino34_anomaly`` calculates the standardized
# anomaly for each time step in the ``nino34_index`` data. It subtracts the
# ``climatology`` from the ``nino34_index`` and then divides by the ``std_dev``.
# The resulting ``nino34_anomaly`` data represents how much the SST in the Niño
# 3.4 region deviates from the 1961-1990 average, in units of standard
# deviations. This is a common way to quantify climate anomalies like El Niño
# The resulting ``nino34_anomaly`` data represents how much the SST in the Niño
# 3.4 region deviates from the 1961-1990 average, in units of standard
# deviations. This is a common way to quantify climate anomalies like El Niño
# and La Niña events:
nino34_anomaly = (nino34_index - climatology) / std_dev

Expand Down Expand Up @@ -228,7 +228,7 @@
elnino = nino34_rolling >= 0.4
lanina = nino34_rolling <= -0.4

cfp.gset(xmin='1940-1-1', xmax='2022-12-31', ymin=-3, ymax=3)
cfp.gset(xmin="1940-1-1", xmax="2022-12-31", ymin=-3, ymax=3)

cfp.gopen(figsize=(10, 6))
cfp.lineplot(
Expand Down
2 changes: 1 addition & 1 deletion docs/_downloads/plot_14_recipe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 2c70d98

Please sign in to comment.