In [1]:
from __future__ import print_function
import os
import sys
import flopy
print(sys.version)
print('flopy version: {}'.format(flopy.__version__))
Load our old friend...the Freyberg model
In [2]:
nam_file = "freyberg.nam"
model_ws = os.path.join("..", "data", "freyberg_multilayer_transient")
ml = flopy.modflow.Modflow.load(nam_file, model_ws=model_ws, check=False)
We can see the SpatialReference
instance has generic entries, as does start_datetime
In [3]:
ml.dis.sr
Out[3]:
In [4]:
ml.dis.start_datetime
Out[4]:
Setting the attributes of the ml.dis.sr
is easy:
In [5]:
ml.dis.sr.xul = 123456.7
ml.dis.sr.yul = 765432.1
rotation = 15.0
proj4_str = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
ml.dis.start_datetime = '7/4/1776'
ml.dis.sr
Out[5]:
In [6]:
ml.dis.start_datetime
Out[6]:
In [7]:
# make directory
pth = os.path.join('data', 'netCDF_export')
if not os.path.exists(pth):
os.makedirs(pth)
In [8]:
fnc = ml.export(os.path.join(pth, ml.name+'.in.nc'))
hds = flopy.utils.HeadFile(os.path.join(model_ws,"freyberg.hds"))
flopy.export.utils.output_helper(os.path.join(pth, ml.name+'.out.nc'), ml, {"hds":hds})
Out[8]:
In [9]:
# export a 2d array
ml.dis.top.export(os.path.join(pth, 'top.nc'))
ml.dis.top.export(os.path.join(pth, 'top.shp'))
package.stress_period_data
) squeeze=True
); only stress periods with different values are exported squeeze=False
to export all stress periods
In [10]:
ml.drn.stress_period_data.export(os.path.join(pth, 'drn.shp'), sparse=True)
In [11]:
#export a 3d array
ml.upw.hk.export(os.path.join(pth, 'hk.nc'))
ml.upw.hk.export(os.path.join(pth, 'hk.shp'))
In [12]:
# export lots of things to the same nc file
fnc = ml.dis.botm.export(os.path.join(pth, 'test.nc'))
ml.upw.hk.export(fnc)
ml.dis.top.export(fnc)
# export transient 2d
ml.rch.rech.export(fnc)
Out[12]:
In [13]:
# export mflist
fnc = ml.wel.export(os.path.join(pth, 'packages.nc'))
ml.upw.export(fnc)
fnc.nc
Out[13]:
In [14]:
fnc = ml.export(os.path.join(pth, 'model.nc'))
fnc.nc
Out[14]:
In [ ]: