@@ -60,21 +60,9 @@ def compare_netcdf(base, gen, projection=False, update=None):
60
60
# assert epsg_b == epsg_g
61
61
continue
62
62
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
+ )
78
66
79
67
80
68
def compare_netcdf_data (base , gen ):
@@ -93,19 +81,47 @@ def compare_netcdf_data(base, gen):
93
81
if varname == "projection" :
94
82
continue
95
83
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
+
98
91
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
102
96
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 ])
107
109
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 )
109
125
110
126
111
127
@pytest .mark .regression
@@ -533,9 +549,9 @@ def test_gwfsto01(function_tmpdir, example_data_path):
533
549
534
550
# npf
535
551
# 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 ) )
539
555
icelltype = np .array ([ic1 , ic2 , ic3 ])
540
556
541
557
# k
@@ -563,7 +579,7 @@ def test_gwfsto01(function_tmpdir, example_data_path):
563
579
ss2 = np .full ((nrow , ncol ), 3e-4 )
564
580
ss3 = np .full ((nrow , ncol ), 6e-4 )
565
581
ss = np .array ([ss1 , ss2 , ss3 ])
566
- sy = np .full ((nlay , nrow , ncol ), 0 )
582
+ sy = np .full ((nlay , nrow , ncol ), 0.0 )
567
583
568
584
# define longnames
569
585
delr_longname = "spacing along a row"
@@ -939,7 +955,8 @@ def test_disv01b(function_tmpdir, example_data_path):
939
955
[1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
940
956
[1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
941
957
[1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ],
942
- ]
958
+ ],
959
+ dtype = np .int32 ,
943
960
)
944
961
945
962
botm = []
@@ -949,8 +966,8 @@ def test_disv01b(function_tmpdir, example_data_path):
949
966
botm = np .array (botm )
950
967
951
968
# 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 )
954
971
955
972
# ic
956
973
strt = np .full ((nlay , ncpl ), 0.0 )
@@ -1171,3 +1188,4 @@ def test_disv_transform(function_tmpdir, example_data_path):
1171
1188
sim .write_simulation (netcdf = nc_type )
1172
1189
1173
1190
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