From 383b4d1d2def979cad4e34c6ab417735f27511cb Mon Sep 17 00:00:00 2001 From: Soroosh Mani <77082694+SorooshMani-NOAA@users.noreply.github.com> Date: Fri, 26 Apr 2024 14:17:15 -0400 Subject: [PATCH 1/5] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 72944c7b..5f2b1914 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ enable = true python = '^3.8, <3.12' appdirs = '*' dunamai = { version = '*', optional = true } -geopandas = '<0.11' +geopandas = '*' haversine = '*' matplotlib = '<3.9' netCDF4 = '*' From df4ca8eb062d07931595c169e0928225808d8dac Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Thu, 1 Aug 2024 16:11:55 -0400 Subject: [PATCH 2/5] Fix issues with potentially empty datasets --- adcircpy/mesh/base.py | 29 +++++++++++++++++------------ adcircpy/mesh/fort14.py | 8 ++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/adcircpy/mesh/base.py b/adcircpy/mesh/base.py index 21ddb0da..ae3a6f3a 100644 --- a/adcircpy/mesh/base.py +++ b/adcircpy/mesh/base.py @@ -7,8 +7,7 @@ import pathlib from typing import Hashable, Mapping, Union -import geopandas as gpd -from geopandas import GeoDataFrame +from geopandas import tools, GeoDataFrame from matplotlib.collections import PolyCollection from matplotlib.path import Path import matplotlib.pyplot as plt @@ -187,7 +186,9 @@ def gdf(self): } for id, element in self.elements.iterrows() ] - self._gdf = gpd.GeoDataFrame(data, crs=self.crs) + self._gdf = GeoDataFrame() + if len(data) > 0: + self._gdf = GeoDataFrame(data, crs=self.crs) return self._gdf @@ -209,6 +210,8 @@ def edges(self) -> GeoDataFrame: 'type': ring.type, } ) + if len(data) == 0: + return GeoDataFrame() return GeoDataFrame(data, crs=self._grd.crs) @@ -217,7 +220,7 @@ def __init__(self, grd: 'Grd'): self._grd = grd @lru_cache(maxsize=1) - def __call__(self) -> gpd.GeoDataFrame: + def __call__(self) -> GeoDataFrame: data = [] for bnd_id, rings in self.sorted().items(): geometry = LinearRing(self._grd.coords.iloc[rings['exterior'][:, 0], :].values) @@ -225,6 +228,8 @@ def __call__(self) -> gpd.GeoDataFrame: for interior in rings['interiors']: geometry = LinearRing(self._grd.coords.iloc[interior[:, 0], :].values) data.append({'geometry': geometry, 'bnd_id': bnd_id, 'type': 'interior'}) + if len(data) == 0: + return GeoDataFrame() return GeoDataFrame(data, crs=self._grd.crs) def exterior(self): @@ -258,6 +263,8 @@ def geodataframe(self) -> GeoDataFrame: 'bnd_id': bnd_id, } ) + if len(data) == 0: + return GeoDataFrame() return GeoDataFrame(data, crs=self._grd.crs) @property @@ -265,6 +272,8 @@ def exterior(self) -> GeoDataFrame: data = [] for exterior in self.rings().loc[self.rings()['type'] == 'exterior'].itertuples(): data.append({'geometry': Polygon(exterior.geometry.coords)}) + if len(data) == 0: + return GeoDataFrame() return GeoDataFrame(data, crs=self._grd.crs) @property @@ -272,18 +281,14 @@ def interior(self) -> GeoDataFrame: data = [] for interior in self.rings().loc[self.rings()['type'] == 'interior'].itertuples(): data.append({'geometry': Polygon(interior.geometry.coords)}) + if len(data) == 0: + return GeoDataFrame() return GeoDataFrame(data, crs=self._grd.crs) @property def implode(self) -> GeoDataFrame: - return GeoDataFrame( - { - 'geometry': MultiPolygon( - [polygon.geometry for polygon in self.geodataframe.itertuples()] - ) - }, - crs=self._grd.crs, - ) + return tools.collect(self.geodataframe) + @property @lru_cache(maxsize=1) diff --git a/adcircpy/mesh/fort14.py b/adcircpy/mesh/fort14.py index 74c95397..768c0c8f 100644 --- a/adcircpy/mesh/fort14.py +++ b/adcircpy/mesh/fort14.py @@ -55,7 +55,9 @@ def gdf(self): **boundary, } ) - self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) + self._gdf = GeoDataFrame() + if len(data) > 0: + self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) return self._gdf def __eq__(self, other: 'BaseBoundaries') -> bool: @@ -97,7 +99,9 @@ def gdf(self): **boundary, } ) - self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) + self._gdf = GeoDataFrame() + if len(data) > 0: + self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) return self._gdf From 4611041f299bf1216cbde331658bfecb3a4207b9 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Thu, 1 Aug 2024 16:13:00 -0400 Subject: [PATCH 3/5] Lint fix --- adcircpy/mesh/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adcircpy/mesh/base.py b/adcircpy/mesh/base.py index ae3a6f3a..f9e0510d 100644 --- a/adcircpy/mesh/base.py +++ b/adcircpy/mesh/base.py @@ -289,7 +289,6 @@ def interior(self) -> GeoDataFrame: def implode(self) -> GeoDataFrame: return tools.collect(self.geodataframe) - @property @lru_cache(maxsize=1) def multipolygon(self) -> MultiPolygon: From 86806b58fb3a42d0894a97351c1f51583d459ea3 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Thu, 1 Aug 2024 16:14:42 -0400 Subject: [PATCH 4/5] Import fix --- adcircpy/mesh/fort14.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adcircpy/mesh/fort14.py b/adcircpy/mesh/fort14.py index 768c0c8f..be1d8be0 100644 --- a/adcircpy/mesh/fort14.py +++ b/adcircpy/mesh/fort14.py @@ -1,6 +1,6 @@ from typing import Union -import geopandas as gpd +from geopandas import GeoDataFrame from matplotlib.cm import ScalarMappable import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable @@ -57,7 +57,7 @@ def gdf(self): ) self._gdf = GeoDataFrame() if len(data) > 0: - self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) + self._gdf = GeoDataFrame(data, crs=self._mesh.crs) return self._gdf def __eq__(self, other: 'BaseBoundaries') -> bool: @@ -101,7 +101,7 @@ def gdf(self): ) self._gdf = GeoDataFrame() if len(data) > 0: - self._gdf = gpd.GeoDataFrame(data, crs=self._mesh.crs) + self._gdf = GeoDataFrame(data, crs=self._mesh.crs) return self._gdf From 87582f72d9973c9115f593c5517e79542a49baf8 Mon Sep 17 00:00:00 2001 From: SorooshMani-NOAA Date: Thu, 1 Aug 2024 16:26:08 -0400 Subject: [PATCH 5/5] Fix #186 Update color maps fetching call --- adcircpy/plotting.py | 4 ++-- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adcircpy/plotting.py b/adcircpy/plotting.py index d00fa36c..1860be9d 100644 --- a/adcircpy/plotting.py +++ b/adcircpy/plotting.py @@ -8,7 +8,7 @@ import geopandas from matplotlib import pyplot from matplotlib.axes import Axes -from matplotlib.cm import get_cmap +from matplotlib import colormaps import numpy import requests from shapely.geometry import MultiPoint, MultiPolygon, Polygon @@ -92,7 +92,7 @@ def plot_polygons( colors = [kwargs['c'] for _ in range(len(geometries))] elif colors is None: colors = [ - get_cmap('gist_rainbow')(color_index / len(geometries)) + colormaps['gist_rainbow'](color_index / len(geometries)) for color_index in range(len(geometries)) ] diff --git a/pyproject.toml b/pyproject.toml index 5f2b1914..3987ee74 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ appdirs = '*' dunamai = { version = '*', optional = true } geopandas = '*' haversine = '*' -matplotlib = '<3.9' +matplotlib = '*' netCDF4 = '*' numpy = '*' pandas = '*'