Skip to content

Commit df579a3

Browse files
pp-motrexfeathersbjlittlelbdreyerjonseddon
authored
Update ng-vat with recent changes+fixes from master (#3685)
* Fixed tests since Numpy 1.18 deprecation of non-int num arguments for linspace. (#3655) * remove redundant tests (#3650) * Remove obsolete test. (#3662) * Remove grib-specific test. (#3663) * Removed ununused skipIf. (#3632) * Remove test_grib_save_rules.py which has been moved to iris-grib (#3666) * 2v4 mergeback picks (#3668) * Stop PPDataProxy accessing the file when no data is needed. (#3659) * Add 2.4 whatsnew into full whatsnew list. Co-authored-by: Martin Yeo <[email protected]> * Remove uri callback test which is moved to iris-grib (#3665) * Remove test_grib2 integration tests (#3664) * Remove test_grib_save.py (#3669) * Remove cube iter (#3656) * Fixed asv project name to 'scitools-iris'. (#3660) * Removed grib-specific test to iris-grib. (#3671) * Removed iris.tests.integration.test_grib_load and related CML files. (#3670) * Remove TestGribMessage (#3672) * Switched use of datetime.weekday() to datetime.dayofwk. (#3687) * New image hashes for mpl 3x2 (#3682) * New image hash for iris.test.test_plot.TestSymbols.test_cloud_cover with matplotlib 3.2.0. * Further images changes for mpl3x2. * Yet more updated image results. * Correct and improve dev-guide section on fixing graphics-tests. (#3683) * Correct and improve dev-guide section on fixing graphics-tests. * Review changes + general rethink. * Reduce duplication between 'graphics-tests' and general 'tests' page. * Update docs/iris/src/developers_guide/graphics_tests.rst Co-Authored-By: Martin Yeo <[email protected]> * Update docs/iris/src/developers_guide/graphics_tests.rst Co-Authored-By: Martin Yeo <[email protected]> * Update docs/iris/src/developers_guide/graphics_tests.rst Co-Authored-By: Martin Yeo <[email protected]> * Update docs/iris/src/developers_guide/graphics_tests.rst Co-Authored-By: Martin Yeo <[email protected]> * Update docs/iris/src/developers_guide/graphics_tests.rst Co-Authored-By: Martin Yeo <[email protected]> Co-authored-by: Martin Yeo <[email protected]> Co-authored-by: Martin Yeo <[email protected]> Co-authored-by: Bill Little <[email protected]> Co-authored-by: lbdreyer <[email protected]> Co-authored-by: Jon Seddon <[email protected]>
1 parent c9506e6 commit df579a3

File tree

65 files changed

+448
-3379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+448
-3379
lines changed

asv.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// details on what can be included in this file.
33
{
44
"version": 1,
5-
"project": "iris",
5+
"project": "scitools-iris",
66
"project_url": "https://github.com/SciTools/iris",
77
"repo": ".",
88
"environment_type": "conda",

docs/iris/src/developers_guide/graphics_tests.rst

Lines changed: 102 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ For this, a basic 'graphics test' assertion operation is provided in the method
1010
match against a stored reference.
1111
A "graphics test" is any test which employs this.
1212

13-
At present (Iris version 1.10), such tests include the testing for modules
14-
`iris.tests.test_plot` and `iris.tests.test_quickplot`, and also some other
15-
'legacy' style tests (as described in :ref:`developer_tests`).
13+
At present, such tests include the testing for modules `iris.tests.test_plot`
14+
and `iris.tests.test_quickplot`, all output plots from the gallery examples
15+
(contained in `docs/iris/example_tests`), and a few other 'legacy' style tests
16+
(as described in :ref:`developer_tests`).
1617
It is conceivable that new 'graphics tests' of this sort can still be added.
1718
However, as graphics tests are inherently "integration" style rather than true
1819
unit tests, results can differ with the installed versions of dependent
@@ -38,80 +39,110 @@ Testing actual plot results introduces some significant difficulties :
3839
Graphics Testing Strategy
3940
=========================
4041

41-
Prior to Iris 1.10, all graphics tests compared against a stored reference
42-
image with a small tolerance on pixel values.
42+
In the Iris Travis matrix, and over time, graphics tests must run with
43+
multiple versions of Python, and of key dependencies such as matplotlib.
44+
To make this manageable, the "check_graphic" test routine tests against
45+
multiple alternative 'acceptable' results. It does this using an image "hash"
46+
comparison technique which avoids storing reference images in the Iris
47+
repository itself, to avoid space problems.
4348

44-
From Iris v1.11 onward, we want to support testing Iris against multiple
45-
versions of matplotlib (and some other dependencies).
46-
To make this manageable, we have now rewritten "check_graphic" to allow
47-
multiple alternative 'correct' results without including many more images in
48-
the Iris repository.
4949
This consists of :
5050

51-
* using a perceptual 'image hash' of the outputs (see
52-
https://github.com/JohannesBuchner/imagehash) as the basis for checking
51+
* The 'check_graphic' function uses a perceptual 'image hash' of the outputs
52+
(see https://github.com/JohannesBuchner/imagehash) as the basis for checking
5353
test results.
54-
* storing the hashes of 'known accepted results' for each test in a
55-
database in the repo (which is actually stored in
56-
``lib/iris/tests/results/imagerepo.json``).
57-
* storing associated reference images for each hash value in a separate public
58-
repository, currently in https://github.com/SciTools/test-images-scitools ,
59-
allowing human-eye judgement of 'valid equivalent' results.
60-
* a new version of the 'iris/tests/idiff.py' assists in comparing proposed
61-
new 'correct' result images with the existing accepted ones.
62-
63-
BRIEF...
64-
There should be sufficient work-flow detail here to allow an iris developer to:
65-
66-
* understand the new check graphic test process
67-
* understand the steps to take and tools to use to add a new graphic test
68-
* understand the steps to take and tools to use to diagnose and fix an graphic test failure
69-
70-
71-
Basic workflow
72-
==============
73-
74-
If you notice that a graphics test in the Iris testing suite has failed
75-
following changes in Iris or any of its dependencies, this is the process
76-
you now need to follow:
77-
78-
#. Create a directory in iris/lib/iris/tests called 'result_image_comparison'.
79-
#. From your Iris root directory, run the tests by using the command:
80-
``python setup.py test``.
81-
#. Navigate to iris/lib/iris/tests and run the command: ``python idiff.py``.
82-
This will open a window for you to visually inspect the changes to the
83-
graphic and then either accept or reject the new result.
84-
#. Upon acceptance of a change or a new image, a copy of the output PNG file
85-
is added to the reference image repository in
86-
https://github.com/SciTools/test-images-scitools. The file is named
87-
according to the image hash value, as ``<hash>.png``.
88-
#. The hash value of the new result is added into the relevant set of 'valid
89-
result hashes' in the image result database file,
90-
``tests/results/imagerepo.json``.
91-
#. The tests must now be re-run, and the 'new' result should be accepted.
92-
Occasionally there are several graphics checks in a single test, only the
93-
first of which will be run should it fail. If this is the case, then you
94-
may well encounter further graphical test failures in your next runs, and
95-
you must repeat the process until all the graphical tests pass.
96-
#. To add your changes to Iris, you need to make two pull requests. The first
97-
should be made to the test-images-scitools repository, and this should
98-
contain all the newly-generated png files copied into the folder named
99-
'image_files'.
100-
#. The second pull request should be created in the Iris repository, and should
101-
only include the change to the image results database
102-
(``tests/results/imagerepo.json``) :
103-
This pull request must contain a reference to the matching one in
104-
test-images-scitools.
54+
* The hashes of known 'acceptable' results for each test are stored in a
55+
lookup dictionary, saved to the repo file
56+
``lib/iris/tests/results/imagerepo.json`` .
57+
* An actual reference image for each hash value is stored in a *separate*
58+
public repository : https://github.com/SciTools/test-iris-imagehash .
59+
* The reference images allow human-eye assessment of whether a new output is
60+
judged to be 'close enough' to the older ones, or not.
61+
* The utility script ``iris/tests/idiff.py`` automates checking, enabling the
62+
developer to easily compare proposed new 'acceptable' result images against the
63+
existing accepted reference images, for each failing test.
10564

106-
Note: the Iris pull-request will not test out successfully in Travis until the
107-
test-images-scitools pull request has been merged : This is because there is
108-
an Iris test which ensures the existence of the reference images (uris) for all
109-
the targets in the image results database.
11065

66+
How to Add New 'Acceptable' Result Images to Existing Tests
67+
========================================
68+
69+
When you find that a graphics test in the Iris testing suite has failed,
70+
following changes in Iris or the run dependencies, this is the process
71+
you should follow:
72+
73+
#. Create a new, empty directory to store temporary image results, at the path
74+
``lib/iris/tests/result_image_comparison`` in your Iris repository checkout.
75+
76+
#. **In your Iris repo root directory**, run the relevant (failing) tests
77+
directly as python scripts, or by using a command such as
78+
``python -m unittest discover paths/to/test/files``.
79+
80+
#. **In the** ``iris/lib/iris/tests`` **folder**, run the command: ``python idiff.py``.
81+
This will open a window for you to visually inspect side-by-side 'old', 'new'
82+
and 'difference' images for each failed graphics test.
83+
Hit a button to either "accept", "reject" or "skip" each new result ...
84+
85+
* If the change is *"accepted"* :
86+
87+
* the imagehash value of the new result image is added into the relevant
88+
set of 'valid result hashes' in the image result database file,
89+
``tests/results/imagerepo.json`` ;
90+
91+
* the relevant output file in ``tests/result_image_comparison`` is
92+
renamed according to the image hash value, as ``<hash>.png``.
93+
A copy of this new PNG file must then be added into the reference image
94+
repository at https://github.com/SciTools/test-iris-imagehash.
95+
(See below).
96+
97+
* If a change is *"skipped"* :
98+
99+
* no further changes are made in the repo.
100+
101+
* when you run idiff again, the skipped choice will be presented again.
111102

112-
Fixing a failing graphics test
113-
==============================
103+
* If a change is *"rejected"* :
114104

105+
* the output image is deleted from ``result_image_comparison``.
115106

116-
Adding a new graphics test
117-
==========================
107+
* when you run idiff again, the skipped choice will not appear, unless
108+
and until the relevant failing test is re-run.
109+
110+
#. Now re-run the tests. The 'new' result should now be recognised and the
111+
relevant test should pass. However, some tests can perform *multiple* graphics
112+
checks within a single testcase function : In those cases, any failing
113+
check will prevent the following ones from being run, so a test re-run may
114+
encounter further (new) graphical test failures. If that happens, simply
115+
repeat the check-and-accept process until all tests pass.
116+
117+
#. To add your changes to Iris, you need to make two pull requests :
118+
119+
* (1) The first PR is made in the test-iris-imagehash repository, at
120+
https://github.com/SciTools/test-iris-imagehash.
121+
122+
* First, add all the newly-generated referenced PNG files into the
123+
``images/v4`` directory. In your Iris repo, these files are to be found
124+
in the temporary results folder ``iris/tests/result_image_comparison``.
125+
126+
.. Note::
127+
128+
The ``result_image_comparison`` folder is covered by a project
129+
``.gitignore`` setting, so those files *will not show up* in a
130+
``git status`` check.
131+
132+
* Then, run ``python recreate_v4_files_listing.py``, to update the file
133+
which lists available images, ``v4_files_listing.txt``.
134+
135+
* Create a PR proposing these changes, in the usual way.
136+
137+
* (2) The second PR is created in the Iris repository, and
138+
should only include the change to the image results database,
139+
``tests/results/imagerepo.json`` :
140+
The description box of this pull request should contain a reference to
141+
the matching one in test-iris-imagehash.
142+
143+
Note: the Iris pull-request will not test out successfully in Travis until the
144+
test-iris-imagehash pull request has been merged : This is because there is
145+
an Iris test which ensures the existence of the reference images (uris) for all
146+
the targets in the image results database. N.B. likewise, it will *also* fail
147+
if you forgot to run ``recreate_v4_files_listing.py`` to update the image-listing
148+
file in test-iris-imagehash.

docs/iris/src/developers_guide/tests.rst

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,5 @@ This the only way of testing the modules :mod:`iris.plot` and
139139
:mod:`iris.quickplot`, but is also used for some other legacy and integration-
140140
style testcases.
141141

142-
Prior to Iris version 1.10, a single reference image for each testcase was
143-
stored in the main Iris repository, and a 'tolerant' comparison was performed
144-
against this.
145-
146-
From version 1.11 onwards, graphics testcase outputs are compared against
147-
possibly *multiple* known-good images, of which only the signature is stored.
148-
This uses a sophisticated perceptual "image hashing" scheme (see:
149-
<https://github.com/JohannesBuchner/imagehash>).
150-
Only imagehash signatures are stored in the Iris repo itself, thus freeing up
151-
valuable space. Meanwhile, the actual reference *images* -- which are required
152-
for human-eyes evaluation of proposed new "good results" -- are all stored
153-
elsewhere in a separate public repository.
142+
There are specific mechanisms for handling this.
154143
See :ref:`developer_graphics_tests`.

docs/iris/src/userguide/subsetting_a_cube.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ same way as loading with constraints:
103103

104104
Cube iteration
105105
^^^^^^^^^^^^^^^
106+
It is not possible to directly iterate over an Iris cube. That is, you cannot use code such as
107+
``for x in cube:``. However, you can iterate over cube slices, as this section details.
108+
106109
A useful way of dealing with a Cube in its **entirety** is by iterating over its layers or slices.
107110
For example, to deal with a 3 dimensional cube (z,y,x) you could iterate over all 2 dimensional slices in y and x
108111
which make up the full 3d cube.::

docs/iris/src/whatsnew/2.4.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
What's New in Iris 2.4.0
2+
************************
3+
4+
:Release: 2.4.0
5+
:Date: 2020-02-20
6+
7+
This document explains the new/changed features of Iris in version 2.4.0
8+
(:doc:`View all changes <index>`.)
9+
10+
11+
Iris 2.4.0 Features
12+
===================
13+
14+
.. admonition:: Last python 2 version of Iris
15+
16+
Iris 2.4 is a final extra release of Iris 2, which back-ports specific desired features from
17+
Iris 3 (not yet released).
18+
19+
The purpose of this is both to support early adoption of certain newer features,
20+
and to provide a final release for Python 2.
21+
22+
The next release of Iris will be version 3.0 : a major-version release which
23+
introduces breaking API and behavioural changes, and only supports Python 3.
24+
25+
* :class:`iris.coord_systems.Geostationary` can now accept creation arguments of
26+
`false_easting=None` or `false_northing=None`, equivalent to values of 0.
27+
Previously these kwargs could be omitted, but could not be set to `None`.
28+
This also enables loading of netcdf data on a Geostationary grid, where either of these
29+
keys is not present as a grid-mapping variable property : Previously, loading any
30+
such data caused an exception.
31+
* The area weights used when performing area weighted regridding with :class:`iris.analysis.AreaWeighted`
32+
are now cached.
33+
This allows a significant speedup when regridding multiple similar cubes, by repeatedly using
34+
a `'regridder' object <../iris/iris/analysis.html?highlight=regridder#iris.analysis.AreaWeighted.regridder>`_
35+
which you created first.
36+
* Name constraint matching against cubes during loading or extracting has been relaxed from strictly matching
37+
against the :meth:`~iris.cube.Cube.name`, to matching against either the
38+
``standard_name``, ``long_name``, NetCDF ``var_name``, or ``STASH`` attributes metadata of a cube.
39+
* Cubes and coordinates now have a new ``names`` property that contains a tuple of the
40+
``standard_name``, ``long_name``, NetCDF ``var_name``, and ``STASH`` attributes metadata.
41+
* The :class:`~iris.NameConstraint` provides richer name constraint matching when loading or extracting
42+
against cubes, by supporting a constraint against any combination of
43+
``standard_name``, ``long_name``, NetCDF ``var_name`` and ``STASH``
44+
from the attributes dictionary of a :class:`~iris.cube.Cube`.
45+
46+
47+
Iris 2.4.0 Dependency Updates
48+
=============================
49+
* Iris is now able to use the latest version of matplotlib.
50+
51+
52+
Bugs Fixed
53+
==========
54+
* Fixed a problem which was causing file loads to fetch *all* field data
55+
whenever UM files (PP or Fieldsfiles) were loaded.
56+
With large sourcefiles, initial file loads are slow, with large memory usage
57+
before any cube data is even fetched. Large enough files will cause a crash.
58+
The problem occurs only with Dask versions >= 2.0.
59+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* The `__iter__()` method in class:`iris.cube.Cube` was set to `None`.
2+
`TypeError` is still raised if a `Cube` is iterated over but
3+
`isinstance(cube, collections.Iterable)` now behaves as expected.

docs/iris/src/whatsnew/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Iris versions.
1111

1212
latest.rst
1313
3.0.rst
14+
2.4.rst
1415
2.3.rst
1516
2.2.rst
1617
2.1.rst

lib/iris/coord_categorisation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def add_day_of_year(cube, coord, name="day_of_year"):
182182
def add_weekday_number(cube, coord, name="weekday_number"):
183183
"""Add a categorical weekday coordinate, values 0..6 [0=Monday]."""
184184
add_categorised_coord(
185-
cube, name, coord, lambda coord, x: _pt_date(coord, x).weekday()
185+
cube, name, coord, lambda coord, x: _pt_date(coord, x).dayofwk
186186
)
187187

188188

@@ -192,7 +192,7 @@ def add_weekday_fullname(cube, coord, name="weekday_fullname"):
192192
cube,
193193
name,
194194
coord,
195-
lambda coord, x: calendar.day_name[_pt_date(coord, x).weekday()],
195+
lambda coord, x: calendar.day_name[_pt_date(coord, x).dayofwk],
196196
units="no_unit",
197197
)
198198

@@ -203,7 +203,7 @@ def add_weekday(cube, coord, name="weekday"):
203203
cube,
204204
name,
205205
coord,
206-
lambda coord, x: calendar.day_abbr[_pt_date(coord, x).weekday()],
206+
lambda coord, x: calendar.day_abbr[_pt_date(coord, x).dayofwk],
207207
units="no_unit",
208208
)
209209

lib/iris/cube.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,8 +2622,9 @@ def _repr_html_(self):
26222622
representer = CubeRepresentation(self)
26232623
return representer.repr_html()
26242624

2625-
def __iter__(self):
2626-
raise TypeError("Cube is not iterable")
2625+
# Indicate that the iter option is not available. Python will raise
2626+
# TypeError with a useful message if a Cube is iterated over.
2627+
__iter__ = None
26272628

26282629
def __getitem__(self, keys):
26292630
"""

lib/iris/fileformats/pp.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939
import iris.fileformats.rules
4040
import iris.coord_systems
41-
41+
from iris.util import _array_slice_ifempty
4242

4343
try:
4444
import mo_pack
@@ -594,19 +594,25 @@ def ndim(self):
594594
return len(self.shape)
595595

596596
def __getitem__(self, keys):
597-
with open(self.path, "rb") as pp_file:
598-
pp_file.seek(self.offset, os.SEEK_SET)
599-
data_bytes = pp_file.read(self.data_len)
600-
data = _data_bytes_to_shaped_array(
601-
data_bytes,
602-
self.lbpack,
603-
self.boundary_packing,
604-
self.shape,
605-
self.src_dtype,
606-
self.mdi,
607-
)
608-
data = data.__getitem__(keys)
609-
return np.asanyarray(data, dtype=self.dtype)
597+
# Check for 'empty' slicings, in which case don't fetch the data.
598+
# Because, since Dask v2, 'dask.array.from_array' performs an empty
599+
# slicing and we must not fetch the data at that time.
600+
result = _array_slice_ifempty(keys, self.shape, self.dtype)
601+
if result is None:
602+
with open(self.path, "rb") as pp_file:
603+
pp_file.seek(self.offset, os.SEEK_SET)
604+
data_bytes = pp_file.read(self.data_len)
605+
data = _data_bytes_to_shaped_array(
606+
data_bytes,
607+
self.lbpack,
608+
self.boundary_packing,
609+
self.shape,
610+
self.src_dtype,
611+
self.mdi,
612+
)
613+
result = data.__getitem__(keys)
614+
615+
return np.asanyarray(result, dtype=self.dtype)
610616

611617
def __repr__(self):
612618
fmt = (

0 commit comments

Comments
 (0)