Skip to content

Commit

Permalink
Merge pull request #189 from xylar/support_shapely_2.0
Browse files Browse the repository at this point in the history
Improve testing and support shapely 2.0
  • Loading branch information
xylar authored Jan 3, 2023
2 parents 3a77b02 + 4267256 commit e596a81
Show file tree
Hide file tree
Showing 16 changed files with 745 additions and 215 deletions.
3 changes: 2 additions & 1 deletion dev-spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ matplotlib-base
numpy
progressbar2
requests
shapely
shapely>=2.0,<3.0

# Development
pip
pytest

# Documentation
sphinx
Expand Down
2 changes: 1 addition & 1 deletion examples/setup_ocean_region_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def remove_small_polygons(fc, minArea):
else:
# a MultiPolygon
outPolygons = []
for polygon in featureShape:
for polygon in featureShape.geoms:
if polygon.area > minArea:
outPolygons.append(polygon)
else:
Expand Down
40 changes: 20 additions & 20 deletions geometric_features/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@


def combine_features():
'''
"""
Entry point for combining features from a file
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand All @@ -39,9 +39,9 @@ def combine_features():


def difference_features():
'''
"""
Entry point for differencing features from a file
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand Down Expand Up @@ -70,9 +70,9 @@ def difference_features():


def fix_features_at_antimeridian():
'''
"""
Entry point for splitting features that cross +/- 180 degrees
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand All @@ -95,9 +95,9 @@ def fix_features_at_antimeridian():


def merge_features():
'''
"""
Entry point for merging features from the geometric_data cache
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand All @@ -106,7 +106,7 @@ def merge_features():
metavar="FILE")
parser.add_argument("-c", "--component", dest="component",
help="The component (ocean, landice, etc.) from which "
"to retieve the geometric features",
"to retrieve the geometric features",
metavar="COMP")
parser.add_argument("-b", "--object_type", dest="object_type",
help="The type of geometry to load, a point (0D), "
Expand Down Expand Up @@ -154,9 +154,9 @@ def merge_features():


def plot_features():
'''
"""
Entry point for plotting features from a file
'''
"""

parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
Expand Down Expand Up @@ -202,9 +202,9 @@ def plot_features():


def set_group_name():
'''
"""
Set the group name of the feature collection
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand All @@ -228,9 +228,9 @@ def set_group_name():


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


def split_features():
'''
"""
Features in the collection are split into individual files in the
geometric_data cache
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand All @@ -283,9 +283,9 @@ def split_features():


def tag_features():
'''
"""
Features in the collection are tagged with the given tag(s)
'''
"""
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-f", "--feature_file", dest="feature_file",
Expand Down
9 changes: 5 additions & 4 deletions geometric_features/aggregation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def get_aggregator_by_name(region_group):
region_group : str
The name of a region group to get mask features for, one of
'Antarctic Regions', 'Arctic Ocean Regions', 'Arctic Sea Ice Regions',
'Ocean Basins', 'Ice Shelves', 'Ocean Subbasins', or 'ISMIP6 Regions'
'Ocean Basins', 'Ice Shelves', 'Ocean Subbasins', 'ISMIP6 Regions',
'MOC Basins', 'Transport Transects', or 'Arctic Transport Transects'
Returns
-------
Expand Down Expand Up @@ -60,11 +61,11 @@ def get_aggregator_by_name(region_group):
'date': '20210323',
'function': transport},
'Arctic Transport Transects': {'prefix': 'arcticTransportTransects',
'date': '20220926',
'function': arctic_transport}}
'date': '20220926',
'function': arctic_transport}}

if region_group not in regions:
raise ValueError('Unknown region group {}'.format(region_group))
raise ValueError(f'Unknown region group {region_group}')

region = regions[region_group]

Expand Down
4 changes: 2 additions & 2 deletions geometric_features/aggregation/ocean/moc_basins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def moc(gf):
Parameters
----------
gf : ``GeometricFeatures``
An object that knows how to download and read geometric featuers
An object that knows how to download and read geometric features
Returns
-------
Expand Down Expand Up @@ -99,7 +99,7 @@ def _remove_small_polygons(fc, minArea):
fcOut.add_feature(copy.deepcopy(feature))
else:
featureShape = shapely.geometry.shape(geom)
if featureShape.type == 'Polygon':
if featureShape.geom_type == 'Polygon':
if featureShape.area > minArea:
add = True
else:
Expand Down
16 changes: 4 additions & 12 deletions geometric_features/download.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
Utilities for downloading files
"""
# Authors
# -------
# Milena Veneziani
# Xylar Asay-Davis

from __future__ import absolute_import, division, print_function, \
unicode_literals

Expand All @@ -18,9 +10,9 @@

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


def download_files(fileList, urlBase, outDir):
'''
"""
Download a list of files from a URL to a directory
'''
"""
# Authors
# -------
# Milena Veneziani
Expand Down
Loading

0 comments on commit e596a81

Please sign in to comment.