diff --git a/da/ct/obs.py b/da/ct/obs.py index cba90862fce90b901211a4b74e1827cbfa5266ad..bc025464ff90ea2753ca41b22d08dbe9d3e4a4d2 100755 --- a/da/ct/obs.py +++ b/da/ct/obs.py @@ -107,32 +107,47 @@ class CtObservations(object): Note that this routine was not yet ported to Nio because it cannot read string arrays !!! """ - + import pyhdf.SD as HDF import Nio import datetime as dtm from string import strip, join - ncf = Nio.open_file(self.ObsFilename) - idates = ncf.variables['date_components'].get_value() - ids = ncf.variables['id'].get_value() - #sites = ncf.variables['site'].get_value() - #sites = [s.tostring().lower() for s in sites] - #sites = map(strip,sites) - sites = map(str,range(len(ids))) - lats = ncf.variables['lat'].get_value() - lons = ncf.variables['lon'].get_value() - alts = ncf.variables['alt'].get_value() - obs = ncf.variables['obs'].get_value() - #species = ncf.variables['species'].get_value() - species = map(str,range(len(ids))) - date = ncf.variables['date'].get_value() - #window = ncf.variables['sampling_strategy'].get_value() - window = map(str,range(len(ids))) - #flags = ncf.variables['NOAA_QC_flags'].get_value() - #flags = [s.tostring().lower() for s in flags] - #flags = map(strip,flags) - flags = map(str,range(len(ids))) - dummy = ncf.close() + ncf = HDF.SD(self.ObsFilename) + idates = ncf.select('date_components').get() + ids = ncf.select('id').get() + sites = ncf.select('site').get() + sites = [s.tostring().lower() for s in sites] + sites = map(strip,sites) + lats = ncf.select('lat').get() + lons = ncf.select('lon').get() + alts = ncf.select('alt').get() + obs = ncf.select('obs').get() + species = ncf.select('species').get() + date = ncf.select('date').get() + window = ncf.select('sampling_strategy').get() + flags = ncf.select('NOAA_QC_flags').get() + flags = [s.tostring().lower() for s in flags] + flags = map(strip,flags) + dummy = ncf.end() + +#+ ncf = Nio.open_file(self.ObsFilename) +#+ idates = ncf.variables['date_components'].get_value() +#+ ids = ncf.variables['id'].get_value() +#+ sites = ncf.variables['site'].get_value() +#+ sites = [s.tostring().lower() for s in sites] +#+ sites = map(strip,sites) +#+ lats = ncf.variables['lat'].get_value() +#+ lons = ncf.variables['lon'].get_value() +#+ alts = ncf.variables['alt'].get_value() +#+ obs = ncf.variables['obs'].get_value() +#+ species = ncf.variables['species'].get_value() +#+ date = ncf.variables['date'].get_value() +#+ window = ncf.variables['sampling_strategy'].get_value() +#+ flags = ncf.variables['NOAA_QC_flags'].get_value() +#+ flags = [s.tostring().lower() for s in flags] +#+ flags = map(strip,flags) +#+ dummy = ncf.close() + msg = "Successfully read data from obs file (%s)"%self.ObsFilename ; logging.debug(msg) dates = [dtm.datetime(*d) for d in idates]