Skip to content

Commit

Permalink
MNT: Removing numpy float/bool conversions
Browse files Browse the repository at this point in the history
Numpy 1.20 raises a deprecation warning when using np.float and
np.bool instead of Python's builtin float/bool. Replacing those
throughout the codebase.
  • Loading branch information
greglucas committed Feb 2, 2021
1 parent efd15f1 commit e663bbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,

super().__init__(proj4_params, globe=globe)

a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
a = float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)

# Find the antipode, and shift it a small amount in latitude to
# approximate the extent of the projection:
Expand Down Expand Up @@ -1324,7 +1324,7 @@ def __init__(self, central_longitude=0.0, globe=None):
globe = Globe(semimajor_axis=math.degrees(1), ellipse=None)

# TODO: Let the globe return the semimajor axis always.
a = np.float(globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
a = float(globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)

proj4_params = [('proj', 'mill'), ('lon_0', central_longitude)]
# See Snyder, 1987. Eqs (11-1) and (11-2) substituting maximums of
Expand Down Expand Up @@ -1457,8 +1457,8 @@ def __init__(self, central_latitude=0.0, central_longitude=0.0,
super().__init__(proj4_params, globe=globe)

# TODO: Let the globe return the semimajor axis always.
a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
b = np.float(self.globe.semiminor_axis or WGS84_SEMIMINOR_AXIS)
a = float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
b = float(self.globe.semiminor_axis or WGS84_SEMIMINOR_AXIS)

# Note: The magic number has been picked to maintain consistent
# behaviour with a wgs84 globe. There is no guarantee that the scaling
Expand Down Expand Up @@ -1534,7 +1534,7 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
super().__init__(proj4_params, globe=globe)

# TODO: Let the globe return the semimajor axis always.
a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
a = float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)

# To stabilise the projection of geometries, we reduce the boundary by
# a tiny fraction at the cost of the extreme edges.
Expand Down Expand Up @@ -2089,8 +2089,8 @@ def __init__(self, central_longitude=0.0, satellite_height=35785831,
sweep_axis=sweep_axis)

# TODO: Let the globe return the semimajor axis always.
a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
h = np.float(satellite_height)
a = float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
h = float(satellite_height)

# These are only exact for a spherical Earth, owing to assuming a is
# constant. Handling elliptical would be much harder for this.
Expand Down Expand Up @@ -2156,7 +2156,7 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
# TODO: Let the globe return the semimajor axis always.
a = self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS

h = np.float(satellite_height)
h = float(satellite_height)
max_x = a * np.sqrt(h / (2 * a + h))
coords = _ellipse_boundary(max_x, max_x,
false_easting, false_northing, 61)
Expand Down Expand Up @@ -2299,8 +2299,8 @@ def __init__(self, central_longitude=0.0, central_latitude=0.0,
super().__init__(proj4_params, globe=globe)

# TODO: Let the globe return the semimajor axis always.
a = np.float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
b = np.float(self.globe.semiminor_axis or a)
a = float(self.globe.semimajor_axis or WGS84_SEMIMAJOR_AXIS)
b = float(self.globe.semiminor_axis or a)

coords = _ellipse_boundary(a * np.pi, b * np.pi,
false_easting, false_northing, 61)
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/io/srtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def _create_srtm_mask(resolution, filename=None):
with open(filename) as f:
html = f.read()

mask = np.zeros((360, 181), dtype=np.bool)
mask = np.zeros((360, 181), dtype=bool)

soup = BeautifulSoup(html)

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ def _pcolormesh_patched(self, *args, **kwargs):
# at this point C has a shape of (Ny-1, Nx-1), to_mask has
# a shape of (Ny-1, Nx-1) and pts has a shape of (Ny*Nx, 2)

mask = np.zeros(C.shape, dtype=np.bool)
mask = np.zeros(C.shape, dtype=bool)

# Mask out the cells if there was a diagonal found with a
# large length. NB. Masking too much only has
Expand Down

0 comments on commit e663bbb

Please sign in to comment.