Commit b9dcfd9c authored by GROUAZEL's avatar GROUAZEL

Merge remote-tracking branch 'origin/master'

parents 9918165e ffce29ef
__pycache__/
*.pyc
......
......@@ -8,21 +8,22 @@ import logging
import spectrumUtil as spUtil
import os
class AbstractSpectrumReader():
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def read_spectrum(ncfile,mode="satfull",index=None):
def read_spectrum(ncfile, mode="satfull", index=None):
pass
#-----------------------------------------------
# -----------------------------------------------
# Reader for Buoys Globwave File (Ndbc and cdip)
#-----------------------------------------------
# -----------------------------------------------
class SpectrumReaderBuoyGlobwave(AbstractSpectrumReader):
@staticmethod
def read_spectrum(ncf,index,mode="buoyglobwavendbc",phi = np.arange(0,365,10),dataName='UNK'):
def read_spectrum(ncf, index, mode="buoyglobwavendbc", phi=np.arange(0, 365, 10), dataName='UNK'):
"""
read_spectra_globwave: Function that return a spectrum object from a globwave file
ncf: Net CDF File already open
......@@ -42,77 +43,79 @@ class SpectrumReaderBuoyGlobwave(AbstractSpectrumReader):
"""
if isinstance(ncf, basestring):
fileToRead = Dataset(ncf, 'r')
fileToRead = Dataset(ncf, 'r')
else:
fileToRead = ncf
mywind = SpectrumReaderBuoyGlobwave.read_wind_globwave(fileToRead,index)
mywsys = SpectrumReaderBuoyGlobwave.read_wsys_globwave(fileToRead,index)
myspec_data = SpectrumReaderBuoyGlobwave.read_spec_data_globwave(fileToRead,index,mode,phi = phi)
mymeta = SpectrumReaderBuoyGlobwave.read_meta_globwave(fileToRead,index,mode)
mywind = SpectrumReaderBuoyGlobwave.read_wind_globwave(fileToRead, index)
mywsys = SpectrumReaderBuoyGlobwave.read_wsys_globwave(fileToRead, index)
myspec_data = SpectrumReaderBuoyGlobwave.read_spec_data_globwave(fileToRead, index, mode, phi=phi)
mymeta = SpectrumReaderBuoyGlobwave.read_meta_globwave(fileToRead, index, mode)
if isinstance(ncf, basestring):
fileToRead.close()
return spc.Spectrum(myspec_data,mywsys,mywind,mymeta,dataName=dataName)
return spc.Spectrum(myspec_data, mywsys, mywind, mymeta, dataName=dataName)
@staticmethod
def read_wind_globwave(ncf,index):
wind={}
def read_wind_globwave(ncf, index):
wind = {}
return wind
@staticmethod
def read_wsys_globwave(ncf,index):
lon,lat =None,None
def read_wsys_globwave(ncf, index):
lon, lat = None, None
lat = np.squeeze(ncf.variables['lat'][:])
lon = np.squeeze(ncf.variables['lon'][:])
wsys={'lon':lon,'lat':lat}
wsys = {'lon': lon, 'lat': lat}
return wsys
@staticmethod
def read_spec_data_globwave(ncf,index,mode='buoyglobwavendbc',phi = np.arange(0,365,10),con='to'):
time = nc.num2date( ncf.variables['time'][:], ncf.variables['time'].units )
def read_spec_data_globwave(ncf, index, mode='buoyglobwavendbc', phi=np.arange(0, 365, 10), con='to'):
time = nc.num2date(ncf.variables['time'][:], ncf.variables['time'].units)
time = time[int(index)]
c1 = ncf.variables['theta1'][index,:] # theta1
c2 = ncf.variables['theta2'][index,:] # theta2
c3 = ncf.variables['stheta1'][index,:] # stheta1
c4 = ncf.variables['stheta2'][index,:] # stheta2
c1 = ncf.variables['theta1'][index, :] # theta1
c2 = ncf.variables['theta2'][index, :] # theta2
c3 = ncf.variables['stheta1'][index, :] # stheta1
c4 = ncf.variables['stheta2'][index, :] # stheta2
# convert theta & stheta(globwave data used) to a1,b1,a2,b2
a1,a2,b1,b2 = spUtil.th2ab(c1,c2,c3,c4)
a1, a2, b1, b2 = spUtil.th2ab(c1, c2, c3, c4)
if mode == "buoyglobwavendbc":
f,sf = SpectrumReaderBuoyGlobwave.read_spec_data_ndbc_globwave(ncf,index)
f, sf = SpectrumReaderBuoyGlobwave.read_spec_data_ndbc_globwave(ncf, index)
else:
f,sf = SpectrumReaderBuoyGlobwave.read_spec_data_cdip_globwave(ncf,index)
f, sf = SpectrumReaderBuoyGlobwave.read_spec_data_cdip_globwave(ncf, index)
spfphitmp,d = spUtil.buoy_spectrum2d(sf,a1,a2,b1,b2, dirs = phi)
spfphi=[spfphitmp]
#spfphi2kphi wait an array of values
spfphitmp, d = spUtil.buoy_spectrum2d(sf, a1, a2, b1, b2, dirs=phi)
spfphi = [spfphitmp]
# spfphi2kphi wait an array of values
sp2d,k = spUtil.spfphi2kphi(spfphi,f)
sp2d, k = spUtil.spfphi2kphi(spfphi, f)
if con=='to':
sp2d = spUtil.spfrom2to(sp2d,phi)
#sp2d is an array of values : so we use the first and only element
spec_data = spc.Spec_data(k=k,phi=phi,sp=sp2d[0],start_time=time,)
if con == 'to':
sp2d = spUtil.spfrom2to(sp2d, phi)
# sp2d is an array of values : so we use the first and only element
spec_data = spc.Spec_data(k=k, phi=phi, sp=sp2d[0], start_time=time, )
return spec_data
@staticmethod
def read_spec_data_ndbc_globwave(ncf,index):
def read_spec_data_ndbc_globwave(ncf, index):
f = np.squeeze(ncf.variables['wave_directional_spectrum_central_frequency'][:])
sf = ncf.variables['spectral_wave_density'][index,:]
return f,sf
sf = ncf.variables['spectral_wave_density'][index, :]
return f, sf
@staticmethod
def read_spec_data_cdip_globwave(ncf,index):
f = np.squeeze(ncf.variables['central_frequency'][index,:])
sf = ncf.variables['sea_surface_variance_spectral_density'][index,:]
return f,sf
def read_spec_data_cdip_globwave(ncf, index):
f = np.squeeze(ncf.variables['central_frequency'][index, :])
sf = ncf.variables['sea_surface_variance_spectral_density'][index, :]
return f, sf
@staticmethod
def read_meta_globwave(ncf,index,mode='buoyglobwavendbc'):
def read_meta_globwave(ncf, index, mode='buoyglobwavendbc'):
if mode == "buoyglobwavendbc":
mymeta = spc.Meta(type=mode)
......@@ -131,14 +134,14 @@ class SpectrumReaderBuoyGlobwave(AbstractSpectrumReader):
return meta
@staticmethod
def read_wsys_ndbc(ncf,index):
lon,lat =None,None
def read_wsys_ndbc(ncf, index):
lon, lat = None, None
lat = np.squeeze(ncf.variables['latitude'][:])
lon = np.squeeze(ncf.variables['longitude'][:])
wsys={'lon':lon,'lat':lat}
wsys = {'lon': lon, 'lat': lat}
return wsys
#-----------------------------------------------
# -----------------------------------------------
# End of Reader for Buoys Globwave File (Ndbc and cdip)
#-----------------------------------------------
# -----------------------------------------------
......@@ -465,7 +465,7 @@ def add_spectrum_to_plot(fig,myspectrum,vmin,vmax,colormap,cb_label,nrow,ncolumn
if hasattr(myspectrum.spec_data,'part') and myspectrum.spec_data.part is not None:
myspectrum.spec_data.part = myspectrum.spec_data.part+1
part_u = np.unique(myspectrum.spec_data.part)
part_u = part_u[part_u<200]
part_u = part_u[(part_u<200) & (part_u>=0)]
logging.debug('part_u shape before removing masked values: %s %s',part_u.shape,part_u)
if isinstance(part_u,np.ma.core.masked_array):
if isinstance(part_u.mask,np.ndarray):
......
......@@ -17,6 +17,7 @@ import os, socket
from datetime import datetime
import collections
import time
import traceback
if __name__ == "__main__":
root = logging.getLogger()
if root.handlers:
......@@ -75,13 +76,11 @@ if __name__ == "__main__":
nbsuccess += 1
except Exception as e:
print('exception occured:')
# print(e)
print(traceback.format_exc())
logging.error(traceback.format_exc())
filewriter = open(filesinerror, 'a')
filewriter.write(line)
filewriter.close()
logging.error("problem generate spectrum for:" + input_file)
nberror += 1
logging.info("{} generated successfully, {} not generated".format(nbsuccess, nberror))
logging.info('all product in error can be find in %s',filesinerror)
\ 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