fixes to check.py, mfsfr2.py, modpathfile.py (#294)
* t010 passes * t031 runs * proposed fix to np.core.records.fromarrays issue * t009 passes except for issue with gage package file paths * fixed several np.core.records.fromarrays issues; stuck on t041 a bytes-like object is required, not 'float'develop
parent
97de43bb19
commit
921b40c009
|
@ -6,6 +6,8 @@ import os
|
|||
import glob
|
||||
import shutil
|
||||
import numpy as np
|
||||
from flopy.utils.recarray_utils import create_empty_recarray
|
||||
|
||||
try:
|
||||
import matplotlib
|
||||
# if os.getenv('TRAVIS'): # are we running https://travis-ci.org/ automated tests ?
|
||||
|
@ -47,15 +49,12 @@ sfr_items = {0: {'mfnam': 'test1ss.nam',
|
|||
}
|
||||
|
||||
def create_sfr_data():
|
||||
r = np.zeros((27, 2), dtype=[('iseg', int), ('ireach', int)])
|
||||
r = np.core.records.fromarrays(r.transpose(),
|
||||
dtype=[('iseg', int), ('ireach', int)])
|
||||
|
||||
r = create_empty_recarray(27, dtype = [('iseg', int), ('ireach', int)])
|
||||
r['iseg'] = sorted(list(range(1, 10)) * 3)
|
||||
r['ireach'] = [1, 2, 3] * 9
|
||||
|
||||
d = np.zeros((9, 2), dtype=[('nseg', int), ('outseg', int)])
|
||||
d = np.core.records.fromarrays(d.transpose(),
|
||||
dtype=[('nseg', int), ('outseg', int)])
|
||||
d = create_empty_recarray(9, dtype=[('nseg', int), ('outseg', int)])
|
||||
d['nseg'] = range(1, 10)
|
||||
d['outseg'] = [4, 0, 6, 8, 3, 8, 1, 2, 8]
|
||||
return r, d
|
||||
|
@ -166,15 +165,13 @@ def test_sfr():
|
|||
def test_sfr_renumbering():
|
||||
# test segment renumbering
|
||||
|
||||
r = np.zeros((27, 2), dtype=[('iseg', int), ('ireach', int)])
|
||||
r = np.core.records.fromarrays(r.transpose(),
|
||||
dtype=[('iseg', int), ('ireach', int)])
|
||||
dtype = [('iseg', int), ('ireach', int)]
|
||||
r = create_empty_recarray(27, dtype)
|
||||
r['iseg'] = sorted(list(range(1, 10)) * 3)
|
||||
r['ireach'] = [1, 2, 3] * 9
|
||||
|
||||
d = np.zeros((9, 2), dtype=[('nseg', int), ('outseg', int)])
|
||||
d = np.core.records.fromarrays(d.transpose(),
|
||||
dtype=[('nseg', int), ('outseg', int)])
|
||||
dtype = [('nseg', int), ('outseg', int)]
|
||||
d = create_empty_recarray(9, dtype)
|
||||
d['nseg'] = range(1, 10)
|
||||
d['outseg'] = [4, 0, 6, 8, 3, 8, 1, 2, 8]
|
||||
m = flopy.modflow.Modflow()
|
||||
|
@ -190,9 +187,8 @@ def test_sfr_renumbering():
|
|||
r['iseg'] *= 2
|
||||
r['ireach'] = [1, 2, 3] * 9
|
||||
|
||||
d = np.zeros((9, 2), dtype=[('nseg', int), ('outseg', int)])
|
||||
d = np.core.records.fromarrays(d.transpose(),
|
||||
dtype=[('nseg', int), ('outseg', int)])
|
||||
dtype = [('nseg', int), ('outseg', int)]
|
||||
d = create_empty_recarray(9, dtype)
|
||||
d['nseg'] = np.arange(1, 10) * 2
|
||||
d['outseg'] = np.array([4, 0, 6, 8, 3, 8, 1, 2, 8]) * 2
|
||||
m = flopy.modflow.Modflow()
|
||||
|
@ -399,12 +395,12 @@ def test_sfr_plot():
|
|||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_sfr()
|
||||
test_sfr_renumbering()
|
||||
test_example()
|
||||
#test_transient_example()
|
||||
#test_sfr_plot()
|
||||
#test_assign_layers()
|
||||
#test_SfrFile()
|
||||
#test_const()
|
||||
#test_sfr()
|
||||
#test_sfr_renumbering()
|
||||
#test_example()
|
||||
test_transient_example()
|
||||
test_sfr_plot()
|
||||
test_assign_layers()
|
||||
test_SfrFile()
|
||||
test_const()
|
||||
pass
|
||||
|
|
|
@ -122,4 +122,4 @@ def test_sfrloadcheck():
|
|||
if __name__ == '__main__':
|
||||
test_sfrcheck()
|
||||
for i, case in sfr_items.items():
|
||||
test_sfrloadcheck(i, case['mfnam'], path, cpth)
|
||||
load_check_sfr(i, case['mfnam'], path, cpth)
|
||||
|
|
|
@ -320,7 +320,7 @@ def test_mfnwt_LKT():
|
|||
pth = os.path.join(pthNWT, 'lkt')
|
||||
namefile = 'lkt_mf.nam'
|
||||
mf = flopy.modflow.Modflow.load(namefile, model_ws=pth,
|
||||
version='mfnwt', verbose=True,
|
||||
version='mfnwt', verbose=True, forgive=False,
|
||||
exe_name=mfnwt_exe)
|
||||
|
||||
assert not mf.load_fail, 'MODFLOW model did not load'
|
||||
|
@ -398,5 +398,5 @@ if __name__ == '__main__':
|
|||
test_mf2000_tob()
|
||||
#test_mf2000_zeroth()
|
||||
#test_mfnwt_CrnkNic()
|
||||
#test_mfnwt_LKT()
|
||||
test_mfnwt_LKT()
|
||||
#test_mfnwt_keat_uzf()
|
||||
|
|
|
@ -25,7 +25,7 @@ if v is None:
|
|||
|
||||
|
||||
def load_str(mfnam, pth):
|
||||
m = flopy.modflow.Modflow.load(mfnam, exe_name=exe_name,
|
||||
m = flopy.modflow.Modflow.load(mfnam, exe_name=exe_name, forgive=False,
|
||||
model_ws=pth, verbose=True)
|
||||
assert m.load_fail is False
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ def load_lak(mfnam, pth, run):
|
|||
apth = cpth
|
||||
compth = cpth
|
||||
|
||||
m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True,
|
||||
m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True, forgive=False,
|
||||
exe_name=exe_name)
|
||||
assert m.load_fail is False
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import flopy
|
|||
import numpy as np
|
||||
from flopy.utils.reference import SpatialReference
|
||||
from flopy.utils.modpathfile import EndpointFile, PathlineFile
|
||||
from flopy.utils.recarray_utils import ra_slice
|
||||
from flopy.modpath.mpsim import StartingLocationsFile
|
||||
|
||||
mffiles = glob.glob('../examples/data/mp6/EXAMPLE*')
|
||||
|
@ -107,7 +108,7 @@ def test_get_destination_data():
|
|||
|
||||
# check that all starting locations are included in the pathline data
|
||||
# (pathline data slice not just endpoints)
|
||||
starting_locs = well_epd[['k0', 'i0', 'j0']]
|
||||
starting_locs = ra_slice(well_epd, ['k0', 'i0', 'j0'])
|
||||
pathline_locs = np.array(well_pthld[['k', 'i', 'j']].tolist(),
|
||||
dtype=starting_locs.dtype)
|
||||
assert np.all(np.in1d(starting_locs, pathline_locs))
|
||||
|
@ -211,6 +212,6 @@ def test_loadtxt():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# test_mpsim()
|
||||
test_mpsim()
|
||||
test_get_destination_data()
|
||||
# test_loadtxt()
|
||||
test_loadtxt()
|
||||
|
|
|
@ -35,7 +35,7 @@ def test_uzf_unit_numbers():
|
|||
apth = cpth
|
||||
compth = cpth
|
||||
|
||||
m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth,
|
||||
m = flopy.modflow.Modflow.load(mfnam, verbose=True, model_ws=lpth, forgive=False,
|
||||
exe_name=exe_name)
|
||||
assert m.load_fail is False, 'failed to load all packages'
|
||||
|
||||
|
@ -150,4 +150,4 @@ def test_unitnums_load_and_write():
|
|||
|
||||
if __name__ == '__main__':
|
||||
test_uzf_unit_numbers()
|
||||
#test_unitnums_load_and_write()
|
||||
test_unitnums_load_and_write()
|
||||
|
|
|
@ -5,6 +5,7 @@ import os
|
|||
import shutil
|
||||
import numpy as np
|
||||
import flopy
|
||||
from flopy.utils.recarray_utils import recarray
|
||||
|
||||
cpth = os.path.join('temp', 't047')
|
||||
# delete the directory if it exists
|
||||
|
@ -42,9 +43,7 @@ def get_namefile_entries(fpth):
|
|||
status = status.decode()
|
||||
|
||||
data.append([ftype, iu, filename, status])
|
||||
|
||||
data = np.rec.array(data, dtype=dtype)
|
||||
|
||||
data = recarray(data, dtype)
|
||||
return data
|
||||
|
||||
def test_gage():
|
||||
|
|
|
@ -134,7 +134,7 @@ def test_pathline_plot():
|
|||
lpth = pth
|
||||
|
||||
# load the modflow files for model map
|
||||
m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True,
|
||||
m = flopy.modflow.Modflow.load(mfnam, model_ws=lpth, verbose=True, forgive=False,
|
||||
exe_name=mf2005_exe)
|
||||
|
||||
# load modpath output files
|
||||
|
|
|
@ -12,7 +12,7 @@ import sys
|
|||
import numpy as np
|
||||
|
||||
from ..pakbase import Package
|
||||
|
||||
from ..utils.recarray_utils import create_empty_recarray
|
||||
|
||||
class ModflowFhb(Package):
|
||||
"""
|
||||
|
@ -282,9 +282,7 @@ class ModflowFhb(Package):
|
|||
# get an empty recarray that correponds to dtype
|
||||
dtype = ModflowFhb.get_default_dtype(nbdtim=nbdtim,
|
||||
structured=structured, head=head)
|
||||
d = np.zeros((ncells, len(dtype)), dtype=dtype)
|
||||
d[:, :] = -1.0E+10
|
||||
return np.core.records.fromarrays(d.transpose(), dtype=dtype)
|
||||
return create_empty_recarray(ncells, dtype, default_value=-1.0E+10)
|
||||
|
||||
@staticmethod
|
||||
def get_default_dtype(nbdtim=1, structured=True, head=False):
|
||||
|
|
|
@ -14,7 +14,7 @@ import numpy as np
|
|||
|
||||
from ..pakbase import Package
|
||||
from ..utils import read_fixed_var, write_fixed_var
|
||||
|
||||
from ..utils.recarray_utils import create_empty_recarray
|
||||
|
||||
class ModflowGage(Package):
|
||||
"""
|
||||
|
@ -207,9 +207,7 @@ class ModflowGage(Package):
|
|||
def get_empty(ncells=0, aux_names=None, structured=True):
|
||||
# get an empty recaray that correponds to dtype
|
||||
dtype = ModflowGage.get_default_dtype()
|
||||
d = np.zeros((ncells, len(dtype)), dtype=dtype)
|
||||
d[:, :] = -1.0E+10
|
||||
return np.core.records.fromarrays(d.transpose(), dtype=dtype)
|
||||
return create_empty_recarray(ncells, dtype, default_value=-1.0E+10)
|
||||
|
||||
def ncells(self):
|
||||
# Return 0 for the gage package
|
||||
|
|
|
@ -2,7 +2,7 @@ import sys
|
|||
import collections
|
||||
import numpy as np
|
||||
from ..pakbase import Package
|
||||
|
||||
from ..utils.recarray_utils import create_empty_recarray
|
||||
|
||||
# Create HeadObservation instance from a time series array
|
||||
|
||||
|
@ -183,10 +183,9 @@ class HeadObservation(object):
|
|||
def get_empty(ncells=0):
|
||||
# get an empty recaray that correponds to dtype
|
||||
dtype = HeadObservation.get_default_dtype()
|
||||
d = np.zeros((ncells, len(dtype)), dtype=dtype)
|
||||
d[:, :] = -1.0E+10
|
||||
d[:]['obsname'] = ''
|
||||
return np.core.records.fromarrays(d.transpose(), dtype=dtype)
|
||||
d = create_empty_recarray(ncells, dtype, default_value=-1.0E+10)
|
||||
d['obsname'] = ''
|
||||
return d
|
||||
|
||||
@staticmethod
|
||||
def get_default_dtype():
|
||||
|
|
|
@ -11,6 +11,7 @@ from ..utils import MfList
|
|||
from ..utils.flopy_io import line_parse
|
||||
import matplotlib.pyplot as plt
|
||||
from ..utils import SpatialReference
|
||||
from ..utils.recarray_utils import create_empty_recarray
|
||||
|
||||
try:
|
||||
import pandas as pd
|
||||
|
@ -516,9 +517,7 @@ class ModflowSfr2(Package):
|
|||
dtype = ModflowSfr2.get_default_reach_dtype(structured=structured)
|
||||
if aux_names is not None:
|
||||
dtype = Package.add_to_dtype(dtype, aux_names, np.float32)
|
||||
d = np.zeros((nreaches, len(dtype)))
|
||||
d[:, :] = default_value
|
||||
d = np.core.records.fromarrays(d.transpose(), dtype=dtype)
|
||||
d = create_empty_recarray(nreaches, dtype, default_value=default_value)
|
||||
d['reachID'] = np.arange(1, nreaches + 1)
|
||||
return d
|
||||
|
||||
|
@ -528,9 +527,8 @@ class ModflowSfr2(Package):
|
|||
dtype = ModflowSfr2.get_default_segment_dtype()
|
||||
if aux_names is not None:
|
||||
dtype = Package.add_to_dtype(dtype, aux_names, np.float32)
|
||||
d = np.zeros((nsegments, len(dtype)))
|
||||
d[:, :] = default_value
|
||||
return np.core.records.fromarrays(d.transpose(), dtype=dtype)
|
||||
d = create_empty_recarray(nsegments, dtype, default_value=default_value)
|
||||
return d
|
||||
|
||||
@staticmethod
|
||||
def get_default_reach_dtype(structured=True):
|
||||
|
@ -1777,8 +1775,7 @@ class check:
|
|||
http://stackoverflow.com/questions/22865877/how-do-i-write-to-multiple-fields-of-a-structured-array
|
||||
"""
|
||||
txt = ''
|
||||
return txt
|
||||
array = array.copy()
|
||||
array = array.view(np.recarray).copy()
|
||||
if isinstance(col1, np.ndarray):
|
||||
array = recfunctions.append_fields(array, names='tmp1', data=col1,
|
||||
asrecarray=True)
|
||||
|
@ -1811,7 +1808,7 @@ class check:
|
|||
# currently failed_info[cols] results in a warning. Not sure
|
||||
# how to do this properly with a recarray.
|
||||
failed_info = recfunctions.append_fields(
|
||||
failed_info[cols].copy(),
|
||||
failed_info[cols].view(np.recarray).copy(),
|
||||
names='diff',
|
||||
data=diff,
|
||||
asrecarray=True)
|
||||
|
|
|
@ -12,7 +12,7 @@ import sys
|
|||
import numpy as np
|
||||
from ..utils import MfList
|
||||
from ..pakbase import Package
|
||||
|
||||
from ..utils.recarray_utils import create_empty_recarray
|
||||
|
||||
class ModflowStr(Package):
|
||||
"""
|
||||
|
@ -377,12 +377,8 @@ class ModflowStr(Package):
|
|||
dtype, dtype2 = ModflowStr.get_default_dtype(structured=structured)
|
||||
if aux_names is not None:
|
||||
dtype = Package.add_to_dtype(dtype, aux_names, np.float32)
|
||||
d = np.zeros((ncells, len(dtype)), dtype=dtype)
|
||||
d[:, :] = -1.0E+10
|
||||
d2 = np.zeros((nss, len(dtype2)), dtype=dtype2)
|
||||
d2[:, :] = 0
|
||||
return (np.core.records.fromarrays(d.transpose(), dtype=dtype),
|
||||
np.core.records.fromarrays(d2.transpose(), dtype=dtype2))
|
||||
return (create_empty_recarray(ncells, dtype=dtype, default_value=-1.0E+10),
|
||||
create_empty_recarray(nss, dtype=dtype, default_value=0))
|
||||
|
||||
@staticmethod
|
||||
def get_default_dtype(structured=True):
|
||||
|
|
|
@ -40,3 +40,4 @@ from .zonbud import ZoneBudget, read_zbarray, write_zbarray
|
|||
from .mfgrdfile import MfGrdFile
|
||||
from .postprocessing import get_transmissivities
|
||||
from .sfroutputfile import SfrFile
|
||||
from .recarray_utils import create_empty_recarray, ra_slice
|
||||
|
|
|
@ -312,7 +312,6 @@ class check:
|
|||
#inds = stress_period_data[criteria][inds_col].view(int)\
|
||||
# .reshape(stress_period_data[criteria].shape + (-1,))
|
||||
|
||||
|
||||
if col is not None:
|
||||
v = stress_period_data[criteria][col]
|
||||
else:
|
||||
|
|
|
@ -9,6 +9,7 @@ important classes that can be accessed by the user.
|
|||
|
||||
import numpy as np
|
||||
from ..utils.flopy_io import loadtxt
|
||||
from ..utils.recarray_utils import ra_slice
|
||||
|
||||
class PathlineFile():
|
||||
"""
|
||||
|
@ -563,8 +564,10 @@ class EndpointFile():
|
|||
ra = self.get_alldata()
|
||||
# find the intersection of endpoints and dest_cells
|
||||
# convert dest_cells to same dtype for comparison
|
||||
raslice = ra[['k', 'i', 'j']]
|
||||
dest_cells = np.array(dest_cells, dtype=raslice.dtype)
|
||||
raslice = ra_slice(ra, ['k', 'i', 'j'])
|
||||
dest_cells = np.array(dest_cells, dtype=[('k', int),
|
||||
('i', int),
|
||||
('j', int)])
|
||||
inds = np.in1d(raslice, dest_cells)
|
||||
epdest = ra[inds].copy().view(np.recarray)
|
||||
return epdest
|
||||
|
@ -615,4 +618,4 @@ class EndpointFile():
|
|||
# convert back to one-based
|
||||
for n in self.kijnames:
|
||||
epd[n] += 1
|
||||
recarray2shp(epd, geoms, shpname=shpname, epsg=epsg, **kwargs)
|
||||
recarray2shp(epd, geoms, shpname=shpname, epsg=epsg, **kwargs)
|
|
@ -0,0 +1,20 @@
|
|||
import numpy as np
|
||||
|
||||
def create_empty_recarray(length, dtype, default_value=0):
|
||||
r = np.zeros(length, dtype=dtype)
|
||||
if default_value != 0:
|
||||
r[:] = default_value
|
||||
return r.view(np.recarray)
|
||||
|
||||
def ra_slice(ra, cols):
|
||||
raslice = np.column_stack([ra[c] for c in cols])
|
||||
dtype = [(str(d[0]), d[1]) for d in ra.dtype.descr if d[0] in cols]
|
||||
return np.array([tuple(r) for r in raslice],
|
||||
dtype=dtype).view(np.recarray)
|
||||
|
||||
def recarray(array, dtype):
|
||||
# handle sequences of lists
|
||||
# (recarrays must be constructed from tuples)
|
||||
if not isinstance(array[0], tuple):
|
||||
array = list(map(tuple, array))
|
||||
return np.array(array, dtype=dtype).view(np.recarray)
|
Loading…
Reference in New Issue