IODA
06-ReadIodaOutputFile.py
Go to the documentation of this file.
1 #
2 # (C) Copyright 2020 UCAR
3 #
4 # This software is licensed under the terms of the Apache Licence Version 2.0
5 # which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 #
7 
8 # This example opens and reads a sample ioda output file (v2 format).
9 
10 import os
11 import sys
12 import numpy as np
13 
14 if os.environ.get('LIBDIR') is not None:
15  sys.path.append(os.environ['LIBDIR'])
16 
17 import ioda
18 
19 # grab arguments
20 print(sys.argv)
21 InFile = sys.argv[1]
22 
23 # First task is to open the ioda file for reading. This is accomplished by constructing
24 # an ObsGroup object. This is done in two steps:
25 # 1. create a "backend" which is based on a file (ioda.Engines.HH.openFile call)
26 # 2. construct an ObsGroup based on the backend created in step 1.
27 #
29  name = InFile,
30  mode = ioda.Engines.BackendOpenModes.Read_Only)
32 
33 # The radiance data is organized as a 2D array (locations X channels). The dimension
34 # names are "nlocs" and "nchans" for locataion and channels respectively.
35 
36 # You can access the dimension variables to get coordinate values
37 locsDimName = "nlocs"
38 chansDimName = "nchans"
39 
40 locsDimVar = og.vars.open(locsDimName)
41 chansDimVar = og.vars.open(chansDimName)
42 
43 locsCoords = locsDimVar.readVector.int()
44 chansCoords = chansDimVar.readVector.int()
45 
46 numLocs = len(locsCoords)
47 numChans = len(chansCoords)
48 
49 print("INFO: locations dimension: ", locsDimName, " (", numLocs, ")")
50 print("INFO: coordinates: ")
51 for i in range(numLocs):
52  print("INFO: ", i, " --> ", locsCoords[i])
53 print("")
54 
55 print("INFO: channels dimension: ", chansDimName, " (", numChans, ")")
56 print("INFO: coordinates: ")
57 for i in range(numChans):
58  print("INFO: ", i, " --> ", chansCoords[i])
59 print("")
60 
61 # We are interested in the following variables for diagnostics:
62 # ObsValue/brightness_temperature --> y
63 # hofx/brightness_temperature --> H(x)
64 # MetaData/latitude
65 # MeatData/lognitude
66 
67 tbName = "ObsValue/brightness_temperature"
68 hofxName = "hofx/brightness_temperature"
69 latName = "MetaData/latitude"
70 lonName = "MetaData/longitude"
71 
72 tbVar = og.vars.open(tbName)
73 hofxVar = og.vars.open(hofxName)
74 latVar = og.vars.open(latName)
75 lonVar = og.vars.open(lonName)
76 
77 tbData = tbVar.readNPArray.float() # produces a numpy 2D array
78 hofxData = hofxVar.readNPArray.float()
79 latData = latVar.readVector.float() # produces a python list
80 lonData = lonVar.readVector.float()
81 
82 print("INFO: input Tb variable: ", tbName, " (", tbData.shape, ")")
83 print("INFO: output Tb H(x) variable: ", hofxName, " (", hofxData.shape, ")")
84 print("INFO: latitude variable: ", latName, " (", len(latData), ")")
85 print("INFO: longitude variable: ", lonName, " (", len(lonData), ")")
86 print("")
87 
88 # Grab channel 7 data from Tb and H(x) data
89 chanIndex = chansCoords.index(7)
90 
91 tbDataCh7 = tbData[:, chanIndex]
92 hofxDataCh7 = hofxData[:, chanIndex]
93 
94 print("INFO: Channel 7 is located at channel index: ", chanIndex)
95 print("INFO: input Tb variable, channel 7: ", tbName, " (", tbDataCh7.shape, ")")
96 print("INFO: output Tb H(x) variable, channel 7: ", hofxName, " (", hofxDataCh7.shape, ")")
97 print("")
98 
An ObsGroup is a specialization of a ioda::Group. It provides convenience functions and guarantees th...
Definition: ObsGroup.h:32
IODA_DL Group openFile(const std::string &filename, BackendOpenModes mode, HDF5_Version_Range compat=defaultVersionRange())
Open a ioda::Group backed by an HDF5 file.
Definition: HH.cpp:135