flopy

flopy get_rc() not working for rotated grid


I am setting up my model spatial reference as follows:

m = flopy.modflow.Modflow.load(nam, verbose=True,load_only=['dis'])
x_offset = 963091.522224#x lower limit (SW corner)
y_offset = 9280278.473164#y lower limit (SW corner)
rot = 35.0# CCW
m.sr.xll = x_offset#x lower limit (SW corner)
m.sr.yll = y_offset#y lower limit (SW corner)
m.sr.rotation = rot

I believe the properties are being set correctly as geotiff rasters I export are rotated correctly. However, my results for get_rc() are not coming out right. The x,y pairs I am passing are at cell centers, the results have been perfect with unrotated grids.

The method call I am using (Psuedo code) is:

(r,c) = m.sr.get_rc(X,Y)

where X and Y are numpy arrays.


Solution

  • We have been replacing spatial reference (SR) with a general model grid object that is attached to the model so that we can more broadly support unstructured grids in flopy. Here is an example of how to register your model in space. For your specific case, you would call the set_coord_info method after the load.

    import flopy
    m = flopy.modflow.Modflow()
    dis = flopy.modflow.ModflowDis(m)
    xoff = 963091.522224
    yoff = 9280278.473164
    angrot = 35.
    m.modelgrid.set_coord_info(xoff=xoff, yoff=yoff, angrot=angrot)
    m.modelgrid.plot()
    

    All subsequent plots and exports will now use this georegistered information.

    enter image description here

    The modelgrid object has other methods too, like intersect, which will return the cell information for a specified x and y point. These methods will continue to evolve for unstructured grids and other types of intersections.