From 8829c891be2726bb4c26386c3d6110983e95a245 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 17:32:03 +0100 Subject: [PATCH 1/6] Fix flake8 lint in aggregation --- geometric_features/aggregation/__init__.py | 12 ++++++------ .../aggregation/landice/nasa_greenland_extended.py | 3 ++- .../aggregation/seaice/historical_sea_ice.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/geometric_features/aggregation/__init__.py b/geometric_features/aggregation/__init__.py index 32e06b79..fc38333d 100644 --- a/geometric_features/aggregation/__init__.py +++ b/geometric_features/aggregation/__init__.py @@ -58,11 +58,11 @@ def get_aggregator_by_name(region_group): 'date': '20201123', 'function': subbasins}, 'ISMIP6 Greenland Regions': {'prefix': 'ismip6GreenlandRegions', - 'date': '20240510', - 'function': ismip6_greenland}, - 'NASA Greenland Regions': {'prefix':'nasaGreenlandRegions', - 'date':'20241017', - 'function': nasa_greenland}, + 'date': '20240510', + 'function': ismip6_greenland}, + 'NASA Greenland Regions': {'prefix': 'nasaGreenlandRegions', + 'date': '20241017', + 'function': nasa_greenland}, 'ISMIP6 Regions': {'prefix': 'ismip6Regions', 'date': '20210201', 'function': ismip6}, @@ -75,7 +75,7 @@ def get_aggregator_by_name(region_group): 'Transport Transects': {'prefix': 'transportTransects', 'date': '20210323', 'function': transport}, - 'Arctic Transport Transects': {'prefix': 'arcticTransportTransects', + 'Arctic Transport Transects': {'prefix': 'arcticTransportTransects', # noqa: E501 'date': '20220926', 'function': arctic_transport}} diff --git a/geometric_features/aggregation/landice/nasa_greenland_extended.py b/geometric_features/aggregation/landice/nasa_greenland_extended.py index 9915c570..45dcbe24 100644 --- a/geometric_features/aggregation/landice/nasa_greenland_extended.py +++ b/geometric_features/aggregation/landice/nasa_greenland_extended.py @@ -1,6 +1,7 @@ def nasa_greenland(gf): """ - Aggregate NASA Greenland ice sheet basin regions extended to continental shelf. + Aggregate NASA Greenland ice sheet basin regions extended to continental + shelf. Parameters ---------- diff --git a/geometric_features/aggregation/seaice/historical_sea_ice.py b/geometric_features/aggregation/seaice/historical_sea_ice.py index 2001b118..019398b6 100644 --- a/geometric_features/aggregation/seaice/historical_sea_ice.py +++ b/geometric_features/aggregation/seaice/historical_sea_ice.py @@ -27,8 +27,8 @@ def qgreenland(gf): 'May Historical Median Sea Ice Extent', 'November Historical Median Sea Ice Extent', 'October Historical Median Sea Ice Extent', - 'September Historical Median Sea Ice Extent' - ] + 'September Historical Median Sea Ice Extent'] + fc = gf.read(componentName='seaice', objectType='region', featureNames=regions) From 97a2000104cb439e2f7840fed1cbdc8c721b4874 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 17:37:16 +0100 Subject: [PATCH 2/6] Fix flake8 in feature_collection --- geometric_features/feature_collection.py | 33 ++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/geometric_features/feature_collection.py b/geometric_features/feature_collection.py index bac08c02..17c9d180 100644 --- a/geometric_features/feature_collection.py +++ b/geometric_features/feature_collection.py @@ -261,7 +261,7 @@ def difference(self, maskingFC, show_progress=False): featureCount = len(self.features) maskCount = len(maskingFC.features) - totalCount = featureCount*maskCount + totalCount = featureCount * maskCount if show_progress: print('Masking features...') @@ -285,7 +285,7 @@ def difference(self, maskingFC, show_progress=False): masked = False for maskIndex, maskFeature in enumerate(maskingFC.features): if show_progress: - bar.update(maskIndex + featureIndex*maskCount) + bar.update(maskIndex + featureIndex * maskCount) maskShape = shapely.geometry.shape(maskFeature['geometry']) if featureShape.intersects(maskShape): masked = True @@ -613,7 +613,8 @@ def _validate_feature(feature): raise KeyError(f'Feature {name} missing [{outerKey}] key') for innerKey in required[outerKey]: if innerKey not in feature[outerKey]: - raise KeyError(f'Feature {name} missing [{outerKey}][{innerKey}] key') + raise KeyError( + f'Feature {name} missing [{outerKey}][{innerKey}] key') geomType = feature['geometry']['type'] objectType = feature['properties']['object'] @@ -666,18 +667,18 @@ def _validate_feature(feature): def _split_geometry_crossing_antimeridian(geometry): def _to_polar(lon, lat): - phi = np.pi/180.*(np.mod(lon + 180., 360.) - 180.) - radius = np.pi/180.*(90. - sign*lat) + phi = np.pi / 180. * (np.mod(lon + 180., 360.) - 180.) + radius = np.pi / 180. * (90. - sign * lat) # nudge points at +/- 180 out of the way so they don't intersect the # testing wedge phi = np.sign(phi) * \ - np.where(np.abs(phi) > np.pi - 1.5*epsilon, - np.pi - 1.5*epsilon, np.abs(phi)) + np.where(np.abs(phi) > np.pi - 1.5 * epsilon, + np.pi - 1.5 * epsilon, np.abs(phi)) # radius = np.where(radius < 1.5*epsilon, 1.5*epsilon, radius) - x = radius*np.sin(phi) - y = radius*np.cos(phi) + x = radius * np.sin(phi) + y = radius * np.cos(phi) if isinstance(lon, list): x = x.tolist() y = y.tolist() @@ -688,17 +689,17 @@ def _to_polar(lon, lat): return x, y def _from_polar(x, y): - radius = np.sqrt(np.array(x)**2+np.array(y)**2) + radius = np.sqrt(np.array(x)**2 + np.array(y)**2) phi = np.arctan2(x, y) # close up the tiny gap - radius = np.where(radius < 2*epsilon, 0., radius) + radius = np.where(radius < 2 * epsilon, 0., radius) phi = np.sign(phi) * \ - np.where(np.abs(phi) > np.pi - 2*epsilon, + np.where(np.abs(phi) > np.pi - 2 * epsilon, np.pi, np.abs(phi)) - lon = 180./np.pi*phi - lat = sign*(90. - 180./np.pi*radius) + lon = 180. / np.pi * phi + lat = sign * (90. - 180. / np.pi * radius) if isinstance(x, list): lon = lon.tolist() @@ -717,8 +718,8 @@ def _from_polar(x, y): (epsilon, -np.pi)]) featureShape = shapely.geometry.shape(geometry) - sign = (2.*(0.5*(featureShape.bounds[1] + featureShape.bounds[3]) >= 0.) - - 1.) + sign_mask = featureShape.bounds[1] + featureShape.bounds[3] >= 0. + sign = 2. * sign_mask - 1. polarShape = shapely.ops.transform(_to_polar, featureShape) if not polarShape.intersects(antimeridianWedge): From 9139beefc7b5e7c97192dd1cc76ea31d6a8b1e1c Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 17:38:17 +0100 Subject: [PATCH 3/6] Fix flake8 in plot --- geometric_features/plot.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/geometric_features/plot.py b/geometric_features/plot.py index d1734c0d..63156831 100644 --- a/geometric_features/plot.py +++ b/geometric_features/plot.py @@ -83,17 +83,17 @@ def subdivide_line_string(lineString, periodic=False): coords.append(coords[0]) outCoords = [coords[0]] - for iVert in range(len(coords)-1): + for iVert in range(len(coords) - 1): segment = shapely.geometry.LineString([coords[iVert], - coords[iVert+1]]) + coords[iVert + 1]]) if segment.length < maxLength: - outCoords.append(coords[iVert+1]) + outCoords.append(coords[iVert + 1]) else: # we need to subdivide this segment - subsegment_count = int(np.ceil(segment.length/maxLength)) + subsegment_count = int(np.ceil(segment.length / maxLength)) for index in range(subsegment_count): point = segment.interpolate( - float(index+1)/float(subsegment_count), + float(index + 1) / float(subsegment_count), normalized=True) outCoords.append(point.coords[0]) @@ -126,7 +126,8 @@ def subdivide_line_string(lineString, periodic=False): elif geomtype == 'Point': newGeometry = geometry else: - print(f"Warning: subdividing geometry type {geomtype} is not supported.") + print( + f"Warning: subdividing geometry type {geomtype} is not supported.") newGeometry = geometry return newGeometry From b21faadb7ebd5c95aa48437bfc3c910303a92726 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 17:39:02 +0100 Subject: [PATCH 4/6] Fix flake8 in utils --- geometric_features/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geometric_features/utils.py b/geometric_features/utils.py index 37c78e5a..0cb8e6cb 100644 --- a/geometric_features/utils.py +++ b/geometric_features/utils.py @@ -64,5 +64,5 @@ def provenance_command(): call = ' '.join(sys.argv) host = socket.gethostname() sep = ' : ' - provstr = sep.join([curtime, host, user, cwd, call]) + ';' + provstr = sep.join([curtime, host, user, cwd, call]) + ';' return provstr From a669340c64f7be23ec3759781282d939c1a47a42 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 17:42:28 +0100 Subject: [PATCH 5/6] Fix flake8 lint for tests --- geometric_features/test/test_aggregation.py | 15 +++++++-------- .../test/test_feature_collection.py | 4 ++-- geometric_features/test/test_features_and_tags.py | 9 +++------ .../test/test_geometric_features.py | 4 ++-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/geometric_features/test/test_aggregation.py b/geometric_features/test/test_aggregation.py index e77c0e47..fc83106e 100644 --- a/geometric_features/test/test_aggregation.py +++ b/geometric_features/test/test_aggregation.py @@ -1,5 +1,3 @@ -import pytest - from geometric_features import GeometricFeatures from geometric_features.aggregation import (antarctic, arctic_ocean, arctic_seaice, arctic_transport, @@ -8,18 +6,19 @@ ismip6_greenland, moc, nasa_greenland, qgreenland_seaice, subbasins, transport) -from geometric_features.test import TestCase, loaddatadir +from geometric_features.test import TestCase -@pytest.mark.usefixtures('loaddatadir') class TestAggregation(TestCase): def test_get_aggregator_by_name(self): gf = GeometricFeatures() - names = ['Antarctic Regions', 'Arctic Ocean Regions', 'ISMIP6 Greenland Regions', - 'NASA Greenland Regions', 'Arctic Sea Ice Regions', 'Ocean Basins', - 'Ice Shelves', 'Ocean Subbasins', 'ISMIP6 Regions', 'MOC Basins', 'Historical Sea Ice', - 'Transport Transects', 'Arctic Transport Transects'] + names = ['Antarctic Regions', 'Arctic Ocean Regions', + 'ISMIP6 Greenland Regions', 'NASA Greenland Regions', + 'Arctic Sea Ice Regions', 'Ocean Basins', 'Ice Shelves', + 'Ocean Subbasins', 'ISMIP6 Regions', 'MOC Basins', + 'Historical Sea Ice', 'Transport Transects', + 'Arctic Transport Transects'] for name in names: function, prefix, date = get_aggregator_by_name(name) diff --git a/geometric_features/test/test_feature_collection.py b/geometric_features/test/test_feature_collection.py index 62f77d68..75b5e794 100644 --- a/geometric_features/test/test_feature_collection.py +++ b/geometric_features/test/test_feature_collection.py @@ -7,7 +7,7 @@ from geometric_features import (FeatureCollection, GeometricFeatures, read_feature_collection) -from geometric_features.test import TestCase, loaddatadir +from geometric_features.test import TestCase, loaddatadir # noqa: F401 @pytest.mark.usefixtures('loaddatadir') @@ -393,7 +393,7 @@ def test_plot(self): projection = 'cyl' - fig = fc.plot(projection, maxLength=4.0, figsize=(12,12), + fig = fc.plot(projection, maxLength=4.0, figsize=(12, 12), colors=colors, dpi=200) dest_filename = str(self.datadir.join('plot.png')) diff --git a/geometric_features/test/test_features_and_tags.py b/geometric_features/test/test_features_and_tags.py index d5d1436c..e1892b20 100644 --- a/geometric_features/test/test_features_and_tags.py +++ b/geometric_features/test/test_features_and_tags.py @@ -1,13 +1,10 @@ import difflib import os -import pytest - -from geometric_features.test import TestCase, loaddatadir +from geometric_features.test import TestCase from geometric_features.utils import write_feature_names_and_tags -@pytest.mark.usefixtures('loaddatadir') class TestFeaturesAndTags(TestCase): def test_features_and_tags(self): @@ -36,5 +33,5 @@ def test_features_and_tags(self): if count != 0: raise ValueError( - 'Unexpected differences in geometric_features/features_and_tags.json ' - 'compared with the results of geometric_features.utils.write_feature_names_and_tags()') + 'Unexpected differences in geometric_features/features_and_tags.json ' # noqa: E501 + 'compared with the results of geometric_features.utils.write_feature_names_and_tags()') # noqa: E501 diff --git a/geometric_features/test/test_geometric_features.py b/geometric_features/test/test_geometric_features.py index a401bf43..4c21c634 100644 --- a/geometric_features/test/test_geometric_features.py +++ b/geometric_features/test/test_geometric_features.py @@ -3,7 +3,7 @@ import pytest from geometric_features import GeometricFeatures -from geometric_features.test import TestCase, loaddatadir +from geometric_features.test import TestCase, loaddatadir # noqa: F401 @pytest.mark.usefixtures('loaddatadir') @@ -138,5 +138,5 @@ def test_split(self, component='ocean', object_type='region', for feature in fc.features: name = feature['properties']['name'] subdir = name.replace(' ', '_') - path = f'{self.datadir}/{component}/{object_type}/{subdir}/{object_type}.geojson' + path = f'{self.datadir}/{component}/{object_type}/{subdir}/{object_type}.geojson' # noqa: E501 assert os.path.exists(path) From e52048c9d0e221b0c1eaf0e721fb3bbe53a5e342 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Sat, 21 Dec 2024 18:01:25 +0100 Subject: [PATCH 6/6] Only run pre-commit on changed files --- .github/workflows/build_workflow.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/build_workflow.yml b/.github/workflows/build_workflow.yml index f6ecd051..ba236ba1 100644 --- a/.github/workflows/build_workflow.yml +++ b/.github/workflows/build_workflow.yml @@ -37,12 +37,20 @@ jobs: with: python-version: "3.10" + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} + id: file_changes + uses: trilom/file-changes-action@1.2.4 + with: + output: ' ' + - if: ${{ steps.skip_check.outputs.should_skip != 'true' }} # Run all pre-commit hooks on all the files. # Getting only staged files can be tricky in case a new PR is opened # since the action is run on a branch in detached head state name: Install and Run Pre-commit uses: pre-commit/action@v3.0.1 + with: + extra_args: --files ${{ steps.file_changes.outputs.files}} build: name: test geometric_features - python ${{ matrix.python-version }}