3 import binning_utils
as bu
4 from predefined_configs
import anIter, appName
5 from copy
import deepcopy
9 import plot_utils
as pu
10 import stat_utils
as su
11 import var_utils
as vu
13 _logger = logging.getLogger(__name__)
19 class BiasCorrectedObs:
22 self.
baseVarsbaseVars.append(vu.selfDepValue)
23 self.
baseVarsbaseVars.append(vu.selfHofXValue)
26 bcdep = dbVals[insituParameters[vu.selfDepValue]]
27 mod = dbVals[insituParameters[vu.selfHofXValue]]
28 return np.subtract(mod, bcdep)
34 self.
baseVarsbaseVars.append(vu.selfDepValue)
35 self.
baseVarsbaseVars.append(vu.selfHofXValue)
36 self.
baseVarsbaseVars.append(vu.selfObsValue)
39 bcdep = dbVals[insituParameters[vu.selfDepValue]]
40 mod = dbVals[insituParameters[vu.selfHofXValue]]
41 obs = dbVals[insituParameters[vu.selfObsValue]]
42 return np.subtract(np.subtract(mod, bcdep), obs)
48 self.
baseVarsbaseVars.append(vu.selfDepValue)
51 bcdep = dbVals[insituParameters[vu.selfDepValue]]
52 return np.negative(bcdep)
58 self.
baseVarsbaseVars.append(vu.selfDepValue)
59 self.
baseVarsbaseVars.append(vu.selfObsValue)
62 bcdep = dbVals[insituParameters[vu.selfDepValue]]
63 obs = dbVals[insituParameters[vu.selfObsValue]]
65 OMM = np.negative(bcdep)
66 valid = bu.greatBound(np.abs(obs), 0.0,
False)
67 OMM[valid] = np.divide(OMM[valid], obs[valid])
70 return np.multiply(OMM, 100.0)
76 self.
baseVarsbaseVars.append(vu.selfHofXValue)
77 self.
baseVarsbaseVars.append(vu.selfObsValue)
80 obs = dbVals[insituParameters[vu.selfObsValue]]
81 mod = dbVals[insituParameters[vu.selfHofXValue]]
82 return np.subtract(obs, mod)
88 self.
baseVarsbaseVars.append(vu.selfHofXValue)
89 self.
baseVarsbaseVars.append(vu.selfObsValue)
92 obs = dbVals[insituParameters[vu.selfObsValue]]
93 mod = dbVals[insituParameters[vu.selfHofXValue]]
95 OMM = np.subtract(obs, mod)
96 valid = bu.greatBound(np.abs(obs), 0.0,
False)
97 OMM[valid] = np.divide(OMM[valid],obs[valid])
100 return np.multiply(OMM, 100.0)
106 self.
baseVarsbaseVars.append(vu.selfHofXValue)
107 self.
baseVarsbaseVars.append(vu.bgHofXValue)
110 ana = dbVals[insituParameters[vu.selfHofXValue]]
111 bak = dbVals[insituParameters[vu.bgHofXValue]]
112 return np.subtract(ana, bak)
118 self.
baseVarsbaseVars.append(vu.selfHofXValue)
119 self.
baseVarsbaseVars.append(vu.selfObsValue)
120 self.
baseVarsbaseVars.append(vu.bgHofXValue)
123 ana = dbVals[insituParameters[vu.selfHofXValue]]
124 bak = dbVals[insituParameters[vu.bgHofXValue]]
125 obs = dbVals[insituParameters[vu.selfObsValue]]
127 AMB = np.subtract(ana, bak)
128 valid = bu.greatBound(np.abs(obs), 0.0,
False)
129 AMB[valid] = np.divide(AMB[valid], obs[valid])
132 return np.multiply(AMB, 100.0)
137 self.
baseVarsbaseVars.append(vu.selfHofXValue)
138 self.
baseVarsbaseVars.append(vu.selfObsValue)
139 self.
baseVarsbaseVars.append(vu.bgHofXValue)
142 ana = dbVals[insituParameters[vu.selfHofXValue]]
143 bak = dbVals[insituParameters[vu.bgHofXValue]]
144 obs = dbVals[insituParameters[vu.selfObsValue]]
146 AMBoOMB = np.subtract(ana, bak)
147 OMB = np.subtract(obs, bak)
148 valid = bu.greatBound(np.abs(OMB), 0.0,
False)
150 AMBoOMB[valid] = np.divide(AMBoOMB[valid], OMB[valid])
151 AMBoOMB[~valid] = np.NaN
160 self.
baseVarsbaseVars.append(vu.selfHofXValue)
163 meanVarName = insituParameters[vu.selfHofXValue]
165 for key
in dbVals.keys():
166 if meanVarName+vu.ensSuffixBase
in key:
167 memberKeys.append(key)
168 nMembers = len(memberKeys)
170 nLocs = len(dbVals[memberKeys[0]])
171 mods = np.full((nMembers, nLocs), np.NaN)
172 for member, key
in enumerate(memberKeys):
173 mods[member,:] = dbVals[key]
174 std = np.nanstd(mods, axis=0, ddof=1)
176 std = np.full(nLocs, np.NaN)
179 CRStatNames = [
'CRd',
'CRh',
'CRo']
187 assert stateType
in [
'b',
'a',
'f'],
'ConsistencyRatioFromDFW: wrong stateType: '+stateType
191 ommStr =
'om'+stateType
192 sigmamStr =
'sigma'+stateType
193 sigmaoStr =
'sigmao'+stateType
196 availableDiagNames = dfw.levels(
'diagName')
197 if (ommStr
not in availableDiagNames
or
198 sigmamStr
not in availableDiagNames
or
199 sigmaoStr
not in availableDiagNames):
return None
201 omm = dfw.loc({
'diagName': ommStr},
'MS').to_numpy()
202 sigmam = dfw.loc({
'diagName': sigmamStr},
'MS').to_numpy()
203 sigmao = dfw.loc({
'diagName': sigmaoStr},
'MS').to_numpy()
206 for statName
in CRStatNames:
207 CRStats[statName] = np.full_like(omm, np.NaN)
209 p = np.logical_and(np.isfinite(omm),
210 np.logical_and(np.isfinite(sigmam), np.isfinite(sigmao)))
218 q = np.logical_and(bu.greatBound(np.absolute(omm), 0.0), p)
219 CRStats[CRStatNames[0]][q] = (sigmam[q] + sigmao[q]) / omm[q]
223 q = np.logical_and(bu.greatBound(np.absolute(omm - sigmao), 0.0), p)
224 CRStats[CRStatNames[1]][q] = sigmam[q] / (omm[q] - sigmao[q])
228 q = np.logical_and(bu.greatBound(np.absolute(omm - sigmam), 0.0), p)
229 CRStats[CRStatNames[2]][q] = sigmao[q] / (omm[q] - sigmam[q])
234 CRyDict = dfw.loc({
'diagName': [ommStr]}).reset_index().to_dict(orient=
'list')
235 nrows = len(CRStats[CRStatNames[0]])
236 CRyDict[
'diagName'] = [
'CRy'+stateType] * nrows
239 for statistic, CRStat
in CRStats.items():
240 CRStat[bu.lessBound(CRStat, 0.0)] = np.NaN
241 CRyDict[statistic] = np.sqrt(CRStat)
243 for statName
in su.allFileStats:
244 del CRyDict[statName]
247 CRyDF = pd.DataFrame.from_dict(CRyDict)
249 CRyDF.set_index(dfw.indexNames, inplace=
True)
250 CRyDF.sort_index(inplace=
True)
275 availableDiagnostics = {
277 'variable': BiasCorrection,
279 'label':
'$y_{bias}$',
282 'variable': BiasCorrectedObsMinusModel,
284 'label':
'$y - x_b$',
288 'variable': BiasCorrectedObsMinusModel,
290 'label':
'$y - x_a$',
293 'variable': ObsMinusModel,
294 'label':
'$y - x_f$',
297 'variable': AnalysisMinusBackground,
299 'label':
'$x_a - x_b$',
303 'label':
'$x - x_{a,GFS}$',
306 'variable': ObsMinusModel,
308 'label':
'$y - x_b$',
311 'variable': ObsMinusModel,
313 'label':
'$y - x_a$',
316 'variable': RelativeBiasCorrectedObsMinusModel,
318 'label':
'$(y - x_b) / y$',
321 'variable': RelativeBiasCorrectedObsMinusModel,
323 'label':
'$(y - x_a) / y$',
326 'variable': RelativeObsMinusModel,
327 'label':
'$(y - x_f) / y$',
330 'variable': RelativeAnalysisMinusBackground,
332 'label':
'$(x_a - x_b) / y$',
335 'variable': RelativeObsMinusModel,
337 'label':
'$(y - x_b) / y$',
340 'variable': RelativeObsMinusModel,
342 'label':
'$(y - x_a) / y$',
345 'variable': AnalysisMinusBackgroundOverObsMinusBackground,
347 'label':
'$(x_a - x_b) / (y - x_b)$',
350 'variable': vu.selfObsValue,
353 'variable': BiasCorrectedObs,
357 'variable': vu.selfHofXValue,
361 'variable': vu.selfHofXValue,
366 'variable': vu.selfHofXValue,
371 'variable': vu.selfErrorValue,
374 'label':
'$\sigma_o$',
377 'variable': STDofHofX,
382 'label':
'$\sigma_{h_b}$',
385 'variable': vu.selfErrorValue,
388 'label':
'$\sigma_o$',
391 'variable': STDofHofX,
396 'label':
'$\sigma_{h_a}$',
399 'variable': vu.selfErrorValue,
401 'label':
'$\sigma_o$',
404 'variable': STDofHofX,
408 'label':
'$\sigma_{h_f}$',
416 'DFWFunction': ConsistencyRatioFromDFW,
420 'analysisStatistics': CRStatNames,
421 'label':
'$CR_{y,b}$',
425 'DFWFunction': ConsistencyRatioFromDFW,
429 'analysisStatistics': CRStatNames,
430 'label':
'$CR_{y,a}$',
433 'DFWFunction': ConsistencyRatioFromDFW,
437 'analysisStatistics': CRStatNames,
438 'label':
'$CR_{y,f}$',
441 'variable': bu.SCIOkamoto,
443 'onlyObsSpaces': [
'abi_g16',
'ahi_himawari8'],
446 'variable': bu.AsymmetricCloudImpact,
447 'onlyObsSpaces': [
'abi_g16',
'ahi_himawari8'],
450 'variable': bu.ABEILambda,
451 'onlyObsSpaces': [
'abi_g16',
'ahi_himawari8'],
452 'label':
'$\lambda_{ABEI}$',
458 def diagnosticConfigs(diagnosticNames_, ObsSpaceName, includeEnsembleDiagnostics=True,
459 analysisStatistics = su.allFileStats, fileFormat=vu.hdfFileFormat):
461 diagnosticConfigs = {}
462 diagnosticNames = list(set(diagnosticNames_))
464 for diagnosticName
in diagnosticNames:
465 if diagnosticName
in availableDiagnostics:
466 config = deepcopy(availableDiagnostics[diagnosticName])
467 elif diagnosticName
in diagnosticConfigs:
468 _logger.warning(
'diagnosticName is duplicated: '+diagnosticName)
471 _logger.error(
'diagnosticName is undefined: '+diagnosticName)
473 config[
'analyze'] = config.get(
'analyze',
True)
474 config[
'derived'] = config.get(
'derived',
False)
475 config[
'offline'] = config.get(
'offline',
False)
476 config[vu.mean] = config.get(vu.mean,
True)
477 config[vu.ensemble] = (config.get(vu.ensemble,
False)
and includeEnsembleDiagnostics)
478 config[
'onlyObsSpaces'] = config.get(
'onlyObsSpaces',[])
479 config[
'analysisStatistics'] = config.get(
'analysisStatistics', analysisStatistics)
480 config[
'staticArg'] = config.get(
'staticArg',
None)
481 config[
'label'] = config.get(
'label',diagnosticName)
484 if (
not config[vu.mean]
and not config[vu.ensemble]):
continue
485 if (len(config[
'onlyObsSpaces']) > 0
and
486 ObsSpaceName
not in config[
'onlyObsSpaces']):
continue
488 config[
'osName'] = ObsSpaceName
489 config[
'fileFormat'] = fileFormat
491 diagnosticConfigs[diagnosticName] = deepcopy(config)
493 outerIterStr = config.get(
'iter',
None)
494 if outerIterStr
is None or outerIterStr ==
'':
495 if appName ==
'hofx':
498 outerIter = vu.bgIter
500 if outerIterStr ==
'bg':
501 outerIter = vu.bgIter
502 elif outerIterStr ==
'an':
504 elif pu.isint(outerIterStr):
505 outerIter = outerIterStr
507 _logger.error(
'outerIter is undefined: '+outerIterStr)
509 diagnosticConfigs[diagnosticName][
'outerIter'] = outerIter
511 if config[
'derived']:
continue
512 if config[
'offline']:
continue
513 diagnosticConfigs[diagnosticName][
'ObsFunction'] = bu.ObsFunctionWrapper(config)
515 return diagnosticConfigs
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def evaluate(self, dbVals, insituParameters)
def ConsistencyRatioFromDFW(dfw, stateType)
def diagnosticConfigs(diagnosticNames_, ObsSpaceName, includeEnsembleDiagnostics=True, analysisStatistics=su.allFileStats, fileFormat=vu.hdfFileFormat)