Skip to content

Commit f019bae

Browse files
committed
untested refactor to isolate noise loading from annotation
1 parent 2913b29 commit f019bae

File tree

5 files changed

+192
-267
lines changed

5 files changed

+192
-267
lines changed

src/s1reader/s1_annotation.py

Lines changed: 0 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -201,114 +201,6 @@ def from_et(cls, et_in: ET, path_annotation: str):
201201
return cls
202202

203203

204-
@dataclass
205-
class NoiseAnnotation(AnnotationBase):
206-
'''
207-
Reader for Noise Annotation Data Set (NADS) for IW SLC
208-
Based on ESA documentation: "Thermal Denoising of Products Generated by the S-1 IPF"
209-
'''
210-
211-
basename_annotation: str
212-
rg_list_azimuth_time: np.ndarray
213-
rg_list_line: list
214-
rg_list_pixel: list
215-
rg_list_noise_range_lut: list
216-
az_first_azimuth_line: int
217-
az_first_range_sample: int
218-
az_last_azimuth_line: int
219-
az_last_range_sample: int
220-
az_line: np.ndarray
221-
az_noise_azimuth_lut: np.ndarray
222-
223-
@classmethod
224-
def from_et(cls,et_in: ET, ipf_version: version.Version, path_annotation: str):
225-
'''
226-
Extracts list of noise information from etree
227-
228-
Parameter
229-
----------
230-
et_in : xml.etree.ElementTree
231-
Parsed NADS annotation .xml
232-
233-
Return
234-
-------
235-
cls: NoiseAnnotation
236-
Parsed NADS from et_in
237-
'''
238-
239-
cls.xml_et = et_in
240-
cls.basename_annotation = os.path.basename(path_annotation)
241-
242-
if ipf_version < min_ipf_version_az_noise_vector: # legacy SAFE data
243-
cls.rg_list_azimuth_time = \
244-
cls._parse_vectorlist('noiseVectorList',
245-
'azimuthTime',
246-
'datetime')
247-
cls.rg_list_line = \
248-
cls._parse_vectorlist('noiseVectorList',
249-
'line',
250-
'scalar_int')
251-
cls.rg_list_pixel = \
252-
cls._parse_vectorlist('noiseVectorList',
253-
'pixel',
254-
'vector_int')
255-
cls.rg_list_noise_range_lut = \
256-
cls._parse_vectorlist('noiseVectorList',
257-
'noiseLut',
258-
'vector_float')
259-
260-
cls.az_first_azimuth_line = None
261-
cls.az_first_range_sample = None
262-
cls.az_last_azimuth_line = None
263-
cls.az_last_range_sample = None
264-
cls.az_line = None
265-
cls.az_noise_azimuth_lut = None
266-
267-
else:
268-
cls.rg_list_azimuth_time = \
269-
cls._parse_vectorlist('noiseRangeVectorList',
270-
'azimuthTime',
271-
'datetime')
272-
cls.rg_list_line = \
273-
cls._parse_vectorlist('noiseRangeVectorList',
274-
'line',
275-
'scalar_int')
276-
cls.rg_list_pixel = \
277-
cls._parse_vectorlist('noiseRangeVectorList',
278-
'pixel',
279-
'vector_int')
280-
cls.rg_list_noise_range_lut = \
281-
cls._parse_vectorlist('noiseRangeVectorList',
282-
'noiseRangeLut',
283-
'vector_float')
284-
cls.az_first_azimuth_line = \
285-
cls._parse_vectorlist('noiseAzimuthVectorList',
286-
'firstAzimuthLine',
287-
'scalar_int')[0]
288-
cls.az_first_range_sample = \
289-
cls._parse_vectorlist('noiseAzimuthVectorList',
290-
'firstRangeSample',
291-
'scalar_int')[0]
292-
cls.az_last_azimuth_line = \
293-
cls._parse_vectorlist('noiseAzimuthVectorList',
294-
'lastAzimuthLine',
295-
'scalar_int')[0]
296-
cls.az_last_range_sample = \
297-
cls._parse_vectorlist('noiseAzimuthVectorList',
298-
'lastRangeSample',
299-
'scalar_int')[0]
300-
cls.az_line = \
301-
cls._parse_vectorlist('noiseAzimuthVectorList',
302-
'line',
303-
'vector_int')[0]
304-
cls.az_noise_azimuth_lut = \
305-
cls._parse_vectorlist('noiseAzimuthVectorList',
306-
'noiseAzimuthLut',
307-
'vector_float')[0]
308-
309-
return cls
310-
311-
312204
@dataclass
313205
class ProductAnnotation(AnnotationBase):
314206
'''
@@ -557,135 +449,6 @@ def closest_block_to_azimuth_time(vector_azimuth_time: np.ndarray,
557449
return np.argmin(np.abs(vector_azimuth_time-azimuth_time_burst))
558450

559451

560-
@dataclass
561-
class BurstNoise:
562-
'''Noise correction information for Sentinel-1 burst'''
563-
basename_nads: str
564-
range_azimith_time: datetime.datetime
565-
range_line: float
566-
range_pixel: np.ndarray
567-
range_lut: np.ndarray
568-
569-
azimuth_first_azimuth_line: int
570-
azimuth_first_range_sample: int
571-
azimuth_last_azimuth_line: int
572-
azimuth_last_range_sample: int
573-
azimuth_line: np.ndarray
574-
azimuth_lut: np.ndarray
575-
576-
line_from: int
577-
line_to: int
578-
579-
@classmethod
580-
def from_noise_annotation(cls, noise_annotation: NoiseAnnotation,
581-
azimuth_time: datetime.datetime,
582-
line_from: int,
583-
line_to: int,
584-
ipf_version: version.Version):
585-
'''
586-
Extracts the noise correction information for individual burst from NoiseAnnotation
587-
588-
Parameters
589-
----------
590-
noise_annotation: NoiseAnnotation
591-
Subswath-wide noise annotation information
592-
azimuth_time : datetime.datetime
593-
Azimuth time of the burst
594-
line_from: int
595-
First line of the burst in the subswath
596-
line_to: int
597-
Last line of the burst in the subswath
598-
ipf_version: float
599-
IPF version of the SAFE data
600-
601-
Returns
602-
-------
603-
cls: BurstNoise
604-
Instance of BurstNoise initialized by the input parameters
605-
606-
'''
607-
608-
basename_nads = noise_annotation.basename_annotation
609-
id_closest = closest_block_to_azimuth_time(noise_annotation.rg_list_azimuth_time,
610-
azimuth_time)
611-
612-
range_azimith_time = noise_annotation.rg_list_azimuth_time[id_closest]
613-
range_line = noise_annotation.rg_list_line[id_closest]
614-
range_pixel = noise_annotation.rg_list_pixel[id_closest]
615-
range_lut = noise_annotation.rg_list_noise_range_lut[id_closest]
616-
617-
azimuth_first_azimuth_line = noise_annotation.az_first_azimuth_line
618-
azimuth_first_range_sample = noise_annotation.az_first_range_sample
619-
azimuth_last_azimuth_line = noise_annotation.az_last_azimuth_line
620-
azimuth_last_range_sample = noise_annotation.az_last_range_sample
621-
622-
if ipf_version >= min_ipf_version_az_noise_vector:
623-
# Azimuth noise LUT exists - crop to the extent of the burst
624-
id_top = np.argmin(np.abs(noise_annotation.az_line-line_from))
625-
id_bottom = np.argmin(np.abs(noise_annotation.az_line-line_to))
626-
627-
# put some margin when possible
628-
if id_top > 0:
629-
id_top -= 1
630-
if id_bottom < len(noise_annotation.az_line)-1:
631-
id_bottom += 1
632-
azimuth_line = noise_annotation.az_line[id_top:id_bottom + 1]
633-
azimuth_lut = noise_annotation.az_noise_azimuth_lut[id_top:id_bottom + 1]
634-
635-
else:
636-
azimuth_line = None
637-
azimuth_lut = None
638-
639-
return cls(basename_nads, range_azimith_time, range_line, range_pixel, range_lut,
640-
azimuth_first_azimuth_line, azimuth_first_range_sample,
641-
azimuth_last_azimuth_line, azimuth_last_range_sample,
642-
azimuth_line, azimuth_lut,
643-
line_from, line_to)
644-
645-
646-
def compute_thermal_noise_lut(self, shape_lut):
647-
'''
648-
Calculate thermal noise LUT whose shape is `shape_lut`
649-
650-
Parameter:
651-
----------
652-
shape_lut: tuple or list
653-
Shape of the output LUT
654-
655-
Returns
656-
-------
657-
arr_lut_total: np.ndarray
658-
2d array containing thermal noise correction look up table values
659-
'''
660-
661-
nrows, ncols = shape_lut
662-
663-
# Interpolate the range noise vector
664-
rg_lut_interp_obj = InterpolatedUnivariateSpline(self.range_pixel,
665-
self.range_lut,
666-
k=1)
667-
if self.azimuth_last_range_sample is not None:
668-
vec_rg = np.arange(self.azimuth_last_range_sample + 1)
669-
else:
670-
vec_rg = np.arange(ncols)
671-
rg_lut_interpolated = rg_lut_interp_obj(vec_rg)
672-
673-
# Interpolate the azimuth noise vector
674-
if (self.azimuth_line is None) or (self.azimuth_lut is None):
675-
az_lut_interpolated = np.ones(nrows)
676-
else: # IPF >= 2.90
677-
az_lut_interp_obj = InterpolatedUnivariateSpline(self.azimuth_line,
678-
self.azimuth_lut,
679-
k=1)
680-
vec_az = np.arange(self.line_from, self.line_to + 1)
681-
az_lut_interpolated = az_lut_interp_obj(vec_az)
682-
683-
arr_lut_total = np.matmul(az_lut_interpolated[..., np.newaxis],
684-
rg_lut_interpolated[np.newaxis, ...])
685-
686-
return arr_lut_total
687-
688-
689452
@dataclass
690453
class BurstCalibration:
691454
'''Calibration information for Sentinel-1 IW SLC burst

0 commit comments

Comments
 (0)