3 import binning_utils
as bu
4 from collections
import defaultdict
5 from copy
import deepcopy
6 from jediApplicationArgs
import jediAppName, nOuterIter
15 outerIter = str(nOuterIter)
16 anIter = str(nOuterIter)
25 modelDiags = [
'mmgfsan']
28 diffDiagnostics_ = defaultdict(list)
29 diffDiagnostics_[
'variational'] += [
'omb']
30 diffDiagnostics_[
'hofx'] += [
'omf']
33 relativeDiagnostics_ = defaultdict(list)
34 relativeDiagnostics_[
'variational'] += [
'rltv_omb']
35 relativeDiagnostics_[
'hofx'] += [
'rltv_omf']
38 absoluteDiagnostics_ = defaultdict(list)
39 absoluteDiagnostics_[
'variational'] += [
'obs',
'bak']
40 absoluteDiagnostics_[
'hofx'] += [
'obs',
'h(x)']
43 cloudyRadDiagnostics = [
'SCI']
46 sigmaDiagnostics_ = defaultdict(list)
47 sigmaDiagnostics_[
'variational'] = [
'omb',
'sigmaob',
'sigmab',
'CRyb']
48 sigmaDiagnostics_[
'hofx'] = [
'omf',
'sigmaof',
'sigmaf',
'CRyf']
52 diffDiagnostics_[
'variational'] += [
'oma']
53 relativeDiagnostics_[
'variational'] += [
'rltv_oma']
54 absoluteDiagnostics_[
'variational'] += [
'ana']
55 sigmaDiagnostics_[
'variational'] += [
'oma',
'sigmaoa',
'sigmaa',
'CRya']
57 diffDiagnostics = diffDiagnostics_[jediAppName]
58 relativeDiagnostics = relativeDiagnostics_[jediAppName]
59 absoluteDiagnostics = absoluteDiagnostics_[jediAppName]
60 sigmaDiagnostics = sigmaDiagnostics_[jediAppName]
62 defaultDiagnostics = diffDiagnostics
65 nonQCedDiagnostics = [
'obs']
76 allNamedLatBands[
'values'] = [
'NPol',
'NXTro',
'Tro',
'SXTro',
'SPol']
77 allNamedLatBands[
'minBounds'] = [60.0, 30.0, -30.0, -90.0, -90.0]
78 allNamedLatBands[
'maxBounds'] = [90.0, 90.0, 30.0, -30.0, -60.0]
81 namedLatBands[
'values'] = [
'NXTro',
'Tro',
'SXTro']
82 namedLatBands[
'minBounds'] = []
83 namedLatBands[
'maxBounds'] = []
85 for latBand
in namedLatBands[
'values']:
86 iband = allNamedLatBands[
'values'].index(latBand)
87 namedLatBands[
'minBounds'].append(allNamedLatBands[
'minBounds'][iband])
88 namedLatBands[
'maxBounds'].append(allNamedLatBands[
'maxBounds'][iband])
93 cldskyThresh = 1.0 - clrskyThresh
95 namedCldFracBands = {}
96 namedCldFracBands[
'values'] = [bu.clrskyMethod, bu.mixskyMethod, bu.cldskyMethod, bu.allskyMethod]
97 namedCldFracBands[
'minBounds'] = [0.0, clrskyThresh, cldskyThresh, 0.0]
98 namedCldFracBands[
'maxBounds'] = [clrskyThresh, cldskyThresh, 1.0, 1.0]
103 landsurfThresh = 1.0 - seasurfThresh
105 namedLandFracBands = {}
106 namedLandFracBands[
'values'] = [bu.seasurfMethod, bu.mixsurfMethod, bu.landsurfMethod, bu.allsurfMethod]
107 namedLandFracBands[
'minBounds'] = [0.0, seasurfThresh, landsurfThresh, 0.0]
108 namedLandFracBands[
'maxBounds'] = [seasurfThresh, landsurfThresh, 1.0, 1.0]
112 geoirLonBands = deepcopy(bu.geoirlatlonBoxParams)
113 geoirLatBands = deepcopy(bu.geoirlatlonBoxParams)
116 for centerLon
in geoirLonBands[
'centerLon']:
117 geoirLonBands[
'minBounds'] += \
118 [centerLon - bu.geoirMaxZenith]
119 geoirLonBands[
'maxBounds'] += \
120 [centerLon + bu.geoirMaxZenith]
121 geoirLatBands[
'minBounds'] += \
123 geoirLatBands[
'maxBounds'] += \
127 for bound
in [
'minBounds',
'maxBounds']:
128 for ii, lon
in enumerate(geoirLonBands[bound]):
129 while geoirLonBands[bound][ii] > 360.:
130 geoirLonBands[bound][ii] -= 360.
131 while geoirLonBands[bound][ii] < 0.:
132 geoirLonBands[bound][ii] += 360.
143 binLims[vu.obsVarPrs] = {}
144 binLims[vu.obsVarPrs][
'start'] = 0.0
145 binLims[vu.obsVarPrs][
'finish'] = 1000.0
146 binLims[vu.obsVarPrs][
'step'] = 100.0
147 binLims[vu.obsVarPrs][
'format'] =
'{:.0f}'
149 binLims[vu.obsVarAlt] = {}
150 binLims[vu.obsVarAlt][
'start'] = 1000.0
151 binLims[vu.obsVarAlt][
'finish'] = 50000.0
152 binLims[vu.obsVarAlt][
'step'] = 2000.0
153 binLims[vu.obsVarAlt][
'format'] =
'{:.0f}'
155 binLims[vu.obsVarLat] = {}
156 binLims[vu.obsVarLat][
'start'] = -90.0
157 binLims[vu.obsVarLat][
'finish'] = 90.0
158 binLims[vu.obsVarLat][
'step'] = 10.0
159 binLims[vu.obsVarLat][
'format'] =
'{:.0f}'
161 binLims[vu.obsVarLT] = {}
162 binLims[vu.obsVarLT][
'start'] = bu.LH0
163 binLims[vu.obsVarLT][
'finish'] = bu.LH1
164 binLims[vu.obsVarLT][
'step'] = bu.LHDT
165 binLims[vu.obsVarLT][
'format'] =
'{:.0f}'
167 binLims[vu.obsVarSenZen] = {}
168 binLims[vu.obsVarSenZen][
'start'] = 0.0
169 binLims[vu.obsVarSenZen][
'finish'] = 70.0
170 binLims[vu.obsVarSenZen][
'step'] = 5.0
171 binLims[vu.obsVarSenZen][
'format'] =
'{:.0f}'
173 binLims[vu.obsVarGlint] = {}
174 binLims[vu.obsVarGlint][
'start'] = 0.0
175 binLims[vu.obsVarGlint][
'finish'] = bu.maxGlint
176 binLims[vu.obsVarGlint][
'step'] = 10.0
177 binLims[vu.obsVarGlint][
'format'] =
'{:.0f}'
179 binLims[vu.obsVarLandFrac] = {}
180 binLims[vu.obsVarLandFrac][
'start'] = 0.0
181 binLims[vu.obsVarLandFrac][
'finish'] = 1.0
182 binLims[vu.obsVarLandFrac][
'step'] = seasurfThresh / 2.0
183 binLims[vu.obsVarLandFrac][
'format'] =
'{:.3f}'
185 binLims[vu.obsVarCldFrac] = {}
186 binLims[vu.obsVarCldFrac][
'start'] = 0.0
187 binLims[vu.obsVarCldFrac][
'finish'] = 1.0
188 binLims[vu.obsVarCldFrac][
'step'] = clrskyThresh / 2.0
189 binLims[vu.obsVarCldFrac][
'format'] =
'{:.3f}'
191 binLims[vu.obsVarSCI] = {}
192 binLims[vu.obsVarSCI][
'start'] = 0.0
193 binLims[vu.obsVarSCI][
'finish'] = 60.0
194 binLims[vu.obsVarSCI][
'step'] = 1.0
195 binLims[vu.obsVarSCI][
'format'] =
'{:.0f}'
197 binLims[vu.obsVarACI] = {}
198 binLims[vu.obsVarACI][
'start'] = -20.0
199 binLims[vu.obsVarACI][
'finish'] = 20.0
200 binLims[vu.obsVarACI][
'step'] = 2.0
201 binLims[vu.obsVarACI][
'format'] =
'{:.0f}'
203 binLims[vu.obsVarNormErr] = {}
204 binLims[vu.obsVarNormErr][
'start'] = -7.0
205 binLims[vu.obsVarNormErr][
'finish'] = 7.0
206 binLims[vu.obsVarNormErr][
'step'] = 0.25
207 binLims[vu.obsVarNormErr][
'format'] =
'{:.2f}'
209 binLims[vu.modVarLat] = {}
210 binLims[vu.modVarLat][
'start'] = -90.0
211 binLims[vu.modVarLat][
'finish'] = 90.0
212 binLims[vu.modVarLat][
'step'] = 5.0
213 binLims[vu.modVarLat][
'format'] =
'{:.0f}'
221 for binType, param
in binLims.items():
222 binBounds = list(np.arange(
223 param[
'start']-0.5*np.abs(param[
'step']),
224 param[
'finish']+1.5*param[
'step'],
226 binLims[binType][
'minBounds'] = []
227 binLims[binType][
'maxBounds'] = []
228 binLims[binType][
'values'] = []
229 for ibin
in list(range(len(binBounds)-1)):
230 binLims[binType][
'minBounds'].append(binBounds[ibin])
231 binLims[binType][
'maxBounds'].append(binBounds[ibin+1])
233 binVal = 0.5 * (binBounds[ibin+1] + binBounds[ibin])
234 binLims[binType][
'values'].append(param[
'format'].
format(binVal))
262 goodFlagNames = [
'pass',
'passive']
264 badFlags = [10, 11, 12, 13,
267 22, 23, 24, 25, 26, 27,
269 badFlagNames = [
'missing',
'preQC',
'bounds',
'domain',
270 'exclude',
'Hfailed',
'thinned',
'diffref',
271 'clw',
'fguess',
'seaice',
'track',
272 'buddy',
'derivative',
'profile',
'onedvar',
'bayesianQC',
'modelobthresh',
294 nullBinMethod = {
'filters': [],
'values': [] }
295 nullBinVarConfig = { bu.identityBinMethod:nullBinMethod }
299 'where': bu.notEqualAnyBound,
300 'variable': vu.selfQCValue,
301 'bounds': [goodFlags],
302 'except_diags': nonQCedDiagnostics,
309 {
'where': bu.notEqualBound,
310 'variable': vu.selfQCValue,
312 'except_diags': nonQCedDiagnostics}
314 'values': goodFlagNames,
318 {
'where': bu.notEqualBound,
319 'variable': vu.selfQCValue,
321 'except_diags': nonQCedDiagnostics},
322 {
'where': bu.equalBound,
323 'variable': vu.selfQCValue,
325 'except_diags': nonQCedDiagnostics,
328 'values': badFlagNames,
332 {
'where': bu.notEqualBound,
333 'variable': vu.selfQCValue,
334 'bounds': goodFlags+badFlags,
335 'except_diags': nonQCedDiagnostics},
336 {
'where': bu.equalBound,
337 'variable': vu.selfQCValue,
338 'bounds': goodFlags+badFlags,
339 'except_diags': nonQCedDiagnostics,
342 'values': goodFlagNames+badFlagNames,
349 {
'where': bu.lessBound,
350 'variable': vu.prsMeta,
351 'bounds': bu.P_jet_min},
352 {
'where': bu.greatEqualBound,
353 'variable': vu.prsMeta,
354 'bounds': bu.P_jet_max},
357 'values': bu.P_jet_val,
364 {
'where': bu.lessBound,
365 'variable': vu.altMeta,
366 'bounds': bu.alt_jet_min},
367 {
'where': bu.greatEqualBound,
368 'variable': vu.altMeta,
369 'bounds': bu.alt_jet_max},
372 'values': bu.alt_jet_val,
378 {
'where': bu.lessBound,
379 'variable': vu.latMeta,
380 'bounds': namedLatBands[
'minBounds']},
381 {
'where': bu.greatEqualBound,
382 'variable': vu.latMeta,
383 'bounds': namedLatBands[
'maxBounds']},
386 'values': namedLatBands[
'values'],
390 {
'where': bu.lessBound,
391 'variable': vu.latMeta,
392 'bounds': binLims[vu.obsVarLat][
'minBounds']},
393 {
'where': bu.greatEqualBound,
394 'variable': vu.latMeta,
395 'bounds': binLims[vu.obsVarLat][
'maxBounds']},
396 {
'where': bu.lessBound,
397 'variable': vu.prsMeta,
398 'bounds': bu.P_jet_min},
399 {
'where': bu.greatEqualBound,
400 'variable': vu.prsMeta,
401 'bounds': bu.P_jet_max},
404 'values': binLims[vu.obsVarLat][
'values'],
408 {
'where': bu.lessBound,
409 'variable': vu.latMeta,
410 'bounds': binLims[vu.obsVarLat][
'minBounds']},
411 {
'where': bu.greatEqualBound,
412 'variable': vu.latMeta,
413 'bounds': binLims[vu.obsVarLat][
'maxBounds']},
414 {
'where': bu.lessBound,
415 'variable': vu.altMeta,
416 'bounds': bu.alt_jet_min},
417 {
'where': bu.greatEqualBound,
418 'variable': vu.altMeta,
419 'bounds': bu.alt_jet_max},
422 'values': binLims[vu.obsVarLat][
'values'],
426 bu.surfbandsMethod: {
428 {
'where': bu.lessBound,
429 'variable': vu.landfracGeo,
430 'bounds': namedLandFracBands[
'minBounds']},
431 {
'where': bu.greatBound,
432 'variable': vu.landfracGeo,
433 'bounds': namedLandFracBands[
'maxBounds']},
436 'values': namedLandFracBands[
'values'],
440 bu.cloudbandsMethod: {
442 {
'where': bu.lessBound,
443 'variable': vu.cldfracMeta,
444 'bounds': namedCldFracBands[
'minBounds']},
445 {
'where': bu.greatBound,
446 'variable': vu.cldfracMeta,
447 'bounds': namedCldFracBands[
'maxBounds']},
450 'values': namedCldFracBands[
'values'],
456 {
'where': bu.lessBound,
457 'variable': bu.SCIOkamoto,
458 'bounds': binLims[vu.obsVarSCI][
'minBounds']},
459 {
'where': bu.greatEqualBound,
460 'variable': bu.SCIOkamoto,
461 'bounds': binLims[vu.obsVarSCI][
'maxBounds']},
463 'values': binLims[vu.obsVarSCI][
'values'],
465 bu.ScaleOkamotoMethod: {
467 {
'where': bu.lessBound,
468 'variable': bu.ScaledSCIOkamoto,
469 'bounds': binLims[vu.obsVarSCI][
'minBounds']},
470 {
'where': bu.greatEqualBound,
471 'variable': bu.ScaledSCIOkamoto,
472 'bounds': binLims[vu.obsVarSCI][
'maxBounds']},
474 'values': binLims[vu.obsVarSCI][
'values'],
476 bu.ModHarnischMethod: {
478 {
'where': bu.lessBound,
479 'variable': bu.SCIModHarnisch,
480 'bounds': binLims[vu.obsVarSCI][
'minBounds']},
481 {
'where': bu.greatEqualBound,
482 'variable': bu.SCIModHarnisch,
483 'bounds': binLims[vu.obsVarSCI][
'maxBounds']},
485 'values': binLims[vu.obsVarSCI][
'values'],
487 bu.ScaleModHarnischMethod: {
489 {
'where': bu.lessBound,
490 'variable': bu.ScaledSCIModHarnisch,
491 'bounds': binLims[vu.obsVarSCI][
'minBounds']},
492 {
'where': bu.greatEqualBound,
493 'variable': bu.ScaledSCIModHarnisch,
494 'bounds': binLims[vu.obsVarSCI][
'maxBounds']},
496 'values': binLims[vu.obsVarSCI][
'values'],
502 {
'where': bu.lessBound,
503 'variable': bu.OkamotoNormalizedError,
504 'bounds': binLims[vu.obsVarNormErr][
'minBounds']},
505 {
'where': bu.greatEqualBound,
506 'variable': bu.OkamotoNormalizedError,
507 'bounds': binLims[vu.obsVarNormErr][
'maxBounds']},
509 'values': binLims[vu.obsVarNormErr][
'values'],
511 bu.ScaleOkamotoMethod: {
513 {
'where': bu.lessBound,
514 'variable': bu.ScaledOkamotoNormalizedError,
515 'bounds': binLims[vu.obsVarNormErr][
'minBounds']},
516 {
'where': bu.greatEqualBound,
517 'variable': bu.ScaledOkamotoNormalizedError,
518 'bounds': binLims[vu.obsVarNormErr][
'maxBounds']},
520 'values': binLims[vu.obsVarNormErr][
'values'],
522 bu.ModHarnischMethod: {
524 {
'where': bu.lessBound,
525 'variable': bu.ModHarnischNormalizedError,
526 'bounds': binLims[vu.obsVarNormErr][
'minBounds']},
527 {
'where': bu.greatEqualBound,
528 'variable': bu.ModHarnischNormalizedError,
529 'bounds': binLims[vu.obsVarNormErr][
'maxBounds']},
531 'values': binLims[vu.obsVarNormErr][
'values'],
533 bu.ScaleModHarnischMethod: {
535 {
'where': bu.lessBound,
536 'variable': bu.ScaledModHarnischNormalizedError,
537 'bounds': binLims[vu.obsVarNormErr][
'minBounds']},
538 {
'where': bu.greatEqualBound,
539 'variable': bu.ScaledModHarnischNormalizedError,
540 'bounds': binLims[vu.obsVarNormErr][
'maxBounds']},
542 'values': binLims[vu.obsVarNormErr][
'values'],
545 vu.obsRegionBinVar: {
546 'AFRICA': nullBinMethod,
547 'ATLANTIC': nullBinMethod,
548 'AUSTRALIA': nullBinMethod,
551 {
'where': bu.lessBound,
552 'variable': vu.lonMeta,
554 {
'where': bu.greatBound,
555 'variable': vu.lonMeta,
557 {
'where': bu.lessBound,
558 'variable': vu.latMeta,
560 {
'where': bu.greatBound,
561 'variable': vu.latMeta,
567 'EUROPE': nullBinMethod,
568 'E_EUROPE': nullBinMethod,
569 'NAMERICA': nullBinMethod,
570 'PACIFIC': nullBinMethod,
571 'SAMERICA': nullBinMethod,
572 'SE_ASIA': nullBinMethod,
573 'S_ASIA': nullBinMethod,
574 bu.geoirlatlonboxMethod: {
576 {
'where': bu.lessBound,
577 'variable': vu.lonMeta,
578 'bounds': geoirLonBands[
'minBounds']},
579 {
'where': bu.greatBound,
580 'variable': vu.lonMeta,
581 'bounds': geoirLonBands[
'maxBounds']},
582 {
'where': bu.lessBound,
583 'variable': vu.latMeta,
584 'bounds': geoirLatBands[
'minBounds']},
585 {
'where': bu.greatBound,
586 'variable': vu.latMeta,
587 'bounds': geoirLatBands[
'maxBounds']},
589 'values': geoirLonBands[
'values'],
716 identityRangeBinVars = {
717 vu.obsVarAlt: [vu.altMeta, []],
718 vu.obsVarACI: [bu.AsymmetricCloudImpact, [
'obs',
'bak',
'ana',
'SCI']],
719 vu.obsVarCldFrac: [vu.cldfracMeta, [
'obs',
'bak',
'ana',
'SCI']],
720 vu.obsVarGlint: [bu.GlintAngle, [
'obs',
'bak',
'ana',
'SCI']],
721 vu.obsVarLandFrac: [vu.landfracGeo, [
'obs',
'bak',
'ana',
'SCI']],
722 vu.obsVarLat: [vu.latMeta, [
'obs',
'bak',
'ana',
'SCI']],
723 vu.obsVarLT: [bu.LocalHour, [
'obs',
'bak',
'ana',
'SCI']],
724 vu.obsVarNormErr: [bu.NormalizedError, []],
725 vu.obsVarPrs: [vu.prsMeta, []],
726 vu.obsVarSenZen: [vu.senzenMeta, [
'obs',
'bak',
'ana',
'SCI']],
728 for binVar, rangeVar
in identityRangeBinVars.items():
729 if binVar
not in binVarConfigs: binVarConfigs[binVar] = {}
730 binVarConfigs[binVar][bu.identityBinMethod] = {
732 {
'where': bu.lessBound,
733 'variable': rangeVar[0],
734 'bounds': binLims[binVar][
'minBounds']},
735 {
'where': bu.greatEqualBound,
736 'variable': rangeVar[0],
737 'bounds': binLims[binVar][
'maxBounds']},
740 'values': binLims[binVar][
'values'],
741 'override_exclusiveDiags': rangeVar[1],
746 vu.obsVarAlt: [vu.altMeta, []],
747 vu.obsVarPrs: [vu.prsMeta, []],
749 for binVar, rangeVar
in latBinVars.items():
750 if binVar
not in binVarConfigs: binVarConfigs[binVar] = {}
751 for iband, latBand
in enumerate(namedLatBands[
'values']):
752 binVarConfigs[binVar][latBand] = {
754 {
'where': bu.lessBound,
755 'variable': rangeVar[0],
756 'bounds': binLims[binVar][
'minBounds']},
757 {
'where': bu.greatEqualBound,
758 'variable': rangeVar[0],
759 'bounds': binLims[binVar][
'maxBounds']},
760 {
'where': bu.lessBound,
761 'variable': vu.latMeta,
762 'bounds': namedLatBands[
'minBounds'][iband]},
763 {
'where': bu.greatEqualBound,
764 'variable': vu.latMeta,
765 'bounds': namedLatBands[
'maxBounds'][iband]},
768 'values': binLims[binVar][
'values'],
769 'override_exclusiveDiags': rangeVar[1],
777 vu.obsVarLat: [vu.latMeta],
781 for binVar, rangeVar
in cldfracBinVars.items():
782 if binVar
not in binVarConfigs: binVarConfigs[binVar] = {}
783 for iband, cldBand
in enumerate(namedCldFracBands[
'values']):
784 binVarConfigs[binVar][cldBand] = {
786 {
'where': bu.lessBound,
787 'variable': rangeVar[0],
788 'bounds': binLims[binVar][
'minBounds']},
789 {
'where': bu.greatEqualBound,
790 'variable': rangeVar[0],
791 'bounds': binLims[binVar][
'maxBounds']},
792 {
'where': bu.lessBound,
793 'variable': vu.cldfracMeta,
794 'bounds': namedCldFracBands[
'minBounds'][iband]},
795 {
'where': bu.greatBound,
796 'variable': vu.cldfracMeta,
797 'bounds': namedCldFracBands[
'maxBounds'][iband]},
800 'values': binLims[binVar][
'values'],
801 'override_exclusiveDiags': [
'obs',
'bak',
'ana',
'SCI'],
806 vu.obsVarSCI: [bu.SCIOkamoto],
808 for binVar, rangeVar
in landfracBinVars.items():
809 if binVar
not in binVarConfigs: binVarConfigs[binVar] = {}
810 for iband, surfBand
in enumerate(namedLandFracBands[
'values']):
811 binVarConfigs[binVar][surfBand] = {
813 {
'where': bu.lessBound,
814 'variable': rangeVar[0],
815 'bounds': binLims[binVar][
'minBounds']},
816 {
'where': bu.greatEqualBound,
817 'variable': rangeVar[0],
818 'bounds': binLims[binVar][
'maxBounds']},
819 {
'where': bu.lessBound,
820 'variable': vu.landfracGeo,
821 'bounds': namedLandFracBands[
'minBounds'][iband]},
822 {
'where': bu.greatBound,
823 'variable': vu.landfracGeo,
824 'bounds': namedLandFracBands[
'maxBounds'][iband]},
827 'values': binLims[binVar][
'values'],
828 'override_exclusiveDiags': [
'obs',
'bak',
'ana',
'SCI'],