Skip to content

Commit

Permalink
Merge pull request #1707 from eumiro/py2numbers
Browse files Browse the repository at this point in the history
Modernize numeric code to Python3
  • Loading branch information
QuLogic committed Jan 9, 2021
2 parents 545832e + 366fed7 commit 4ae8079
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def __init__(self, central_longitude=0.0, globe=None):
x_max = a_rad * 180
y_max = a_rad * 90
# Set the threshold around 0.5 if the x max is 180.
self._threshold = x_max / 360.
self._threshold = x_max / 360
super().__init__(proj4_params, x_max, y_max, globe=globe)

@property
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/feature/nightshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _julian_day(date):
month += 12
year -= 1

B = 2 - int(year/100) + int(int(year/100)/4)
B = 2 - year // 100 + (year // 100) // 4
C = ((second/60 + minute)/60 + hour)/24

JD = (int(365.25*(year + 4716)) + int(30.6001*(month+1)) +
Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/io/ogc_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def _image_and_extent(self, wms_proj, wms_srs, wms_extent, output_proj,
target_resolution)

def fetch_raster(self, projection, extent, target_resolution):
target_resolution = [int(np.ceil(val)) for val in target_resolution]
target_resolution = [math.ceil(val) for val in target_resolution]
wms_srs = self._native_srs(projection)
if wms_srs is not None:
wms_proj = projection
Expand Down
18 changes: 9 additions & 9 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,11 @@ def background_img(self, name='ne_shaded', resolution='low', extent=None,
else:
# return only a subset of the image:
# set up coordinate arrays:
d_lat = 180.0 / img.shape[0]
d_lon = 360.0 / img.shape[1]
d_lat = 180 / img.shape[0]
d_lon = 360 / img.shape[1]
# latitude starts at 90N for this image:
lat_pts = (np.arange(img.shape[0]) * -d_lat - (d_lat / 2.0)) + 90.0
lon_pts = (np.arange(img.shape[1]) * d_lon + (d_lon / 2.0)) - 180.0
lat_pts = (np.arange(img.shape[0]) * -d_lat - (d_lat / 2)) + 90
lon_pts = (np.arange(img.shape[1]) * d_lon + (d_lon / 2)) - 180

# which points are in range:
lat_in_range = np.logical_and(lat_pts >= extent[2],
Expand All @@ -1126,10 +1126,10 @@ def background_img(self, name='ne_shaded', resolution='low', extent=None,
# now join them up:
img_subset = np.concatenate((img_subset1, img_subset2), axis=1)
# now define the extent for output that matches those points:
ret_extent = [lon_pts[lon_in_range1][0] - d_lon / 2.0,
lon_pts[lon_in_range2][-1] + d_lon / 2.0 + 360,
lat_pts[lat_in_range][-1] - d_lat / 2.0,
lat_pts[lat_in_range][0] + d_lat / 2.0]
ret_extent = [lon_pts[lon_in_range1][0] - d_lon / 2,
lon_pts[lon_in_range2][-1] + d_lon / 2 + 360,
lat_pts[lat_in_range][-1] - d_lat / 2,
lat_pts[lat_in_range][0] + d_lat / 2]
else:
# not crossing the dateline, so just find the region:
lon_in_range = np.logical_and(lon_pts >= extent[0],
Expand Down Expand Up @@ -1349,7 +1349,7 @@ def imshow(self, img, *args, **kwargs):
# As a workaround to a matplotlib limitation, turn any images
# which are RGB(A) with a mask into unmasked RGBA images with alpha
# put into the A channel.
if (np.ma.is_masked(img) and len(img.shape) > 2):
if np.ma.is_masked(img) and len(img.shape) > 2:
# if we don't pop alpha, imshow will apply (erroneously?) a
# 1D alpha to the RGBA array
# kwargs['alpha'] is guaranteed to be either 1D, 2D, or None
Expand Down
16 changes: 9 additions & 7 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def _crs_transform(self):
def _round(x, base=5):
if np.isnan(base):
base = 5
return int(base * round(float(x) / base))
return int(base * round(x / base))

def _find_midpoints(self, lim, ticks):
# Find the center point between each lat gridline.
Expand Down Expand Up @@ -429,12 +429,14 @@ def _draw_gridliner(self, nx=None, ny=None, renderer=None):
# Get nice ticks within crs domain
lon_ticks = self.xlocator.tick_values(lon_lim[0], lon_lim[1])
lat_ticks = self.ylocator.tick_values(lat_lim[0], lat_lim[1])
lon_ticks = [value for value in lon_ticks
if value >= max(lon_lim[0], crs.x_limits[0]) and
value <= min(lon_lim[1], crs.x_limits[1])]
lat_ticks = [value for value in lat_ticks
if value >= max(lat_lim[0], crs.y_limits[0]) and
value <= min(lat_lim[1], crs.y_limits[1])]

inf = max(lon_lim[0], crs.x_limits[0])
sup = min(lon_lim[1], crs.x_limits[1])
lon_ticks = [value for value in lon_ticks if inf <= value <= sup]
inf = max(lat_lim[0], crs.y_limits[0])
sup = min(lat_lim[1], crs.y_limits[1])
lat_ticks = [value for value in lat_ticks if inf <= value <= sup]


#####################
# Gridlines drawing #
Expand Down
4 changes: 2 additions & 2 deletions lib/cartopy/tests/mpl/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_transform_PlateCarree_shortcut():
assert counter.count == 2


class Test_InterProjectionTransform():
class Test_InterProjectionTransform:
def pc_2_pc(self):
return InterProjectionTransform(
ccrs.PlateCarree(), ccrs.PlateCarree())
Expand All @@ -97,7 +97,7 @@ def test_ne(self):
assert self.pc_2_pc() != self.pc_2_rob()


class Test_Axes_add_geometries():
class Test_Axes_add_geometries:
def teardown_method(self):
plt.close()

Expand Down

0 comments on commit 4ae8079

Please sign in to comment.