10 from __future__
import print_function
29 BadMissingVals =
False
30 HasInvalidVals =
False
31 NotFrequency = (re.search(
"[Ff]requency", Var.name) ==
None)
34 if (np.issubdtype(Var.dtype, np.number)):
35 VarData = Var[:].data.flatten()
36 VarMask = Var[:].mask.flatten()
37 if (VarMask.size == 1):
38 VarMask = np.full(VarData.shape, VarMask)
39 for i
in range(Var.shape[0]):
43 if ((np.isnan(VarData[i]))
or (np.isinf(VarData[i]))):
56 if ((NotFrequency)
and (
not VarMask[i])
and (np.fabs(VarData[i]) > 1e8)):
59 return (BadMissingVals, HasInvalidVals)
71 if (os.path.isdir(Item)):
72 for RootPath, Dirs, Files
in os.walk(Item):
74 TempFileList.append(os.path.join(RootPath, File))
76 TempFileList.append(Item)
80 for Item
in TempFileList:
81 if (Item.endswith(
'.nc')
or (Item.endswith(
'.nc4'))):
82 NcFileList.append(Item)
107 NcRootGroup = nc.Dataset(NcFileName,
'r')
108 print(
"Checking netcdf file for ioda conventions: ")
109 print(
" {0:s}".format(NcFileName))
113 MissingGroupMsg =
" Variable: {0:s} " + \
114 "needs to specify a group name (@<group_name> suffix)"
115 DataTypeMsg =
" Variable: {0:s} " + \
116 "has unexpected data type " + \
117 "({1} instead of {2})"
118 MissingValMsg =
" Variable: {0:s} " + \
119 "needs to use netcdf fill values for missing marks"
120 InvalidNumMsg =
" Variable: {0:s} " + \
121 "needs to remove invalid numeric values " + \
124 MissingGroupErrors = 0
128 for Vname
in NcRootGroup.variables:
129 Var = NcRootGroup.variables[Vname]
130 (VarName, Dummy, GroupName) = Vname.partition(
'@')
133 if (GroupName ==
""):
135 print(MissingGroupMsg.format(Vname))
136 MissingGroupErrors += 1
141 VarType = Var.dtype.name
142 if (GroupName ==
"PreQC"):
143 ExpectedVarType =
"int32"
144 elif (VarType ==
"float64"):
145 ExpectedVarType =
"float32"
147 ExpectedVarType = VarType
149 if (VarType != ExpectedVarType):
151 print(DataTypeMsg.format(Vname, VarType, ExpectedVarType))
159 print(MissingValMsg.format(Vname))
160 MissingValErrors += 1
164 print(InvalidNumMsg.format(Vname))
165 InvalidNumErrors += 1
167 TotalErrors = MissingGroupErrors + DataTypeErrors + MissingValErrors + InvalidNumErrors
168 ErrorReport =
" Error counts: Missing group: {0:d}, " + \
169 "data type: {1:d}, " + \
170 "missing value: {2:d}, " + \
171 "invalid numeric values: {3:d}"
172 print(ErrorReport.format(MissingGroupErrors, DataTypeErrors, MissingValErrors, InvalidNumErrors), end=
' ')
173 if (TotalErrors == 0):
185 ScriptName = os.path.basename(sys.argv[0])
188 ap = argparse.ArgumentParser()
189 ap.add_argument(
"-v",
"--verbose", action=
"store_true",
190 help=
"increase verbosity")
191 ap.add_argument(
"nc_file_or_dir", nargs=
'+',
192 help=
"list of files or directories containing netcdf")
194 MyArgs = ap.parse_args()
196 NetcdfList = MyArgs.nc_file_or_dir
197 Verbose = MyArgs.verbose
206 for NcFileName
in NcFileList:
208 TotalErrorCount += TotalErrors
212 sys.exit(TotalErrorCount)
def CheckNcFile(NcFileName, Verbose)
This routine will check the contents of one file for compliance with the ioda netcdf conventions.
def GenNcFileList(ArgList)
This routine will walk through the list of files from the command line arguments and create a list of...
def CheckVarValues(Var)
SUBROUTINES.