diff --git a/src/s1reader/s1_burst_slc.py b/src/s1reader/s1_burst_slc.py index 2097243a..afc68f3b 100644 --- a/src/s1reader/s1_burst_slc.py +++ b/src/s1reader/s1_burst_slc.py @@ -527,45 +527,15 @@ def as_dict(self): self_as_dict[key] = val return self_as_dict + def _steps_to_vecs(self, range_step: float, az_step: float): + """Convert range_step (meters) and az_step (sec) into aranges to generate LUT2ds.""" + radargrid = self.as_isce3_radargrid(az_step=az_step, rg_step=range_step) + n_az, n_range = radargrid.shape - def _steps_to_vecs(self, range_step, az_step): - ''' convert range_step (meters) and az_step (seconds) into aranges to - generate LUT2ds - ''' - step_errs = [] - if range_step <= 0: - step_errs.append('range') - if az_step <= 0: - step_errs.append('azimuth') - if step_errs: - step_errs = ', '.join(step_errs) - err_str = f'Following step size(s) <=0: {step_errs}' - raise ValueError(err_str) - - # container to store names of axis vectors that are invalid: i.e. size 0 - vec_errs = [] - - # compute range vector - n_range = np.ceil(self.width * self.range_pixel_spacing / range_step).astype(int) range_vec = self.starting_range + np.arange(0, n_range) * range_step - if range_vec.size == 0: - vec_errs.append('range') - - # compute azimuth vector - n_az = np.ceil(self.length * self.azimuth_time_interval / az_step).astype(int) - rdrgrid = self.as_isce3_radargrid() - az_vec = rdrgrid.sensing_start + np.arange(0, n_az) * az_step - if az_vec.size == 0: - vec_errs.append('azimuth') - - if vec_errs: - vec_errs = ', '.join(vec_errs) - err_str = f'Cannot build aranges from following step(s): {vec_errs}' - raise ValueError(err_str) - + az_vec = radargrid.sensing_start + np.arange(0, n_az) * az_step return range_vec, az_vec - def bistatic_delay(self, range_step=1, az_step=1): '''Computes the bistatic delay correction in azimuth direction due to the movement of the platform between pulse transmission and echo reception @@ -752,8 +722,7 @@ def az_fm_rate_mismatch_mitigation(self, range_step=None, az_step=None, threshold_rdr2geo=1e-8, - numiter_rdr2geo=25, - custom_radargrid=None): + numiter_rdr2geo=25): ''' - Calculate Lon / Lat / Hgt in radar grid, to be used for the actual computation of az fm mismatch rate @@ -776,9 +745,6 @@ def az_fm_rate_mismatch_mitigation(self, Threshold of the iteration for rdr2geo numiter_rdr2geo: int Maximum number of iteration for rdr2geo - custom_radargrid: isce3.product.RadarGridParameters - ISCE3 radar grid to define the correction grid. - If None, the full resolution radargrid of the burst will be used. Return: ------- @@ -801,29 +767,7 @@ def az_fm_rate_mismatch_mitigation(self, os.makedirs(path_scratch, exist_ok=True) # define the radar grid to calculate az fm mismatch rate - correction_radargrid = self.as_isce3_radargrid() - if custom_radargrid is not None: - correction_radargrid = custom_radargrid - - # Override the radargrid definition if `rg_step` and `az_step` is defined - if range_step and az_step: - if custom_radargrid is not None: - warnings.warn('range_step and az_step assigned. ' - 'Overriding the custom radargrid definition.') - - width_radargrid, length_radargrid = \ - [vec.size for vec in self._steps_to_vecs(range_step, az_step)] - sensing_start_radargrid = self.as_isce3_radargrid().sensing_start - correction_radargrid = isce3.product.RadarGridParameters( - sensing_start_radargrid, - self.wavelength, - 1/az_step, - self.starting_range, - range_step, - isce3.core.LookSide.Right, - length_radargrid, - width_radargrid, - self.as_isce3_radargrid().ref_epoch) + correction_radargrid = self.as_isce3_radargrid(az_step=az_step, rg_step=range_step) # Run topo on scratch directory if not os.path.isfile(path_dem): diff --git a/tests/conftest.py b/tests/conftest.py index fc160ab0..abe8c906 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,7 @@ def test_paths(): test_paths.safe = f"{test_path}/data/S1A_IW_SLC__1SDV_20200511T135117_20200511T135144_032518_03C421_7768.zip" test_paths.orbit_dir = f"{test_path}/data/orbits" test_paths.orbit_file = "S1A_OPER_AUX_POEORB_OPOD_20210318T120818_V20200510T225942_20200512T005942.EOF" + test_paths.dem_file = f"{test_path}/data/dummy_dem.tif" return test_paths @@ -21,7 +22,6 @@ def bursts(test_paths): pol = 'vv' orbit_path = f'{test_paths.orbit_dir}/{test_paths.orbit_file}' - bursts = s1_reader.load_bursts(test_paths.safe, orbit_path, i_subswath, - pol) + bursts = s1_reader.load_bursts(test_paths.safe, orbit_path, i_subswath, pol) return bursts diff --git a/tests/data/dummy_dem.tif b/tests/data/dummy_dem.tif new file mode 100644 index 00000000..937230bf Binary files /dev/null and b/tests/data/dummy_dem.tif differ diff --git a/tests/test_corrections.py b/tests/test_corrections.py new file mode 100644 index 00000000..471a5cc9 --- /dev/null +++ b/tests/test_corrections.py @@ -0,0 +1,20 @@ +def test_correction_shapes(bursts, test_paths): + az_step, rg_step = 0.25, 200 + + for burst in bursts: + az_fm_mismatch = burst.az_fm_rate_mismatch_mitigation( + test_paths.dem_file, range_step=rg_step, az_step=az_step + ) + shape = (az_fm_mismatch.length, az_fm_mismatch.width) + + # Make sure the other two corrections have the same shape + geometrical_steering_doppler = burst.doppler_induced_range_shift( + range_step=rg_step, az_step=az_step + ) + assert shape == ( + geometrical_steering_doppler.length, + geometrical_steering_doppler.width, + ) + + bistatic_delay = burst.bistatic_delay(range_step=rg_step, az_step=az_step) + assert shape == (bistatic_delay.length, bistatic_delay.width)