Skip to content

How does Flopy locate models now in reference coordinates when the computational units are in feet? #578

@ghost

Description

consider this model, which is in feet, but referenced to a coordinate reference system that is in meters:

import os
import numpy as np
import flopy
fm = flopy.modflow
from flopy.discretization import StructuredGrid
from flopy.utils.reference import SpatialReference

dis_kwargs = {#'nlay': 1,
              'nrow': 10,
              'ncol': 10,
              'delr': 1000, # in feet
              'delc': 1000 # in feet
}

# grid location info
xoff = 1000 # lower left x-coordinate in UTM meters
yoff = 1000 # lower left y-coordinate
rotation: 0.
epsg = 26916

tmpdir = 'tmp'
if not os.path.isdir(tmpdir):
    os.makedirs(tmpdir)
    
mf2005 = fm.Modflow('mf2005.nam', model_ws=tmpdir)
dis = fm.ModflowDis(mf2005, **dis_kwargs, lenuni=1)

Previously, with SpatialReference, one could just specify the lower left or upper left corner, and an epsg code for a CRS, and it would convert the grid to the correct location in the CRS:

mf2005.sr.xll = xoff
mf2005.sr.yll = yoff
mf2005.sr.epsg = epsg
mf2005.sr.bounds
(1000.0, 1000.0, 4048.0, 4048.0)

Unless I'm missing something, with modelgrid, there doesn't seem to be a way to do this:

mf2005.modelgrid.set_coord_info(xoff=xoff, yoff=yoff, epsg=epsg)
mf2005.modelgrid.extent
(1000.0, 11000.0, 1000.0, 11000.0)
mg = StructuredGrid(delc=np.ones(10) * 304.8, 
                                    delr=np.ones(10) * 304.8, 
                                    xoff=xoff, yoff=yoff, angrot=0, 
                                    epsg=26916, lenuni=2)
mf2005.modelgrid = mg
mf2005.modelgrid.extent
(1000.0, 11000.0, 1000.0, 11000.0)

(the lenuni argument doesn't seem to have any effect on the last result)

There also doesn't seem to be a way to supply the upper left corner instead of the lower left corner. I get that this makes things a little more complicated, but oftentimes (as in the USGS archiving guidence), only the upper left is given.

SpatialReference supported this as well

sr = SpatialReference(delr=mf2005.dis.delr, 
                      delc=mf2005.dis.delc,
                      xul=1000, yul=4048, epsg=26916, 
                      lenuni=1 # model lenuni
)
sr.yll
1000.0

there is an an _yul_to_yll() method, but it only works if the CRS and model units are the same:

mf2005.modelgrid._yul_to_yll(4048)
-5952.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions