Skip to content

Commit e828b70

Browse files
committed
from cellids to cellid
1 parent 9b7a1d1 commit e828b70

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

nlmod/dims/grid.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def get_icell2d_from_xy(x, y, ds, gi=None, rotated=True):
159159
gi = flopy.utils.GridIntersect(
160160
modelgrid_from_ds(ds, rotated=rotated)
161161
)
162-
cellids = gi.intersects(Point(x, y))["cellids"]
162+
cellids = gi.intersects(Point(x, y), dataframe=True)["cellid"]
163163
if len(cellids) < 1:
164164
raise (ValueError(f"Point ({x}, {y}) is outside of the model grid"))
165165
icell2d = cellids[0]
@@ -227,7 +227,7 @@ def get_row_col_from_xy(x, y, ds, rotated=True, gi=None):
227227
msg = "get_row_col_from_xy can only be applied to a structured grid"
228228
assert ds.gridtype == "structured", msg
229229
if gi is not None:
230-
cellids = gi.intersects(Point(x, y))["cellids"]
230+
cellids = gi.intersects(Point(x, y), dataframe=True)[["row", "col"]].values
231231
if len(cellids) < 1:
232232
raise (ValueError(f"Point ({x}, {y}) is outside of the model grid"))
233233
row, col = cellids[0]
@@ -1907,18 +1907,17 @@ def gdf_to_count_da(gdf, ds, ix=None, buffer=0.0, **kwargs):
19071907

19081908
for geom in geoms:
19091909
if buffer > 0.0:
1910-
cids = ix.intersects(geom.buffer(buffer), **kwargs)["cellids"]
1910+
df = ix.intersects(geom.buffer(buffer), dataframe=True, **kwargs)
19111911
else:
1912-
cids = ix.intersects(geom, **kwargs)["cellids"]
1912+
df = ix.intersects(geom, dataframe=True, **kwargs)
19131913

1914-
if len(cids) == 0:
1914+
if len(df) == 0:
19151915
continue
19161916

19171917
if ds.gridtype == "structured":
1918-
ixs, iys = zip(*cids)
1919-
da.values[ixs, iys] += 1
1918+
da.values[df['row'], df['col']] += 1
19201919
elif ds.gridtype == "vertex":
1921-
da[cids.astype(int)] += 1
1920+
da[df['cellid']] += 1
19221921

19231922
return da
19241923

@@ -2133,7 +2132,7 @@ def gdf_area_to_da(
21332132
df = ix.intersect(gdf.at[index, geometry], geo_dataframe=True, **kwargs)
21342133
if structured:
21352134
for i in range(df.shape[0]):
2136-
data[df["cellids"][i] + (irow,)] += df["areas"][i]
2135+
data[df.iloc[i]["cellid"] + (irow,)] += df["areas"][i]
21372136
else:
21382137
data[list(df["cellids"]), irow] = df["areas"]
21392138

nlmod/gwf/surface_water.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,17 +1228,20 @@ def get_seaonal_timeseries(
12281228

12291229
def rivdata_from_xylist(gwf, xylist, layer, stage, cond, rbot, aux=None):
12301230
gi = flopy.utils.GridIntersect(gwf.modelgrid)
1231-
cellids = gi.intersect(xylist, shapetype="linestring", geo_dataframe=True)["cellids"]
1231+
df = gi.intersect(xylist, shapetype="linestring", geo_dataframe=True)
12321232
riv_data = []
1233-
for cid in cellids:
1234-
if isinstance(cid, (list, tuple)) and len(cid) == 2:
1235-
idata = [(layer, cid[0], cid[1]), stage, cond, rbot]
1233+
1234+
if 'row' in df.columns: # structured grid
1235+
for row, col in zip(df['row'], df['col']):
1236+
idata = [(layer, row, col), stage, cond, rbot]
12361237
if aux is not None:
12371238
idata.append(aux)
12381239
riv_data.append(idata)
1239-
else:
1240+
else: # unstructured grid
1241+
for cid in df['cellid']:
12401242
idata = [(layer, cid), stage, cond, rbot]
12411243
if aux is not None:
12421244
idata.append(aux)
12431245
riv_data.append(idata)
1246+
12441247
return riv_data

0 commit comments

Comments
 (0)