Skip to content

Commit

Permalink
Merge pull request #185 from oceanmodeling/depend/geopandas
Browse files Browse the repository at this point in the history
Unpin dependencies
  • Loading branch information
SorooshMani-NOAA authored Aug 1, 2024
2 parents 7426384 + 87582f7 commit a54e516
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
28 changes: 16 additions & 12 deletions adcircpy/mesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand All @@ -209,6 +210,8 @@ def edges(self) -> GeoDataFrame:
'type': ring.type,
}
)
if len(data) == 0:
return GeoDataFrame()
return GeoDataFrame(data, crs=self._grd.crs)


Expand All @@ -217,14 +220,16 @@ 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)
data.append({'geometry': geometry, 'bnd_id': bnd_id, 'type': 'exterior'})
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):
Expand Down Expand Up @@ -258,32 +263,31 @@ def geodataframe(self) -> GeoDataFrame:
'bnd_id': bnd_id,
}
)
if len(data) == 0:
return GeoDataFrame()
return GeoDataFrame(data, crs=self._grd.crs)

@property
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
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)
Expand Down
10 changes: 7 additions & 3 deletions adcircpy/mesh/fort14.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = GeoDataFrame(data, crs=self._mesh.crs)
return self._gdf

def __eq__(self, other: 'BaseBoundaries') -> bool:
Expand Down Expand Up @@ -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 = GeoDataFrame(data, crs=self._mesh.crs)
return self._gdf


Expand Down
4 changes: 2 additions & 2 deletions adcircpy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
]

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ enable = true
python = '^3.8, <3.12'
appdirs = '*'
dunamai = { version = '*', optional = true }
geopandas = '<0.11'
geopandas = '*'
haversine = '*'
matplotlib = '<3.9'
matplotlib = '*'
netCDF4 = '*'
numpy = '*'
pandas = '*'
Expand Down

0 comments on commit a54e516

Please sign in to comment.