Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flake8 updating #1991

Merged
merged 3 commits into from
Jan 29, 2022
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
6 changes: 3 additions & 3 deletions lib/cartopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
23 changes: 15 additions & 8 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -554,6 +555,7 @@ class Geodetic(CRS):
geographical distance and coordinates are measured in degrees.

"""

def __init__(self, globe=None):
"""
Parameters
Expand All @@ -577,6 +579,7 @@ class Geocentric(CRS):
coordinates from the center of the Earth.

"""

def __init__(self, globe=None):
"""
Parameters
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -1507,6 +1511,7 @@ class UTM(Projection):
Universal Transverse Mercator projection.

"""

def __init__(self, zone, southern_hemisphere=False, globe=None):
"""
Parameters
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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'):
Expand Down
6 changes: 6 additions & 0 deletions lib/cartopy/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,6 +200,7 @@ class ShapelyFeature(Feature):
shapely geometries.

"""

def __init__(self, geometries, crs, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -227,6 +230,7 @@ class NaturalEarthFeature(Feature):
See https://www.naturalearthdata.com/

"""

def __init__(self, category, name, scale, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions lib/cartopy/feature/nightshade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -162,32 +162,32 @@ 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)) *
np.sin(np.deg2rad(lambda_ecliptic))))

# 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)) *
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/cartopy/geodesic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand Down
3 changes: 3 additions & 0 deletions lib/cartopy/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -370,6 +371,7 @@ class RasterSourceContainer(RasterSource):
contained :class:`RasterSource`.

"""

def __init__(self, contained_source):
"""
Parameters
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions lib/cartopy/io/img_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 5 additions & 0 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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-'
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions lib/cartopy/io/shapereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Record:
their associated geometry.

"""

def __init__(self, shape, attributes, fields):
self._shape = shape

Expand Down Expand Up @@ -108,6 +109,7 @@ class FionaRecord(Record):
with the FionaReader.

"""

def __init__(self, geometry, attributes):
self._geometry = geometry
self.attributes = attributes
Expand All @@ -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)
Expand Down Expand Up @@ -175,6 +178,7 @@ class FionaReader:
:meth:`~Reader.records` and :meth:`~Reader.geometries`.

"""

def __init__(self, filename, bbox=None):
self._data = []

Expand Down
Loading