modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

__setattr__ in pakbase #109

Closed leilamac closed 8 years ago

leilamac commented 8 years ago

I just tried to replace strt array in the BAS package with a new array to update starting heads in this Modflow model e.g.: original_bas.strt = new_inithead

This triggered the setattr in pakbase.py which caused an Attribute Error: fmtin=old_value.fmtin, AttributeError: 'Util3d' object has no attribute 'fmtin'

I'm not an advanced python user so not sure why the bas.strt Util3D array doesn't have any attribute called fmtin at this stage, but I've set it to fmtin=None for my own purposes...

def __setattr__(self, key, value):
    var_dict = vars(self)
    if key in list(var_dict.keys()):
        old_value = var_dict[key]
        if isinstance(old_value, Util2d):
            value = Util2d(self.parent, old_value.shape,
                           old_value.dtype, value,
                           name=old_value.name,
                           fmtin=old_value.format.fortran,
                           locat=old_value.locat)
        elif isinstance(old_value, Util3d):
            value = Util3d(self.parent, old_value.shape,
                           old_value.dtype, value,
                           name=old_value.name_base,
                          ** fmtin=None**,
                           locat=old_value.locat)
jbellino-usgs commented 8 years ago

I think this issue has been fixed on the develop branch of flopy. See this commit: afa103973ffa9b683b3d97e6ef5b83e764951bad. Note the insertion at line 555 of flopy/utils/util_array.py.

leilamac commented 8 years ago

You're right, thanks I've grabbed it.