Skip to content
Merged
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
12 changes: 12 additions & 0 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ def patch(self, *args, **kwargs):
# Return patch replacement object.
return start_result

def assertArrayShapeStats(self, result, shape, mean, std_dev):
"""
Assert that the result, a cube, has the provided shape and that the
mean and standard deviation of the data array are also as provided.
Thus build confidence that a cube processing operation, such as a
cube.regrid, has maintained its behaviour.

"""
self.assertEqual(result.shape, shape)
self.assertAlmostEqual(result.data.mean(), mean, places=5)
self.assertAlmostEqual(result.data.std(), std_dev, places=5)


get_result_path = IrisTest.get_result_path

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013 - 2015, Met Office
# (C) British Crown Copyright 2013 - 2016, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -37,12 +37,6 @@
import iris.analysis._interpolation
import iris.tests.stock

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
import matplotlib.pyplot as plt
import iris.quickplot as qplt


RESULT_DIR = ('experimental', 'regrid',
'regrid_area_weighted_rectilinear_src_and_grid')

Expand Down Expand Up @@ -161,7 +155,7 @@ def _resampled_grid(cube, x_samplefactor, y_samplefactor):
return new_cube


class TestAreaWeightedRegrid(tests.GraphicsTest):
class TestAreaWeightedRegrid(tests.IrisTest):
def setUp(self):
# A cube with a hybrid height derived coordinate.
self.realistic_cube = iris.tests.stock.realistic_4d()[:2, :5, :20, :30]
Expand Down Expand Up @@ -367,25 +361,11 @@ def test_regrid_to_higher_res(self):
res = regrid_area_weighted(src, dest)
self.assertCMLApproxData(res, RESULT_DIR + ('higher.cml',))

@tests.skip_plot
def test_hybrid_height(self):
src = self.realistic_cube
dest = _resampled_grid(src, 0.7, 0.8)
res = regrid_area_weighted(src, dest)
self.assertCMLApproxData(res, RESULT_DIR + ('hybridheight.cml',))
# Consider a single slice to allow visual tests of altitudes.
src = src[1, 2]
res = res[1, 2]
qplt.pcolormesh(res)
self.check_graphic()
plt.contourf(res.coord('grid_longitude').points,
res.coord('grid_latitude').points,
res.coord('altitude').points)
self.check_graphic()
plt.contourf(res.coord('grid_longitude').points,
res.coord('grid_latitude').points,
res.coord('surface_altitude').points)
self.check_graphic()

def test_missing_data(self):
src = self.simple_cube.copy()
Expand Down Expand Up @@ -443,7 +423,6 @@ def test_ten_by_ten_subset(self):
res = regrid_area_weighted(src, dest)
self.assertTrue(res, src[indices])

@tests.skip_plot
def test_cross_section(self):
# Slice to get a cross section.
# Constant latitude
Expand All @@ -458,10 +437,6 @@ def test_cross_section(self):
res = regrid_area_weighted(src, dest)
self.assertCMLApproxData(res, RESULT_DIR +
('const_lat_cross_section.cml',))
# Plot a single slice.
qplt.plot(res[0])
qplt.plot(src[0], 'r')
self.check_graphic()

# Constant longitude
src = self.realistic_cube[0, :, :, 10]
Expand All @@ -475,10 +450,6 @@ def test_cross_section(self):
res = regrid_area_weighted(src, dest)
self.assertCMLApproxData(res, RESULT_DIR +
('const_lon_cross_section.cml',))
# Plot a single slice.
qplt.plot(res[0])
qplt.plot(src[0], 'r')
self.check_graphic()

def test_scalar_source_cube(self):
src = self.simple_cube[1, 2]
Expand All @@ -495,39 +466,32 @@ def test_scalar_source_cube(self):
self.assertEqual(res.data, src.data)

@tests.skip_data
@tests.skip_plot
def test_global_data_reduce_res(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
src.coord('longitude').guess_bounds()
dest = _resampled_grid(src, 0.4, 0.3)
res = regrid_area_weighted(src, dest)
qplt.pcolormesh(res)
self.check_graphic()
self.assertArrayShapeStats(res, (21, 38), 280.137698, 15.998966)

@tests.skip_data
@tests.skip_plot
def test_global_data_increase_res(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
src.coord('longitude').guess_bounds()
dest = _resampled_grid(src, 1.5, 1.5)
res = regrid_area_weighted(src, dest)
qplt.pcolormesh(res)
self.check_graphic()
self.assertArrayShapeStats(res, (109, 144), 279.955722, 16.313940)

@tests.skip_data
@tests.skip_plot
def test_global_data_same_res(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
src.coord('longitude').guess_bounds()
res = regrid_area_weighted(src, src)
qplt.pcolormesh(res)
self.check_graphic()
self.assertArrayShapeStats(res, (73, 96), 279.945167, 16.345842)

@tests.skip_data
@tests.skip_plot
def test_global_data_subset(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
Expand All @@ -545,12 +509,9 @@ def test_global_data_subset(self):
dest.add_dim_coord(dest_lon, 1)

res = regrid_area_weighted(src, dest)
qplt.pcolormesh(res)
plt.gca().coastlines()
self.check_graphic()
self.assertArrayShapeStats(res, (40, 30), 280.979336, 16.640421)

@tests.skip_data
@tests.skip_plot
def test_circular_subset(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
Expand All @@ -568,12 +529,9 @@ def test_circular_subset(self):
dest.add_dim_coord(dest_lon, 1)

res = regrid_area_weighted(src, dest)
qplt.pcolormesh(res)
plt.gca().coastlines()
self.check_graphic()
self.assertArrayShapeStats(res, (40, 7), 285.653967, 15.212710)

@tests.skip_data
@tests.skip_plot
def test_non_circular_subset(self):
src = iris.tests.stock.global_pp()
src.coord('latitude').guess_bounds()
Expand All @@ -592,9 +550,7 @@ def test_non_circular_subset(self):
dest.add_dim_coord(dest_lon, 1)

res = regrid_area_weighted(src, dest)
qplt.pcolormesh(res)
plt.gca().coastlines()
self.check_graphic()
self.assertArrayShapeStats(res, (40, 7), 285.550800, 15.190245)


if __name__ == "__main__":
Expand Down
56 changes: 0 additions & 56 deletions lib/iris/tests/integration/test_grib_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@
from unittest import skipIf


# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
import iris.plot as iplt
import iris.quickplot as qplt

if tests.GRIB_AVAILABLE:
try:
import iris_grib
Expand Down Expand Up @@ -97,64 +90,32 @@ def test_load_masked(self):
self.assertCML(cubes, ('grib_load', 'missing_values_grib2.cml'))

@skip_irisgrib_fails
@tests.skip_plot
def test_y_fastest(self):
cubes = iris.load(tests.get_data_path(("GRIB", "y_fastest",
"y_fast.grib2")))
self.assertCML(cubes, ("grib_load", "y_fastest.cml"))
iplt.contourf(cubes[0])
plt.gca().coastlines()
plt.title("y changes fastest")
self.check_graphic()

@tests.skip_plot
def test_polar_stereo_grib1(self):
cube = iris.load_cube(tests.get_data_path(
("GRIB", "polar_stereo", "ST4.2013052210.01h")))
self.assertCML(cube, ("grib_load", "polar_stereo_grib1.cml"))
qplt.contourf(cube, norm=LogNorm())
plt.gca().coastlines()
plt.gca().gridlines()
plt.title("polar stereo grib1")
self.check_graphic()

@tests.skip_plot
def test_polar_stereo_grib2(self):
cube = iris.load_cube(tests.get_data_path(
("GRIB", "polar_stereo",
"CMC_glb_TMP_ISBL_1015_ps30km_2013052000_P006.grib2")))
self.assertCML(cube, ("grib_load", "polar_stereo_grib2.cml"))

qplt.contourf(cube)
plt.gca().coastlines()
plt.gca().gridlines()
plt.title("polar stereo grib2")
self.check_graphic()

@tests.skip_plot
def test_lambert_grib1(self):
cube = iris.load_cube(tests.get_data_path(
("GRIB", "lambert", "lambert.grib1")))
self.assertCML(cube, ("grib_load", "lambert_grib1.cml"))

qplt.contourf(cube)
plt.gca().coastlines()
plt.gca().gridlines()
plt.title("lambert grib1")
self.check_graphic()

@tests.skip_plot
def test_lambert_grib2(self):
cube = iris.load_cube(tests.get_data_path(
("GRIB", "lambert", "lambert.grib2")))
self.assertCML(cube, ("grib_load", "lambert_grib2.cml"))

qplt.contourf(cube)
plt.gca().coastlines()
plt.gca().gridlines()
plt.title("lambert grib2")
self.check_graphic()

def test_regular_gg_grib1(self):
cube = iris.load_cube(tests.get_data_path(
('GRIB', 'gaussian', 'regular_gg.grib1')))
Expand Down Expand Up @@ -191,38 +152,21 @@ def _old_compat_load(name):
name)))[0]
return [cube]

@tests.skip_plot
def test_ij_directions_ipos_jpos(self):
cubes = self._old_compat_load("ipos_jpos.grib2")
self.assertCML(cubes, ("grib_load", "ipos_jpos.cml"))
iplt.contourf(cubes[0])
plt.gca().coastlines()
plt.title("ipos_jpos cube")
self.check_graphic()

def test_ij_directions_ipos_jneg(self):
cubes = self._old_compat_load("ipos_jneg.grib2")
self.assertCML(cubes, ("grib_load", "ipos_jneg.cml"))
iplt.contourf(cubes[0])
plt.gca().coastlines()
plt.title("ipos_jneg cube")
self.check_graphic()

def test_ij_directions_ineg_jneg(self):
cubes = self._old_compat_load("ineg_jneg.grib2")
self.assertCML(cubes, ("grib_load", "ineg_jneg.cml"))
iplt.contourf(cubes[0])
plt.gca().coastlines()
plt.title("ineg_jneg cube")
self.check_graphic()

def test_ij_directions_ineg_jpos(self):
cubes = self._old_compat_load("ineg_jpos.grib2")
self.assertCML(cubes, ("grib_load", "ineg_jpos.cml"))
iplt.contourf(cubes[0])
plt.gca().coastlines()
plt.title("ineg_jpos cube")
self.check_graphic()


@tests.skip_data
Expand Down
42 changes: 20 additions & 22 deletions lib/iris/tests/integration/test_regridding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013 - 2015, Met Office
# (C) British Crown Copyright 2013 - 2016, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -32,20 +32,17 @@
from iris.cube import Cube
from iris.tests.stock import global_pp

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
import iris.quickplot as qplt


@tests.skip_data
@tests.skip_plot
class TestOSGBToLatLon(tests.GraphicsTest):
class TestOSGBToLatLon(tests.IrisTest):
def setUp(self):
path = tests.get_data_path(
('NIMROD', 'uk2km', 'WO0000000003452',
'201007020900_u1096_ng_ey00_visibility0180_screen_2km'))
self.src = iris.load_cube(path)[0]
self.src.data = self.src.data.astype(np.float32)
# Cast up to float64, to work around numpy<=1.8 bug with means of
# arrays of 32bit floats.
self.src.data = self.src.data.astype(np.float64)
Copy link
Member

@bjlittle bjlittle Sep 13, 2016

Choose a reason for hiding this comment

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

@marqh Is this up-casting to avoid numpy 1.8 issues?

If so, would you agree a comment might be handy? As for line +76 ...

self.grid = Cube(np.empty((73, 96)))
cs = GeogCS(6370000)
lat = DimCoord(np.linspace(46, 65, 73), 'latitude', units='degrees',
Expand All @@ -58,23 +55,25 @@ def setUp(self):
def _regrid(self, method):
regridder = Regridder(self.src, self.grid, method, 'mask')
result = regridder(self.src)
qplt.pcolor(result, antialiased=False)
qplt.plt.gca().coastlines()
return result

def test_linear(self):
self._regrid('linear')
self.check_graphic()
res = self._regrid('linear')
self.assertArrayShapeStats(res, (73, 96), -16100.351951, 5603.850769)

def test_nearest(self):
self._regrid('nearest')
self.check_graphic()
res = self._regrid('nearest')
self.assertArrayShapeStats(res, (73, 96), -16095.965585, 5612.657155)


@tests.skip_data
@tests.skip_plot
class TestGlobalSubsample(tests.GraphicsTest):
class TestGlobalSubsample(tests.IrisTest):
def setUp(self):
self.src = global_pp()
_ = self.src.data
Copy link
Member

Choose a reason for hiding this comment

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

self.src.data on it's own will do the job, no need to assign

Copy link
Member Author

Choose a reason for hiding this comment

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

it will, but it can make for messy output during debugging
I tend to prefer to assign to _ as a way to throw this away (so to speak)

# Cast up to float64, to work around numpy<=1.8 bug with means of
# arrays of 32bit floats.
self.src.data = self.src.data.astype(np.float64)
# Subsample and shift the target grid so that we can see a visual
# difference between regridding scheme methods.
grid = self.src[1::2, 1::3]
Expand All @@ -85,16 +84,15 @@ def setUp(self):
def _regrid(self, method):
regridder = Regridder(self.src, self.grid, method, 'mask')
result = regridder(self.src)
qplt.pcolormesh(result)
qplt.plt.gca().coastlines()
return result

def test_linear(self):
self._regrid('linear')
self.check_graphic()
res = self._regrid('linear')
self.assertArrayShapeStats(res, (36, 32), 280.35907, 15.997223)

def test_nearest(self):
self._regrid('nearest')
self.check_graphic()
res = self._regrid('nearest')
self.assertArrayShapeStats(res, (36, 32), 280.33726, 16.064001)


if __name__ == "__main__":
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Loading