Commit 722758c4 authored by ARCHER's avatar ARCHER

silent useless warnings

parent 7971c9c8
......@@ -12,74 +12,58 @@ import netCDF4
import numpy as np
import numpy.ma as ma
import logging
import pdb
import warnings
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
def readFile(fname):
data={}
#list_var=('owiLon','owiLat','owiHeading','owiEcmwfWindSpeed','owiWindSpeed_IPF', 'owiPreProcessing/estimWindDir200', 'owiPreProcessing/MixWindDir200', 'owiPreProcessing/CoefMixWindDir200', 'owiEcmwfWindDirection','owiWindDirection_mod1','owiWindSpeed_mod1','owiWindDirection_mod2','owiWindSpeed_mod2','owiWindDirection_mod3','owiWindSpeed_mod3','owiPreProcessing/FilterBinary200','owiLandFlag','owiIncidenceAngle')
try:
nc=netCDF4.Dataset(fname)
except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None
# read owiLon to get valid shape
data['owiLon']=nc.variables['owiLon'][::]
refDims=nc.variables['owiLon'].dimensions
#refShape=np.shape(data['owiLon'])
#pdb.set_trace()
# read regular var
#for varname in nc.variables:
# var=nc.variables[varname]
# if var.dimensions == refDims:
# pdb.set_trace()
# data[varname]=var[::]
# read groups
for groupName in [ None ] + list(nc.groups.keys()):
if groupName:
group=nc.groups[groupName]
groupNamePref="%s/" % groupName
else:
group=nc
groupNamePref=""
groupAttrs=group.ncattrs()
for varName in group.variables:
var=group[varName]
dims=var.dimensions
if dims == refDims:
data["%s%s" % (groupNamePref,varName)] = var[::]
with warnings.catch_warnings():
warnings.simplefilter("ignore")
data={}
#list_var=('owiLon','owiLat','owiHeading','owiEcmwfWindSpeed','owiWindSpeed_IPF', 'owiPreProcessing/estimWindDir200', 'owiPreProcessing/MixWindDir200', 'owiPreProcessing/CoefMixWindDir200', 'owiEcmwfWindDirection','owiWindDirection_mod1','owiWindSpeed_mod1','owiWindDirection_mod2','owiWindSpeed_mod2','owiWindDirection_mod3','owiWindSpeed_mod3','owiPreProcessing/FilterBinary200','owiLandFlag','owiIncidenceAngle')
try:
nc=netCDF4.Dataset(fname)
except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None
# read owiLon to get valid shape
data['owiLon']=nc.variables['owiLon'][::]
refDims=nc.variables['owiLon'].dimensions
# read groups
for groupName in [ None ] + list(nc.groups.keys()):
if groupName:
group=nc.groups[groupName]
groupNamePref="%s/" % groupName
else:
# some vars are 3D:
# pdb.set_trace()
try:
if dims[1:] == refDims:
values3D=var[::]
for islice in range(np.shape(values3D)[0]):
value=values3D[islice,:,:]
try:
# try to find sliceName from varName and ncattrs
sliceName=group.getncattr([ groupAttr for groupAttr in groupAttrs if groupAttr in varName ][0]).split(', ')[islice]
except:
sliceName="%d" % islice
#pdb.set_trace()
data["%s%s/%s" % (groupNamePref,varName, sliceName)]=value
#pdb.set_trace()
except:
pass
#for var in nc.groups[group].variables:
# values=nc.groups[group].variables[var][::]
# if np.shape(values) == refShape:
# data["%s/%s" % (group,var)]=values
nc.close
group=nc
groupNamePref=""
groupAttrs=group.ncattrs()
for varName in group.variables:
var=group[varName]
dims=var.dimensions
if dims == refDims:
data["%s%s" % (groupNamePref,varName)] = var[::]
else:
# some vars are 3D:
try:
if dims[1:] == refDims:
values3D=var[::]
for islice in range(np.shape(values3D)[0]):
value=values3D[islice,:,:]
try:
# try to find sliceName from varName and ncattrs
sliceName=group.getncattr([ groupAttr for groupAttr in groupAttrs if groupAttr in varName ][0]).split(', ')[islice]
except:
sliceName="%d" % islice
data["%s%s/%s" % (groupNamePref,varName, sliceName)]=value
except:
pass
nc.close
return data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment