@@ -60,21 +60,9 @@ def compare_netcdf(base, gen, projection=False, update=None):
6060 # assert epsg_b == epsg_g
6161 continue
6262
63- # check variable name
64- assert varname in xrg .data_vars
65-
66- # check variable attributes
67- for a in da .attrs :
68- if a == "grid_mapping" and not projection :
69- continue
70- assert da .attrs [a ] == xrg .data_vars [varname ].attrs [a ]
71-
72- # check variable data
73- print (f"NetCDF file check data equivalence for variable: { varname } " )
74- if update and varname in update :
75- assert np .allclose (update [varname ], xrg .data_vars [varname ].data )
76- else :
77- assert np .allclose (da .data , xrg .data_vars [varname ].data )
63+ compare_netcdf_var (
64+ varname , xrb .data_vars , xrg .data_vars , xrg .coords , projection , update
65+ )
7866
7967
8068def compare_netcdf_data (base , gen ):
@@ -93,19 +81,47 @@ def compare_netcdf_data(base, gen):
9381 if varname == "projection" :
9482 continue
9583
96- # check variable name
97- assert varname in xrg .data_vars or varname in xrg .coords
84+ compare_netcdf_var (
85+ varname ,
86+ xrb .data_vars ,
87+ xrg .data_vars ,
88+ xrg .coords ,
89+ )
90+
9891
99- if "bnds" in varname :
100- # TODO
101- continue
92+ def compare_netcdf_var (varname , base_d , gen_d , coord_d , projection = False , update = None ):
93+ # check variable name
94+ # assert varname in xrg.data_vars
95+ assert varname in gen_d or varname in coord_d
10296
103- # check variable data
104- print (f"NetCDF file check data equivalence for variable: { varname } " )
105- if varname in xrg .data_vars :
106- assert np .allclose (da .data , xrg .data_vars [varname ].data )
97+ if varname in gen_d :
98+ var_d = gen_d
99+ else :
100+ var_d = coord_d
101+
102+ # encodings
103+ for e in base_d [varname ].encoding :
104+ if e .lower () == "source" :
105+ continue
106+ assert e in var_d [varname ].encoding
107+ if e == "_FillValue" :
108+ assert np .allclose (base_d [varname ].encoding [e ], var_d [varname ].encoding [e ])
107109 else :
108- assert np .allclose (da .data , xrg .coords [varname ].data )
110+ assert base_d [varname ].encoding [e ] == var_d [varname ].encoding [e ]
111+
112+ # check variable attributes
113+ for a in base_d [varname ].attrs :
114+ if a == "grid_mapping" and not projection :
115+ continue
116+ assert a in var_d [varname ].attrs
117+ assert base_d [varname ].attrs [a ] == var_d [varname ].attrs [a ]
118+
119+ # check variable data
120+ print (f"NetCDF file check data equivalence for variable: { varname } " )
121+ if update and varname in update :
122+ assert np .allclose (update [varname ], var_d [varname ].data )
123+ else :
124+ assert np .allclose (base_d [varname ].data , var_d [varname ].data )
109125
110126
111127@pytest .mark .regression
@@ -533,9 +549,9 @@ def test_gwfsto01(function_tmpdir, example_data_path):
533549
534550 # npf
535551 # icelltype
536- ic1 = np .full ((nrow , ncol ), 1 )
537- ic2 = np .full ((nrow , ncol ), 0 )
538- ic3 = np .full ((nrow , ncol ), 0 )
552+ ic1 = np .full ((nrow , ncol ), np . int32 ( 1 ) )
553+ ic2 = np .full ((nrow , ncol ), np . int32 ( 0 ) )
554+ ic3 = np .full ((nrow , ncol ), np . int32 ( 0 ) )
539555 icelltype = np .array ([ic1 , ic2 , ic3 ])
540556
541557 # k
@@ -563,7 +579,7 @@ def test_gwfsto01(function_tmpdir, example_data_path):
563579 ss2 = np .full ((nrow , ncol ), 3e-4 )
564580 ss3 = np .full ((nrow , ncol ), 6e-4 )
565581 ss = np .array ([ss1 , ss2 , ss3 ])
566- sy = np .full ((nlay , nrow , ncol ), 0 )
582+ sy = np .full ((nlay , nrow , ncol ), 0.0 )
567583
568584 # define longnames
569585 delr_longname = "spacing along a row"
@@ -939,7 +955,8 @@ def test_disv01b(function_tmpdir, example_data_path):
939955 [1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
940956 [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
941957 [1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
942- ]
958+ ],
959+ dtype = np .int32 ,
943960 )
944961
945962 botm = []
@@ -949,8 +966,8 @@ def test_disv01b(function_tmpdir, example_data_path):
949966 botm = np .array (botm )
950967
951968 # npf
952- icelltype = np .full ((nlay , ncpl ), 0 )
953- k = np .full ((nlay , ncpl ), 1 )
969+ icelltype = np .full ((nlay , ncpl ), np . int32 ( 0 ) )
970+ k = np .full ((nlay , ncpl ), 1.0 )
954971
955972 # ic
956973 strt = np .full ((nlay , ncpl ), 0.0 )
@@ -1171,3 +1188,4 @@ def test_disv_transform(function_tmpdir, example_data_path):
11711188 sim .write_simulation (netcdf = nc_type )
11721189
11731190 compare_netcdf_data (cmp_pth / f"tri.{ nc_type } .nc" , mf6_ws / "tri.in.nc" )
1191+ # compare_netcdf_data(cmp_pth / f"tri.{nc_type}.nc", vertex_ws / "tri.nc")
0 commit comments