Commit 2b4c0526 authored by Antoine Grouazel's avatar Antoine Grouazel

define a new noise for S1 Level-1 + py3 compat in urltimeseries mapper

parent 2a6f6783
......@@ -51,6 +51,15 @@ GDAL2NP = {'Byte': np.dtype(np.uint8),
'CFloat64': np.dtype(np.complex128)}
EARTHRADIUS = 6371009. # Mean earth radius [m]
noise_calibration_cst_pp1 = {'S1A':
{'wv1':{'EAPold':38.13,'EAPnew':38.13},
'wv2':{'EAPold':36.84,'EAPnew':np.nan}
},
'S1B':
{'wv1' : {'EAPold' : 39.30,'EAPnew' : 39.30},
'wv2' : {'EAPold' : 37.44,'EAPnew' : np.nan}
} #dB I removed the negative sign by purpose
} #given by pauline in https://jira-projects.cls.fr/browse/MPCS-2007
class SAFEGeoTiffFile(AbstractMapper):
"""
......@@ -547,27 +556,45 @@ class SAFEGeoTiffFile(AbstractMapper):
if '002.9' in ipf_version: #thre was a bug with noise vectors, Nuno suggested to use 36.8dB noise value instead (see https://jira-projects.cls.fr/browse/MPCS-1978 )
logging.debug('version IPF is special = %s',ipf_version)
# logging.info('%s',self._url)
if 'wv1' in self._url:
logging.debug('wv1')
cst = 10**(36.3/10) #this is a guess from Huimin, we are not sure this is the proper way to turn into linear the cst givne by Nuno (august 2019)
cst = 10**(37.9/10)
else:
logging.debug('wv2')
sat = os.path.basename(self._url)[0:3].upper()
start_date = datetime.strptime(os.path.basename(self._url).split('-')[4],'%Y%m%dt%H%M%S')
if sat=='S1A':
if start_date>=datetime(2019,2,28) and start_date<=datetime(2019,3,12):
cst = 10**(37./10) #wv2 optimised
else:
# cst = 10**(39.1/10) #wv2
cst = 10**(36.8/10) #wv2
elif sat=='S1B':
if start_date>=datetime(2019,5,14) and start_date<=datetime(2019,5,28):
cst = 10**(37./10) #wv2 optimised
else:
cst = 10**(36.8/10) #wv2
sat = os.path.basename(self._url)[0 :3].upper()
wv = os.path.basename(self._url).split('-')[1]
start_date = datetime.strptime(os.path.basename(self._url).split('-')[4],'%Y%m%dt%H%M%S')
if sat=='S1A':
if start_date>=datetime(2019,2,28) and start_date<=datetime(2019,3,12):
EAP = 'EAPnew'
else:
EAP = 'EAPold'
elif sat=='S1B':
if start_date>=datetime(2019,5,14) and start_date<=datetime(2019,5,28):
EAP = 'EAPnew' #optimised EAP
else:
raise Exception('satellite not yet taken into account for calibration')
EAP = 'EAPold'
else:
raise Exception('satellite not yet taken into account for calibration')
cst_noise = noise_calibration_cst_pp1[sat][wv][EAP]
cst = 10 ** (cst_noise / 10)
# if 'wv1' in self._url:
# logging.debug('wv1')
# cst = 10**(36.3/10) #this is a guess from Huimin, we are not sure this is the proper way to turn into linear the cst givne by Nuno (august 2019)
# cst = 10**(37.9/10)
# else:
# logging.debug('wv2')
#
#
# if sat=='S1A':
# if start_date>=datetime(2019,2,28) and start_date<=datetime(2019,3,12):
# cst = 10**(37./10) #wv2 optimised
# else:
# # cst = 10**(39.1/10) #wv2
# cst = 10**(36.8/10) #wv2
# elif sat=='S1B':
# if start_date>=datetime(2019,5,14) and start_date<=datetime(2019,5,28):
# cst = 10**(37./10) #wv2 optimised
# else:
# cst = 10**(36.8/10) #wv2
# else:
# raise Exception('satellite not yet taken into account for calibration')
luts = self._attributes['noise']
xval, yval = luts['line'], luts['pixel']
......
......@@ -6,6 +6,7 @@ import numpy
from dateutil import relativedelta
import pdb
import re
import sys
class URLSeries(object):
"""
......@@ -219,7 +220,7 @@ class URLSeries(object):
pattern_struct.append(pattern[0:i])
k = 0
while i != -1:
print i,k
print(i,k)
k = pattern.find('#',i+1)
code = pattern[k+1]
directive = pattern[i:k]
......@@ -271,7 +272,7 @@ class URLSeries(object):
ss = ss.replace('%S','??')
subpattern += ss
subpattern = subpattern.replace(anticode,'')
print "SUB : ", url, pattern, subpattern
logging.debug("SUB : %s %s %s", url, pattern, subpattern)
date = datetime.datetime.strptime( url,subpattern )
return date
_get_time_from_directives=classmethod(_get_time_from_directives)
......@@ -334,14 +335,13 @@ class URLSeries(object):
tcurrent = tstart
# print 'interval file start file end',tstart,fstart,fend,tend
if self.periodicity[-1] == 'S':
steprange = xrange( int(abs((tend-tstart).total_seconds()) / periodicity) + 1)
steprange = numpy.arange( int(abs((tend-tstart).total_seconds()) / periodicity) + 1)
# print 'steprange',steprange
elif self.periodicity[-1] == 'M':
difftime = relativedelta.relativedelta(tend, tstart)
difftime_in_month = difftime.years*12 + difftime.months
steprange = xrange(abs(difftime_in_month) / periodicity)
steprange = numpy.arange(abs(difftime_in_month) / periodicity)
for i in steprange:
# print 'tcurrent',tcurrent
f,t = self.get_url_for_time(tcurrent, 'exact', forbid_overlap=forbid_overlap )
if f is not None:
if type(f) == 'list':
......@@ -475,12 +475,14 @@ class URLSeries(object):
If times is not None, it will contains the corresponding list of
reference time associated with each found URL.
'''
logging.debug('chop')
print('test')
tmp = self._get_urllist_and_timesteps_in_interval(start, end, forbid_overlap=forbid_overlap ,unique_result=unique_result)
logging.debug('get_urllist_in_interval propose: %s',tmp)
# if times:
# del times[:]
# times.extend([t for u, t in tmp])
# logging.debug("Interval : %s", times)
logging.debug("Interval : %s", times)
if isinstance(tmp,list):
res = [u for u, t in tmp]
else:
......@@ -488,7 +490,10 @@ class URLSeries(object):
final_res = []
for uu in res:
if os.path.exists(uu):
logging.debug('ok %s exists',uu)
final_res.append(uu)
else:
logging.debug('%s doesnt exist',uu)
return final_res
def get_timesteps_in_interval(self,start, end,forbid_overlap=True):
......@@ -507,13 +512,13 @@ if __name__ == '__main__' :
timePattern={"%TIME":'%Y/%j/%Y%m%d'},periodicity="86400S", \
timeReference=datetime.datetime(2011,9,1,0) )
f = series.get_url_for_time(t, proximity='after')
print t, f
print(t, f)
t1 = datetime.datetime(2012,5,23,23,0,0)
t2 = datetime.datetime(2012,5,30,23,0,0)
files = series.getURLInTimeInterval( t1, t2 )
for f in files:
print f
print('f=',f)
......
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