-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ParticleData): support partlocs as ndarray or list of lists (#1752)
- Loading branch information
Showing
2 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import numpy as np | ||
|
||
from flopy.modpath import ParticleData | ||
|
||
structured_plocs = [(1, 1, 1), (1, 1, 2)] | ||
structured_dtype = np.dtype( | ||
[ | ||
("k", "<i4"), | ||
("i", "<i4"), | ||
("j", "<i4"), | ||
("localx", "<f4"), | ||
("localy", "<f4"), | ||
("localz", "<f4"), | ||
("timeoffset", "<f4"), | ||
("drape", "<i4"), | ||
] | ||
) | ||
structured_array = np.core.records.fromrecords( | ||
[ | ||
(1, 1, 1, 0.5, 0.5, 0.5, 0.0, 0), | ||
(1, 1, 2, 0.5, 0.5, 0.5, 0.0, 0), | ||
], | ||
dtype=structured_dtype, | ||
) | ||
|
||
|
||
def test_particledata_structured_partlocs_as_list_of_tuples(): | ||
locs = structured_plocs | ||
data = ParticleData(partlocs=locs, structured=True) | ||
|
||
assert data.particlecount == 2 | ||
assert data.dtype == structured_dtype | ||
assert np.array_equal(data.particledata, structured_array) | ||
|
||
|
||
def test_particledata_structured_partlocs_as_ndarray(): | ||
locs = np.array(structured_plocs) | ||
data = ParticleData(partlocs=locs, structured=True) | ||
|
||
assert data.particlecount == 2 | ||
assert data.dtype == structured_dtype | ||
assert np.array_equal(data.particledata, structured_array) | ||
|
||
|
||
def test_particledata_structured_partlocs_as_list_of_lists(): | ||
locs = [list(p) for p in structured_plocs] | ||
data = ParticleData(partlocs=locs, structured=True) | ||
|
||
assert data.particlecount == 2 | ||
assert data.dtype == structured_dtype | ||
assert np.array_equal(data.particledata, structured_array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters