11import sys
22from pathlib import Path
3- from pprint import pformat
3+ from pprint import pformat , pprint
44from tempfile import TemporaryDirectory
55
66import numpy as np
1515DNODATA = 3.0e30
1616
1717
18+ # A FloPy simulation ASCII sim that will be updated
19+ # use netcdf inputs
1820def create_sim (ws ):
1921 name = "flow"
2022 gwfname = name
@@ -186,6 +188,8 @@ def create_sim(ws):
186188 return sim
187189
188190
191+ # A subroutine that can update an xarray dataset
192+ # with package netcdf information stored in a dict
189193def add_netcdf_vars (dataset , nc_info , dimmap ):
190194 def _data_shape (shape ):
191195 dims_l = []
@@ -197,18 +201,19 @@ def _data_shape(shape):
197201 for v in nc_info :
198202 varname = nc_info [v ]["varname" ]
199203 data = np .full (
200- _data_shape (nc_info [v ]["nc_shape " ]),
204+ _data_shape (nc_info [v ]["netcdf_shape " ]),
201205 nc_info [v ]["attrs" ]["_FillValue" ],
202- dtype = nc_info [v ]["nc_type " ],
206+ dtype = nc_info [v ]["xarray_type " ],
203207 )
204- var_d = {varname : (nc_info [v ]["nc_shape " ], data )}
208+ var_d = {varname : (nc_info [v ]["netcdf_shape " ], data )}
205209 dataset = dataset .assign (var_d )
206210 for a in nc_info [v ]["attrs" ]:
207211 dataset [varname ].attrs [a ] = nc_info [v ]["attrs" ][a ]
208212
209213 return dataset
210214
211215
216+ # create temporary directories
212217temp_dir = TemporaryDirectory ()
213218workspace = Path (temp_dir .name )
214219
@@ -229,6 +234,7 @@ def _data_shape(shape):
229234
230235# get model netcdf info
231236nc_info = gwf .netcdf_info ()
237+ pprint (nc_info )
232238
233239# update dataset with required attributes
234240for a in nc_info ["attrs" ]:
@@ -258,6 +264,7 @@ def _data_shape(shape):
258264# update for welg
259265welg = gwf .get_package ("wel-1" )
260266nc_info = welg .netcdf_info ()
267+ pprint (nc_info )
261268
262269# create welg dataset variables
263270ds = add_netcdf_vars (ds , nc_info , dimmap )
@@ -292,6 +299,7 @@ def _data_shape(shape):
292299 # get ghbg package netcdf info
293300 ghbg = gwf .get_package (f"ghb-{ ip } " )
294301 nc_info = ghbg .netcdf_info ()
302+ pprint (nc_info )
295303
296304 # create ghbg dataset variables
297305 ds = add_netcdf_vars (ds , nc_info , dimmap )
@@ -334,6 +342,7 @@ def _data_shape(shape):
334342 # get rivg package netcdf info
335343 rivg = gwf .get_package (f"riv-{ ip } " )
336344 nc_info = rivg .netcdf_info ()
345+ pprint (nc_info )
337346
338347 # create rivg dataset variables
339348 ds = add_netcdf_vars (ds , nc_info , dimmap )
@@ -382,6 +391,7 @@ def _data_shape(shape):
382391 # get drng package netcdf info
383392 drng = gwf .get_package (f"drn-{ ip } " )
384393 nc_info = drng .netcdf_info ()
394+ pprint (nc_info )
385395
386396 # create drng dataset variables
387397 ds = add_netcdf_vars (ds , nc_info , dimmap )
@@ -416,6 +426,9 @@ def _data_shape(shape):
416426 f .write (" concentration NETCDF\n " )
417427 f .write ("END period 1\n \n " )
418428
429+ # show the dataset
430+ print (ds )
431+
419432# write the netcdf
420433ds .to_netcdf (
421434 workspace / "netcdf/flow.structured.nc" , format = "NETCDF4" , engine = "netcdf4"
0 commit comments