python-awips
python-awips copied to clipboard
Numpy Deprication (WWA Notebook)
Section 7.2 of the WWA notebook is throwing the following warning:
/Users/scarter/opt/miniconda3/envs/python3-awips-latest/lib/python3.10/site-packages/numpy/core/fromnumeric.py:1859: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry.
return asanyarray(a).ravel(order=order)
/Users/scarter/opt/miniconda3/envs/python3-awips-latest/lib/python3.10/site-packages/numpy/core/fromnumeric.py:1859: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.
return asanyarray(a).ravel(order=order)
Not entirely sure where this is coming from but I assume it might have to do with either line 49 and/or the for loop at line 54
This functionality is now deprecated with Shapely 2.0 (and numPy 2.0) and throws an error - so needed to update the WWA Notebook. Needed to add .geoms in order to access the geometry parts of a multi-part geometry
TypeError Traceback (most recent call last)
Cell In[32], line 55
52 geometries = np.append(geometries,Polygon(poly))
54 for geom in geometries:
---> 55 bounds = Polygon(geom)
56 intersection = bounds.intersection
57 geoms = (intersection(geom) for geom in geometries if bounds.intersects(geom))
File ~/micromamba/envs/python-awips-v23-t/lib/python3.11/site-packages/shapely/geometry/polygon.py:230, in Polygon.__new__(self, shell, holes)
228 return shell
229 else:
--> 230 shell = LinearRing(shell)
232 if holes is not None:
233 if len(holes) == 0:
234 # shapely constructor cannot handle holes=[]
File ~/micromamba/envs/python-awips-v23-t/lib/python3.11/site-packages/shapely/geometry/polygon.py:93, in LinearRing.__new__(self, coordinates)
90 else:
91 return [float(c) for c in o]
---> 93 coordinates = np.array([_coords(o) for o in coordinates])
94 if not np.issubdtype(coordinates.dtype, np.number):
95 # conversion of coords to 2D array failed, this might be due
96 # to inconsistent coordinate dimensionality
97 raise ValueError("Inconsistent coordinate dimensionality")
TypeError: 'MultiPolygon' object is not iterable
# set the geometries based on whether it's a MultiPolygon or Polygon
if poly.geom_type == 'MultiPolygon':
geometries = np.array([])
geometries = np.append(geometries,MultiPolygon(poly).geoms)