def read_ioda_obsspace(iodafile, varlist, qcvar=None, qcvals=None, iodalayout=0): """ read_ioda_obsspace will read an IODA obsspace for a given input file and return a dictionary of all variables in varlist layout supports classic - 0 and ioda-engines - 1 as values """ g = ioda.Engines.HH.openFile( name=iodafile, mode=ioda.Engines.BackendOpenModes.Read_Only, ) dlp = ioda._ioda_python.DLP.DataLayoutPolicy.generate( ioda._ioda_python.DLP.DataLayoutPolicy.Policies(iodalayout)) og = ioda.ObsGroup(g, dlp) iodaout = {} if qcvar: iodaQCVar = og.vars.open(qcvar) iodaQC = iodaQCVar.readNPArray.int() goodobs = np.isin(iodaQC, qcvals) goodobs = np.where(goodobs) iodaQC = iodaQC[goodobs] iodaout['QC'] = iodaQC for v in varlist: iodaVar = og.vars.open(v) iodaData = iodaVar.readNPArray.float() if qcvar: iodaData = iodaData[goodobs] iodaout[v] = iodaData return iodaout
def _open_ioda_obsgroup(self, filepath): # open the obs group for a specified file and return an object g = ioda.Engines.HH.openFile( name=filepath, mode=ioda.Engines.BackendOpenModes.Read_Only, ) dlp = ioda._ioda_python.DLP.DataLayoutPolicy.generate( ioda._ioda_python.DLP.DataLayoutPolicy.Policies(self.layout)) og = ioda.ObsGroup(g, dlp) return og
def __init__(self, fn, date=None, mask=None, verbose=False, reallyverbose=False, in_data=None): self.fn = None self.verbose = verbose self.reallyverbose = reallyverbose # try: ##NCD self.nc4 = nc4.Dataset(fn) if (self.reallyverbose): print(fn) self.gr = ioda.Engines.HH.openFile( name=fn, mode=ioda.Engines.BackendOpenModes.Read_Only) self.og = ioda.ObsGroup(self.gr) # except: # raise ValueError('NCDIAG File {} failed'.format(self.fn)) # print('warning') # return self.fn = fn self.data = { 'fn': self.fn, 'date': date, 'centroid_lat': None, 'centroid_lon': None } # for key in derived_var: # self.data[key] = None self.centroid_calculated = False if in_data is not None: for key in in_data: self.data[key] = in_data[key] if mask is None: self.mask = None else: self.set_mask(mask) self.mask_enabled = None self.obs_var = None
# For this to successfully run, you need Cartopy, Matplotlib and NumPy. import os import sys import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs if os.environ.get('LIBDIR') is not None: sys.path.append(os.environ['LIBDIR']) import ioda g = ioda.Engines.HH.openFile(name="Example-05a-python.hdf5", mode=ioda.Engines.BackendOpenModes.Read_Only) og = ioda.ObsGroup(g) tbName = "ObsValue/brightness_temperature" latName = "MetaData/latitude" lonName = "MetaData/longitude" tbVar = og.vars.open(tbName) latVar = og.vars.open(latName) lonVar = og.vars.open(lonName) tbData = tbVar.readNPArray.float() latData = latVar.readVector.float() lonData = lonVar.readVector.float() #fig = plt.figure(figsize=(10, 5)) ax = plt.axes(projection=ccrs.PlateCarree())