Skip to content

Commit

Permalink
Merge pull request #19 from cpelley/interp_test_fixes_replacement
Browse files Browse the repository at this point in the history
MAINT: Interp test fixes replacement
  • Loading branch information
Carwyn Pelley committed Apr 4, 2014
2 parents a8d9f74 + 602acd8 commit ac8a4ec
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 82 deletions.
52 changes: 26 additions & 26 deletions lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ def _quadrant_area(radian_colat_bounds, radian_lon_bounds, radius_of_earth):
*(radian_colat_bounds.shape[0], radian_lon_bounds.shape[0])*
"""
#ensure pairs of bounds
# ensure pairs of bounds
if (radian_colat_bounds.shape[-1] != 2 or
radian_lon_bounds.shape[-1] != 2 or
radian_colat_bounds.ndim != 2 or
radian_lon_bounds.ndim != 2):
raise ValueError("Bounds must be [n,2] array")

#fill in a new array of areas
# fill in a new array of areas
radius_sqr = radius_of_earth ** 2
areas = np.ndarray((radian_colat_bounds.shape[0],
radian_lon_bounds.shape[0]))
Expand Down Expand Up @@ -602,28 +602,28 @@ def project(cube, target_proj, nx=None, ny=None):
'to have 1 or 2 dimensions, got {} and '
'{}.'.format(lat_coord.ndim, lon_coord.ndim))

## Mask out points outside of extent in source_cs - disabled until
## a way to specify global/limited extent is agreed upon and code
## is generalised to handle -180 to +180, 0 to 360 and >360 longitudes.
#source_desired_xy = source_cs.transform_points(target_proj,
# target_x.flatten(),
# target_y.flatten())
#if np.any(source_x < 0.0) and np.any(source_x > 180.0):
# raise ValueError('Unable to handle range of longitude.')
## This does not work in all cases e.g. lon > 360
#if np.any(source_x > 180.0):
# source_desired_x = (source_desired_xy[:, 0].reshape(ny, nx) +
# 360.0) % 360.0
#else:
# source_desired_x = source_desired_xy[:, 0].reshape(ny, nx)
#source_desired_y = source_desired_xy[:, 1].reshape(ny, nx)
#outof_extent_points = ((source_desired_x < source_x.min()) |
# (source_desired_x > source_x.max()) |
# (source_desired_y < source_y.min()) |
# (source_desired_y > source_y.max()))
## Make array a mask by default (rather than a single bool) to allow mask
## to be assigned to slices.
#new_data.mask = np.zeros(new_shape)
# # Mask out points outside of extent in source_cs - disabled until
# # a way to specify global/limited extent is agreed upon and code
# # is generalised to handle -180 to +180, 0 to 360 and >360 longitudes.
# source_desired_xy = source_cs.transform_points(target_proj,
# target_x.flatten(),
# target_y.flatten())
# if np.any(source_x < 0.0) and np.any(source_x > 180.0):
# raise ValueError('Unable to handle range of longitude.')
# # This does not work in all cases e.g. lon > 360
# if np.any(source_x > 180.0):
# source_desired_x = (source_desired_xy[:, 0].reshape(ny, nx) +
# 360.0) % 360.0
# else:
# source_desired_x = source_desired_xy[:, 0].reshape(ny, nx)
# source_desired_y = source_desired_xy[:, 1].reshape(ny, nx)
# outof_extent_points = ((source_desired_x < source_x.min()) |
# (source_desired_x > source_x.max()) |
# (source_desired_y < source_y.min()) |
# (source_desired_y > source_y.max()))
# # Make array a mask by default (rather than a single bool) to allow mask
# # to be assigned to slices.
# new_data.mask = np.zeros(new_shape)

# Step through cube data, regrid onto desired projection and insert results
# in new_data array
Expand All @@ -638,8 +638,8 @@ def project(cube, target_proj, nx=None, ny=None):
target_proj,
target_x, target_y)

## Mask out points beyond extent
#new_data[index].mask[outof_extent_points] = True
# # Mask out points beyond extent
# new_data[index].mask[outof_extent_points] = True

# Remove mask if it is unnecessary
if not np.any(new_data.mask):
Expand Down
8 changes: 4 additions & 4 deletions lib/iris/coord_categorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add_categorised_coord(cube, name, from_coord, category_function,
cube.add_aux_coord(new_coord, cube.coord_dims(from_coord))


#======================================
# ======================================
# Specific functions for particular purposes
#
# NOTE: all the existing ones are calendar operations, so are for 'Time'
Expand Down Expand Up @@ -118,7 +118,7 @@ def _pt_date(coord, time):
return coord.units.num2date(time)


#--------------------------------------------
# --------------------------------------------
# Time categorisations : calendar date components

def add_year(cube, coord, name='year'):
Expand Down Expand Up @@ -169,7 +169,7 @@ def add_day_of_year(cube, coord, name='day_of_year'):
lambda coord, x: _pt_date(coord, x).timetuple().tm_yday)


#--------------------------------------------
# --------------------------------------------
# Time categorisations : days of the week

def add_weekday_number(cube, coord, name='weekday_number'):
Expand All @@ -195,7 +195,7 @@ def add_weekday(cube, coord, name='weekday'):
units='no_unit')


#----------------------------------------------
# ----------------------------------------------
# Time categorisations : meteorological seasons

def _months_in_season(season):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ def coord_dims(self, coord):
factories]

# Deprecate name based searching
### Search by coord name, if have no match
# -- Search by coord name, if have no match
# XXX Where did this come from? And why isn't it reflected in the
# docstring?
if not matches:
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/fileformats/grib/grib_phenom_translation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2013, Met Office
# (C) British Crown Copyright 2013 - 2014, Met Office
#
# This file is part of Iris.
#
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, *args, **kwargs):
self._super.__init__(*args, **kwargs)

def __getitem__(self, key):
if not key in self:
if key not in self:
return None
return self._super.__getitem__(key)

Expand Down
14 changes: 7 additions & 7 deletions lib/iris/fileformats/grib/grib_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def gribbability_check(cube):
raise iris.exceptions.TranslationError("time coord not found")


###########################
### grid template stuff ###
###########################
# ###########################
# ### grid template stuff ###
# ###########################


def shape_of_the_earth(cube, grib):
Expand Down Expand Up @@ -177,9 +177,9 @@ def grid_template(cube, grib):
raise ValueError("Currently unhandled CoordSystem: %s" % cs)


##############################
### product template stuff ###
##############################
# ##############################
# ### product template stuff ###
# ##############################


def param_code(cube, grib):
Expand Down Expand Up @@ -610,7 +610,7 @@ def data(cube, grib):
gribapi.grib_set_double_array(grib, "values", data.flatten())

# todo: check packing accuracy?
#print "packingError", gribapi.getb_get_double(grib, "packingError")
# print "packingError", gribapi.getb_get_double(grib, "packingError")


def run(cube, grib):
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ def symbols(x, y, symbols, size, axes=None, units='inches'):
# match_original
# See matplotlib.collections.PatchCollection.__init__
# Specifically matplotlib/collections line 1053
#pc = PatchCollection(symbols, offsets=offsets, transOffset=ax.transData,
# match_original=True)
# pc = PatchCollection(symbols, offsets=offsets, transOffset=ax.transData,
# match_original=True)
facecolors = [p.get_facecolor() for p in symbols]
edgecolors = [p.get_edgecolor() for p in symbols]
linewidths = [p.get_linewidth() for p in symbols]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def test_multidimensional(self):
ylims = _minmax(c1.coord(axis='y').contiguous_bounds())
# Reduce the dimensions slightly to avoid NaNs in regridded orography
delta = 0.05
# NOTE: this is *not* a small amount. Think there is a bug.
# NOTE: See https://github.com/SciTools/iris/issues/458
# || NOTE: this is *not* a small amount. Think there is a bug.
# || NOTE: See https://github.com/SciTools/iris/issues/458
xlims = np.interp([delta, 1.0 - delta], [0, 1], xlims)
ylims = np.interp([delta, 1.0 - delta], [0, 1], ylims)
pole_latlon = (c1_cs.grid_north_pole_latitude,
Expand Down
12 changes: 6 additions & 6 deletions lib/iris/tests/results/COLPEX/small_colpex_theta_p_alt.cml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
[[542.377, 600.215],
[659.081, 716.102],
[518.94, 576.941],
[518.939, 576.941],
...,
[357.758, 416.887],
[315.37, 374.796],
Expand Down Expand Up @@ -251,7 +251,7 @@
[[600.215, 664.488],
[716.102, 779.471],
[576.941, 641.396],
[576.941, 641.395],
...,
[416.887, 482.59],
[374.796, 440.827],
Expand Down Expand Up @@ -301,7 +301,7 @@
[[664.488, 735.199],
[779.471, 849.192],
[641.396, 712.305],
[641.395, 712.305],
...,
[482.59, 554.867],
[440.827, 513.464],
Expand Down Expand Up @@ -722,7 +722,7 @@
[[542.377, 600.215],
[659.081, 716.102],
[518.94, 576.941],
[518.939, 576.941],
...,
[357.758, 416.887],
[315.37, 374.796],
Expand Down Expand Up @@ -772,7 +772,7 @@
[[600.215, 664.488],
[716.102, 779.471],
[576.941, 641.396],
[576.941, 641.395],
...,
[416.887, 482.59],
[374.796, 440.827],
Expand Down Expand Up @@ -822,7 +822,7 @@
[[664.488, 735.199],
[779.471, 849.192],
[641.396, 712.305],
[641.395, 712.305],
...,
[482.59, 554.867],
[440.827, 513.464],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
</coord>
</coords>
<cellMethods/>
<data byteorder="little" checksum="-0x65f736e8" dtype="float64" shape="(25, 49)"/>
<data byteorder="little" dtype="float64" shape="(25, 49)" state="loaded"/>
</cube>
</cubes>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
</coord>
</coords>
<cellMethods/>
<data byteorder="little" checksum="-0x41634f7b" dtype="float32" shape="(3,)"/>
<data byteorder="little" dtype="float32" shape="(3,)" state="loaded"/>
</cube>
</cubes>
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
[[542.377, 600.215],
[659.081, 716.102],
[518.94, 576.941],
[518.939, 576.941],
...,
[357.758, 416.887],
[315.37, 374.796],
Expand Down Expand Up @@ -252,7 +252,7 @@
[[600.215, 664.488],
[716.102, 779.471],
[576.941, 641.396],
[576.941, 641.395],
...,
[416.887, 482.59],
[374.796, 440.827],
Expand Down Expand Up @@ -302,7 +302,7 @@
[[664.488, 735.199],
[779.471, 849.192],
[641.396, 712.305],
[641.395, 712.305],
...,
[482.59, 554.867],
[440.827, 513.464],
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/results/netcdf/save_load_traj.cml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
<coord name="time"/>
</cellMethod>
</cellMethods>
<data byteorder="little" checksum="0x76bb250b" dtype="float64" shape="(10,)"/>
<data dtype="float64" shape="(10,)" state="deferred"/>
</cube>
</cubes>
2 changes: 1 addition & 1 deletion lib/iris/tests/results/trajectory/constant_latitude.cml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@
</coord>
</coords>
<cellMethods/>
<data byteorder="little" checksum="-0xb6dfd43" dtype="float64" shape="(6, 70, 100)"/>
<data byteorder="little" checksum="0x4a491a7d" dtype="float64" shape="(6, 70, 100)"/>
</cube>
</cubes>
2 changes: 1 addition & 1 deletion lib/iris/tests/results/trajectory/zigzag.cml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@
</coord>
</coords>
<cellMethods/>
<data byteorder="little" checksum="0x24d7792b" dtype="float64" shape="(6, 70, 100)"/>
<data byteorder="little" checksum="0x2236104" dtype="float64" shape="(6, 70, 100)"/>
</cube>
</cubes>
7 changes: 6 additions & 1 deletion lib/iris/tests/test_analysis_calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ def test_contrived_non_spherical_curl1(self):
# Curl returns None when there is no components of Curl
self.assertEqual(r[0], None)
self.assertEqual(r[1], None)
self.assertCML(r[2], ('analysis', 'calculus', 'grad_contrived_non_spherical1.cml'))
cube = r[2]
self.assertCML(
cube,
('analysis', 'calculus', 'grad_contrived_non_spherical1.cml'),
checksum=False)
self.assertTrue(np.all(np.abs(cube.data - (-1.0)) < 1.0e-7))

def test_contrived_non_spherical_curl2(self):
# testing :
Expand Down
16 changes: 8 additions & 8 deletions lib/iris/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ def get_file_results(self):

class TestCodeFormat(unittest.TestCase):
def test_pep8_conformance(self):
#
# Tests the iris codebase against the "pep8" tool.
#
# Users can add their own excluded files (should files exist in the
# local directory which is not in the repository) by adding a
# ".pep8_test_exclude.txt" file in the same directory as this test.
# The file should be a line separated list of filenames/directories
# as can be passed to the "pep8" tool's exclude list.
#
# Tests the iris codebase against the "pep8" tool.
#
# Users can add their own excluded files (should files exist in the
# local directory which is not in the repository) by adding a
# ".pep8_test_exclude.txt" file in the same directory as this test.
# The file should be a line separated list of filenames/directories
# as can be passed to the "pep8" tool's exclude list.

# To get a list of bad files, rather than the specific errors, add
# "reporter=pep8.FileReport" to the StyleGuide constructor.
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/tests/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ def concatenate(cubes, order=None):

for cube in result:
if ma.isMaskedArray(cube.data):
# cube.data = ma.copy(cube.data, order=order)
# cube.data = ma.copy(cube.data, order=order)
data = np.array(cube.data.data, copy=True, order=order)
mask = np.array(cube.data.mask, copy=True, order=order)
fill_value = cube.data.fill_value
cube.data = ma.array(data, mask=mask, fill_value=fill_value)
else:
# cube.data = np.copy(cube.data, order=order)
# cube.data = np.copy(cube.data, order=order)
cube.data = np.array(cube.data, copy=True, order=order)

return result
Expand Down
Loading

0 comments on commit ac8a4ec

Please sign in to comment.