Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration test for iris.plot.contour with 2d coords. #3189

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 31 additions & 1 deletion lib/iris/tests/integration/plot/test_plot_2d_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@
# importing anything else
import iris.tests as tests

import cartopy.crs as ccrs
import numpy as np
Copy link
Member

Choose a reason for hiding this comment

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

@pp-mo why is the NumPy import separate at the top? At minimum I feel it should be after the pyplot import. Preferably they would both be after the Iris imports.

Copy link
Member Author

@pp-mo pp-mo Oct 8, 2018

Choose a reason for hiding this comment

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

I think this is just another slip-up 😁

But... presumably you mean "NumPy ... after the pyplot ... before the Iris imports" ??
My understanding of our guidelines for imports is to separate into 3 or 4 specific groups :

  1. standard-library packages
  2. other 3rd party libraries
  3. "own" packages + modules
  4. (in tests only) test subjects

So here, numpy and pyplot should be in the same block,
but before any Iris stuff
(except iris.tests, which is required to happen first. 🤢 yech ).

This agree with your understanding @dkillick ?

Copy link
Member

Choose a reason for hiding this comment

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

This agree with your understanding

Yes... and no, at the same time! Basically, I feel like we've slipped away from separating (2.) and (3.), even in test modules. It's not worth sweating about here, but I would still like to see the NumPy import at least after the pyplot import 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

👍


import matplotlib.pyplot as plt

import cartopy.crs as ccrs
import iris
from iris.analysis.cartography import unrotate_pole
from iris.cube import Cube
from iris.coords import AuxCoord


# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
Expand Down Expand Up @@ -63,5 +69,29 @@ def test_2d_coord_bounds_northpolarstereo(self):
self.check_graphic()


@tests.skip_plot
@tests.skip_data
Copy link
Member

Choose a reason for hiding this comment

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

@pp-mo you shouldn't need this decorator as you're not making use of external test data.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 cut+paste error, I think.
Good spot !!

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, that old chestnut 🌰

class Test2dContour(tests.GraphicsTest):
def test_2d_coords_contour(self):
ny, nx = 4, 6
x1 = np.linspace(-20, 70, nx)
y1 = np.linspace(10, 60, ny)
data = np.zeros((ny, nx))
data.flat[:] = np.arange(nx * ny) % 7
cube = Cube(data, long_name='Odd data')
x2, y2 = np.meshgrid(x1, y1)
true_lons, true_lats = unrotate_pole(x2, y2, -130., 77.)
co_x = AuxCoord(true_lons, standard_name='longitude', units='degrees')
co_y = AuxCoord(true_lats, standard_name='latitude', units='degrees')
cube.add_aux_coord(co_y, (0, 1))
cube.add_aux_coord(co_x, (0, 1))
ax = plt.axes(projection=ccrs.PlateCarree())
qplt.contourf(cube)
ax.coastlines(color='red')
ax.gridlines(draw_labels=True)
ax.set_extent((0, 180, 0, 90))
self.check_graphic()


if __name__ == "__main__":
tests.main()
Loading