Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModflowGwf has no "output" attribute #1165

Closed
agbreda opened this issue Aug 2, 2021 · 5 comments · Fixed by #1169
Closed

ModflowGwf has no "output" attribute #1165

agbreda opened this issue Aug 2, 2021 · 5 comments · Fixed by #1169
Assignees
Milestone

Comments

@agbreda
Copy link

agbreda commented Aug 2, 2021

I got an AttributeError while trying to run the Quickstart code. I have Anaconda Python 3.8, and just installed floppy through the suggested conda installation command line.

Here is the outputs:

runfile('C:/angelo/test_flopy/test_flopy0.py', wdir='C:/angelo/test_flopy')
writing simulation...
  writing simulation name file...
  writing simulation tdis package...
  writing ims package ims_-1...
  writing model mymodel...
    writing model name file...
    writing package dis...
    writing package ic...
    writing package npf...
    writing package chd_0...
INFORMATION: maxbound in ('gwf6', 'chd', 'dimensions') changed to 2 based on size of stress_period_data
    writing package oc...
FloPy is using the following  executable to run the model: .\mf6.EXE
                                   MODFLOW 6
                U.S. GEOLOGICAL SURVEY MODULAR HYDROLOGIC MODEL
                            VERSION 6.2.1 02/18/2021

   MODFLOW 6 compiled Feb 18 2021 08:24:05 with IFORT compiler (ver. 19.10.2)

This software has been approved for release by the U.S. Geological 
Survey (USGS). Although the software has been subjected to rigorous 
review, the USGS reserves the right to update the software as needed 
pursuant to further analysis and review. No warranty, expressed or 
implied, is made by the USGS or the U.S. Government as to the 
functionality of the software and related material nor shall the 
fact of release constitute any such warranty. Furthermore, the 
software is released on condition that neither the USGS nor the U.S. 
Government shall be held liable for any damages resulting from its 
authorized or unauthorized use. Also refer to the USGS Water 
Resources Software User Rights Notice for complete use, copyright, 
and distribution information.

 
 Run start date and time (yyyy/mm/dd hh:mm:ss): 2021/08/02 20:32:51
 
 Writing simulation list file: mfsim.lst
 Using Simulation name file: mfsim.nam
 
    Solving:  Stress period:     1    Time step:     1
 
 Run end date and time (yyyy/mm/dd hh:mm:ss): 2021/08/02 20:32:51
 Elapsed run time:  0.047 Seconds
 
 Normal termination of simulation.
Traceback (most recent call last):

  File "C:\angelo\test_flopy\test_flopy0.py", line 29, in <module>
    head = gwf.output.head().get_data()

  File "C:\Users\c3273262\Anaconda3\lib\site-packages\flopy\mf6\mfmodel.py", line 218, in __getattr__
    raise AttributeError(item)

AttributeError: output

And here it is the first few lines of my code, the rest is exactly the same as in the initial Floppy's github page

import os
import flopy
ws = r'C:\angelo\test_flopy'
name = 'mymodel'
sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name='mf6')
@agbreda
Copy link
Author

agbreda commented Aug 3, 2021

Using more specific methods to read the data worked!

import os
import flopy
ws = r'C:\angelo\test_flopy'
name = 'mymodel'
sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name='mf6')
tdis = flopy.mf6.ModflowTdis(sim)
ims = flopy.mf6.ModflowIms(sim)
gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
dis = flopy.mf6.ModflowGwfdis(gwf, nrow=10, ncol=10)
ic = flopy.mf6.ModflowGwfic(gwf)
npf = flopy.mf6.ModflowGwfnpf(gwf, save_specific_discharge=True)
chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=[[(0, 0, 0), 1.],
                                                       [(0, 9, 9), 0.]])
budget_file = name + '.bud'
head_file = name + '.hds'
oc = flopy.mf6.ModflowGwfoc(gwf,
                            budget_filerecord=budget_file,
                            head_filerecord=head_file,
                            saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])
sim.write_simulation()
sim.run_simulation()

# head = gwf.output.head().get_data()
# bud = gwf.output.budget()

hdobj = flopy.utils.HeadFile(name+'.hds')
head = hdobj.get_data()

bud = flopy.utils.CellBudgetFile(name+'.bud')

spdis = bud.get_data(text='DATA-SPDIS')[0]
pmv = flopy.plot.PlotMapView(gwf)
pmv.plot_array(head)
pmv.plot_grid(colors='white')
pmv.contour_array(head, levels=[.2, .4, .6, .8], linewidths=3.)
pmv.plot_specific_discharge(spdis, color='white')

@rodreras
Copy link

rodreras commented Aug 3, 2021

@agbreda how did you come up with this solution? after making these changes, were you able to keep on running the tutorial?

@rodreras
Copy link

rodreras commented Aug 3, 2021

Well, I also found a solution.

The point is: I have flopy 3.3.3, and the tutorial is with latest label. I don't know if there's any difference, but before you start following the tutorials, make sure to check your flopy version.

In the end, I was able to find the solution within the documentation. The differences are in the way of reading the file.

Version 3.3.3

hds = flopy.utils.binaryfile.HeadFile(headfile)
h = hds.get_data(kstpkper=(0, 0))
x = y = np.linspace(0, L, N)
y = y[::-1]
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, aspect="equal")
c = ax.contour(x, y, h[0], np.arange(90, 100.1, 0.2), colors="black")
plt.clabel(c, fmt="%2.1f")

Latest Version

hds = flopy.utils.binaryfile.HeadFile(headfile)
h = hds.get_data(kstpkper=(0, 0))
x = y = np.linspace(0, L, N)
y = y[::-1]
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, aspect="equal")
c = ax.contour(x, y, h[0], np.arange(90, 100.1, 0.2), colors="black")
plt.clabel(c, fmt="%2.1f")

Basically, that's the same @agbreda did before, but following in a distinct way.

@agbreda
Copy link
Author

agbreda commented Aug 3, 2021

Hi Rodrigo, yes you've nailed it...

It is weird that installing flopy through conda give us the 3.3.3 version, but it definitively does not match with the "lastest" version.

Later in the same tutorial I came across if another issue before the last plot. The command
residual = flopy.mf6.utils.get_residuals(flowja, grb_file=grb_file)
returned the following error:
AttributeError: module 'flopy.mf6.utils' has no attribute 'get_residuals'
but when I did
dir(flopy.mf6.utils)
I got

['__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'binaryfile_utils',
 'createpackages',
 'generate_classes',
 'mfenums',
 'mfobservation']

In the flopy documentation (https://flopy.readthedocs.io/en/latest/_modules/index.html), the flopy.mf6.utils should have:
flopy.mf6.utils.binaryfile_utils
flopy.mf6.utils.binarygrid_util *
flopy.mf6.utils.createpackages
flopy.mf6.utils.generate_classes
flopy.mf6.utils.mfenums
flopy.mf6.utils.mfobservation
flopy.mf6.utils.output_util *
flopy.mf6.utils.postprocessing *
flopy.mf6.utils.reference **
flopy.mf6.utils.testutils **

The libs with * are indeed missing, and those with ** already have a .py file in C:\Users\<user name>\Anaconda3\Lib\site-packages\flopy\mf6\utils but are not loaded. So, what I did was to copy the code from the docs to create the missing files. Unfortunately, even after restarting the kernel (close and open Spyder/Jupyter) the import flopy does not load these "new" sub-libs, so you have to do import them directly, like from flopy.mf6.utils import postprocessing

So, back to tutorial 1, the comand
residual = flopy.mf6.utils.get_residuals(flowja, grb_file=grb_file)
must be replaced by
residual = postprocessing.get_residuals(flowja, grb_file=grb_file)
and it will run, but will raise a DeprecationWarning. However, you are able to run the last plot smooth!

@jdhughes-usgs
Copy link
Contributor

Sorry about the confusion. By default, readthedocs points to the latest release and latest points to the development version of the flopy. Also the GitHub repo also opens to the development branch. So as you see some of the functionality shown in the latest readthedocs and shown on the GitHub README.md is not available in the version of flopy that is installed with pip or conda. To use the latest flopy functionality you need to install the development version of flopy. Instructions for installing the development version of flopy (latest release candidate) are given on the GitHub README.md.

The readthedocs issues in flopy.mf6.utils have been addressed. flopy.mf6.utils.testutils was intentionally left out of the readthe docs. The __init__ files have been modified in the development version so that new functionality is directly imported.

We will try to provide some clarification of these issues on the GitHub README.md in the next release.

@jdhughes-usgs jdhughes-usgs self-assigned this Aug 4, 2021
@jdhughes-usgs jdhughes-usgs added this to the 3.3.4 milestone Aug 4, 2021
jdhughes-usgs added a commit to jdhughes-usgs/flopy that referenced this issue Aug 5, 2021
jdhughes-usgs added a commit that referenced this issue Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants