Skip to content

Commit 383777e

Browse files
authored
Merge pull request #223 from xylar/fix-flake8
Fix `flake8` lint in `geometric_features`
2 parents c06adaf + e52048c commit 383777e

File tree

11 files changed

+57
-50
lines changed

11 files changed

+57
-50
lines changed

.github/workflows/build_workflow.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,20 @@ jobs:
3737
with:
3838
python-version: "3.10"
3939

40+
- if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
41+
id: file_changes
42+
uses: trilom/file-changes-action@1.2.4
43+
with:
44+
output: ' '
45+
4046
- if: ${{ steps.skip_check.outputs.should_skip != 'true' }}
4147
# Run all pre-commit hooks on all the files.
4248
# Getting only staged files can be tricky in case a new PR is opened
4349
# since the action is run on a branch in detached head state
4450
name: Install and Run Pre-commit
4551
uses: pre-commit/action@v3.0.1
52+
with:
53+
extra_args: --files ${{ steps.file_changes.outputs.files}}
4654

4755
build:
4856
name: test geometric_features - python ${{ matrix.python-version }}

geometric_features/aggregation/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def get_aggregator_by_name(region_group):
5858
'date': '20201123',
5959
'function': subbasins},
6060
'ISMIP6 Greenland Regions': {'prefix': 'ismip6GreenlandRegions',
61-
'date': '20240510',
62-
'function': ismip6_greenland},
63-
'NASA Greenland Regions': {'prefix':'nasaGreenlandRegions',
64-
'date':'20241017',
65-
'function': nasa_greenland},
61+
'date': '20240510',
62+
'function': ismip6_greenland},
63+
'NASA Greenland Regions': {'prefix': 'nasaGreenlandRegions',
64+
'date': '20241017',
65+
'function': nasa_greenland},
6666
'ISMIP6 Regions': {'prefix': 'ismip6Regions',
6767
'date': '20210201',
6868
'function': ismip6},
@@ -75,7 +75,7 @@ def get_aggregator_by_name(region_group):
7575
'Transport Transects': {'prefix': 'transportTransects',
7676
'date': '20210323',
7777
'function': transport},
78-
'Arctic Transport Transects': {'prefix': 'arcticTransportTransects',
78+
'Arctic Transport Transects': {'prefix': 'arcticTransportTransects', # noqa: E501
7979
'date': '20220926',
8080
'function': arctic_transport}}
8181

geometric_features/aggregation/landice/nasa_greenland_extended.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
def nasa_greenland(gf):
22
"""
3-
Aggregate NASA Greenland ice sheet basin regions extended to continental shelf.
3+
Aggregate NASA Greenland ice sheet basin regions extended to continental
4+
shelf.
45
56
Parameters
67
----------

geometric_features/aggregation/seaice/historical_sea_ice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def qgreenland(gf):
2727
'May Historical Median Sea Ice Extent',
2828
'November Historical Median Sea Ice Extent',
2929
'October Historical Median Sea Ice Extent',
30-
'September Historical Median Sea Ice Extent'
31-
]
30+
'September Historical Median Sea Ice Extent']
31+
3232
fc = gf.read(componentName='seaice', objectType='region',
3333
featureNames=regions)
3434

geometric_features/feature_collection.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def difference(self, maskingFC, show_progress=False):
261261
featureCount = len(self.features)
262262
maskCount = len(maskingFC.features)
263263

264-
totalCount = featureCount*maskCount
264+
totalCount = featureCount * maskCount
265265

266266
if show_progress:
267267
print('Masking features...')
@@ -285,7 +285,7 @@ def difference(self, maskingFC, show_progress=False):
285285
masked = False
286286
for maskIndex, maskFeature in enumerate(maskingFC.features):
287287
if show_progress:
288-
bar.update(maskIndex + featureIndex*maskCount)
288+
bar.update(maskIndex + featureIndex * maskCount)
289289
maskShape = shapely.geometry.shape(maskFeature['geometry'])
290290
if featureShape.intersects(maskShape):
291291
masked = True
@@ -613,7 +613,8 @@ def _validate_feature(feature):
613613
raise KeyError(f'Feature {name} missing [{outerKey}] key')
614614
for innerKey in required[outerKey]:
615615
if innerKey not in feature[outerKey]:
616-
raise KeyError(f'Feature {name} missing [{outerKey}][{innerKey}] key')
616+
raise KeyError(
617+
f'Feature {name} missing [{outerKey}][{innerKey}] key')
617618

618619
geomType = feature['geometry']['type']
619620
objectType = feature['properties']['object']
@@ -666,18 +667,18 @@ def _validate_feature(feature):
666667

667668
def _split_geometry_crossing_antimeridian(geometry):
668669
def _to_polar(lon, lat):
669-
phi = np.pi/180.*(np.mod(lon + 180., 360.) - 180.)
670-
radius = np.pi/180.*(90. - sign*lat)
670+
phi = np.pi / 180. * (np.mod(lon + 180., 360.) - 180.)
671+
radius = np.pi / 180. * (90. - sign * lat)
671672

672673
# nudge points at +/- 180 out of the way so they don't intersect the
673674
# testing wedge
674675
phi = np.sign(phi) * \
675-
np.where(np.abs(phi) > np.pi - 1.5*epsilon,
676-
np.pi - 1.5*epsilon, np.abs(phi))
676+
np.where(np.abs(phi) > np.pi - 1.5 * epsilon,
677+
np.pi - 1.5 * epsilon, np.abs(phi))
677678
# radius = np.where(radius < 1.5*epsilon, 1.5*epsilon, radius)
678679

679-
x = radius*np.sin(phi)
680-
y = radius*np.cos(phi)
680+
x = radius * np.sin(phi)
681+
y = radius * np.cos(phi)
681682
if isinstance(lon, list):
682683
x = x.tolist()
683684
y = y.tolist()
@@ -688,17 +689,17 @@ def _to_polar(lon, lat):
688689
return x, y
689690

690691
def _from_polar(x, y):
691-
radius = np.sqrt(np.array(x)**2+np.array(y)**2)
692+
radius = np.sqrt(np.array(x)**2 + np.array(y)**2)
692693
phi = np.arctan2(x, y)
693694

694695
# close up the tiny gap
695-
radius = np.where(radius < 2*epsilon, 0., radius)
696+
radius = np.where(radius < 2 * epsilon, 0., radius)
696697
phi = np.sign(phi) * \
697-
np.where(np.abs(phi) > np.pi - 2*epsilon,
698+
np.where(np.abs(phi) > np.pi - 2 * epsilon,
698699
np.pi, np.abs(phi))
699700

700-
lon = 180./np.pi*phi
701-
lat = sign*(90. - 180./np.pi*radius)
701+
lon = 180. / np.pi * phi
702+
lat = sign * (90. - 180. / np.pi * radius)
702703

703704
if isinstance(x, list):
704705
lon = lon.tolist()
@@ -717,8 +718,8 @@ def _from_polar(x, y):
717718
(epsilon, -np.pi)])
718719

719720
featureShape = shapely.geometry.shape(geometry)
720-
sign = (2.*(0.5*(featureShape.bounds[1] + featureShape.bounds[3]) >= 0.) -
721-
1.)
721+
sign_mask = featureShape.bounds[1] + featureShape.bounds[3] >= 0.
722+
sign = 2. * sign_mask - 1.
722723
polarShape = shapely.ops.transform(_to_polar, featureShape)
723724

724725
if not polarShape.intersects(antimeridianWedge):

geometric_features/plot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ def subdivide_line_string(lineString, periodic=False):
8383
coords.append(coords[0])
8484

8585
outCoords = [coords[0]]
86-
for iVert in range(len(coords)-1):
86+
for iVert in range(len(coords) - 1):
8787
segment = shapely.geometry.LineString([coords[iVert],
88-
coords[iVert+1]])
88+
coords[iVert + 1]])
8989
if segment.length < maxLength:
90-
outCoords.append(coords[iVert+1])
90+
outCoords.append(coords[iVert + 1])
9191
else:
9292
# we need to subdivide this segment
93-
subsegment_count = int(np.ceil(segment.length/maxLength))
93+
subsegment_count = int(np.ceil(segment.length / maxLength))
9494
for index in range(subsegment_count):
9595
point = segment.interpolate(
96-
float(index+1)/float(subsegment_count),
96+
float(index + 1) / float(subsegment_count),
9797
normalized=True)
9898
outCoords.append(point.coords[0])
9999

@@ -126,7 +126,8 @@ def subdivide_line_string(lineString, periodic=False):
126126
elif geomtype == 'Point':
127127
newGeometry = geometry
128128
else:
129-
print(f"Warning: subdividing geometry type {geomtype} is not supported.")
129+
print(
130+
f"Warning: subdividing geometry type {geomtype} is not supported.")
130131
newGeometry = geometry
131132

132133
return newGeometry

geometric_features/test/test_aggregation.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import pytest
2-
31
from geometric_features import GeometricFeatures
42
from geometric_features.aggregation import (antarctic, arctic_ocean,
53
arctic_seaice, arctic_transport,
@@ -8,18 +6,19 @@
86
ismip6_greenland, moc,
97
nasa_greenland, qgreenland_seaice,
108
subbasins, transport)
11-
from geometric_features.test import TestCase, loaddatadir
9+
from geometric_features.test import TestCase
1210

1311

14-
@pytest.mark.usefixtures('loaddatadir')
1512
class TestAggregation(TestCase):
1613

1714
def test_get_aggregator_by_name(self):
1815
gf = GeometricFeatures()
19-
names = ['Antarctic Regions', 'Arctic Ocean Regions', 'ISMIP6 Greenland Regions',
20-
'NASA Greenland Regions', 'Arctic Sea Ice Regions', 'Ocean Basins',
21-
'Ice Shelves', 'Ocean Subbasins', 'ISMIP6 Regions', 'MOC Basins', 'Historical Sea Ice',
22-
'Transport Transects', 'Arctic Transport Transects']
16+
names = ['Antarctic Regions', 'Arctic Ocean Regions',
17+
'ISMIP6 Greenland Regions', 'NASA Greenland Regions',
18+
'Arctic Sea Ice Regions', 'Ocean Basins', 'Ice Shelves',
19+
'Ocean Subbasins', 'ISMIP6 Regions', 'MOC Basins',
20+
'Historical Sea Ice', 'Transport Transects',
21+
'Arctic Transport Transects']
2322

2423
for name in names:
2524
function, prefix, date = get_aggregator_by_name(name)

geometric_features/test/test_feature_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from geometric_features import (FeatureCollection, GeometricFeatures,
99
read_feature_collection)
10-
from geometric_features.test import TestCase, loaddatadir
10+
from geometric_features.test import TestCase, loaddatadir # noqa: F401
1111

1212

1313
@pytest.mark.usefixtures('loaddatadir')
@@ -393,7 +393,7 @@ def test_plot(self):
393393

394394
projection = 'cyl'
395395

396-
fig = fc.plot(projection, maxLength=4.0, figsize=(12,12),
396+
fig = fc.plot(projection, maxLength=4.0, figsize=(12, 12),
397397
colors=colors, dpi=200)
398398

399399
dest_filename = str(self.datadir.join('plot.png'))

geometric_features/test/test_features_and_tags.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import difflib
22
import os
33

4-
import pytest
5-
6-
from geometric_features.test import TestCase, loaddatadir
4+
from geometric_features.test import TestCase
75
from geometric_features.utils import write_feature_names_and_tags
86

97

10-
@pytest.mark.usefixtures('loaddatadir')
118
class TestFeaturesAndTags(TestCase):
129

1310
def test_features_and_tags(self):
@@ -36,5 +33,5 @@ def test_features_and_tags(self):
3633

3734
if count != 0:
3835
raise ValueError(
39-
'Unexpected differences in geometric_features/features_and_tags.json '
40-
'compared with the results of geometric_features.utils.write_feature_names_and_tags()')
36+
'Unexpected differences in geometric_features/features_and_tags.json ' # noqa: E501
37+
'compared with the results of geometric_features.utils.write_feature_names_and_tags()') # noqa: E501

geometric_features/test/test_geometric_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44

55
from geometric_features import GeometricFeatures
6-
from geometric_features.test import TestCase, loaddatadir
6+
from geometric_features.test import TestCase, loaddatadir # noqa: F401
77

88

99
@pytest.mark.usefixtures('loaddatadir')
@@ -138,5 +138,5 @@ def test_split(self, component='ocean', object_type='region',
138138
for feature in fc.features:
139139
name = feature['properties']['name']
140140
subdir = name.replace(' ', '_')
141-
path = f'{self.datadir}/{component}/{object_type}/{subdir}/{object_type}.geojson'
141+
path = f'{self.datadir}/{component}/{object_type}/{subdir}/{object_type}.geojson' # noqa: E501
142142
assert os.path.exists(path)

0 commit comments

Comments
 (0)