Skip to content

Conversation

@jonseddon
Copy link
Contributor

Added a gallery example showing how to concatenate NEMO ocean model data as suggested by @bjlittle . This PR requires SciTools/iris-sample-data#24.

them without the intervention shown here.
"""
from __future__ import unicode_literals
import iris

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I003 isort expected 1 blank line in imports, found 0

"""
from __future__ import unicode_literals
import iris
from iris.util import promote_aux_coord_to_dim_coord

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I001 isort found an import in the wrong position

@bjlittle
Copy link
Member

bjlittle commented Sep 16, 2019

@jonseddon Awesome, thanks! 😄

You weren't to know, but you also need to add a test for this new gallery example, that ensures our gallery items aren't broken.

You'll find boiler plate code of example tests for individual gallery items in the iris/docs/iris/example_tests directory. In particular, look at the other Oceanography gallery example test for atlantic_profiles, which you'll find in iris/docs/iris/example_tests/test_atlantic_profiles.py.

So you'll need a test_load_nemo.py file, that looks like this:

# (C) British Crown Copyright 2019, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Iris.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip)  # noqa

# Import Iris tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests

from .extest_util import (add_examples_to_path,
                          show_replaced_by_check_graphic,
                          fail_any_deprecation_warnings)


class TestLoadNemo(tests.GraphicsTest):
    """Test the load_nemo example code."""
    def test_load_nemo(self):
        with fail_any_deprecation_warnings():
            with add_examples_to_path():
                import load_nemo
            with show_replaced_by_check_graphic(self):
                load_nemo.main()


if __name__ == '__main__':
    tests.main()

When this test runs in our travis-ci instance, it will fail, simply because we don't have an entry for the perceptual image hash of the image generated by the gallery. Unfortunately, there is a bit more work involved to configure this, but I'll help you through this (somehow) 😅

@bjlittle
Copy link
Member

bjlittle commented Sep 16, 2019

@jonseddon Please apply the following patch to your branch...

Go to the directory containing the git branch for this PR.

Then, copy the following and paste it into a file called patchfile:

From c453b2e4e264f31226ffdf327c261e07fe84f3b8 Mon Sep 17 00:00:00 2001
From: Bill Little <[email protected]>
Date: Mon, 16 Sep 2019 19:52:39 +0100
Subject: [PATCH 1/2] added test_load_nemo.py

---
 docs/iris/example_tests/test_load_nemo.py | 41 +++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 docs/iris/example_tests/test_load_nemo.py

diff --git a/docs/iris/example_tests/test_load_nemo.py b/docs/iris/example_tests/test_load_nemo.py
new file mode 100644
index 000000000..13785609e
--- /dev/null
+++ b/docs/iris/example_tests/test_load_nemo.py
@@ -0,0 +1,41 @@
+# (C) British Crown Copyright 2019, Met Office
+#
+# This file is part of Iris.
+#
+# Iris is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Iris is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Iris.  If not, see <http://www.gnu.org/licenses/>.
+
+from __future__ import (absolute_import, division, print_function)
+from six.moves import (filter, input, map, range, zip)  # noqa
+
+# Import Iris tests first so that some things can be initialised before
+# importing anything else.
+import iris.tests as tests
+
+from .extest_util import (add_examples_to_path,
+                          show_replaced_by_check_graphic,
+                          fail_any_deprecation_warnings)
+
+
+class TestLoadNemo(tests.GraphicsTest):
+    """Test the load_nemo example code."""
+    def test_load_nemo(self):
+        with fail_any_deprecation_warnings():
+            with add_examples_to_path():
+                import load_nemo
+            with show_replaced_by_check_graphic(self):
+                load_nemo.main()
+
+
+if __name__ == '__main__':
+    tests.main()
-- 
2.16.5


From e540587fc37c406475ff48b87950d74cb8accb08 Mon Sep 17 00:00:00 2001
From: Bill Little <[email protected]>
Date: Mon, 16 Sep 2019 22:17:48 +0100
Subject: [PATCH 2/2] update imagerepo.json

---
 lib/iris/tests/results/imagerepo.json | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/iris/tests/results/imagerepo.json b/lib/iris/tests/results/imagerepo.json
index 540743366..3a5f0ab17 100644
--- a/lib/iris/tests/results/imagerepo.json
+++ b/lib/iris/tests/results/imagerepo.json
@@ -83,6 +83,9 @@
         "https://scitools.github.io/test-iris-imagehash/images/v4/eae942146540b869961f8de694589da69543cc9af1014afbc3fd596b84fe19a7.png",
         "https://scitools.github.io/test-iris-imagehash/images/v4/eafd9e12a5a061e9925ec716de489e9685078ec981b229e70ddb79219cc3768d.png"
     ],
+    "example_tests.test_load_nemo.TestLoadNemo.test_load_nemo.0": [
+        "https://scitools.github.io/test-iris-imagehash/images/v4/a3ff34e87f0049496d17c4d9c04fc225d256971392d39f1696df0f16cec00f36.png"
+    ],
     "example_tests.test_orca_projection.TestOrcaProjection.test_orca_projection.0": [
         "https://scitools.github.io/test-iris-imagehash/images/v4/fb11731a94cea4ee64b35e91d1d2304e9e5ac7397b20e1fe12852487e666ce46.png",
         "https://scitools.github.io/test-iris-imagehash/images/v4/bb11721a87cce5e4cce79e81d19b3b5e1e1cd3783168e07835853485e65e2e1e.png"
-- 
2.16.5


Then, perform the following command to apply the patch to your branch, which will introduce two new commits:

$ cat patchfile | git am

Then, to view the contents of those new commits in your branch from applying the patch:

$ git log -n2 -p

Once you're happy, push this to your repo to automatically update this PR:

$ git push origin HEAD

@bjlittle
Copy link
Member

bjlittle commented Sep 16, 2019

@jonseddon For this PR to run successfully on travis-ci, this PR SciTools/test-iris-imagehash#24 will require to be merged first.

@bjlittle
Copy link
Member

Ping @jonseddon ... do you have capacity to service this PR?

If not, then I'm happy to create another PR based on this to get it over the line 😉

@jonseddon
Copy link
Contributor Author

@bjlittle thanks for another prod. I should be able to finish the coding to get a big chunk of data out of the door this morning. As that's running I'll finish this PR. Sadly the tape system was too efficient last week and wrote my data in only a few hours and so I didn't get the rest that I hoped for then.

@jonseddon
Copy link
Contributor Author

@bjlittle Thanks for doing all the work for me! The patch has been applied and the tests successfully pass.

@bjlittle
Copy link
Member

@jonseddon Awesome, nice one! Thanks for the PR, hopefully the first of many 😉

@bjlittle bjlittle merged commit cb678c7 into SciTools:master Sep 24, 2019
@jonseddon jonseddon deleted the gallery-example branch September 25, 2019 09:33
@jonseddon jonseddon mentioned this pull request May 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants