Skip to content
Merged

Orca eg #1054

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:
- export IRIS_TEST_DATA_REF="3378fe68c00ca7f31895ab6630a59a39ccef94e3"
- export IRIS_TEST_DATA_SUFFIX=$(echo "${IRIS_TEST_DATA_REF}" | sed "s/^v//")

- export IRIS_SAMPLE_DATA_REF="2e7c73504e3d675d97dc8a2c2939f9fd2cfe51f1"
- export IRIS_SAMPLE_DATA_REF="1ed3e26606366717e2053bacc12bf5e8d8fa2704"
- export IRIS_SAMPLE_DATA_SUFFIX=$(echo "${IRIS_SAMPLE_DATA_REF}" | sed "s/^v//")

# Switch off virtualenv so we can use apt-get for Python packages.
Expand Down
58 changes: 58 additions & 0 deletions docs/iris/example_code/graphics/orca_projection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Tru-Polar Grid Projected Ploting
================================

This example demonstrates cell plots of data on the semi-structured ORCA2 model
grid.

First, the data is projected into the PlateCarree coordinate reference system.

Second four pcolormesh plots are created from this projected dataset,
using different projections for the output image.

"""

import matplotlib
import matplotlib.pyplot as plt

import cartopy.crs as ccrs
import iris
import iris.analysis.cartography
import iris.quickplot as qplt


def main():
# Load data
filepath = iris.sample_data_path('orca2_votemper.nc')
cube = iris.load_cube(filepath)

# Choose plot projections
projections = {}
projections['Mollweide'] = ccrs.Mollweide()
projections['PlateCarree'] = ccrs.PlateCarree()
projections['NorthPolarStereo'] = ccrs.NorthPolarStereo()
projections['Orthographic'] = ccrs.Orthographic(central_longitude=-90,
central_latitude=45)
Copy link
Member

Choose a reason for hiding this comment

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

@marqh You could slightly refactor this to be ...

    projections = dict(Mollweide=ccrs.Mollweide(),
                       PlateCarree=ccrs.PlateCarree(),
                       NorthPolarStereo=ccrs.NorthPolarStereo(),
                       Orthographic=ccrs.Orthographic(central_longitude=-90,
                                                      central_latitude=45))


pcarree = projections['PlateCarree']
# Transform cube to target projection
new_cube, extent = iris.analysis.cartography.project(cube, pcarree,
nx=400, ny=200)

# Plot data in each projection
for name in sorted(projections):
fig = plt.figure()
fig.suptitle('ORCA2 Data Projected to {}'.format(name))
# Set up axes and title
ax = plt.subplot(projection=projections[name])
# Set limits
ax.set_global()
# plot with Iris quickplot pcolormesh
qplt.pcolormesh(new_cube)
# Draw coastlines
ax.coastlines()

plt.show()

if __name__ == '__main__':
main()
37 changes: 37 additions & 0 deletions docs/iris/example_tests/test_orca_projection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# (C) British Crown Copyright 2014, 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/>.


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

import extest_util

with extest_util.add_examples_to_path():
import orca_projection


class TestOrcaProjection(tests.GraphicsTest):
"""Test the orca projection example code."""
def test_orca_projection(self):
with extest_util.show_replaced_by_check_graphic(self):
orca_projection.main()


if __name__ == '__main__':
tests.main()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.