Commit 47aab4c0 authored by CEVAER's avatar CEVAER
Browse files

Automatic conversion to compatible python2/3 code with futurize

parent 8b809944
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division
from builtins import str
from builtins import range
from past.utils import old_div
import sys import sys
import os import os
import datetime import datetime
...@@ -19,7 +23,7 @@ def readFile(fname): ...@@ -19,7 +23,7 @@ def readFile(fname):
#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') #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: try:
nc=netCDF4.Dataset(fname) nc=netCDF4.Dataset(fname)
except Exception, e: except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e))) logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None return None
...@@ -38,7 +42,7 @@ def readFile(fname): ...@@ -38,7 +42,7 @@ def readFile(fname):
# data[varname]=var[::] # data[varname]=var[::]
# read groups # read groups
for groupName in [ None ] + nc.groups.keys(): for groupName in [ None ] + list(nc.groups.keys()):
if groupName: if groupName:
group=nc.groups[groupName] group=nc.groups[groupName]
groupNamePref="%s/" % groupName groupNamePref="%s/" % groupName
...@@ -84,7 +88,7 @@ def readMeta(fname): ...@@ -84,7 +88,7 @@ def readMeta(fname):
#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') #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: try:
nc=netCDF4.Dataset(fname) nc=netCDF4.Dataset(fname)
except Exception, e: except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e))) logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None return None
...@@ -96,7 +100,7 @@ def readMeta(fname): ...@@ -96,7 +100,7 @@ def readMeta(fname):
refDims=nc.variables['owiLon'].dimensions refDims=nc.variables['owiLon'].dimensions
# read groups # read groups
for groupName in [ None ] + nc.groups.keys(): for groupName in [ None ] + list(nc.groups.keys()):
if groupName: if groupName:
group=nc.groups[groupName] group=nc.groups[groupName]
groupNamePref="%s/" % groupName groupNamePref="%s/" % groupName
...@@ -155,7 +159,7 @@ def readMeta(fname): ...@@ -155,7 +159,7 @@ def readMeta(fname):
def getAttribute(fname, attr): def getAttribute(fname, attr):
try: try:
nc=netCDF4.Dataset(fname) nc=netCDF4.Dataset(fname)
except Exception, e: except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e))) logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None return None
...@@ -166,7 +170,7 @@ def getAttribute(fname, attr): ...@@ -166,7 +170,7 @@ def getAttribute(fname, attr):
def getFootprint(fname): def getFootprint(fname):
try: try:
nc=netCDF4.Dataset(fname) nc=netCDF4.Dataset(fname)
except Exception, e: except Exception as e:
logger.warn('skipping unreadable %s : %s' % (fname, str(e))) logger.warn('skipping unreadable %s : %s' % (fname, str(e)))
return None return None
...@@ -180,7 +184,7 @@ def getDateFromFname(fname): ...@@ -180,7 +184,7 @@ def getDateFromFname(fname):
tmp=os.path.basename(fname).split('-') tmp=os.path.basename(fname).split('-')
startDate=datetime.datetime.strptime(tmp[4],"%Y%m%dt%H%M%S") startDate=datetime.datetime.strptime(tmp[4],"%Y%m%dt%H%M%S")
stopDate=datetime.datetime.strptime(tmp[5],"%Y%m%dt%H%M%S") stopDate=datetime.datetime.strptime(tmp[5],"%Y%m%dt%H%M%S")
date=startDate+(stopDate-startDate)/2 date=startDate+old_div((stopDate-startDate),2)
return date return date
def getDataAtCoord(data,lon,lat): def getDataAtCoord(data,lon,lat):
...@@ -220,4 +224,4 @@ def getDataAtCoord(data,lon,lat): ...@@ -220,4 +224,4 @@ def getDataAtCoord(data,lon,lat):
dataAtCoord[key]=dataAtCoord[key]-180 dataAtCoord[key]=dataAtCoord[key]-180
else : else :
dataAtCoord[key]=dataAtCoord[key]+180 dataAtCoord[key]=dataAtCoord[key]+180
return dataAtCoord return dataAtCoord
\ No newline at end of file
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