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
61 changes: 35 additions & 26 deletions lib/iris/_shapefiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ def create_shapefile_mask(
given shapely geometry and cube with x/y DimCoords.
Can take a minimum weight and evaluate area overlaps instead


Parameters
----------
geometry : A :class:`shapely.Geometry` object

cube : A :class:`iris.cube.Cube`
which has 1d x and y coordinates
minimum_weight : A float between 0 and 1 determining what % of a cell
a shape must cover for the cell to remain unmasked.
eg: 0.1 means that at least 10% of the shape overlaps the cell
to be unmasked
Requires geometry to be a Polygon or MultiPolygon
Defaults to 0.0 (eg only test intersection)
geometry : :class:`shapely.Geometry`
cube : :class:`iris.cube.Cube`
A :class:`~iris.cube.Cube` which has 1d x and y coordinates
minimum_weight : float, default 0.0
A float between 0 and 1 determining what % of a cell
a shape must cover for the cell to remain unmasked.
eg: 0.1 means that at least 10% of the shape overlaps the cell
to be unmasked.
Requires geometry to be a Polygon or MultiPolygon
Defaults to 0.0 (eg only test intersection)

Returns
-------
A :class:`np.array` of the shape of the x & y coordinates of the cube, with points to mask equal to True
:class:`np.array`
An array of the shape of the x & y coordinates of the cube, with points
to mask equal to True

"""
from iris.cube import Cube, CubeList
Expand Down Expand Up @@ -120,18 +121,20 @@ def _transform_coord_system(geometry, cube, geometry_system=None):

Parameters
----------
geometry: A :class:`shapely.Geometry` object

cube: A :class:`iris.cube.Cube` with the coord_system to
be projected to and a x coordinate

geometry_system: A :class:`iris.coord_systems` object describing
the coord_system of the shapefile. Defaults to None,
which is treated as GeogCS
geometry: :class:`shapely.Geometry`
cube: :class:`iris.cube.Cube`
:class:`~iris.cube.Cube` with the coord_system to be projected to and
a x coordinate
geometry_system: :class:`iris.coord_systems`, optional
A :class:`~iris.coord_systems` object describing
the coord_system of the shapefile. Defaults to None,
which is treated as GeogCS

Returns
-------
:class:`shapely.Geometry`
A transformed copy of the provided :class:`shapely.Geometry`

"""
y_name, x_name = _cube_primary_xy_coord_names(cube)
import iris.analysis.cartography
Expand Down Expand Up @@ -177,12 +180,15 @@ def _trans_func(geometry):
def _cube_primary_xy_coord_names(cube):
"""Return the primary latitude and longitude coordinate names, or long names, from a cube.

Arguments:
cube (:class:`iris.cube.Cube`): An Iris cube
Parameters
----------
cube : :class:`iris.cube.Cube`

Returns
-------
tuple of str
The names of the primary latitude and longitude coordinates

"""
latc = (
cube.coords(axis="y", dim_coords=True)[0]
Expand All @@ -207,13 +213,16 @@ def _cube_primary_xy_coord_names(cube):
def _get_mod_rebased_coord_bounds(coord):
"""Take in a coord and returns a array of the bounds of that coord rebased to the modulus.

Arguments:
coord (:class:`iris.coords.Coord`): An Iris coordinate
with a modulus
Parameters
----------
coord : :class:`iris.coords.Coord`
An Iris coordinate with a modulus

Returns
-------
A 1d Numpy array of [start,end] pairs for bounds of the coord
:class:`np.array`
A 1d Numpy array of [start,end] pairs for bounds of the coord

"""
modulus = coord.units.modulus
# Force realisation (rather than core_bounds) - more efficient for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Integration tests for :func:`iris.util.mask_cube_from_shapefile`."""

import math

Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/util/test_mask_cube_from_shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Unit tests for :func:`iris.util.mask_cube_from_shapefile`."""

import numpy as np
import pytest
Expand Down