From 487a445f8d87c756495c143d2fb510e64a791434 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 22 Jan 2022 13:27:10 -0700 Subject: [PATCH 1/3] MNT: Fixing flake8 E402 module imports --- lib/cartopy/__init__.py | 6 +++--- setup.cfg | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cartopy/__init__.py b/lib/cartopy/__init__.py index d6c4bcd70..d2bd7e8c2 100644 --- a/lib/cartopy/__init__.py +++ b/lib/cartopy/__init__.py @@ -12,6 +12,7 @@ # Configuration import os.path + # for the writable data directory (i.e. the one where new data goes), follow # the XDG guidelines found at # https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html @@ -101,8 +102,7 @@ except ImportError: pass - # Commonly used sub-modules. Imported here to provide end-user # convenience. -import cartopy.crs -import cartopy.feature # noqa: F401 (flake8 = unused import) +import cartopy.crs # noqa: E402 module-level imports +import cartopy.feature # noqa: E402,F401 (unused import) diff --git a/setup.cfg b/setup.cfg index 1433c16c6..2eb60e062 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [flake8] -ignore = E402,\ # Due to conditional imports - E226,\ # Due to whitespace around operators (e.g. 2*x + 3) +ignore = E226,\ # Due to whitespace around operators (e.g. 2*x + 3) E241,\ # Due to multiple spaces after comma W504 # Line break after binary operator exclude = \ From 9c3d92e963eab38446e5d41dc6bae35a8dda29e8 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 22 Jan 2022 13:31:49 -0700 Subject: [PATCH 2/3] MNT: Fixing flake8 E241 multiple spaces after comma --- lib/cartopy/tests/crs/test_azimuthal_equidistant.py | 4 ++-- lib/cartopy/tests/crs/test_lambert_conformal.py | 2 +- lib/cartopy/tests/crs/test_utm.py | 4 ++-- lib/cartopy/tests/test_crs.py | 4 ++-- setup.cfg | 1 - 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/cartopy/tests/crs/test_azimuthal_equidistant.py b/lib/cartopy/tests/crs/test_azimuthal_equidistant.py index f8c4ce96f..1d93819c0 100644 --- a/lib/cartopy/tests/crs/test_azimuthal_equidistant.py +++ b/lib/cartopy/tests/crs/test_azimuthal_equidistant.py @@ -21,7 +21,7 @@ def test_default(self): assert_almost_equal(np.array(aeqd.x_limits), [-20037508.34278924, 20037508.34278924], decimal=6) assert_almost_equal(np.array(aeqd.y_limits), - [-19970326.371123, 19970326.371123], decimal=6) + [-19970326.371123, 19970326.371123], decimal=6) def test_eccentric_globe(self): globe = ccrs.Globe(semimajor_axis=1000, semiminor_axis=500, @@ -47,7 +47,7 @@ def test_eastings(self): assert_almost_equal(np.array(aeqd_offset.x_limits), [-20036274.34278924, 20038742.34278924], decimal=6) assert_almost_equal(np.array(aeqd_offset.y_limits), - [-19974647.371123, 19966005.371123], decimal=6) + [-19974647.371123, 19966005.371123], decimal=6) def test_grid(self): # USGS Professional Paper 1395, pp 196--197, Table 30 diff --git a/lib/cartopy/tests/crs/test_lambert_conformal.py b/lib/cartopy/tests/crs/test_lambert_conformal.py index bf7d55d04..6032d2e5c 100644 --- a/lib/cartopy/tests/crs/test_lambert_conformal.py +++ b/lib/cartopy/tests/crs/test_lambert_conformal.py @@ -78,7 +78,7 @@ def test_single_spole(self): def test_single_npole(self): n_pole_crs = ccrs.LambertConformal(standard_parallels=[1.]) assert_array_almost_equal(n_pole_crs.x_limits, - (-20130569, 20130569), + (-20130569, 20130569), decimal=0) assert_array_almost_equal(n_pole_crs.y_limits, (-8170229, 726200683), diff --git a/lib/cartopy/tests/crs/test_utm.py b/lib/cartopy/tests/crs/test_utm.py index 7c82f1eee..13dcd412a 100644 --- a/lib/cartopy/tests/crs/test_utm.py +++ b/lib/cartopy/tests/crs/test_utm.py @@ -28,7 +28,7 @@ def test_default(south): assert_almost_equal(np.array(utm.x_limits), [-250000, 1250000]) assert_almost_equal(np.array(utm.y_limits), - [-10000000, 25000000]) + [-10000000, 25000000]) def test_ellipsoid_transform(): @@ -43,7 +43,7 @@ def test_ellipsoid_transform(): assert_almost_equal(np.array(utm.x_limits), [-250000, 1250000]) assert_almost_equal(np.array(utm.y_limits), - [-10000000, 25000000]) + [-10000000, 25000000]) result = utm.transform_point(-73.5, 40.5, geodetic) assert_almost_equal(result, np.array([127106.5 + 500000, 4484124.4]), diff --git a/lib/cartopy/tests/test_crs.py b/lib/cartopy/tests/test_crs.py index 43384ccd7..977494f58 100644 --- a/lib/cartopy/tests/test_crs.py +++ b/lib/cartopy/tests/test_crs.py @@ -66,7 +66,7 @@ def _check_osgb(self, osgb): # results obtained by streetmap.co.uk. lat, lon = np.array([50.462023, -3.478831], dtype=np.double) - east, north = np.array([295132.1, 63512.6], dtype=np.double) + east, north = np.array([295132.1, 63512.6], dtype=np.double) # note the handling of precision here... assert_almost_equal(osgb.transform_point(lon, lat, ll), [east, north], @@ -89,7 +89,7 @@ def test_osgb(self, approx): def test_epsg(self): uk = ccrs.epsg(27700) assert uk.epsg_code == 27700 - assert_almost_equal(uk.x_limits, (-104009.357, 688806.007), decimal=3) + assert_almost_equal(uk.x_limits, (-104009.357, 688806.007), decimal=3) assert_almost_equal(uk.y_limits, (-8908.37, 1256558.45), decimal=2) assert_almost_equal(uk.threshold, 7928.15, decimal=2) self._check_osgb(uk) diff --git a/setup.cfg b/setup.cfg index 2eb60e062..5f0acda70 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [flake8] ignore = E226,\ # Due to whitespace around operators (e.g. 2*x + 3) - E241,\ # Due to multiple spaces after comma W504 # Line break after binary operator exclude = \ build, \ From 91db58800ff29b75e3d5321efab0f3efa8f36d0c Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 22 Jan 2022 13:42:13 -0700 Subject: [PATCH 3/3] MNT: Fixing flake8 E225/E226 spaces after binary operators --- lib/cartopy/crs.py | 23 ++++++---- lib/cartopy/feature/__init__.py | 6 +++ lib/cartopy/feature/nightshade.py | 34 +++++++-------- lib/cartopy/geodesic.py | 2 +- lib/cartopy/io/__init__.py | 3 ++ lib/cartopy/io/img_nest.py | 12 +++--- lib/cartopy/io/img_tiles.py | 5 +++ lib/cartopy/io/shapereader.py | 4 ++ lib/cartopy/io/srtm.py | 12 ++++-- lib/cartopy/mpl/feature_artist.py | 1 + lib/cartopy/mpl/geoaxes.py | 6 +-- lib/cartopy/mpl/slippy_image_artist.py | 1 + lib/cartopy/tests/feature/test_nightshade.py | 8 ++-- lib/cartopy/tests/mpl/test_gridliner.py | 2 +- lib/cartopy/tests/mpl/test_images.py | 7 ++-- lib/cartopy/tests/mpl/test_mpl_integration.py | 4 +- lib/cartopy/tests/test_util.py | 42 +++++++++---------- setup.cfg | 2 - 18 files changed, 102 insertions(+), 72 deletions(-) diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py index f1ae00cbe..90a145bf7 100644 --- a/lib/cartopy/crs.py +++ b/lib/cartopy/crs.py @@ -62,6 +62,7 @@ class Globe(object): Define an ellipsoid and, optionally, how to relate it to the real world. """ + def __init__(self, datum=None, ellipse='WGS84', semimajor_axis=None, semiminor_axis=None, flattening=None, inverse_flattening=None, @@ -501,8 +502,8 @@ def transform_vectors(self, src_proj, x, y, u, v): # perturbation to fix this. eps = 1e-9 invalid_x = np.logical_or( - source_x + x_perturbations < src_proj.x_limits[0]-eps, - source_x + x_perturbations > src_proj.x_limits[1]+eps) + source_x + x_perturbations < src_proj.x_limits[0] - eps, + source_x + x_perturbations > src_proj.x_limits[1] + eps) if invalid_x.any(): x_perturbations[invalid_x] *= -1 y_perturbations[invalid_x] *= -1 @@ -511,8 +512,8 @@ def transform_vectors(self, src_proj, x, y, u, v): # that will be outside the x-domain when the perturbation is # applied. invalid_y = np.logical_or( - source_y + y_perturbations < src_proj.y_limits[0]-eps, - source_y + y_perturbations > src_proj.y_limits[1]+eps) + source_y + y_perturbations < src_proj.y_limits[0] - eps, + source_y + y_perturbations > src_proj.y_limits[1] + eps) if invalid_y.any(): x_perturbations[invalid_y] *= -1 y_perturbations[invalid_y] *= -1 @@ -523,8 +524,8 @@ def transform_vectors(self, src_proj, x, y, u, v): # of the perturbation to get the perturbed point within the valid # domain of the projection, and issue a warning if there are. problem_points = np.logical_or( - source_x + x_perturbations < src_proj.x_limits[0]-eps, - source_x + x_perturbations > src_proj.x_limits[1]+eps) + source_x + x_perturbations < src_proj.x_limits[0] - eps, + source_x + x_perturbations > src_proj.x_limits[1] + eps) if problem_points.any(): warnings.warn('Some vectors at source domain corners ' 'may not have been transformed correctly') @@ -554,6 +555,7 @@ class Geodetic(CRS): geographical distance and coordinates are measured in degrees. """ + def __init__(self, globe=None): """ Parameters @@ -577,6 +579,7 @@ class Geocentric(CRS): coordinates from the center of the Earth. """ + def __init__(self, globe=None): """ Parameters @@ -606,6 +609,7 @@ class RotatedGeodetic(CRS): central_rotated_longitude value. """ + def __init__(self, pole_longitude, pole_latitude, central_rotated_longitude=0.0, globe=None): """ @@ -1507,6 +1511,7 @@ class UTM(Projection): Universal Transverse Mercator projection. """ + def __init__(self, zone, southern_hemisphere=False, globe=None): """ Parameters @@ -1541,13 +1546,13 @@ def boundary(self): def x_limits(self): easting = 5e5 # allow 50% overflow - return (0 - easting/2, 2 * easting + easting/2) + return (0 - easting / 2, 2 * easting + easting / 2) @property def y_limits(self): northing = 1e7 # allow 50% overflow - return (0 - northing, 2 * northing + northing/2) + return (0 - northing, 2 * northing + northing / 2) class EuroPP(UTM): @@ -1557,6 +1562,7 @@ class EuroPP(UTM): Ellipsoid is International 1924, Datum is ED50. """ + def __init__(self): globe = Globe(ellipse='intl') super().__init__(32, globe=globe) @@ -2563,6 +2569,7 @@ class Geostationary(_Satellite): the satellite. """ + def __init__(self, central_longitude=0.0, satellite_height=35785831, false_easting=0, false_northing=0, globe=None, sweep_axis='y'): diff --git a/lib/cartopy/feature/__init__.py b/lib/cartopy/feature/__init__.py index e7685522e..41f96bcc0 100644 --- a/lib/cartopy/feature/__init__.py +++ b/lib/cartopy/feature/__init__.py @@ -113,6 +113,7 @@ class Scaler: """ General object for handling the scale of the geometries used in a Feature. """ + def __init__(self, scale): self._scale = scale @@ -140,6 +141,7 @@ class AdaptiveScaler(Scaler): """ Automatically select scale of geometries based on extent of plotted axes. """ + def __init__(self, default_scale, limits): """ Parameters @@ -198,6 +200,7 @@ class ShapelyFeature(Feature): shapely geometries. """ + def __init__(self, geometries, crs, **kwargs): """ Parameters @@ -227,6 +230,7 @@ class NaturalEarthFeature(Feature): See https://www.naturalearthdata.com/ """ + def __init__(self, category, name, scale, **kwargs): """ Parameters @@ -345,6 +349,7 @@ class GSHHSFeature(Feature): instantiating multiple GSHHS artists, by reducing repeated file IO. """ + def __init__(self, scale='auto', levels=None, **kwargs): super().__init__(cartopy.crs.PlateCarree(), **kwargs) @@ -424,6 +429,7 @@ class WFSFeature(Feature): This feature requires additional dependencies. If installed via pip, try ``pip install cartopy[ows]``. """ + def __init__(self, wfs, features, **kwargs): """ Parameters diff --git a/lib/cartopy/feature/nightshade.py b/lib/cartopy/feature/nightshade.py index 8a8f28858..7873a7f9e 100644 --- a/lib/cartopy/feature/nightshade.py +++ b/lib/cartopy/feature/nightshade.py @@ -61,9 +61,9 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, pole_longitude=pole_lon, central_rotated_longitude=central_lon) - npts = int(180/delta) - x = np.empty(npts*2) - y = np.empty(npts*2) + npts = int(180 / delta) + x = np.empty(npts * 2) + y = np.empty(npts * 2) # Solve the equation for sunrise/sunset: # https://en.wikipedia.org/wiki/Sunrise_equation#Generalized_equation @@ -72,7 +72,7 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83, # Therefore, the max/min latitude is +/- (90+refraction) # Fill latitudes up and then down - y[:npts] = np.linspace(-(90+refraction), 90+refraction, npts) + y[:npts] = np.linspace(-(90 + refraction), 90 + refraction, npts) y[npts:] = y[:npts][::-1] # Solve the generalized equation for omega0, which is the @@ -131,9 +131,9 @@ def _julian_day(date): year -= 1 B = 2 - year // 100 + (year // 100) // 4 - C = ((second/60 + minute)/60 + hour)/24 + C = ((second / 60 + minute) / 60 + hour) / 24 - JD = (int(365.25*(year + 4716)) + int(30.6001*(month+1)) + + JD = (int(365.25 * (year + 4716)) + int(30.6001 * (month + 1)) + day + B - 1524.5 + C) return JD @@ -162,20 +162,20 @@ def _solar_position(date): # so we need to convert the values from deg2rad when taking sin/cos # Centuries from J2000 - T_UT1 = (_julian_day(date) - 2451545.0)/36525 + T_UT1 = (_julian_day(date) - 2451545.0) / 36525 # solar longitude (deg) - lambda_M_sun = (280.460 + 36000.771*T_UT1) % 360 + lambda_M_sun = (280.460 + 36000.771 * T_UT1) % 360 # solar anomaly (deg) - M_sun = (357.5277233 + 35999.05034*T_UT1) % 360 + M_sun = (357.5277233 + 35999.05034 * T_UT1) % 360 # ecliptic longitude - lambda_ecliptic = (lambda_M_sun + 1.914666471*np.sin(np.deg2rad(M_sun)) + - 0.019994643*np.sin(np.deg2rad(2*M_sun))) + lambda_ecliptic = (lambda_M_sun + 1.914666471 * np.sin(np.deg2rad(M_sun)) + + 0.019994643 * np.sin(np.deg2rad(2 * M_sun))) # obliquity of the ecliptic (epsilon in Vallado's notation) - epsilon = 23.439291 - 0.0130042*T_UT1 + epsilon = 23.439291 - 0.0130042 * T_UT1 # declination of the sun delta_sun = np.rad2deg(np.arcsin(np.sin(np.deg2rad(epsilon)) * @@ -183,11 +183,11 @@ def _solar_position(date): # Greenwich mean sidereal time (seconds) theta_GMST = (67310.54841 + - (876600*3600 + 8640184.812866)*T_UT1 + - 0.093104*T_UT1**2 - - 6.2e-6*T_UT1**3) + (876600 * 3600 + 8640184.812866) * T_UT1 + + 0.093104 * T_UT1**2 - + 6.2e-6 * T_UT1**3) # Convert to degrees - theta_GMST = (theta_GMST % 86400)/240 + theta_GMST = (theta_GMST % 86400) / 240 # Right ascension calculations numerator = (np.cos(np.deg2rad(epsilon)) * @@ -200,7 +200,7 @@ def _solar_position(date): # longitude is opposite of Greenwich Hour Angle (GHA) # GHA == theta_GMST - alpha_sun - lon = -(theta_GMST-alpha_sun) + lon = -(theta_GMST - alpha_sun) if lon < -180: lon += 360 diff --git a/lib/cartopy/geodesic.py b/lib/cartopy/geodesic.py index 4cc99a611..6afa9c098 100644 --- a/lib/cartopy/geodesic.py +++ b/lib/cartopy/geodesic.py @@ -22,7 +22,7 @@ class Geodesic: """ - def __init__(self, radius=6378137.0, flattening=1/298.257223563): + def __init__(self, radius=6378137.0, flattening=1 / 298.257223563): """ Parameters ---------- diff --git a/lib/cartopy/io/__init__.py b/lib/cartopy/io/__init__.py index fe11c9a96..d00dee4f3 100644 --- a/lib/cartopy/io/__init__.py +++ b/lib/cartopy/io/__init__.py @@ -323,6 +323,7 @@ class RasterSource: .. _raster-source-interface: """ + def validate_projection(self, projection): """ Raise an error if this raster source cannot provide images in the @@ -370,6 +371,7 @@ class RasterSourceContainer(RasterSource): contained :class:`RasterSource`. """ + def __init__(self, contained_source): """ Parameters @@ -394,6 +396,7 @@ class PostprocessedRasterSource(RasterSourceContainer): post-processing step on the raster fetched from the contained source. """ + def __init__(self, contained_source, img_post_process): """ Parameters diff --git a/lib/cartopy/io/img_nest.py b/lib/cartopy/io/img_nest.py index ecef0727f..c1ca9dfbb 100644 --- a/lib/cartopy/io/img_nest.py +++ b/lib/cartopy/io/img_nest.py @@ -176,12 +176,12 @@ def world_file_extent(worldfile_handle, im_shape): 'supported.') ul_corner = (float(lines[4]), float(lines[5])) - min_x, max_x = (ul_corner[0] - pix_size[0]/2., - ul_corner[0] + pix_size[0]*im_shape[0] - - pix_size[0]/2.) - min_y, max_y = (ul_corner[1] - pix_size[1]/2., - ul_corner[1] + pix_size[1]*im_shape[1] - - pix_size[1]/2.) + min_x, max_x = (ul_corner[0] - pix_size[0] / 2., + ul_corner[0] + pix_size[0] * im_shape[0] - + pix_size[0] / 2.) + min_y, max_y = (ul_corner[1] - pix_size[1] / 2., + ul_corner[1] + pix_size[1] * im_shape[1] - + pix_size[1] / 2.) return (min_x, max_x, min_y, max_y), pix_size diff --git a/lib/cartopy/io/img_tiles.py b/lib/cartopy/io/img_tiles.py index 0039d4896..82129d63e 100644 --- a/lib/cartopy/io/img_tiles.py +++ b/lib/cartopy/io/img_tiles.py @@ -355,6 +355,7 @@ class Stamen(GoogleWTS): * https://github.com/migurski/DEM-Tools """ + def __init__(self, style='toner', desired_tile_form='RGB', cache=False): super().__init__(desired_tile_form=desired_tile_form, @@ -373,6 +374,7 @@ class MapboxTiles(GoogleWTS): For terms of service, see https://www.mapbox.com/tos/. """ + def __init__(self, access_token, map_id, cache=False): """ Set up a new Mapbox tiles instance. @@ -416,6 +418,7 @@ class MapboxStyleTiles(GoogleWTS): For terms of service, see https://www.mapbox.com/tos/. """ + def __init__(self, access_token, username, map_id, cache=False): """ Set up a new instance to retrieve tiles from a Mapbox style. @@ -457,6 +460,7 @@ class QuadtreeTiles(GoogleWTS): where the length of the quatree is the zoom level in Google Tile terms. """ + def _image_url(self, tile): return ('http://ecn.dynamic.t1.tiles.virtualearth.net/comp/' f'CompositionHandler/{tile}?mkt=en-' @@ -548,6 +552,7 @@ class OrdnanceSurvey(GoogleWTS): https://developer.ordnancesurvey.co.uk/os-api-framework-agreement. """ # API Documentation: https://apidocs.os.uk/docs/os-maps-wmts + def __init__(self, apikey, layer='Road', diff --git a/lib/cartopy/io/shapereader.py b/lib/cartopy/io/shapereader.py index ae063b171..7398db9bb 100644 --- a/lib/cartopy/io/shapereader.py +++ b/lib/cartopy/io/shapereader.py @@ -54,6 +54,7 @@ class Record: their associated geometry. """ + def __init__(self, shape, attributes, fields): self._shape = shape @@ -108,6 +109,7 @@ class FionaRecord(Record): with the FionaReader. """ + def __init__(self, geometry, attributes): self._geometry = geometry self.attributes = attributes @@ -122,6 +124,7 @@ class BasicReader: :meth:`~Reader.records` and :meth:`~Reader.geometries`. """ + def __init__(self, filename): # Validate the filename/shapefile self._reader = reader = shapefile.Reader(filename) @@ -175,6 +178,7 @@ class FionaReader: :meth:`~Reader.records` and :meth:`~Reader.geometries`. """ + def __init__(self, filename, bbox=None): self._data = [] diff --git a/lib/cartopy/io/srtm.py b/lib/cartopy/io/srtm.py index b2b92e0d1..cfa99b814 100644 --- a/lib/cartopy/io/srtm.py +++ b/lib/cartopy/io/srtm.py @@ -31,6 +31,7 @@ class _SRTMSource(RasterSource): interface `. """ + def __init__(self, resolution, downloader, max_nx, max_ny): """ Parameters @@ -172,6 +173,7 @@ class SRTM3Source(_SRTMSource): interface `. """ + def __init__(self, downloader=None, max_nx=3, max_ny=3): """ Parameters @@ -199,6 +201,7 @@ class SRTM1Source(_SRTMSource): interface `. """ + def __init__(self, downloader=None, max_nx=3, max_ny=3): """ Parameters @@ -238,12 +241,12 @@ def add_shading(elevation, azimuth, altitude): azimuth = np.deg2rad(azimuth) altitude = np.deg2rad(altitude) x, y = np.gradient(elevation) - slope = np.pi/2. - np.arctan(np.sqrt(x*x + y*y)) + slope = np.pi / 2 - np.arctan(np.sqrt(x * x + y * y)) # -x here because of pixel orders in the SRTM tile aspect = np.arctan2(-x, y) - shaded = np.sin(altitude) * np.sin(slope)\ - + np.cos(altitude) * np.cos(slope)\ - * np.cos((azimuth - np.pi/2.) - aspect) + shaded = np.sin(altitude) * np.sin(slope) \ + + np.cos(altitude) * np.cos(slope) \ + * np.cos((azimuth - np.pi / 2) - aspect) return shaded @@ -319,6 +322,7 @@ class SRTMDownloader(Downloader): available to download. """ + def __init__(self, target_path_template, pre_downloaded_path_template='', diff --git a/lib/cartopy/mpl/feature_artist.py b/lib/cartopy/mpl/feature_artist.py index bf0f823e4..6a84d7e12 100644 --- a/lib/cartopy/mpl/feature_artist.py +++ b/lib/cartopy/mpl/feature_artist.py @@ -32,6 +32,7 @@ class _GeomKey: A workaround for Shapely polygons no longer being hashable as of 1.5.13. """ + def __init__(self, geom): self._id = id(geom) diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py index f0b2cfd66..85169bce5 100644 --- a/lib/cartopy/mpl/geoaxes.py +++ b/lib/cartopy/mpl/geoaxes.py @@ -679,7 +679,7 @@ def tissot(self, rad_km=500, lons=None, lats=None, n_samples=80, **kwargs): raise ValueError('lons and lats must have the same shape.') for lon, lat in zip(lons, lats): - circle = geod.circle(lon, lat, rad_km*1e3, n_samples=n_samples) + circle = geod.circle(lon, lat, rad_km * 1e3, n_samples=n_samples) geoms.append(sgeom.Polygon(circle)) feature = cartopy.feature.ShapelyFeature(geoms, ccrs.Geodetic(), @@ -1767,8 +1767,8 @@ def _interp_grid(X, wrap=0): dX = np.diff(X, axis=1) # account for the wrap if wrap: - dX = (dX + wrap/2) % wrap - wrap/2 - dX = dX/2 + dX = (dX + wrap / 2) % wrap - wrap / 2 + dX = dX / 2 X = np.hstack((X[:, [0]] - dX[:, [0]], X[:, :-1] + dX, X[:, [-1]] + dX[:, [-1]])) diff --git a/lib/cartopy/mpl/slippy_image_artist.py b/lib/cartopy/mpl/slippy_image_artist.py index 0b3088c68..4fa9d6480 100644 --- a/lib/cartopy/mpl/slippy_image_artist.py +++ b/lib/cartopy/mpl/slippy_image_artist.py @@ -24,6 +24,7 @@ class SlippyImageArtist(AxesImage): Kwargs are passed to the AxesImage constructor. """ + def __init__(self, ax, raster_source, **kwargs): self.raster_source = raster_source # This artist fills the Axes, so should not influence layout. diff --git a/lib/cartopy/tests/feature/test_nightshade.py b/lib/cartopy/tests/feature/test_nightshade.py index 062f91eab..753d193ac 100644 --- a/lib/cartopy/tests/feature/test_nightshade.py +++ b/lib/cartopy/tests/feature/test_nightshade.py @@ -35,10 +35,10 @@ def test_julian_day(): # ?month=6&day=21&year=2030&hour=0&min=0&sec=0&n=&ntxt=&earth=0 @pytest.mark.parametrize('dt, true_lat, true_lon', [ - (datetime(2018, 9, 29, 0, 0), -(2 + 18/60), (177 + 37/60)), - (datetime(2018, 9, 29, 14, 0), -(2 + 32/60), -(32 + 25/60)), - (datetime(1992, 2, 14, 0, 0), -(13 + 20/60), -(176 + 26/60)), - (datetime(2030, 6, 21, 0, 0), (23 + 26/60), -(179 + 34/60)) + (datetime(2018, 9, 29, 0, 0), -(2 + 18 / 60), (177 + 37 / 60)), + (datetime(2018, 9, 29, 14, 0), -(2 + 32 / 60), -(32 + 25 / 60)), + (datetime(1992, 2, 14, 0, 0), -(13 + 20 / 60), -(176 + 26 / 60)), + (datetime(2030, 6, 21, 0, 0), (23 + 26 / 60), -(179 + 34 / 60)) ]) def test_solar_position(dt, true_lat, true_lon): lat, lon = _solar_position(dt) diff --git a/lib/cartopy/tests/mpl/test_gridliner.py b/lib/cartopy/tests/mpl/test_gridliner.py index fae19e4f8..ba1614f95 100644 --- a/lib/cartopy/tests/mpl/test_gridliner.py +++ b/lib/cartopy/tests/mpl/test_gridliner.py @@ -419,7 +419,7 @@ def test_gridliner_draw_labels_param(draw_labels, result): fig.canvas.draw() res = {} for loc in 'left', 'right', 'top', 'bottom': - artists = getattr(gl, loc+'_label_artists') + artists = getattr(gl, f'{loc}_label_artists') res[loc] = [a.get_text() for a in artists if a.get_visible()] assert res == result diff --git a/lib/cartopy/tests/mpl/test_images.py b/lib/cartopy/tests/mpl/test_images.py index c46c4ef27..b424708c3 100644 --- a/lib/cartopy/tests/mpl/test_images.py +++ b/lib/cartopy/tests/mpl/test_images.py @@ -142,7 +142,7 @@ def test_imshow_wrapping(): def test_imshow_rgba(): # tests that the alpha of a RGBA array passed to imshow is set to 0 # instead of masked - z = np.ones((100, 100))*0.5 + z = np.full((100, 100), 0.5) cmap = cm.get_cmap() norm = colors.Normalize(vmin=0, vmax=1) z1 = cmap(norm(z)) @@ -161,7 +161,8 @@ def test_imshow_rgba_alpha(): ax = plt.axes(projection=ccrs.Orthographic(-120, 45)) # Create RGBA Image with random data and linspace alpha - RGBA = np.linspace(0, 255*31, dx*dy*4, dtype=np.uint8).reshape((dy, dx, 4)) + RGBA = np.linspace(0, 255 * 31, dx * dy * 4, + dtype=np.uint8).reshape((dy, dx, 4)) alpha = np.array([0, 85, 170, 255]) RGBA[:, :, 3] = alpha @@ -173,7 +174,7 @@ def test_imshow_rgba_alpha(): def test_imshow_rgb(): # tests that the alpha of a RGB array passed to imshow is set to 0 # instead of masked - z = np.ones((100, 100, 3))*0.5 + z = np.full((100, 100, 3), 0.5) plt_crs = ccrs.LambertAzimuthalEqualArea() latlon_crs = ccrs.PlateCarree() ax = plt.axes(projection=plt_crs) diff --git a/lib/cartopy/tests/mpl/test_mpl_integration.py b/lib/cartopy/tests/mpl/test_mpl_integration.py index 367d46323..a47193871 100644 --- a/lib/cartopy/tests/mpl/test_mpl_integration.py +++ b/lib/cartopy/tests/mpl/test_mpl_integration.py @@ -137,7 +137,7 @@ def test_global_hexbin_wrap_transform(): ax.coastlines(zorder=2) x, y = np.meshgrid(np.arange(0, 360), np.arange(-90, 91)) # wrap values so to match x values from test_global_hexbin_wrap - x_wrap = np.where(x >= 180, x-360, x) + x_wrap = np.where(x >= 180, x - 360, x) data = np.sin(np.sqrt(x_wrap**2 + y**2)) ax.hexbin( x.flatten(), @@ -859,5 +859,5 @@ def test_streamplot(): ax.set_extent(plot_extent, crs=ccrs.PlateCarree()) ax.coastlines() ax.streamplot(x, y, u, v, transform=ccrs.PlateCarree(), - density=(1.5, 2), color=mag, linewidth=2*mag) + density=(1.5, 2), color=mag, linewidth=2 * mag) return fig diff --git a/lib/cartopy/tests/test_util.py b/lib/cartopy/tests/test_util.py index 2ba6fab5b..c6a807f89 100644 --- a/lib/cartopy/tests/test_util.py +++ b/lib/cartopy/tests/test_util.py @@ -29,7 +29,7 @@ def test_data_only(self): def test_data_and_coord(self): c_data, c_lons = add_cyclic_point(self.data2d, coord=self.lons) r_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1) - r_lons = np.concatenate((self.lons, np.array([360.]))) + r_lons = np.concatenate((self.lons, np.array([360]))) assert_array_equal(c_data, r_data) assert_array_equal(c_lons, r_lons) @@ -41,7 +41,7 @@ def test_data_only_with_axis(self): def test_data_and_coord_with_axis(self): c_data, c_lons = add_cyclic_point(self.data4d, coord=self.lons, axis=1) r_data = np.concatenate((self.data4d, self.data4d[:, :1]), axis=1) - r_lons = np.concatenate((self.lons, np.array([360.]))) + r_lons = np.concatenate((self.lons, np.array([360]))) assert_array_equal(c_data, r_data) assert_array_equal(c_lons, r_lons) @@ -86,7 +86,7 @@ def setup_class(cls): # len(lat) != data.shape[0] # len(lon) == data.shape[1] cls.lons = np.arange(0, 360, 60) - cls.lats = np.arange(-90, 90, 180/5) + cls.lats = np.arange(-90, 90, 180 / 5) # 2d lat and lon cls.lon2d, cls.lat2d = np.meshgrid(cls.lons, cls.lats) # 3d lat and lon but with different 3rd dimension (4) as 4d data (2) @@ -95,13 +95,13 @@ def setup_class(cls): # cyclic data, lon, lat cls.c_data2d = np.concatenate((cls.data2d, cls.data2d[:, :1]), axis=1) cls.c_data4d = np.concatenate((cls.data4d, cls.data4d[:, :1]), axis=1) - cls.c_lons = np.concatenate((cls.lons, np.array([360.]))) + cls.c_lons = np.concatenate((cls.lons, np.array([360]))) cls.c_lon2d = np.concatenate( - (cls.lon2d, np.full((cls.lon2d.shape[0], 1), 360.)), + (cls.lon2d, np.full((cls.lon2d.shape[0], 1), 360)), axis=1) cls.c_lon3d = np.concatenate( (cls.lon3d, - np.full((cls.lon3d.shape[0], 1, cls.lon3d.shape[2]), 360.)), + np.full((cls.lon3d.shape[0], 1, cls.lon3d.shape[2]), 360)), axis=1) cls.c_lats = cls.lats cls.c_lat2d = np.concatenate((cls.lat2d, cls.lat2d[:, -1:]), axis=1) @@ -246,7 +246,7 @@ def test_masked_data_and_x_y_2d(self): y=self.lat2d) r_data = ma.concatenate((self.data2d, self.data2d[:, :1]), axis=1) r_lons = np.concatenate((self.lon2d, - np.full((self.lon2d.shape[0], 1), 360.)), + np.full((self.lon2d.shape[0], 1), 360)), axis=1) assert_array_equal(c_data, r_data) assert_array_equal(c_lons, r_lons) @@ -261,11 +261,11 @@ def test_cyclic(self): new_lats = np.deg2rad(self.lat2d) c_data, c_lons, c_lats = add_cyclic(self.data4d, x=new_lons, y=new_lats, axis=1, - cyclic=np.deg2rad(360.)) + cyclic=np.deg2rad(360)) r_lons = np.concatenate( (new_lons, np.full((new_lons.shape[0], 1, new_lons.shape[2]), - np.deg2rad(360.))), + np.deg2rad(360))), axis=1) r_lats = np.concatenate((new_lats, new_lats[:, -1:]), axis=1) assert_array_equal(c_data, self.c_data4d) @@ -279,13 +279,13 @@ def test_cyclic_has_cyclic(self): r_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1) r_lons = np.concatenate( (new_lons, - np.full((new_lons.shape[0], 1), np.deg2rad(360.))), + np.full((new_lons.shape[0], 1), np.deg2rad(360))), axis=1) r_lats = np.concatenate((new_lats, new_lats[:, -1:]), axis=1) c_data, c_lons, c_lats = add_cyclic(r_data, x=r_lons, y=r_lats, - cyclic=np.deg2rad(360.)) + cyclic=np.deg2rad(360)) assert_array_equal(c_data, self.c_data2d) assert_array_equal(c_lons, r_lons) assert_array_equal(c_lats, r_lats) @@ -293,7 +293,7 @@ def test_cyclic_has_cyclic(self): def test_precision_has_cyclic(self): '''Test precision keyword detecting cyclic point''' r_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1) - r_lons = np.concatenate((self.lons, np.array([360.+1e-3]))) + r_lons = np.concatenate((self.lons, np.array([360 + 1e-3]))) c_data, c_lons = add_cyclic(r_data, x=r_lons, precision=1e-2) assert_array_equal(c_data, r_data) assert_array_equal(c_lons, r_lons) @@ -301,10 +301,10 @@ def test_precision_has_cyclic(self): def test_precision_has_cyclic_no(self): '''Test precision keyword detecting no cyclic point''' new_data = np.concatenate((self.data2d, self.data2d[:, :1]), axis=1) - new_lons = np.concatenate((self.lons, np.array([360.+1e-3]))) + new_lons = np.concatenate((self.lons, np.array([360. + 1e-3]))) c_data, c_lons = add_cyclic(new_data, x=new_lons, precision=2e-4) r_data = np.concatenate((new_data, new_data[:, :1]), axis=1) - r_lons = np.concatenate((new_lons, np.array([360.]))) + r_lons = np.concatenate((new_lons, np.array([360]))) assert_array_equal(c_data, r_data) assert_array_equal(c_lons, r_lons) @@ -360,20 +360,20 @@ class TestHasCyclic: # 1d lon (6), lat (5) lons = np.arange(0, 360, 60) - lats = np.arange(-90, 90, 180/5) + lats = np.arange(-90, 90, 180 / 5) # 2d lon, lat lon2d, lat2d = np.meshgrid(lons, lats) # 3d lon lon3d = np.repeat(lon2d, 4).reshape((*lon2d.shape, 4)) # cyclic lon 1d, 2d, 3d - c_lons = np.concatenate((lons, np.array([360.]))) + c_lons = np.concatenate((lons, np.array([360]))) c_lon2d = np.concatenate( (lon2d, - np.full((lon2d.shape[0], 1), 360.)), + np.full((lon2d.shape[0], 1), 360)), axis=1) c_lon3d = np.concatenate( (lon3d, - np.full((lon3d.shape[0], 1, lon3d.shape[2]), 360.)), + np.full((lon3d.shape[0], 1, lon3d.shape[2]), 360)), axis=1) @pytest.mark.parametrize( @@ -406,11 +406,11 @@ def test_3d_axis_cyclic(self): '''Test 3d with axis and cyclic keywords''' new_clons = np.deg2rad(self.c_lon3d) new_lons = np.deg2rad(self.lon3d) - assert has_cyclic(new_clons, axis=1, cyclic=np.deg2rad(360.)) - assert not has_cyclic(new_lons, axis=1, cyclic=np.deg2rad(360.)) + assert has_cyclic(new_clons, axis=1, cyclic=np.deg2rad(360)) + assert not has_cyclic(new_lons, axis=1, cyclic=np.deg2rad(360)) def test_1d_precision(self): '''Test 1d with precision keyword''' - new_clons = np.concatenate((self.lons, np.array([360.+1e-3]))) + new_clons = np.concatenate((self.lons, np.array([360 + 1e-3]))) assert has_cyclic(new_clons, precision=1e-2) assert not has_cyclic(new_clons, precision=2e-4) diff --git a/setup.cfg b/setup.cfg index 5f0acda70..54cb6aa0b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,4 @@ [flake8] -ignore = E226,\ # Due to whitespace around operators (e.g. 2*x + 3) - W504 # Line break after binary operator exclude = \ build, \ setup.py, \