99# format_version: '1.5'
1010# jupytext_version: 1.17.2
1111# kernelspec:
12- # display_name: Python 3
12+ # display_name: Python 3 (ipykernel)
1313# language: python
1414# name: python3
1515# metadata:
4747print (sys .version )
4848print (f"flopy version: { flopy .__version__ } " )
4949
50- # ## Define DNODATA constant
50+ # ## Define ` DNODATA` constant
5151#
52- # DNODATA is an important constant for MODFLOW 6 timeseries grid input
52+ # ` DNODATA` is an important constant for MODFLOW 6 timeseries grid input
5353# data. It signifies that the cell has no data defined for the time step
54- # in question. These cell values are discared and have no impact on the
54+ # in question. These cell values are discarded and have no impact on the
5555# simulation.
5656
5757# DNODATA constant
6262# For the purposes of this tutorial, the specifics of this simulation
6363# other than it is a candidate for NetCDF input are not a focus. It
6464# is a NetCDF input candidate because it defines a candidate model type
65- # (GWF6) with packages that support NetCDF input parameters.
65+ # (` GWF6` ) with packages that support NetCDF input parameters.
6666#
67- # A NetCDF dataset will be created from array data in the DIS, NPF and
68- # GHBG packages. Data will be copied from the package objects into dataset
67+ # A NetCDF dataset will be created from array data in the ` DIS`, ` NPF` and
68+ # ` GHBG` packages. Data will be copied from the package objects into dataset
6969# arrays.
7070
7171
@@ -284,20 +284,30 @@ def _data_shape(shape):
284284success , buff = sim .run_simulation (silent = True , report = True )
285285assert success , pformat (buff )
286286
287+ # ## Create NetCDF based simulation
288+ #
289+ # Reset the simulation path and set the GWF name file `nc_filerecord`
290+ # attribute to the name of the intended input NetCDF file. Display
291+ # the resultant name file changes.
292+
287293# create directory for netcdf sim
288294# set model name file nc_filerecord attribute to export name
289295sim .set_sim_path (workspace / "netcdf" )
290296gwf = sim .get_model ("uzf01" )
291297gwf .name_file .nc_filerecord = "uzf01.structured.nc"
292298sim .write_simulation ()
299+ with open (workspace / "netcdf" / "uzf01.nam" , "r" ) as fh :
300+ print (fh .read ())
301+
302+ # ## Create dataset
293303
294304# create the dataset
295305ds = xr .Dataset ()
296306
297307# ## Access model NetCDF attributes
298308#
299309# Access model scoped NetCDF details by storing the dictionary
300- # returned from netcdf_info(). In particular, we need to set dataset
310+ # returned from ` netcdf_info()` . In particular, we need to set dataset
301311# scoped attributes that are stored in the model netcdf info dict.
302312#
303313# First, retrieve and store the netcdf info dictionary and display
@@ -312,6 +322,8 @@ def _data_shape(shape):
312322for a in nc_info ["attrs" ]:
313323 ds .attrs [a ] = nc_info ["attrs" ][a ]
314324
325+ # ## Define dimensions relevant to NetCDF input file
326+
315327# define dimensional info
316328dis = gwf .modelgrid
317329xoff = dis .xoffset
@@ -326,14 +338,16 @@ def _data_shape(shape):
326338ncol = dis .ncol
327339dimmap = {"time" : nstp , "z" : nlay , "y" : nrow , "x" : ncol }
328340
341+ # ## Create dataset dimensions
342+
329343# create dataset coordinate vars
330344var_d = {"time" : (["time" ], time ), "z" : (["z" ], z ), "y" : (["y" ], y ), "x" : (["x" ], x )}
331345ds = ds .assign (var_d )
332346
333347# ## Access package NetCDF attributes
334348#
335349# Access package scoped NetCDF details by storing the dictionary returned
336- # from netcdf_info(). We need to set package variable attributes that are
350+ # from ` netcdf_info()` . We need to set package variable attributes that are
337351# stored in the package netcdf info dict, but we also need other information
338352# that is relevant to creating the variables themselves.
339353#
@@ -369,7 +383,7 @@ def _data_shape(shape):
369383# file for the package array input. The ASCII will no longer defined the arrays-
370384# instead the array names will be followed by the NETCDF keyword.
371385#
372- # We will simply overwrite the entire MODFLOW 6 DIS package input file with the
386+ # We will simply overwrite the entire MODFLOW 6 ` DIS` package input file with the
373387# following code block.
374388
375389# rewrite mf6 dis input to read from netcdf
@@ -389,10 +403,13 @@ def _data_shape(shape):
389403 f .write (" botm NETCDF\n " )
390404 f .write (" idomain NETCDF\n " )
391405 f .write ("END griddata\n " )
406+ with open (workspace / "netcdf" / "uzf01.dis" , "r" ) as fh :
407+ print (fh .read ())
408+
392409
393410# ## Update MODFLOW 6 package input file
394411#
395- # Follow the same process as above for the NPF package.
412+ # Follow the same process as above for the ` NPF` package.
396413
397414# get npf package netcdf info
398415npf = gwf .get_package ("npf" )
@@ -414,10 +431,12 @@ def _data_shape(shape):
414431 f .write (" icelltype NETCDF\n " )
415432 f .write (" k NETCDF\n " )
416433 f .write ("END griddata\n " )
434+ with open (workspace / "netcdf" / "uzf01.npf" , "r" ) as fh :
435+ print (fh .read ())
417436
418437# ## Update MODFLOW 6 package input file
419438#
420- # Follow the same process as above for the GHBG package. The difference is
439+ # Follow the same process as above for the ` GHBG` package. The difference is
421440# that this is PERIOD input and therefore stored as timeseries data in the
422441# NetCDF file. As NETCDF timeseries and defined in terms of total number of
423442# simulation steps, care must be taken in the translation of FloPy period
@@ -443,9 +462,13 @@ def _data_shape(shape):
443462 istp = sum (gwf .modeltime .nstp [0 :p ])
444463 ds ["ghbg_0_cond" ].values [istp ] = ghbg .cond .get_data ()[p ]
445464
465+ # ## Display generated dataset
466+
446467# show the dataset
447468print (ds )
448469
470+ # ## Export generated dataset to NetCDF
471+
449472# write dataset to netcdf
450473ds .to_netcdf (
451474 workspace / "netcdf/uzf01.structured.nc" , format = "NETCDF4" , engine = "netcdf4"
@@ -463,8 +486,14 @@ def _data_shape(shape):
463486 f .write (" bhead NETCDF\n " )
464487 f .write (" cond NETCDF\n " )
465488 f .write ("END period 1\n " )
489+ with open (workspace / "netcdf" / "uzf01.ghbg" , "r" ) as fh :
490+ print (fh .read ())
491+
492+ # ## Run MODFLOW 6 simulation with NetCDF input
493+ #
494+ # The simulation generated by this tutorial should be runnable by
495+ # Extended MODFLOW 6, available from the nightly-build repository
496+ # (linked above).
466497
467- # TODO need extended modflow 6 to run this simulation
468- # run the netcdf sim
469498# success, buff = sim.run_simulation(silent=True, report=True)
470499# assert success, pformat(buff)
0 commit comments