Commit 9918165e authored by GROUAZEL's avatar GROUAZEL

change to prepare plot_spec_V3

parent fec0b4bb
*.pyc
.idea/
.settings/
.pydevproject
.project
......@@ -118,16 +118,16 @@ class SpectrumReaderBuoyGlobwave(AbstractSpectrumReader):
mymeta = spc.Meta(type=mode)
else:
mymeta = SpectrumReaderBuoyGlobwave.read_meta_cdip_globwave(ncf,index,mode)
return mymeta
return mymeta
@staticmethod
def read_meta_cdip_globwave(ncf,index,mode):
meta={}
meta={}
meta['type'] = mode
meta['wp'] = ncf.variables['dominant_wave_period'][index]
meta['dirp'] = np.squeeze(ncf.variables['dominant_wave_direction'][index])
meta['hst'] = np.squeeze(ncf.variables['significant_wave_height'][index])
meta['wp'] = ncf.variables['dominant_wave_period'][index]
meta['dirp'] = np.squeeze(ncf.variables['dominant_wave_direction'][index])
meta['hst'] = np.squeeze(ncf.variables['significant_wave_height'][index])
return meta
@staticmethod
......
This diff is collapsed.
import netCDF4
import sys
import logging
sys.path.append('/home1/datahome/agrouaze/git/mpc/graphics')
sys.path.append('/home1/datahome/agrouaze/git/mpc/qualitycheck')
sys.path.append('/home1/datahome/agrouaze/git/mpc/colocation')
sys.path.append('/home1/datahome/agrouaze/git/cerform')
sys.path.append('/home1/datahome/agrouaze/git/cfosat-calval-exe')
import Spectrum as spc
import os
from SpectrumReaderWW3 import SpectrumReaderWw3
from SpectrumReaderSentinel import SpectrumReaderSat
def do_simple_spectra(filepath1,title,dirout=None,mode='satfull'):
nc=netCDF4.Dataset(filepath1)
inst = SpectrumReaderSat()
spectra = inst.read_spectrum(nc,dataName=title,mode=mode)
# print(dir(spectra))
# print(spectra.spec_data.sp)
style0 = spc.init_spectrum_style(mode)
if False:
spectra.wind = None
# style = {'legendsize':20,'vmin':None,'vmax':None}
style = {'nrow':1,'ncolumn':1,'xsize':9,'ysize':6,
'titlecolor':"black", 'titlesize':20,'legendsize':11,'markersize':10,
'colormap':style0['colormap'], 'circleradius':[50,100,200,400],# 'legend_style':None,
'vmin':None,'vmax':None, 'colorbarTitle':'Spectral energy [$m^4$]',
'hs':1,'colorbarlabelfontsize':10,'annotationfontsize':15,'cutoff':50}
#spectra.show(style=style,cut_off=style['cutoff'])
# outputfile = os.path.join(dirout,os.path.basename(filepath1).replace('.nc','.eps'))
outputfile = os.path.join(dirout,mode+os.path.basename(filepath1).replace('.nc','.png'))
if True:
spectra.write(outputfile,showresult=False,style=style,
overwrite=True,dpi=500)
print("outputfile",outputfile)
def do_simple_spectra_ww3(filepath1,title,dirout=None,mode='ww3'):
nc=netCDF4.Dataset(filepath1)
inst = SpectrumReaderWw3()
spectra = inst.read_spectrum(nc,dataName=title,mode=mode,path=filepath1)
# print(dir(spectra))
# print(spectra.spec_data.sp)
style0 = spc.init_spectrum_style(mode)
#if False:
# spectra.wind = None
# style = {'legendsize':20,'vmin':None,'vmax':None}
style = {'nrow':1,'ncolumn':1,'xsize':9,'ysize':6,
'titlecolor':"black", 'titlesize':20,'legendsize':11,'markersize':10,
'colormap':style0['colormap'], 'circleradius':[50,100,200,400],# 'legend_style':None,
'vmin':None,'vmax':None, 'colorbarTitle':'Spectral energy [$m^4$]',
'hs':1,'colorbarlabelfontsize':10,'annotationfontsize':15,'cutoff':50}
#spectra.show(style=style,cut_off=style['cutoff'])
# outputfile = os.path.join(dirout,os.path.basename(filepath1).replace('.nc','.eps'))
outputfile = os.path.join(dirout,os.path.basename(filepath1).replace('.nc','.png'))
if True:
spectra.write(outputfile,showresult=False,style=style,
overwrite=True,dpi=500)
print("outputfile",outputfile)
if __name__ =='__main__':
import argparse
parser = argparse.ArgumentParser(description = 'my title')
parser.add_argument('--verbose',action = 'store_true',default = False)
args = parser.parse_args()
if args.verbose :
logging.basicConfig(level = logging.DEBUG,format = '%(asctime)s %(levelname)-5s %(message)s',
datefmt = '%d/%m/%Y %H:%M:%S')
else :
logging.basicConfig(level = logging.INFO,format = '%(asctime)s %(levelname)-5s %(message)s',
datefmt = '%d/%m/%Y %H:%M:%S')
filepath1 = '/home/datawork-cersat-public/project/mpc-sentinel1/data/esa/sentinel-1b/L2/WV/S1B_WV_OCN__2S/2020/060/S1B_WV_OCN__2SSV_20200229T020943_20200229T024440_020477_026CCB_86C0.SAFE/measurement/s1b-wv2-ocn-vv-20200229t024310-20200229t024313-020477-026ccb-138.nc'
datestr = os.path.basename(filepath1).split('-')[4]
dirout = '/tmp/testsp'
if False:
do_simple_spectra(filepath1,title='S1 OCN wave spectra\n %s'%datestr,dirout = dirout,mode = 'satfull')
do_simple_spectra(filepath1,title = 'S1 Re image spectra\n %s' % datestr,dirout = dirout,mode = 'satreal')
do_simple_spectra(filepath1,title = 'S1 Im image spectra\n %s' % datestr,dirout = dirout,mode = 'satimaginary')
ffww3 = '/home/cercache/project/mpc-sentinel1/data/colocation/sentinel-1b/sar-model/ww3spectra/201905/netCDF_L2_daily/20190502/ww3-wv1-ocn-vv-20190502t001225-20190502t001228-016057-01e33a-001.nc'
ffww3 = '/home/datawork-cersat-public/project/mpc-sentinel1/data/colocation/sentinel-1b/sar-model/ww3spectra/202002/netCDF_L2_daily/20200229/ww3-wv2-ocn-vv-20200229t024310-20200229t024313-020477-026ccb-138.nc'
do_simple_spectra_ww3(ffww3,'test ww3',dirout = dirout,mode = 'ww3')
\ No newline at end of file
......@@ -6,15 +6,22 @@ import Spectrum
# from SpectrumReader import SpectrumReader
# from SpectrumReaderSentinel import SpectrumReaderSat
from SpectrumReader_V2 import SpectrumReader
import SpectrumReader_V2
print('SpectrumReader_V2',SpectrumReader_V2.__file__)
import matplotlib
import spectrumUtil
import logging
import sys
import traceback
import os, socket
from datetime import datetime
import collections
import time
if __name__ == "__main__":
root = logging.getLogger()
if root.handlers:
for handler in root.handlers:
root.removeHandler(handler)
print("start generating Xspec png files")
import argparse
parser = argparse.ArgumentParser(description='generate png spectra')
......@@ -30,7 +37,7 @@ if __name__ == "__main__":
year = str(datetime.now().year)
month = str(datetime.now().month).zfill(2)
day = str(datetime.now().day).zfill(2)
filesinerror = '/home/cercache/project/mpc-sentinel1/analysis/s1_data_analysis/L2_V2/wavetools_error/' + year + month + day + '_filesinerror_' + socket.gethostname() + '_' + str(os.getpid()) + '.log'
filesinerror = '/home/datawork-cersat-public/project/mpc-sentinel1/analysis/s1_data_analysis/L2_V2/wavetools_error/' + year + month + day + '_filesinerror_' + socket.gethostname() + '_' + str(os.getpid()) + '.log'
if not os.path.exists(os.path.split(filesinerror)[0]):
os.makedirs(os.path.split(filesinerror)[0])
root = logging.getLogger()
......@@ -59,15 +66,17 @@ if __name__ == "__main__":
output_dir, filename = os.path.split(output_file)
output_file, extension = os.path.splitext(output_file)
if not os.path.exists(output_dir):
os.makedirs(output_dir, 0775)
os.makedirs(output_dir, 0o0775)
if os.path.exists(output_file+'.png') and args.overwrite:
os.remove(output_file+'.png')
currentSpectrum = SpectrumReader.read_spectrum(input_file, mode).write(output_file+'.png')#add .png at the end agrouaze august 2018 fix missing .png at the end of the filenames
instance = SpectrumReader()
print('gooo ninja')
currentSpectrum = instance.read_spectrum(input_file, mode).write(output_file+'.png')#add .png at the end agrouaze august 2018 fix missing .png at the end of the filenames
nbsuccess += 1
except Exception as e:
print('exception occured:')
print(e)
# print(e)
print(traceback.format_exc())
filewriter = open(filesinerror, 'a')
filewriter.write(line)
filewriter.close()
......
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