Skip to content

Commit

Permalink
feat(zb netcdf): zonebudget netcdf export support added (#781)
Browse files Browse the repository at this point in the history
* Updates to netcdf.py and utilities for zonebudget data

* Update requirements.travis.txt to test netCDF4 error

* update requirements.travis.txt for netCDF error testing

* Update travis/install.sh and requirements.travis.txt for binary conflicts

* updates for binary HDF binary conflict testing

* Feat(ZoneBudgetOutput): Added ZoneBudgetOutput to read in zonebudget output files

* added postprocessing methods to prepare budget data for netcdf writing
* updated NetCdf to include zonebudget group
* updated export/utils.py for zonebudget netcdf exporting

* Update(test_zonebudget_output_to_netcdf): for linux os

* Debug travis error with coverage package

* Debug coverage package issue due to 5.0.2 update (known issue in coveragepy repository)

* Update(test_zonebudget_output_to_netcdf): fix file case issue for travis-ci

* Update travis install.sh to check if coverage issue has been fixed
  • Loading branch information
jlarsen-usgs authored and langevin-usgs committed Jan 17, 2020
1 parent 102d25b commit 491f4fe
Show file tree
Hide file tree
Showing 12 changed files with 130,253 additions and 1,180 deletions.
104 changes: 104 additions & 0 deletions autotest/t039_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,109 @@ def test_get_model_shape():
return


def test_zonebudget_output_to_netcdf():
from flopy.utils import HeadFile, ZoneBudgetOutput
from flopy.modflow import Modflow
from flopy.mf6 import MFSimulation
from flopy.export.utils import output_helper

model_ws = os.path.join("..", "examples", "data",
"freyberg_multilayer_transient")
zb_ws = os.path.join("..", "examples", "data", "zonbud_examples")

hds = "freyberg.hds"
nam = "freyberg.nam"
zon = "zonef_mlt.zbr"

hds = HeadFile(os.path.join(model_ws, hds))
ml = Modflow.load(nam, model_ws=model_ws)
zone_array = read_zbarray(os.path.join(zb_ws, zon))

# test with standard zonebudget output
zbout = "freyberg_mlt.txt"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
vdf = zb.volumetric_flux()

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test with zonebudget csv 1 output
zbout = "freyberg_mlt.1.csv"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)

netobj = zb.dataframe_to_netcdf_fmt(zb.dataframe)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test with zonebudget csv 2 output
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
vdf = zb.volumetric_flux(extrapolate_kper=True)

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)

export_dict = {"hds": hds,
"zonebud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)

# test built in export function
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".bi1" + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
zb.export(os.path.join(outpth, ncf_name), ml)

# test built in export function with NetCdf output object
zbout = "freyberg_mlt.2.csv"
ncf_name = zbout + ".bi2" + ".nc"

zb = ZoneBudgetOutput(os.path.join(zb_ws, zbout), ml.dis, zone_array)
export_dict = {"hds": hds}
ncfobj = output_helper(os.path.join(outpth, ncf_name), ml, export_dict)
zb.export(ncfobj, ml)

# test with modflow6/zonebudget6
sim_ws = os.path.join("..", "examples", 'data',
'mf6', 'test005_advgw_tidal')
hds = "advgw_tidal.hds"
nam = "mfsim"
zon = "zonebudget6.csv"
ncf_name = zon + ".nc"

zone_array = np.ones((3, 15, 10), dtype=int)
zone_array = np.add.accumulate(zone_array, axis=0)
sim = MFSimulation.load(nam, sim_ws=sim_ws, exe_name='mf6')
sim.set_sim_path(outpth)
sim.write_simulation()
sim.run_simulation()
hds = HeadFile(os.path.join(outpth, hds))

ml = sim.get_model("gwf_1")

zb = ZoneBudgetOutput(os.path.join(zb_ws, zon), sim.tdis, zone_array)
vdf = zb.volumetric_flux()

netobj = zb.dataframe_to_netcdf_fmt(vdf, flux=False)
export_dict = {"hds": hds,
"zbud": netobj}

output_helper(os.path.join(outpth, ncf_name), ml, export_dict)


if __name__ == '__main__':
# test_compare2mflist_mlt()
test_compare2zonebudget()
Expand All @@ -244,3 +347,4 @@ def test_get_model_shape():
test_dataframes()
test_get_budget()
test_get_model_shape()
test_zonebudget_output_to_netcdf()
Loading

0 comments on commit 491f4fe

Please sign in to comment.