Not able to read cell vertices for MODFLOW-USG model with Flopy

37 views
Skip to first unread message

W_James

unread,
Jul 31, 2025, 2:11:42 AMJul 31
to MODFLOW Users Group
Good Afternoon,

I am working with a USG model that I have loaded into flopy. The model has loaded successfully, and I can extract data such as iverts, top, and bottom elevations for the cells. However, when I try to extract the cell centers (xcellcenters, ycellcenters, zcellcenters), I get the following error (I am including the section from unstructuredgrid.py that throws the error):


def _build_grid_geometry_info(self):
        cache_index_cc = "cellcenters"
        cache_index_vert = "xyzgrid"

 ---->vertexdict = {int(v[0]): [v[1], v[2]] for v in self._vertices}
        xcenters = self._xc
        ycenters = self._yc
        xvertices = []
        yvertices = []

        # build xy vertex and cell center info
        for iverts in self.iverts:
            xcellvert = []
            ycellvert = []
            for ix in iverts:
                xcellvert.append(vertexdict[ix][0])
                ycellvert.append(vertexdict[ix][1])

            xvertices.append(xcellvert)
            yvertices.append(ycellvert)

        zvertices, zcenters = self._zcoords()

        if self._has_ref_coordinates:
            # transform x and y
            xcenters, ycenters = self.get_coords(xcenters, ycenters)
            xvertxform = []
            yvertxform = []
            # vertices are a list within a list
            for xcellvertices, ycellvertices in zip(xvertices, yvertices):
                xcellvertices, ycellvertices = self.get_coords(
                    xcellvertices, ycellvertices
                )
                xvertxform.append(xcellvertices)
                yvertxform.append(ycellvertices)
            xvertices = xvertxform
            yvertices = yvertxform

        self._cache_dict[cache_index_cc] = CachedData([xcenters, ycenters, zcenters])
        self._cache_dict[cache_index_vert] = CachedData(
            [xvertices, yvertices, zvertices]
        )

TypeError: 'NoneType' object is not iterable

It seems that unstructuredgrid.py is look for a 3D array of vertices, and the model does not have that so it is returning a None type for self._vertices.

Likewise, if I run the code:

if grid.xcellcenters is not None:
    x_coords = grid.xcellcenters
else:
    print("xcellcenters is None")

It returns the same error, without returning the print statement. This leads me to believe that there is a mismatch between the unstructuredgrid.py file and the USG grid structure (using 1D array of nodes), but perhaps this is unlikely as these packages have been in use for a while now...

I believe the model has loaded correctly, is initialized, and is placed in space with set_coord_info.

Any help or input is appreciated.

Richard Winston

unread,
Jul 31, 2025, 7:22:08 AMJul 31
to mod...@googlegroups.com
You could check the model input files to see if the vertices were included. I think with MODFLOW-USG the vertices are optional.

--
This group was created in 2004 by Mr. C. P. Kumar, Former Scientist 'G', National Institute of Hydrology, Roorkee. Please visit his webpage at https://www.angelfire.com/nh/cpkumar/
---
You received this message because you are subscribed to the Google Groups "MODFLOW Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modflow+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/modflow/2a6927a9-390b-498c-989f-929538a35aa9n%40googlegroups.com.

Oscar Fabian Sanchez Ortiz

unread,
Aug 1, 2025, 2:01:13 AMAug 1
to mod...@googlegroups.com
A related issue can be found there, and a solution, my first thought is similar to Richard's comment, you need the GSF file with the spatial data
https://groups.google.com/g/modflow/c/AYrHcx_eAZg

W_James

unread,
Aug 1, 2025, 2:01:25 AMAug 1
to MODFLOW Users Group
I am not sure if my previous reply posted correctly (I did to author and not to all). It does indeed seem that my .disu file does not contain the vertices. I am not seeing the capability with flopy to put together the grid in that case, although it seems it should be possible using the c1/c2 spacings provided and with a coordinate system provided. Is anyone aware if this is possible? Or is the best option to extract the cell vertices in a different method. My ultimate goal is to build a vtk grid of my model in order to perform 3d intersection operations with some underground features.
Reply all
Reply to author
Forward
0 new messages