Skip to content

Commit

Permalink
Merge pull request #54 from noaa-ocs-modeling/bugfix/subset
Browse files Browse the repository at this point in the history
Fix `geopandas` related issues found during `subset_n_mesh` script execution
  • Loading branch information
SorooshMani-NOAA authored Jan 13, 2023
2 parents 1db9fd8 + 142dde3 commit b138502
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion ocsmesh/geom/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from multiprocessing import cpu_count
from typing import Union, Tuple, Optional, Iterable, List, Any

import pandas as pd
import geopandas as gpd
from pyproj import CRS, Transformer
from shapely.geometry import MultiPolygon, Polygon
Expand Down Expand Up @@ -314,7 +315,9 @@ def get_multipolygon(self, **kwargs: Any) -> MultiPolygon:

gdf = gpd.GeoDataFrame(columns=['geometry'], crs=epsg4326)
for f in feather_files:
gdf = gdf.append(gpd.read_feather(f))
gdf = pd.concat(
[gdf, gpd.read_feather(f).to_crs(gdf.crs)]
)

mp = gdf.unary_union
if isinstance(mp, Polygon):
Expand Down
17 changes: 10 additions & 7 deletions ocsmesh/ops/combine_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings
from typing import Union, Sequence, Tuple, List

import pandas as pd
import geopandas as gpd
import numpy as np
from pyproj import CRS, Transformer
Expand Down Expand Up @@ -223,14 +224,16 @@ def run(self):
crs=self._calc_crs
)
for feather_f in poly_files_coll:
rasters_gdf = rasters_gdf.append(
gpd.GeoDataFrame(
{'geometry': self._read_multipolygon(
feather_f)
},
crs=self._calc_crs
rasters_gdf = pd.concat(
[
rasters_gdf,
gpd.GeoDataFrame(
{'geometry': self._read_multipolygon(feather_f)},
crs=self._calc_crs
),
ignore_index=True)
],
ignore_index=True
)


# The assumption is this returns polygon or multipolygon
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"numpy>=1.21", # introduce npt.NDArray
"pyarrow", "pygeos", "pyproj>=3.0", "rasterio", "requests",
"scipy<1.8", # dropping python 3.7
"shapely>=1.8", "tqdm", "typing_extensions", "utm",
"shapely>=1.8, <2", "tqdm", "typing_extensions", "utm",
]
dynamic = ["version"]

Expand Down

0 comments on commit b138502

Please sign in to comment.