Skip to content

Commit 53f0c43

Browse files
allow az_step/rg_step arguments to as_isce3_radargrid (#102)
* allow az_step/rg_step arguments to `as_isce3_radargrid` This allows a more coarse radar grid, as needed by some lookup tables such as the SET correction * Apply PRF suggestions from code review Co-authored-by: Heresh Fattahi <[email protected]> * adjust length/width based on az_step/rg_step * fix the logic for width/length calculation with rg/az_step * reversed order of length/width * add two tests for as_isce3_radar_grid fixed the division to make the tests pass * add clarification to docstring about sensing start --------- Co-authored-by: Heresh Fattahi <[email protected]>
1 parent 2b43f2f commit 53f0c43

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

src/s1reader/s1_burst_slc.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dataclasses import dataclass
33
import datetime
44
import tempfile
5+
from typing import Optional
56
import warnings
67
from packaging import version
78

@@ -263,18 +264,54 @@ def __str__(self):
263264
def __repr__(self):
264265
return f"{self.__class__.__name__}(burst_id={self.burst_id})"
265266

266-
def as_isce3_radargrid(self):
267+
def as_isce3_radargrid(self,
268+
az_step: Optional[float] = None,
269+
rg_step: Optional[float] = None):
267270
'''Init and return isce3.product.RadarGridParameters.
268271
269-
Returns:
270-
--------
272+
The `az_step` and `rg_step` parameters are used to construct a
273+
decimated grid. If not specified, the grid will be at the full radar
274+
resolution.
275+
Note that increasing the range/azimuth step size does not change the sensing
276+
start of the grid, as the grid is decimated rather than multilooked.
277+
278+
Parameters
279+
----------
280+
az_step : float, optional
281+
Azimuth step size in seconds. If not provided, the azimuth step
282+
size is set to the azimuth time interval.
283+
rg_step : float, optional
284+
Range step size in meters. If not provided, the range step size
285+
is set to the range pixel spacing.
286+
287+
Returns
288+
-------
271289
_ : RadarGridParameters
272290
RadarGridParameters constructed from class members.
273291
'''
274292

275-
prf = 1 / self.azimuth_time_interval
276-
277293
length, width = self.shape
294+
if az_step is None:
295+
az_step = self.azimuth_time_interval
296+
else:
297+
if az_step < 0:
298+
raise ValueError("az_step cannot be negative")
299+
length_in_seconds = length * self.azimuth_time_interval
300+
if az_step > length_in_seconds:
301+
raise ValueError("az_step cannot be larger than radar grid")
302+
length = int(length_in_seconds / az_step)
303+
304+
if rg_step is None:
305+
rg_step = self.range_pixel_spacing
306+
else:
307+
if rg_step < 0:
308+
raise ValueError("rg_step cannot be negative")
309+
width_in_meters = width * self.range_pixel_spacing
310+
if rg_step > width_in_meters:
311+
raise ValueError("rg_step cannot be larger than radar grid")
312+
width = int(width_in_meters / rg_step)
313+
314+
prf = 1 / az_step
278315

279316
time_delta = datetime.timedelta(days=2)
280317
ref_epoch = isce3.core.DateTime(self.sensing_start - time_delta)
@@ -286,7 +323,7 @@ def as_isce3_radargrid(self):
286323
self.wavelength,
287324
prf,
288325
self.starting_range,
289-
self.range_pixel_spacing,
326+
rg_step,
290327
isce3.core.LookSide.Right,
291328
length,
292329
width,

tests/test_bursts.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from datetime import timedelta
2+
13
import isce3
24
import numpy as np
35

46

7+
58
def test_burst(bursts):
69
last_valid_lines = [1487, 1489, 1489, 1490, 1487, 1488, 1488, 1489, 1488]
710
first_valid_lines = [28, 27, 27, 27, 28, 28, 28, 27, 28]
@@ -72,3 +75,39 @@ def test_burst(bursts):
7275
assert burst.azimuth_fm_rate.mean == 901673.89084624
7376
assert burst.azimuth_fm_rate.std == 149896229.0
7477
assert burst.azimuth_fm_rate.coeffs == az_fm_rate_poly1d_coeffs[i]
78+
79+
80+
def test_as_isce3_radargrid(bursts):
81+
for burst in bursts:
82+
grid = burst.as_isce3_radargrid()
83+
assert grid.width == burst.width
84+
assert grid.length == burst.length
85+
assert grid.starting_range == burst.starting_range
86+
dt = isce3.core.DateTime((burst.sensing_start - timedelta(days=2)))
87+
assert dt == grid.ref_epoch
88+
assert grid.prf == 1 / burst.azimuth_time_interval
89+
assert grid.range_pixel_spacing == burst.range_pixel_spacing
90+
assert str(grid.lookside) == 'LookSide.Right'
91+
assert grid.wavelength == burst.wavelength
92+
93+
94+
def test_as_isce3_radargrid_step_change(bursts):
95+
# Change the az_step, rg_step in .as_isce3_radargrid()
96+
burst = bursts[0]
97+
rg_step = burst.range_pixel_spacing
98+
az_step = burst.azimuth_time_interval
99+
grid = burst.as_isce3_radargrid(az_step=az_step, rg_step=rg_step)
100+
assert grid.width == burst.width
101+
assert grid.length == burst.length
102+
assert grid.prf == 1 / az_step
103+
104+
105+
rg_step *= 2
106+
grid = burst.as_isce3_radargrid(rg_step=rg_step)
107+
assert grid.width == burst.width // 2
108+
assert grid.length == burst.length
109+
110+
az_step *= 2
111+
grid = burst.as_isce3_radargrid(az_step=az_step)
112+
assert grid.width == burst.width
113+
assert grid.length == burst.length // 2

0 commit comments

Comments
 (0)