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

how to plot an unstructured grid from a disu file #1723

Closed rafaur99 closed 1 year ago

rafaur99 commented 1 year ago

Describe the bug

Hello. There is a problem when I try to plot the grid of my model and data comes from a DISU file. The error looks like this:

 ` The following 9 packages were successfully loaded.

      SNT001.DISU
      SNT001.BAS
      SNT045CPU.SMS
      SNT001.OC
      SNT061.drn
      SNT092.LPF
      SNTSWAc039.sfr
      SNT006.riv
      SNTSWAc007_recharge.rch
   The following 2 packages were not loaded.
      SNT094.LST
      SNT060.TVM

SNT094 MODEL DATA VALIDATION SUMMARY:
  5000 Errors:
    RIV package: rbot below cell bottom
    RIV package: stage below cell bottom
  see SNT094.chk for details.

Traceback (most recent call last):

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File d:\onedrive - universidad industrial de santander\investigacion_articulo\datosmodelos_minesa\a 5.1.6.7 datos fuente modelo hidrogeologico\modflow\work\model.py:31
    linecollection = mapview.plot_grid()

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\flopy\plot\map.py:395 in plot_grid
    grid_lines = self.mg.grid_lines

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\flopy\discretization\unstructuredgrid.py:281 in grid_lines
    xgrid = self.xvertices

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\flopy\discretization\grid.py:445 in xvertices
    return self.xyzvertices[0]

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\flopy\discretization\unstructuredgrid.py:346 in xyzvertices
    self._build_grid_geometry_info()

  File D:\Users\ACER\anaconda3\envs\geogidahatari\lib\site-packages\flopy\discretization\unstructuredgrid.py:666 in _build_grid_geometry_info
    vertexdict = {int(v[0]): [v[1], v[2]] for v in self._vertices}

TypeError: 'NoneType' object is not iterable  `

To Reproduce Link to my model:

https://correouisedu-my.sharepoint.com/:f:/g/personal/rafael2170246_correo_uis_edu_co/Ek5NjuRESxJMo-OyCsAJ4LMBZstNLMFelOzTiuNyfZgs4Q?e=7W2axH

You have to enter to the work folder and open de model.py file. The code inside the file is:

    `import flopy
    import os
    import numpy as np
    import matplotlib as mpl
    import matplotlib.pyplot as plt

    #flopy.__version__
    # first lets load an existing model
    model_ws = os.path.join(".")
    ml = flopy.mfusg.MfUsg.load(
        "SNT094.nam",
        model_ws=".",
        verbose=True,
        check=True,
        exe_name="mfusg.exe",
        version="mfusg",
        forgive=True,
        )

    ##ploting grid
    # let's take a look at our grid before making a cross section
    fig = plt.figure(figsize=(8, 8))
    ax = fig.add_subplot(1, 1, 1, aspect="equal")
    mapview = flopy.plot.PlotMapView(model=ml)
    linecollection = mapview.plot_grid()`

Expected behavior I expected to obtain the plot of the my model's grid as it's posible in models with mf6, mf5, etc. but in this case I obtained an empty plot.

Desktop (please complete the following information):

Additional context I checked that in the repository are few ways to draw an unstructured grid, but any from a disu file.

cnicol-gwlogic commented 1 year ago

@rafaur99 - you need to load the spatial information to use this functionality. Mfusg does not natively store this like mf6 does. I believe you have a couple of options:

  1. use the relatively new "from Grid Specification File" option:
    from flopy.discretization import UnstructuredGrid
    grid = UnstructuredGrid.from_gridspec(spec_path)
    ml.modelgrid = grid # I think this works...

    Example notebook here.

  2. Build the unstructured grid object yourself from for example csv files of lists of vertices (verts and iverts).