Skip to content

Commit e596a81

Browse files
authored
Merge pull request #189 from xylar/support_shapely_2.0
Improve testing and support shapely 2.0
2 parents 3a77b02 + 4267256 commit e596a81

16 files changed

+745
-215
lines changed

dev-spec.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ matplotlib-base
88
numpy
99
progressbar2
1010
requests
11-
shapely
11+
shapely>=2.0,<3.0
1212

1313
# Development
1414
pip
15+
pytest
1516

1617
# Documentation
1718
sphinx

examples/setup_ocean_region_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def remove_small_polygons(fc, minArea):
207207
else:
208208
# a MultiPolygon
209209
outPolygons = []
210-
for polygon in featureShape:
210+
for polygon in featureShape.geoms:
211211
if polygon.area > minArea:
212212
outPolygons.append(polygon)
213213
else:

geometric_features/__main__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111

1212
def combine_features():
13-
'''
13+
"""
1414
Entry point for combining features from a file
15-
'''
15+
"""
1616
parser = argparse.ArgumentParser(
1717
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
1818
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -39,9 +39,9 @@ def combine_features():
3939

4040

4141
def difference_features():
42-
'''
42+
"""
4343
Entry point for differencing features from a file
44-
'''
44+
"""
4545
parser = argparse.ArgumentParser(
4646
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
4747
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -70,9 +70,9 @@ def difference_features():
7070

7171

7272
def fix_features_at_antimeridian():
73-
'''
73+
"""
7474
Entry point for splitting features that cross +/- 180 degrees
75-
'''
75+
"""
7676
parser = argparse.ArgumentParser(
7777
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
7878
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -95,9 +95,9 @@ def fix_features_at_antimeridian():
9595

9696

9797
def merge_features():
98-
'''
98+
"""
9999
Entry point for merging features from the geometric_data cache
100-
'''
100+
"""
101101
parser = argparse.ArgumentParser(
102102
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
103103
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -106,7 +106,7 @@ def merge_features():
106106
metavar="FILE")
107107
parser.add_argument("-c", "--component", dest="component",
108108
help="The component (ocean, landice, etc.) from which "
109-
"to retieve the geometric features",
109+
"to retrieve the geometric features",
110110
metavar="COMP")
111111
parser.add_argument("-b", "--object_type", dest="object_type",
112112
help="The type of geometry to load, a point (0D), "
@@ -154,9 +154,9 @@ def merge_features():
154154

155155

156156
def plot_features():
157-
'''
157+
"""
158158
Entry point for plotting features from a file
159-
'''
159+
"""
160160

161161
parser = argparse.ArgumentParser(
162162
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
@@ -202,9 +202,9 @@ def plot_features():
202202

203203

204204
def set_group_name():
205-
'''
205+
"""
206206
Set the group name of the feature collection
207-
'''
207+
"""
208208
parser = argparse.ArgumentParser(
209209
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
210210
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -228,9 +228,9 @@ def set_group_name():
228228

229229

230230
def simplify_features():
231-
'''
231+
"""
232232
Features in the collection are simplified using ``shapely``
233-
'''
233+
"""
234234
parser = argparse.ArgumentParser(
235235
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
236236
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -239,7 +239,7 @@ def simplify_features():
239239
parser.add_argument("-t", "--tolerance", dest="tolerance", type=float,
240240
default=0.0,
241241
help="A distance in deg lon/lat by which each point "
242-
"in a feature can be moved during simpification",
242+
"in a feature can be moved during simplification",
243243
metavar="TOLERANCE")
244244
parser.add_argument("-o", "--output", dest="output_file_name",
245245
help="Output file, e.g., features.geojson.",
@@ -257,10 +257,10 @@ def simplify_features():
257257

258258

259259
def split_features():
260-
'''
260+
"""
261261
Features in the collection are split into individual files in the
262262
geometric_data cache
263-
'''
263+
"""
264264
parser = argparse.ArgumentParser(
265265
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
266266
parser.add_argument("-f", "--feature_file", dest="feature_file",
@@ -283,9 +283,9 @@ def split_features():
283283

284284

285285
def tag_features():
286-
'''
286+
"""
287287
Features in the collection are tagged with the given tag(s)
288-
'''
288+
"""
289289
parser = argparse.ArgumentParser(
290290
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
291291
parser.add_argument("-f", "--feature_file", dest="feature_file",

geometric_features/aggregation/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def get_aggregator_by_name(region_group):
1414
region_group : str
1515
The name of a region group to get mask features for, one of
1616
'Antarctic Regions', 'Arctic Ocean Regions', 'Arctic Sea Ice Regions',
17-
'Ocean Basins', 'Ice Shelves', 'Ocean Subbasins', or 'ISMIP6 Regions'
17+
'Ocean Basins', 'Ice Shelves', 'Ocean Subbasins', 'ISMIP6 Regions',
18+
'MOC Basins', 'Transport Transects', or 'Arctic Transport Transects'
1819
1920
Returns
2021
-------
@@ -60,11 +61,11 @@ def get_aggregator_by_name(region_group):
6061
'date': '20210323',
6162
'function': transport},
6263
'Arctic Transport Transects': {'prefix': 'arcticTransportTransects',
63-
'date': '20220926',
64-
'function': arctic_transport}}
64+
'date': '20220926',
65+
'function': arctic_transport}}
6566

6667
if region_group not in regions:
67-
raise ValueError('Unknown region group {}'.format(region_group))
68+
raise ValueError(f'Unknown region group {region_group}')
6869

6970
region = regions[region_group]
7071

geometric_features/aggregation/ocean/moc_basins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def moc(gf):
1313
Parameters
1414
----------
1515
gf : ``GeometricFeatures``
16-
An object that knows how to download and read geometric featuers
16+
An object that knows how to download and read geometric features
1717
1818
Returns
1919
-------
@@ -99,7 +99,7 @@ def _remove_small_polygons(fc, minArea):
9999
fcOut.add_feature(copy.deepcopy(feature))
100100
else:
101101
featureShape = shapely.geometry.shape(geom)
102-
if featureShape.type == 'Polygon':
102+
if featureShape.geom_type == 'Polygon':
103103
if featureShape.area > minArea:
104104
add = True
105105
else:

geometric_features/download.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
"""
2-
Utilities for downloading files
3-
"""
4-
# Authors
5-
# -------
6-
# Milena Veneziani
7-
# Xylar Asay-Davis
8-
91
from __future__ import absolute_import, division, print_function, \
102
unicode_literals
113

@@ -18,9 +10,9 @@
1810

1911
# From https://stackoverflow.com/a/1094933/7728169
2012
def sizeof_fmt(num, suffix='B'):
21-
'''
13+
"""
2214
Covert a number of bytes to a human-readable file size
23-
'''
15+
"""
2416
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
2517
if abs(num) < 1024.0:
2618
return "%3.1f%s%s" % (num, unit, suffix)
@@ -29,9 +21,9 @@ def sizeof_fmt(num, suffix='B'):
2921

3022

3123
def download_files(fileList, urlBase, outDir):
32-
'''
24+
"""
3325
Download a list of files from a URL to a directory
34-
'''
26+
"""
3527
# Authors
3628
# -------
3729
# Milena Veneziani

0 commit comments

Comments
 (0)