Skip to content

Commit

Permalink
fix(mbase.BaseModel.__getattr__): refactoring to resolve AttributeErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
aleaf committed Jun 11, 2019
1 parent 0255c80 commit 32b5397
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion autotest/t027_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def test_mnw1_load_write():
m2 = flopy.modflow.Modflow.load('mnw1.nam', model_ws=cpth,
load_only=['mnw1'],
verbose=True, forgive=False)
assert m.stress_period_data == m2.stress_period_data
for k, v in m.mnw1.stress_period_data.data.items():
assert np.array_equal(v, m2.mnw1.stress_period_data[k])

def test_make_package():
"""t027 test make MNW2 Package"""
Expand Down
4 changes: 2 additions & 2 deletions flopy/export/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ def output_helper(f, ml, oudic, **kwargs):
if ml.bas6:
mask_vals.append(ml.bas6.hnoflo)
mask_array3d = ml.bas6.ibound.array == 0
if ml.bcf:
mask_vals.append(ml.bcf.hdry)
if ml.bcf6:
mask_vals.append(ml.bcf6.hdry)
if ml.lpf:
mask_vals.append(ml.lpf.hdry)

Expand Down
5 changes: 4 additions & 1 deletion flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def __init__(self, modelname='modflowtest', namefile_ext='nam',
self.heading = ''
self.exe_name = exe_name
self._verbose = verbose
self.external_path = None
self.external_extension = 'ref'
if model_ws is None: model_ws = os.getcwd()
if not os.path.exists(model_ws):
Expand Down Expand Up @@ -507,8 +508,10 @@ def __getattr__(self, item):
if item == "_packagelist" or item == "packagelist":
raise AttributeError(item)
pckg = self.get_package(item)
if pckg is not None:
if pckg is not None or item in self.mfnam_packages:
return pckg
if item == 'modelgrid':
return
raise AttributeError(item)

def get_ext_dict_attr(self, ext_unit_dict=None, unit=None, filetype=None,
Expand Down
1 change: 1 addition & 0 deletions flopy/modflow/mfsfr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,7 @@ def __init__(self, sfrpackage, verbose=True, level=1):
self.sr = self.sfr.parent.modelgrid.sr
except AttributeError:
self.sr = self.sfr.parent.sr
self.mg = None

self.reach_data = sfrpackage.reach_data
self.segment_data = sfrpackage.segment_data
Expand Down
1 change: 1 addition & 0 deletions flopy/mt3d/mt.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def __init__(self, modelname='mt3dtest', namefile_ext='nam',
self.ftlfilename = ftlfilename
self.ftlfree = ftlfree
self.ftlunit = ftlunit
self.free_format = None

# Check whether specified ftlfile exists in model directory; if not,
# warn user
Expand Down
5 changes: 4 additions & 1 deletion flopy/seawat/swt.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def __init__(self, modelname='swttest', namefile_ext='nam',
self.version_types = {'seawat': 'SEAWAT'}
self.set_version(version)
self.lst = SeawatList(self, listunit=listunit)
self.glo = None
self._mf = None
self._mt = None

# If a MODFLOW model was passed in, then add its packages
self.mf = self
Expand Down Expand Up @@ -160,7 +163,7 @@ def modelgrid(self):
if not self._mg_resync:
return self._modelgrid

if self.bas6 is not None:
if self.has_package('bas6'):
ibound = self.bas6.ibound.array
else:
ibound = None
Expand Down
2 changes: 1 addition & 1 deletion flopy/utils/util_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def fmt_string(self):
use_free = self.list_free_format
else:
use_free = True
if self.package.parent.bas6 is not None:
if self.package.parent.has_package('bas6'):
use_free = self.package.parent.bas6.ifrefm
# mt3d list data is fixed format
if 'mt3d' in self.package.parent.version.lower():
Expand Down

0 comments on commit 32b5397

Please sign in to comment.