IODA Bundle
proc_wrfda_ncdiag.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 import argparse
3 import os
4 import sys
5 from multiprocessing import Pool
6 import glob
7 from pathlib import Path
8 
9 IODA_CONV_PATH = Path(__file__).parent/"@SCRIPT_LIB_PATH@"
10 if not IODA_CONV_PATH.is_dir():
11  IODA_CONV_PATH = Path(__file__).parent/'..'/'lib-python'
12 sys.path.append(str(IODA_CONV_PATH.resolve()))
13 
14 import wrfda_ncdiag as wrfdad
15 
16 
17 def run_radiances_obs(radfile, outdir, datesubs):
18  print("Processing run_radiances_obs:")
19  print("Processing:"+str(radfile))
20  Diag = wrfdad.Radiances(radfile)
21  Diag.read()
22  Diag.toIODAobs(outdir, dateSubDirs=datesubs)
23  Diag.close()
24  return 0
25 
26 
27 ScriptName = os.path.basename(sys.argv[0])
28 
29 # Parse command line
30 ap = argparse.ArgumentParser()
31 ap.add_argument("-n", "--nprocs",
32  help="Number of tasks/processors for multiprocessing")
33 ap.add_argument("input_dir", help="Path to concatenated WRFDA diag files")
34 ap.add_argument("-o", "--obs_dir",
35  help="Path to directory to output observations")
36 ap.add_argument("-d", "--date_subdirs",
37  help="Whether to place output observations in date-specific subdirectories")
38 
39 MyArgs = ap.parse_args()
40 
41 if MyArgs.nprocs:
42  nprocs = int(MyArgs.nprocs)
43 else:
44  nprocs = 1
45 
46 if MyArgs.date_subdirs:
47  print(MyArgs.date_subdirs)
48  print(bool(MyArgs.date_subdirs))
49 
50  datesubs = bool(MyArgs.date_subdirs)
51 else:
52  datesubs = False
53 
54 DiagDir = MyArgs.input_dir
55 
56 obspool = Pool(processes=nprocs)
57 # process obs files
58 if MyArgs.obs_dir:
59  ObsDir = MyArgs.obs_dir
60  # radiances next
61  radfiles = glob.glob(DiagDir+'/diags_*')
62  for radfile in radfiles:
63  process = False
64  for p in wrfdad.rad_platform_sensor_combos:
65  if p in radfile:
66  process = True
67  if process:
68  res = obspool.apply_async(run_radiances_obs, args=(radfile, ObsDir, datesubs))
69 
70 # process all in the same time, because sats with many channels are so slow...
71 obspool.close()
72 obspool.join()
def run_radiances_obs(radfile, outdir, datesubs)