IODA Bundle
test_gsidiag.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 # script to run to test if the GSI ncdiag converters are still working
3 import sys
4 import argparse
5 from pathlib import Path
6 
7 IODA_CONV_PATH = Path(__file__).parent/"@SCRIPT_LIB_PATH@"
8 if not IODA_CONV_PATH.is_dir():
9  IODA_CONV_PATH = Path(__file__).parent/'..'/'lib-python'
10 sys.path.append(str(IODA_CONV_PATH.resolve()))
11 
12 import gsi_ncdiag as gsid
13 
14 parser = argparse.ArgumentParser(
15  description=('Test for GSI netCDF diag file to IODA Obs/GeoVaLs files converters'))
16 parser.add_argument('-i', '--input',
17  help="name of input file",
18  type=str, required=True)
19 parser.add_argument('-o', '--output',
20  help="output directory",
21  type=str, required=True)
22 parser.add_argument('-g', '--geovals',
23  help="geovals output directory",
24  type=str, required=False)
25 parser.add_argument('-t', '--type',
26  help="type of input file",
27  type=str, required=True)
28 parser.add_argument('-p', '--platform',
29  help="platform to run, only works on conv",
30  type=str)
31 parser.add_argument('-b', '--add_obsbias',
32  help="add obsbias groups, only works on rad",
33  type=str)
34 parser.add_argument('-q', '--add_qcvars',
35  help="add qc variables, only works on rad",
36  type=str)
37 parser.add_argument('-r', '--add_testrefs',
38  help="add test variables, only works on rad",
39  type=str)
40 args = parser.parse_args()
41 
42 infile = args.input
43 outdir = args.output
44 obsbias = args.add_obsbias
45 qcvars = args.add_qcvars
46 testrefs = args.add_testrefs
47 if (args.type == 'conv'):
48  diag = gsid.Conv(infile)
49 elif (args.type == 'rad'):
50  diag = gsid.Radiances(infile)
51 elif (args.type == 'aod'):
52  diag = gsid.AOD(infile)
53 elif (args.type == 'oz'):
54  diag = gsid.Ozone(infile)
55 elif (args.type == 'radar'):
56  diag = gsid.Radar(infile)
57 else:
58  raise ValueError
59 diag.read()
60 if (args.platform and args.type == 'conv'):
61  diag.toIODAobs(outdir, platforms=[args.platform])
62 elif (args.type == 'rad'):
63  diag.toIODAobs(outdir, obsbias, qcvars, testrefs)
64 else:
65  diag.toIODAobs(outdir)
66 if args.geovals:
67  diag.toGeovals(outdir)