Skip to content

Commit

Permalink
Review actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjlittle authored and marqh committed Jul 14, 2017
1 parent 6b20c8d commit be6533b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/iris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def callback(cube, field, filename):


# Iris revision.
__version__ = '2.0.dev0'
__version__ = '2.0.0-DEV'

# Restrict the names imported when using "from iris import *"
__all__ = ['load', 'load_cube', 'load_cubes', 'load_raw',
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
extend_circular_coord_and_data,
get_xy_dim_coords, snapshot_grid)
from iris.analysis._scipy_interpolate import _RegularGridInterpolator
from iris.analysis.cartography import _meshgrid
import iris.cube
from iris.util import _meshgrid


class RectilinearRegridder(object):
Expand Down
19 changes: 1 addition & 18 deletions lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import iris.coords
import iris.coord_systems
import iris.exceptions
from iris.util import _meshgrid


# This value is used as a fall-back if the cube does not define the earth
Expand Down Expand Up @@ -239,24 +240,6 @@ def _xy_range(cube, mode=None):
return (x_range, y_range)


def _meshgrid(x, y):
"""
@numpy v1.13, the dtype of each output nD coordinate is the same as its
associated input 1D coordinate. This is not the case prior to numpy v1.13,
where the output dtype is cast up to its highest resolution, regardlessly.
This convenience function ensures consistent meshgrid behaviour across
numpy versions.
"""
mx, my = np.meshgrid(x, y)
if mx.dtype != x.dtype:
mx = mx.astype(x.dtype)
if my.dtype != y.dtype:
my = my.astype(y.dtype)
return mx, my


def get_xy_grids(cube):
"""
Return 2D X and Y points for a given cube.
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from iris.analysis._interpolate_private import \
_nearest_neighbour_indices_ndcoords, linear as linear_regrid
from iris.analysis._interpolation import snapshot_grid
from iris.analysis.cartography import _meshgrid
from iris.util import _meshgrid


class _Segment(object):
Expand Down
8 changes: 3 additions & 5 deletions lib/iris/experimental/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from iris.analysis._regrid import RectilinearRegridder
import iris.coord_systems
import iris.cube
from iris.util import promote_aux_coord_to_dim_coord
from iris.util import _meshgrid, promote_aux_coord_to_dim_coord


_Version = namedtuple('Version', ('major', 'minor', 'micro'))
Expand Down Expand Up @@ -755,8 +755,7 @@ def regrid_area_weighted_rectilinear_src_and_grid(src_cube, grid_cube,

# Wrap up the data as a Cube.
# Create 2d meshgrids as required by _create_cube func.
meshgrid_x, meshgrid_y = iris.analysis.cartography._meshgrid(grid_x.points,
grid_y.points)
meshgrid_x, meshgrid_y = _meshgrid(grid_x.points, grid_y.points)
regrid_callback = RectilinearRegridder._regrid
new_cube = RectilinearRegridder._create_cube(new_data, src_cube,
src_x_dim, src_y_dim,
Expand Down Expand Up @@ -1422,8 +1421,7 @@ def _regrid(src_data, xy_dim, src_x_coord, src_y_coord,
src_projection, src_x_coord.points, src_y_coord.points)

tgt_projection = tgt_x_coord.coord_system.as_cartopy_projection()
tgt_x, tgt_y = iris.analysis.cartography._meshgrid(tgt_x_coord.points,
tgt_y_coord.points)
tgt_x, tgt_y = _meshgrid(tgt_x_coord.points, tgt_y_coord.points)
projected_tgt_grid = projection.transform_points(
tgt_projection, tgt_x, tgt_y)

Expand Down
2 changes: 1 addition & 1 deletion lib/iris/experimental/regrid_conservative.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import iris
from iris.analysis._interpolation import get_xy_dim_coords
from iris.analysis._regrid import RectilinearRegridder
from iris.analysis.cartography import _meshgrid
from iris.util import _meshgrid


#: A static Cartopy Geodetic() instance for transforming to true-lat-lons.
Expand Down
7 changes: 4 additions & 3 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from iris.exceptions import IrisError
# Importing iris.palette to register the brewer palettes.
import iris.palette
from iris.util import _meshgrid


# Cynthia Brewer citation text.
Expand Down Expand Up @@ -703,16 +704,16 @@ def _map_common(draw_method_name, arg_func, mode, cube, plot_defn,
y_coord, x_coord = plot_defn.coords
if mode == iris.coords.POINT_MODE:
if x_coord.ndim == y_coord.ndim == 1:
x, y = np.meshgrid(x_coord.points, y_coord.points)
x, y = _meshgrid(x_coord.points, y_coord.points)
elif x_coord.ndim == y_coord.ndim == 2:
x = x_coord.points
y = y_coord.points
else:
raise ValueError("Expected 1D or 2D XY coords")
else:
try:
x, y = np.meshgrid(x_coord.contiguous_bounds(),
y_coord.contiguous_bounds())
x, y = _meshgrid(x_coord.contiguous_bounds(),
y_coord.contiguous_bounds())
# Exception translation.
except iris.exceptions.CoordinateMultiDimError:
raise ValueError("Could not get XY grid from bounds. "
Expand Down
20 changes: 20 additions & 0 deletions lib/iris/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,3 +1657,23 @@ def demote_dim_coord_to_aux_coord(cube, name_or_coord):
cube.remove_coord(dim_coord)

cube.add_aux_coord(dim_coord, coord_dim)


@functools.wraps(np.meshgrid)
def _meshgrid(*xi, **kwargs):
"""
@numpy v1.13, the dtype of each output nD coordinate is the same as its
associated input 1D coordinate. This is not the case prior to numpy v1.13,
where the output dtype is cast up to its highest resolution, regardlessly.
This convenience function ensures consistent meshgrid behaviour across
numpy versions.
Reference: https://github.com/numpy/numpy/pull/5302
"""
mxi = np.meshgrid(*xi, **kwargs)
for i, (mxii, xii) in enumerate(zip(mxi, xi)):
if mxii.dtype != xii.dtype:
mxi[i] = mxii.astype(xii.dtype)
return mxi

0 comments on commit be6533b

Please sign in to comment.