@@ -362,7 +362,7 @@ def write(self, f=None):
362
362
for v in d :
363
363
f .write (fmt .format (* v ))
364
364
365
- def to_coords (self , grid , localz = False ) -> Iterator [tuple ]:
365
+ def to_coords (self , grid , localz = False , global_xy = False ) -> Iterator [tuple ]:
366
366
"""
367
367
Compute particle coordinates on the given grid.
368
368
@@ -397,9 +397,12 @@ def cvt_z(p, k, i, j):
397
397
span = mx - mn
398
398
return mn + span * p
399
399
400
- def convert (row ) -> tuple [float , float , float ]:
400
+ def convert (row , global_xy = False ) -> tuple [float , float , float ]:
401
401
verts = grid .get_cell_vertices (row .i , row .j )
402
- xs , ys = list (zip (* verts ))
402
+ if global_xy :
403
+ xs , ys = list (zip (* verts ))
404
+ else :
405
+ xs , ys = grid .get_local_coords (* np .array (verts ).T )
403
406
return [
404
407
cvt_xy (row .localx , xs ),
405
408
cvt_xy (row .localy , ys ),
@@ -421,19 +424,22 @@ def cvt_z(p, nn):
421
424
span = mx - mn
422
425
return mn + span * p
423
426
424
- def convert (row ) -> tuple [float , float , float ]:
427
+ def convert (row , global_xy = False ) -> tuple [float , float , float ]:
425
428
verts = grid .get_cell_vertices (row .node )
426
- xs , ys = list (zip (* verts ))
429
+ if global_xy :
430
+ xs , ys = list (zip (* verts ))
431
+ else :
432
+ xs , ys = grid .get_local_coords (* np .array (verts ).T )
427
433
return [
428
434
cvt_xy (row .localx , xs ),
429
435
cvt_xy (row .localy , ys ),
430
436
row .localz if localz else cvt_z (row .localz , row .node ),
431
437
]
432
438
433
439
for t in self .particledata .itertuples ():
434
- yield convert (t )
440
+ yield convert (t , global_xy = global_xy )
435
441
436
- def to_prp (self , grid , localz = False ) -> Iterator [tuple ]:
442
+ def to_prp (self , grid , localz = False , global_xy = False ) -> Iterator [tuple ]:
437
443
"""
438
444
Convert particle data to PRT particle release point (PRP)
439
445
package data entries for the given grid. A model grid is
@@ -447,6 +453,8 @@ def to_prp(self, grid, localz=False) -> Iterator[tuple]:
447
453
The grid on which to locate particle release points.
448
454
localz : bool, optional
449
455
Whether to return local z coordinates.
456
+ global_xy : bool, optional
457
+ Whether to return global x and y coordinates, default is False.
450
458
451
459
Returns
452
460
-------
@@ -459,7 +467,7 @@ def to_prp(self, grid, localz=False) -> Iterator[tuple]:
459
467
for i , (t , c ) in enumerate (
460
468
zip (
461
469
self .particledata .itertuples (index = False ),
462
- self .to_coords (grid , localz ),
470
+ self .to_coords (grid , localz , global_xy = global_xy ),
463
471
)
464
472
):
465
473
row = [i ] # release point index (irpt)
@@ -778,10 +786,14 @@ def write(self, f=None):
778
786
)
779
787
780
788
781
- def get_extent (grid , k = None , i = None , j = None , nn = None , localz = False ) -> Extent :
789
+ def get_extent (
790
+ grid , k = None , i = None , j = None , nn = None , localz = False , global_xy = False
791
+ ) -> Extent :
782
792
# get cell coords and span in each dimension
783
793
if not (k is None or i is None or j is None ):
784
794
verts = grid .get_cell_vertices (i , j )
795
+ if not global_xy and grid ._has_ref_coordinates :
796
+ verts = list (zip (* grid .get_local_coords (* np .array (verts ).T )))
785
797
minz , maxz = (
786
798
(0 , 1 )
787
799
if localz
@@ -792,6 +804,8 @@ def get_extent(grid, k=None, i=None, j=None, nn=None, localz=False) -> Extent:
792
804
)
793
805
elif nn is not None :
794
806
verts = grid .get_cell_vertices (nn )
807
+ if not global_xy and grid ._has_ref_coordinates :
808
+ verts = list (zip (* grid .get_local_coords (* np .array (verts ).T )))
795
809
if grid .grid_type == "structured" :
796
810
k , i , j = grid .get_lrc ([nn ])[0 ]
797
811
minz , maxz = (
@@ -967,7 +981,14 @@ def get_cell_release_points(subdivisiondata, cellid, extent) -> Iterator[tuple]:
967
981
968
982
969
983
def get_release_points (
970
- subdivisiondata , grid , k = None , i = None , j = None , nn = None , localz = False
984
+ subdivisiondata ,
985
+ grid ,
986
+ k = None ,
987
+ i = None ,
988
+ j = None ,
989
+ nn = None ,
990
+ localz = False ,
991
+ global_xy = False ,
971
992
) -> Iterator [tuple ]:
972
993
"""
973
994
Get MODPATH 7 release point tuples for the given cell.
@@ -980,7 +1001,7 @@ def get_release_points(
980
1001
)
981
1002
982
1003
cellid = [k , i , j ] if nn is None else [nn ]
983
- extent = get_extent (grid , k , i , j , nn , localz )
1004
+ extent = get_extent (grid , k , i , j , nn , localz , global_xy = global_xy )
984
1005
985
1006
if isinstance (subdivisiondata , FaceDataType ):
986
1007
return get_face_release_points (subdivisiondata , cellid , extent )
@@ -1351,7 +1372,7 @@ def write(self, f=None):
1351
1372
line += "\n "
1352
1373
f .write (line )
1353
1374
1354
- def to_coords (self , grid , localz = False ) -> Iterator [tuple ]:
1375
+ def to_coords (self , grid , localz = False , global_xy = False ) -> Iterator [tuple ]:
1355
1376
"""
1356
1377
Compute global particle coordinates on the given grid.
1357
1378
@@ -1361,6 +1382,8 @@ def to_coords(self, grid, localz=False) -> Iterator[tuple]:
1361
1382
The grid on which to locate particle release points.
1362
1383
localz : bool, optional
1363
1384
Whether to return local z coordinates.
1385
+ global_xy : bool, optional
1386
+ Whether to return global x, y coordinates. Default is False.
1364
1387
1365
1388
Returns
1366
1389
-------
@@ -1369,23 +1392,27 @@ def to_coords(self, grid, localz=False) -> Iterator[tuple]:
1369
1392
1370
1393
for sd in self .subdivisiondata :
1371
1394
for nd in self .nodedata :
1372
- for rpt in get_release_points (sd , grid , nn = int (nd [0 ]), localz = localz ):
1395
+ for rpt in get_release_points (
1396
+ sd , grid , nn = int (nd [0 ]), localz = localz , global_xy = global_xy
1397
+ ):
1373
1398
yield (* rpt [1 :4 ],)
1374
1399
1375
- def to_prp (self , grid , localz = False ) -> Iterator [tuple ]:
1400
+ def to_prp (self , grid , localz = False , global_xy = False ) -> Iterator [tuple ]:
1376
1401
"""
1377
1402
Convert particle data to PRT particle release point (PRP)
1378
1403
package data entries for the given grid. A model grid is
1379
1404
required because MODPATH supports several ways to specify
1380
1405
particle release locations by cell ID and subdivision info
1381
- or local coordinates, but PRT expects global coordinates.
1406
+ or local coordinates, but PRT expects model coordinates, by default .
1382
1407
1383
1408
Parameters
1384
1409
----------
1385
1410
grid : flopy.discretization.grid.Grid
1386
1411
The grid on which to locate particle release points.
1387
1412
localz : bool, optional
1388
1413
Whether to return local z coordinates.
1414
+ global_xy : bool, optional
1415
+ Whether to return global x, y coordinates. Default is False.
1389
1416
1390
1417
Returns
1391
1418
-------
@@ -1396,7 +1423,9 @@ def to_prp(self, grid, localz=False) -> Iterator[tuple]:
1396
1423
for sd in self .subdivisiondata :
1397
1424
for nd in self .nodedata :
1398
1425
for irpt , rpt in enumerate (
1399
- get_release_points (sd , grid , nn = int (nd [0 ]), localz = localz )
1426
+ get_release_points (
1427
+ sd , grid , nn = int (nd [0 ]), localz = localz , global_xy = global_xy
1428
+ )
1400
1429
):
1401
1430
row = [irpt ]
1402
1431
if grid .grid_type == "structured" :
0 commit comments