sct_paz_reader 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """SCT-Plugin: PAZ product format reader."""
5
+
6
+ __version__ = "1.0.0"
@@ -0,0 +1,36 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """PAZ SCT plugin interface."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from pathlib import Path
9
+ from typing import TYPE_CHECKING, Callable
10
+
11
+ from sct_paz_reader import __version__
12
+
13
+ if TYPE_CHECKING:
14
+ from sct.io.extended_protocols import ALECorrectionFunctionType, SCTInputProduct
15
+
16
+
17
+ class PAZProductPlugin:
18
+ """Plugin for PAZ product format"""
19
+
20
+ version = __version__
21
+
22
+ @classmethod
23
+ def get_manager(cls) -> type[SCTInputProduct]:
24
+ from sct_paz_reader.protocol_implementation import PAZProductManager
25
+
26
+ return PAZProductManager
27
+
28
+ @classmethod
29
+ def get_detector(cls) -> Callable[[str | Path], bool]:
30
+ from eo_products.terrasarx.utilities import is_terrasarx_product
31
+
32
+ return is_terrasarx_product
33
+
34
+ @classmethod
35
+ def get_ale_corrector(cls) -> ALECorrectionFunctionType:
36
+ return None
@@ -0,0 +1,885 @@
1
+ # SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ """PAZ format reader protocol-compliant wrapper for PERSEO-quality."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from itertools import product
9
+ from pathlib import Path
10
+
11
+ import numpy as np
12
+ from eo_products.common.utilities import DopplerEvaluator
13
+ from eo_products.terrasarx.reader import (
14
+ open_product,
15
+ read_channel_data,
16
+ read_product_metadata,
17
+ )
18
+ from eo_products.terrasarx.utilities import (
19
+ TERRASARXChannelMetadata,
20
+ TERRASARXProductVariant,
21
+ )
22
+ from numpy.typing import ArrayLike
23
+ from perseo_core.geometry import compute_ground_velocity, compute_incidence_angles, compute_look_angles
24
+ from perseo_core.geometry.geocoding import inverse_geocoding_monostatic
25
+ from perseo_core.geometry.navigation import Trajectory
26
+ from perseo_core.timing import PreciseDateTime
27
+ from perseo_quality.core.custom_errors import (
28
+ AzimuthExceedsBoundariesError,
29
+ CoordinatesOutOfBounds,
30
+ RangeExceedsBoundariesError,
31
+ )
32
+ from perseo_quality.core.generic_dataclasses import (
33
+ LocationData,
34
+ SARAcquisitionMode,
35
+ SARImageType,
36
+ SAROrbitDirection,
37
+ SARPolarization,
38
+ SARProjection,
39
+ SARRadiometricQuantity,
40
+ SARSamplingFrequencies,
41
+ SARSideLooking,
42
+ )
43
+ from perseo_quality.core.signal_processing import radiometric_correction
44
+ from scipy.constants import speed_of_light
45
+ from shapely import Polygon
46
+
47
+
48
+ class PAZDopplerPolynomial:
49
+ """PERSEO-quality Doppler Function protocol compliant PAZ doppler polynomial wrapper"""
50
+
51
+ def __init__(self, evaluator: DopplerEvaluator) -> None:
52
+ self._evaluator = evaluator
53
+
54
+ def evaluate(self, azimuth_time: PreciseDateTime, range_time: float) -> float:
55
+ """Evaluate the Doppler Polynomial at given azimuth and range times.
56
+
57
+ Parameters
58
+ ----------
59
+ azimuth_time : PreciseDateTime
60
+ azimuth time at which evaluate the polynomial
61
+ range_time : float
62
+ range time at which evaluate the polynomial
63
+
64
+ Returns
65
+ -------
66
+ float
67
+ doppler centroid at that time
68
+ """
69
+ return self._evaluator.evaluate(azimuth_time, range_time)
70
+
71
+
72
+ class PAZProductManager:
73
+ """SCTInputProduct protocol compliant PAZ wrapper"""
74
+
75
+ def __init__(self, path: str | Path, **kwargs) -> None:
76
+ self._path = Path(path)
77
+ self._name = self._path.name
78
+ self._product = open_product(path)
79
+ self._metadata = read_product_metadata(self._product.metadata_file)
80
+ region_corners = list(product(self._product.footprint[:2], self._product.footprint[2:]))
81
+ self._footprint = Polygon(region_corners).convex_hull
82
+
83
+ @property
84
+ def path(self) -> Path:
85
+ """Get product path"""
86
+ return self._path
87
+
88
+ @property
89
+ def name(self) -> str:
90
+ """Get product name"""
91
+ return self._name
92
+
93
+ @property
94
+ def footprint(self) -> Polygon:
95
+ """Get product footprint"""
96
+ return self._footprint
97
+
98
+ @property
99
+ def channels_list(self) -> list[str]:
100
+ """Get list of available channels for this product"""
101
+ return self._product.channels_list
102
+
103
+ def get_channel_data(self, channel_id: str) -> PAZChannelManager:
104
+ """Gathering all the information that are channel dependent and storing them in a protocol compliant object.
105
+
106
+ Parameters
107
+ ----------
108
+ channel_id : int
109
+ selected channel identifier
110
+
111
+ Returns
112
+ -------
113
+ PAZChannelManager
114
+ ChannelData-compliant object containing data corresponding to the selected channel
115
+ """
116
+ return PAZChannelManager(
117
+ channel_metadata=self._metadata[channel_id],
118
+ channel_raster_path=self._product.get_raster_files_from_channel_name(channel_id),
119
+ channel_name=channel_id,
120
+ )
121
+
122
+
123
+ class PAZChannelManager:
124
+ """PERSEO-quality ChannelData protocol compliant PAZ channel wrapper"""
125
+
126
+ def __init__(
127
+ self,
128
+ channel_metadata: TERRASARXChannelMetadata,
129
+ channel_raster_path: Path,
130
+ channel_name: str,
131
+ ) -> None:
132
+ """Creating a ChannelManager object compliant with the ChannelData protocol.
133
+
134
+ Parameters
135
+ ----------
136
+ channel_metadata : TERRASARXChannelMetadata
137
+ channel metadata dataclass
138
+ channel_raster_path : int
139
+ Path to the channel raster file
140
+ channel_name : int
141
+ name of current channel
142
+ """
143
+
144
+ self._channel_id = channel_name
145
+ self._raster_file = channel_raster_path
146
+ self._channel = channel_metadata
147
+ self._sensor_name = (
148
+ "" if self._channel.dataset_info.sensor_name is None else self._channel.dataset_info.sensor_name
149
+ )
150
+
151
+ self._radiometric_quantity = SARRadiometricQuantity[self._channel.image_radiometric_quantity.name]
152
+ self._prod_variant = TERRASARXProductVariant(self._channel.dataset_info.image_type)
153
+ self._polarization = SARPolarization(self._channel.polarization.value)
154
+ self._projection = SARProjection(self._channel.dataset_info.projection)
155
+ self._orbit_direction = SAROrbitDirection[self._channel.state_vectors.orbit_direction.name]
156
+ self._acquisition_mode = SARAcquisitionMode[self._channel.dataset_info.acquisition_mode.name]
157
+
158
+ self._range_step_m = self._compute_range_step_m()
159
+ self._looking_side = SARSideLooking(self._channel.dataset_info.side_looking.upper())
160
+
161
+ # lines per burst array
162
+ if self._channel.burst_info.num > 1:
163
+ self._lines_per_burst_array = self._channel.burst_info.lines_per_burst
164
+ else:
165
+ # should be a 1D array
166
+ self._lines_per_burst_array = np.repeat(self._channel.raster_info.lines.length, 1)
167
+ # compute axes
168
+ if self._channel.burst_info.num > 1:
169
+ self._azimuth_axis = np.concat(
170
+ [
171
+ np.arange(0, lines) * self._channel.raster_info.lines.step + az_start
172
+ for az_start, lines in zip(
173
+ self._channel.burst_info.azimuth_start_times,
174
+ self._channel.burst_info.lines_per_burst,
175
+ strict=True,
176
+ )
177
+ ]
178
+ )
179
+ else:
180
+ self._azimuth_axis = self._channel.raster_info.lines.axis
181
+
182
+ self._az_time_half_swath = self._azimuth_axis[self._azimuth_axis.size // 2]
183
+ self._range_axis = self._channel.raster_info.samples.axis
184
+ self._slant_range_axis = self._compute_slant_range_axis()
185
+ rng_time_half_swath = (
186
+ self._channel.raster_info.samples.start
187
+ + (self._channel.raster_info.samples.length - 1) * self._channel.raster_info.samples.step / 2
188
+ )
189
+ if self._projection == SARProjection.GROUND_RANGE:
190
+ rng_time_half_swath = self._channel.coordinate_conversions.evaluate_ground_to_slant(
191
+ azimuth_time=self._az_time_half_swath,
192
+ ground_range=np.floor(rng_time_half_swath),
193
+ )
194
+ self._rng_time_half_swath = rng_time_half_swath
195
+
196
+ # prf
197
+ self._prf = self._channel.swath_info.prf
198
+
199
+ # steering rate
200
+ self._steering_rate_poly_coeff = self._channel.swath_info.azimuth_steering_rate_poly
201
+
202
+ # trajectory
203
+ self._trajectory_rx = self._channel.state_vectors.orbit
204
+ self._trajectory_tx = None
205
+
206
+ # generating doppler centroid wrappers
207
+ self._doppler_centroid_poly = PAZDopplerPolynomial(evaluator=self._channel.doppler_centroid_poly)
208
+
209
+ # get burst boundaries
210
+ self._burst_az_boundaries, self._burst_rng_boundaries = self._get_raster_layout()
211
+
212
+ self._corrected_calibration_constant = self._channel.image_calibration_factor
213
+
214
+ def _compute_slant_range_axis(self) -> np.ndarray:
215
+ """Computing slant range full axis.
216
+
217
+ Returns
218
+ -------
219
+ np.ndarray
220
+ slant range axis
221
+ """
222
+ slant_rng_axis = self._range_axis
223
+ if self._projection == SARProjection.GROUND_RANGE:
224
+ slant_rng_axis = self._channel.coordinate_conversions.evaluate_ground_to_slant(
225
+ azimuth_time=self._az_time_half_swath, ground_range=self._range_axis
226
+ )
227
+
228
+ return slant_rng_axis
229
+
230
+ def _compute_range_step_m(self) -> float:
231
+ """Computing step along range direction, in meters"""
232
+ if self._channel.raster_info.samples.step_unit == "m":
233
+ return self._channel.raster_info.samples.step
234
+ return self._channel.raster_info.samples.step * speed_of_light / 2
235
+
236
+ def _get_raster_layout(self) -> tuple[list[PreciseDateTime], list[float]]:
237
+ """Evaluating raster boundaries taking into account the bursts, if needed.
238
+
239
+ Returns
240
+ -------
241
+ tuple[list[list[PreciseDateTime, PreciseDateTime]], list[list[float, float]]]
242
+ azimuth raster boundaries (azimuth start, azimuth stop),
243
+ range raster boundaries (range start, range stop)
244
+ """
245
+
246
+ if self._channel.burst_info.num > 1:
247
+ az_times = self._channel.burst_info.azimuth_start_times
248
+ rng_times = np.repeat(self._channel.raster_info.samples.start, az_times.size)
249
+ burst_az_boundaries = []
250
+ for az_id, az_time in enumerate(az_times):
251
+ burst_az_boundaries.append(
252
+ [
253
+ az_time,
254
+ az_time
255
+ + (self._channel.burst_info.lines_per_burst[az_id] * self._channel.raster_info.lines.step),
256
+ ]
257
+ )
258
+ burst_rng_boundaries = []
259
+ for rng_time in rng_times:
260
+ burst_rng_boundaries.append(
261
+ [
262
+ rng_time,
263
+ rng_time + self._channel.raster_info.samples.length * self._channel.raster_info.samples.step,
264
+ ]
265
+ )
266
+ else:
267
+ burst_az_boundaries = [
268
+ [
269
+ self._channel.raster_info.lines.start,
270
+ self._channel.raster_info.lines.start
271
+ + self._channel.raster_info.lines.length * self._channel.raster_info.lines.step,
272
+ ]
273
+ ]
274
+ burst_rng_boundaries = [
275
+ [
276
+ self._channel.raster_info.samples.start,
277
+ self._channel.raster_info.samples.start
278
+ + self._channel.raster_info.samples.length * self._channel.raster_info.samples.step,
279
+ ]
280
+ ]
281
+
282
+ return burst_az_boundaries, burst_rng_boundaries
283
+
284
+ @property
285
+ def sensor_name(self) -> str:
286
+ """Name of the sensor"""
287
+ return self._sensor_name
288
+
289
+ @property
290
+ def swath_name(self) -> str:
291
+ """Name of the swath being analyzed"""
292
+ return self._channel.swath_info.swath
293
+
294
+ @property
295
+ def channel_id(self) -> str:
296
+ """Identifier of current channel data"""
297
+ return self._channel_id
298
+
299
+ @property
300
+ def prf(self) -> float:
301
+ """Sensor Pulse Repetition Frequency (PRF)"""
302
+ return self._prf
303
+
304
+ @property
305
+ def range_step_m(self) -> float:
306
+ """Step along range direction, in meters"""
307
+ return self._range_step_m
308
+
309
+ @property
310
+ def azimuth_step_s(self) -> float:
311
+ """Step along azimuth direction, in seconds"""
312
+ return self._channel.raster_info.lines.step
313
+
314
+ @property
315
+ def projection(self) -> SARProjection:
316
+ """Channel data projection"""
317
+ return self._projection
318
+
319
+ @property
320
+ def polarization(self) -> SARPolarization:
321
+ """Channel data polarization"""
322
+ return self._polarization
323
+
324
+ @property
325
+ def acquisition_mode(self) -> SARAcquisitionMode:
326
+ """Channel data acquisition mode"""
327
+ return self._acquisition_mode
328
+
329
+ @property
330
+ def orbit_direction(self) -> SAROrbitDirection:
331
+ """Channel data orbit direction"""
332
+ return self._orbit_direction
333
+
334
+ @property
335
+ def image_type(self) -> SARImageType:
336
+ """Channel raster image type"""
337
+ return self._prod_variant
338
+
339
+ @property
340
+ def sampling_constants(self) -> SARSamplingFrequencies:
341
+ """Channel data signal sampling frequencies"""
342
+ return None # TODO: self._channel.sampling_constants
343
+
344
+ @property
345
+ def looking_side(self) -> SARSideLooking:
346
+ """Sensor look direction for this channel"""
347
+ return self._looking_side
348
+
349
+ @property
350
+ def carrier_frequency(self) -> float:
351
+ """Signal carrier frequency"""
352
+ return self._channel.dataset_info.fc_hz
353
+
354
+ @property
355
+ def mid_azimuth_time(self) -> PreciseDateTime:
356
+ """Azimuth time at half swath"""
357
+ return self._az_time_half_swath
358
+
359
+ @property
360
+ def trajectory(self) -> Trajectory:
361
+ """Channel trajectory rx 3D curve"""
362
+ return self._trajectory_rx
363
+
364
+ @property
365
+ def attitude(self) -> None:
366
+ """Channel attitude defined in ECEF Reference Frame"""
367
+ return None
368
+
369
+ @property
370
+ def doppler_centroid(self) -> PAZDopplerPolynomial:
371
+ """Channel doppler centroid polynomial wrapper"""
372
+ return self._doppler_centroid_poly
373
+
374
+ @property
375
+ def doppler_rate(self) -> None:
376
+ """Channel doppler rate polynomial wrapper"""
377
+ return None
378
+
379
+ @property
380
+ def mid_range_time(self) -> float:
381
+ """Range time at half swath"""
382
+ return self._rng_time_half_swath
383
+
384
+ @property
385
+ def range_axis(self) -> np.ndarray:
386
+ """Range axis"""
387
+ return self._range_axis
388
+
389
+ @property
390
+ def slant_range_axis(self) -> np.ndarray:
391
+ """Range axis"""
392
+ return self._slant_range_axis
393
+
394
+ @property
395
+ def azimuth_axis(self) -> np.ndarray:
396
+ """Azimuth axis, PreciseDateTime format"""
397
+ return self._azimuth_axis
398
+
399
+ @property
400
+ def lines_per_burst(self) -> np.ndarray:
401
+ """Lines per burst, for each burst in the swath"""
402
+ return self._lines_per_burst_array
403
+
404
+ @property
405
+ def radiometric_quantity(self) -> np.ndarray:
406
+ """Product radiometric quantity"""
407
+ return self._radiometric_quantity
408
+
409
+ def get_mid_burst_times(self, burst: int) -> tuple[PreciseDateTime, float]:
410
+ """Compute mid azimuth and range times for a given burst.
411
+
412
+ Parameters
413
+ ----------
414
+ burst : int
415
+ burst for which azimuth and range times are computed
416
+
417
+ Returns
418
+ -------
419
+ tuple[PreciseDateTime, float]
420
+ azimuth and range mid burst times
421
+ """
422
+ az_mid_burst = self.mid_azimuth_time
423
+ rng_mid_burst = self.mid_range_time
424
+ if self._channel.burst_info.num > 1:
425
+ az_time_boundaries, rng_time_boundaries = self._get_raster_layout()
426
+ az_mid_burst = (az_time_boundaries[burst][1] - az_time_boundaries[burst][0]) / 2 + az_time_boundaries[
427
+ burst
428
+ ][0]
429
+ rng_mid_burst = (rng_time_boundaries[burst][1] - rng_time_boundaries[burst][0]) / 2 + rng_time_boundaries[
430
+ burst
431
+ ][0]
432
+
433
+ return az_mid_burst, rng_mid_burst
434
+
435
+ def get_steering_rate(self, azimuth_time: PreciseDateTime, burst: int) -> float:
436
+ """Compute steering rate at a given azimuth time and for a given burst.
437
+
438
+ Parameters
439
+ ----------
440
+ azimuth_time : PreciseDateTime
441
+ azimuth time
442
+ burst : int
443
+ burst corresponding to the input time
444
+
445
+ Returns
446
+ -------
447
+ float
448
+ azimuth steering rate
449
+ """
450
+ if self._channel.burst_info.num > 1 and burst is not None:
451
+ time_rel = azimuth_time - self._channel.burst_info.azimuth_start_times[burst]
452
+ else:
453
+ time_rel = azimuth_time - self._channel.raster_info.lines.start
454
+ return (
455
+ self._steering_rate_poly_coeff[0]
456
+ + self._steering_rate_poly_coeff[1] * time_rel
457
+ + self._steering_rate_poly_coeff[2] * time_rel**2
458
+ )
459
+
460
+ def get_location_data(self, azimuth_time: PreciseDateTime, range_time: float) -> LocationData:
461
+ """Generating a LocationData object containing data and info derived from the current PAZChannelManager
462
+ and declined to the specific azimuth and range times selected.
463
+
464
+ Parameters
465
+ ----------
466
+ azimuth_time : PreciseDateTime
467
+ selected azimuth time
468
+ range_time : float
469
+ selected range time
470
+
471
+ Returns
472
+ -------
473
+ LocationData
474
+ LocationData instance related to the selected location
475
+ """
476
+
477
+ incidence_angle = compute_incidence_angles(
478
+ trajectory=self.trajectory,
479
+ azimuth_time=azimuth_time,
480
+ range_times=range_time,
481
+ look_direction=self.looking_side.value,
482
+ )
483
+ look_angle = compute_look_angles(
484
+ trajectory=self.trajectory,
485
+ azimuth_time=azimuth_time,
486
+ range_times=self.mid_range_time,
487
+ look_direction=self.looking_side.value,
488
+ )
489
+ v_ground = compute_ground_velocity(
490
+ trajectory=self.trajectory,
491
+ azimuth_time=azimuth_time,
492
+ look_angles_rad=look_angle,
493
+ )
494
+ azimuth_step_m = self.azimuth_step_s * v_ground
495
+
496
+ if self.projection == SARProjection.SLANT_RANGE:
497
+ ground_range_step_m: float = self.range_step_m / np.sin(incidence_angle)
498
+ range_step_m = self.range_step_m
499
+ elif self.projection == SARProjection.GROUND_RANGE:
500
+ ground_range_step_m: float = self.range_step_m
501
+ range_step_m = self.range_step_m * np.sin(incidence_angle)
502
+
503
+ return LocationData(
504
+ abs_azimuth_time=azimuth_time,
505
+ abs_range_time=range_time,
506
+ incidence_angle=incidence_angle,
507
+ look_angle=look_angle,
508
+ ground_velocity=v_ground,
509
+ azimuth_step_m=azimuth_step_m,
510
+ range_step_m=range_step_m,
511
+ ground_range_step_m=ground_range_step_m,
512
+ )
513
+
514
+ def pixel_to_times_conversion(
515
+ self, azimuth_index: float, range_index: float, burst: int = None
516
+ ) -> tuple[PreciseDateTime, float]:
517
+ """Converting input raster pixel coordinates (azimuth_index and range index) to corresponding absolute times,
518
+ azimuth and range.
519
+
520
+ Parameters
521
+ ----------
522
+ azimuth_index : float
523
+ azimuth pixel index, subpixel precision
524
+ range_index : float
525
+ range pixel index, subpixel precision
526
+ burst : int, optional
527
+ burst index, by default None
528
+
529
+ Returns
530
+ -------
531
+ PreciseDateTime
532
+ azimuth time
533
+ float
534
+ range time
535
+ """
536
+
537
+ start_time_rng = self._channel.raster_info.samples.start
538
+ if self._channel.burst_info.num > 1 and burst is not None:
539
+ start_time_az = self._channel.burst_info.azimuth_start_times[burst]
540
+ az_time = (
541
+ azimuth_index - self._channel.burst_info.lines_per_burst[burst] * burst
542
+ ) * self._channel.raster_info.lines.step + start_time_az
543
+ else:
544
+ start_time_az = self._channel.raster_info.lines.start
545
+ az_time = azimuth_index * self._channel.raster_info.lines.step + start_time_az
546
+
547
+ rng_time = range_index * self._channel.raster_info.samples.step + start_time_rng
548
+
549
+ if self.projection == SARProjection.GROUND_RANGE:
550
+ rng_time = self._channel.coordinate_conversions.evaluate_ground_to_slant(
551
+ azimuth_time=self.mid_azimuth_time, ground_range=rng_time
552
+ )
553
+
554
+ return az_time, rng_time
555
+
556
+ def times_to_pixel_conversion(
557
+ self, azimuth_time: PreciseDateTime, range_time: float, burst: int = None
558
+ ) -> tuple[float, float]:
559
+ """Converting azimuth and range times to raster image pixels indexes with subpixel precision.
560
+
561
+ Parameters
562
+ ----------
563
+ azimuth_time : PreciseDateTime
564
+ azimuth time
565
+ range_time : float
566
+ range time
567
+ burst : int
568
+ burst number corresponding to these times
569
+
570
+ Returns
571
+ -------
572
+ float
573
+ pixel corresponding to azimuth time
574
+ float
575
+ pixel corresponding to range time
576
+ """
577
+
578
+ rng_value = range_time
579
+ if self.projection == SARProjection.GROUND_RANGE:
580
+ # if projection is GROUND RANGE, range info are expressed in meters, so it must be converted
581
+ rng_value = self._channel.coordinate_conversions.evaluate_slant_to_ground(
582
+ azimuth_time=azimuth_time, slant_range=range_time
583
+ )
584
+
585
+ rng_idx = (rng_value - self._channel.raster_info.samples.start) / self._channel.raster_info.samples.step
586
+ if self._channel.burst_info.num > 1:
587
+ if burst is None:
588
+ burst = self.times_to_burst_association([azimuth_time])[0]
589
+ azmth_idx = (
590
+ azimuth_time - self._channel.burst_info.azimuth_start_times[burst]
591
+ ) / self._channel.raster_info.lines.step + self._channel.burst_info.lines_per_burst[burst] * burst
592
+ else:
593
+ azmth_idx = (azimuth_time - self._channel.raster_info.lines.start) / self._channel.raster_info.lines.step
594
+
595
+ return azmth_idx, rng_idx
596
+
597
+ def times_to_burst_association(self, azimuth_times: ArrayLike) -> list[int]:
598
+ """Associate the right burst to a given input time point. This function returns 1 association for each
599
+ input time.
600
+ Associating time only to the first burst containing it.
601
+
602
+ Parameters
603
+ ----------
604
+ azimuth_times : ArrayLike
605
+ azimuth time array in PreciseDateTime format
606
+
607
+ Returns
608
+ -------
609
+ list[int]
610
+ burst associated with a given time
611
+
612
+ Raises
613
+ ------
614
+ CoordinatesOutOfBounds
615
+ if input time exceeds tme boundaries of the swath
616
+ """
617
+ if self._channel.burst_info is None:
618
+ return [0] * len(azimuth_times)
619
+
620
+ bursts_start_times = self._channel.burst_info.azimuth_start_times
621
+ last_time = (
622
+ bursts_start_times[0]
623
+ + self._channel.burst_info.num
624
+ * self._channel.burst_info.lines_per_burst
625
+ * self._channel.raster_info.lines.step
626
+ )
627
+
628
+ bursts = []
629
+ for time in azimuth_times:
630
+ if time < bursts_start_times[0] or time > last_time:
631
+ raise CoordinatesOutOfBounds(f"{time} is out of the recorded timeline")
632
+
633
+ time_diff = time - bursts_start_times
634
+ time_mask = np.ma.masked_less(time_diff.astype("float64"), 0)
635
+ # associating time only to the first burst containing it
636
+ bursts.append(time_mask.argmin())
637
+
638
+ return bursts
639
+
640
+ def pixel_to_burst_association(self, azimuth_px_indexes: ArrayLike) -> list[int]:
641
+ """Associate the azimuth pixel value to the right burst. This function returns 1 association for each
642
+ input time.
643
+
644
+ Parameters
645
+ ----------
646
+ azimuth_px_indexes : ArrayLike
647
+ azimuth pixel indexes array
648
+
649
+ Returns
650
+ -------
651
+ list[int]
652
+ burst associated with a given pixel index
653
+
654
+ Raises
655
+ ------
656
+ CoordinatesOutOfBounds
657
+ if input time exceeds tme boundaries of the swath
658
+ """
659
+ if self._channel.burst_info is None:
660
+ return [0] * len(azimuth_px_indexes)
661
+
662
+ bursts_lines = np.repeat(self._channel.burst_info.lines_per_burst, self._channel.burst_info.num)
663
+ burst_boundaries = np.array([0] + [sum(bursts_lines[: t + 1]) for t, _ in enumerate(bursts_lines)])
664
+
665
+ bursts = []
666
+ for coord in azimuth_px_indexes:
667
+ if coord > burst_boundaries[-1]:
668
+ raise CoordinatesOutOfBounds(f"{coord} pixel exceeds swath's bounds")
669
+
670
+ px_diff = coord - burst_boundaries
671
+ px_mask = np.ma.masked_less(px_diff, 0)
672
+
673
+ bursts.append(px_mask.argmin())
674
+
675
+ return bursts
676
+
677
+ def ground_points_to_burst_association(self, coordinates: ArrayLike) -> list[list[int] | None]:
678
+ """Determining the burst (or bursts) where the input coordinates lie. If no association can be found (i.e. the
679
+ point is not visible in the scene), None is returned.
680
+
681
+ Parameters
682
+ ----------
683
+ coordinates : ArrayLike
684
+ array of coordinates, in the form (N, 3)
685
+
686
+ Returns
687
+ -------
688
+ list[list[int] | None]
689
+ list containing the burst association for each input point, None if no association was found
690
+ """
691
+
692
+ coordinates = np.atleast_2d(coordinates)
693
+
694
+ t_azmth, t_rng = [], []
695
+ for coord in coordinates:
696
+ try:
697
+ t_azmth_i, t_rng_i = inverse_geocoding_monostatic(
698
+ trajectory=self.trajectory,
699
+ ground_points=coord,
700
+ doppler_frequencies=0,
701
+ wavelength=1,
702
+ az_initial_time_guesses=self.mid_azimuth_time,
703
+ )
704
+ t_azmth.append(t_azmth_i)
705
+ t_rng.append(t_rng_i)
706
+ except Exception:
707
+ t_azmth.append(np.nan)
708
+ t_rng.append(np.nan)
709
+
710
+ t_azmth = np.asarray(t_azmth)
711
+ t_rng = np.asarray(t_rng)
712
+
713
+ az_check = [
714
+ (
715
+ [(t < az[1] and t > az[0]) for az in self._burst_az_boundaries]
716
+ if isinstance(t, PreciseDateTime)
717
+ else [False]
718
+ )
719
+ for t in t_azmth
720
+ ]
721
+ rng_check = [
722
+ [(t < rng[1] and t > rng[0]) for rng in self._burst_rng_boundaries] if ~np.isnan(t) else [False]
723
+ for t in t_rng
724
+ ]
725
+ check = [np.logical_and(az_check[c], rng_check[c]) for c in range(len(az_check))]
726
+
727
+ bursts = [list(np.where(c)[0]) if c.any() else None for c in check]
728
+
729
+ return bursts
730
+
731
+ def read_data(
732
+ self,
733
+ azimuth_index: float,
734
+ range_index: float,
735
+ cropping_size: tuple[int, int] = (150, 150),
736
+ output_radiometric_quantity: SARRadiometricQuantity = SARRadiometricQuantity.BETA_NOUGHT,
737
+ burst: int | None = None,
738
+ ) -> np.ndarray:
739
+ """Extracting the swath portion centered to the provided target position and of size cropping_size by
740
+ cropping_size. Target position is provided via its azimuth and range indexes in the swath array.
741
+
742
+ Parameters
743
+ ----------
744
+ azimuth_index : float
745
+ index of azimuth time in swath array
746
+ range_index : float
747
+ index of range time in swath array
748
+ cropping_size : tuple[int, int], optional
749
+ size in pixel of the swath portion to be read (number of samples, number of lines), by default (150, 150)
750
+ output_radiometric_quantity : SARRadiometricQuantity, optional
751
+ selected output radiometric quantity to convert the read data to, if needed,
752
+ by default SARRadiometricQuantity.BETA_NOUGHT
753
+ burst : int, optional
754
+ if burst is provided, the roi extraction gives error if the boundaries exceed the burst boundaries,
755
+ by default None
756
+
757
+ Returns
758
+ -------
759
+ np.ndarray
760
+ cropped swath array centered to the input target coordinates, output array is (samples, lines)
761
+ by default the output radiometric quantity is BETA_NOUGHT, unless specified otherwise
762
+
763
+ Raises
764
+ ------
765
+ AzimuthExceedsBoundariesError
766
+ azimuth index exceeds swath boundaries
767
+ RangeExceedsBoundariesError
768
+ range index exceeds swath boundaries
769
+ """
770
+
771
+ # creating the target block identifier for partial swath reading
772
+ # [start line, start sample, number of lines, number of samples]
773
+ target_block = [
774
+ azimuth_index - np.floor(cropping_size[1] / 2).astype(int),
775
+ range_index - np.floor(cropping_size[0] / 2).astype(int),
776
+ cropping_size[1],
777
+ cropping_size[0],
778
+ ]
779
+
780
+ # full raster boundaries and burst boundaries, if applicable
781
+ raster_boundaries = [
782
+ 0,
783
+ 0,
784
+ self._channel.raster_info.lines.length,
785
+ self._channel.raster_info.samples.length,
786
+ ]
787
+ burst_boundaries = None
788
+ # if burst is provided, it means that the ROI to be read must be inside of this burst, otherwise the extracted
789
+ # data are not meaningful with respect to times, acquisition consistency and IRF
790
+ if burst is not None:
791
+ burst_boundaries = [
792
+ sum(self.lines_per_burst[:burst]),
793
+ 0,
794
+ self.lines_per_burst[burst],
795
+ self._channel.raster_info.samples.length,
796
+ ]
797
+
798
+ # validating target block extraction with respect to raster boundaries and burst boundaries
799
+ custom_roi_validation(
800
+ roi=target_block,
801
+ raster_boundaries=(
802
+ [0, 0, sum(self.lines_per_burst), self._channel.raster_info.samples.length]
803
+ if self.lines_per_burst.size > 1
804
+ else raster_boundaries
805
+ ),
806
+ burst_boundaries=burst_boundaries,
807
+ check_raster_only=True if self.lines_per_burst.size > 1 else False,
808
+ )
809
+
810
+ # reading data portion and switching to convention (samples, lines) with transpose
811
+ data = read_channel_data(
812
+ raster_file=self._raster_file,
813
+ block_to_read=target_block,
814
+ burst_info=self._channel.burst_info,
815
+ scaling_conversion=self._corrected_calibration_constant,
816
+ ).T
817
+
818
+ # converting to beta nought if radiometric quantity is different
819
+ if self._radiometric_quantity != output_radiometric_quantity:
820
+ azimuth_time, _ = self.pixel_to_times_conversion(azimuth_index=azimuth_index, range_index=range_index)
821
+ incidence_angles_rad = compute_incidence_angles(
822
+ trajectory=self.trajectory,
823
+ azimuth_time=azimuth_time,
824
+ range_times=self._slant_range_axis[target_block[1] : target_block[1] + target_block[3]],
825
+ look_direction=self.looking_side.value,
826
+ )
827
+ data = radiometric_correction(
828
+ data=data,
829
+ incidence_angle=incidence_angles_rad,
830
+ input_quantity=self._radiometric_quantity,
831
+ output_quantity=output_radiometric_quantity,
832
+ )
833
+
834
+ return data
835
+
836
+
837
+ def custom_roi_validation(
838
+ roi: list[int, int, int, int],
839
+ raster_boundaries: list[int, int, int, int],
840
+ check_raster_only: bool = False,
841
+ burst_boundaries: list[int, int, int, int] | None = None,
842
+ ) -> None:
843
+ """Validating the region of interest to be read from raster.
844
+
845
+ Parameters
846
+ ----------
847
+ roi : list[int, int, int, int]
848
+ [reading start line, reading start sample, number of lines to be read, number of samples to be read]
849
+ raster_boundaries : list[int, int, int, int]
850
+ [0, 0, raster number of lines, raster number of samples]
851
+ check_raster_only: bool
852
+ if True check only raster, by default False
853
+ burst_boundaries : list[int, int, int, int] | None, optional
854
+ [current burst starting line, current burst starting sample, lines of current burst, samples of current burst],
855
+ if None no validation against burst boundaries is performed, by default None
856
+
857
+ Raises
858
+ ------
859
+ AzimuthExceedsBoundariesError
860
+ if roi boundaries exceed raster or burst azimuth boundaries
861
+ RangeExceedsBoundariesError
862
+ ir roi boundaries exceed raster or burst range boundaries
863
+ """
864
+
865
+ if roi[0] >= raster_boundaries[2] or roi[0] < 0:
866
+ # starting azimuth line to be read is out of azimuth swath boundaries
867
+ raise AzimuthExceedsBoundariesError(f"First ROI line {roi[0]} exceeds azimuth swath boundaries")
868
+ if roi[0] + roi[2] > raster_boundaries[2]:
869
+ # last azimuth line to be read is out of azimuth swath boundaries
870
+ raise AzimuthExceedsBoundariesError(f"Last ROI line {roi[0] + roi[2]} exceeds azimuth swath boundaries")
871
+ if roi[1] >= raster_boundaries[3] or roi[1] < 0:
872
+ # starting range sample to be read is out of range swath boundaries
873
+ raise RangeExceedsBoundariesError(f"First ROI sample {roi[1]} exceeds range swath boundaries")
874
+ if roi[1] + roi[3] > raster_boundaries[3]:
875
+ # last range sample to be read is out of range swath boundaries
876
+ raise RangeExceedsBoundariesError(f"Last ROI sample {roi[1] + roi[3]} exceeds range swath boundaries")
877
+
878
+ # checking for burst boundaries
879
+ if burst_boundaries is not None and not check_raster_only:
880
+ if roi[0] < burst_boundaries[0] or roi[0] >= burst_boundaries[0] + burst_boundaries[2]:
881
+ # starting azimuth line to be read is out of azimuth burst boundaries
882
+ raise AzimuthExceedsBoundariesError(f"First ROI line {roi[0]} exceeds azimuth burst boundaries")
883
+ if roi[0] + roi[2] > burst_boundaries[0] + burst_boundaries[2]:
884
+ # last azimuth line to be read is out of azimuth burst boundaries
885
+ raise AzimuthExceedsBoundariesError(f"Last ROI line {roi[0] + roi[2]} exceeds azimuth burst boundaries")
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.5
2
+ Name: sct_paz_reader
3
+ Version: 1.0.0
4
+ Summary: SCT (SAR Calibration Toolbox) plugin for reading PAZ product format.
5
+ Project-URL: Homepage, https://github.com/aresys-srl/sct_plugins
6
+ Project-URL: Repository, https://github.com/aresys-srl/sct_plugins
7
+ Project-URL: Documentation, https://opensource.aresys.it/sct_plugins
8
+ Author-email: "Aresys S.R.L." <info@aresys.it>
9
+ License: MIT License
10
+
11
+ Copyright (C) Aresys S.r.l. <info@aresys.it>
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE.txt
31
+ Classifier: Development Status :: 5 - Production/Stable
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Education
34
+ Classifier: Intended Audience :: Science/Research
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Natural Language :: English
37
+ Classifier: Operating System :: OS Independent
38
+ Classifier: Programming Language :: Python
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Programming Language :: Python :: 3.13
42
+ Classifier: Programming Language :: Python :: 3.14
43
+ Classifier: Topic :: Scientific/Engineering
44
+ Classifier: Topic :: Software Development :: Libraries
45
+ Classifier: Topic :: Utilities
46
+ Classifier: Typing :: Typed
47
+ Requires-Python: >=3.11
48
+ Requires-Dist: eo-products>=1.1.3
49
+ Requires-Dist: numpy>2
50
+ Requires-Dist: perseo-core>=1.0.0
51
+ Requires-Dist: perseo-quality>=1.1.0
52
+ Requires-Dist: scipy
53
+ Requires-Dist: sct>=3.2.1
54
+ Requires-Dist: shapely>=2.1.0
55
+ Provides-Extra: dev
56
+ Requires-Dist: pylint; extra == 'dev'
57
+ Requires-Dist: ruff; extra == 'dev'
58
+ Provides-Extra: docs
59
+ Requires-Dist: mkdocstrings-python; extra == 'docs'
60
+ Requires-Dist: zensical; extra == 'docs'
61
+ Provides-Extra: test
62
+ Requires-Dist: pytest; extra == 'test'
63
+ Requires-Dist: pytest-cov; extra == 'test'
64
+ Requires-Dist: sct[recommended]>=3.2.1; extra == 'test'
65
+ Description-Content-Type: text/markdown
66
+
67
+ # SCT Plugin: PAZ format reader
68
+
69
+ [![PyPI version](https://img.shields.io/pypi/v/sct-paz-reader)](https://pypi.org/project/sct-paz-reader/)
70
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue)](https://python.org)
71
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.txt)
72
+
73
+ [![CI](https://github.com/aresys-srl/sct_plugins/actions/workflows/paz.yml/badge.svg)](https://github.com/aresys-srl/sct_plugins/actions/workflows/paz.yml)
74
+
75
+ [SCT (SAR Calibration Toolbox)](https://github.com/aresys-srl/sct) plugin for reading PAZ
76
+ Level 1 products, both L1A (SLC) and L1B (GRD). This package integrates with SCT through its
77
+ input products plugin system, enabling all SCT analyses on PAZ data.
78
+
79
+ ## Supported Acquisition Modes
80
+
81
+ - **Stripmap**
82
+ - **Scansar** (GRD only, SLC not supported)
83
+ - **Spotlight**
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ pip install sct-paz-reader
89
+ ```
90
+
91
+ SCT is automatically installed as a dependency.
92
+
93
+ ## Compatibility
94
+
95
+ This plugin must be installed in the same Python environment as SCT. Once installed,
96
+ the plugin is automatically discovered and registered by SCT through its entry-point
97
+ based plugin system; no additional configuration is required.
98
+
99
+ ## Documentation
100
+
101
+ - [SCT documentation](https://opensource.aresys.it/sct/)
102
+ - [Plugins documentation](https://opensource.aresys.it/sct_plugins)
103
+
104
+ ## License
105
+
106
+ This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file for details.
107
+
108
+ Copyright &copy; 2026-present Aresys S.r.l. <info@aresys.it>
@@ -0,0 +1,8 @@
1
+ sct_paz_reader/__init__.py,sha256=_JjsON61XBnJz3zcXR40qNLCMT_rj2NGHewiepPGmLg,157
2
+ sct_paz_reader/interface.py,sha256=STnhCw8-CHdCs84gBD_PeWlqr0YYd0J2bcSSn46ug9I,929
3
+ sct_paz_reader/protocol_implementation.py,sha256=ori9V0CCawoQ9AYxU1nZmdXwQggBxSMy8a6ZRZpwyXE,33252
4
+ sct_paz_reader-1.0.0.dist-info/METADATA,sha256=zvkKz02K16UHzBoHkoP_l3oyZoQ5SJmncxN37OPiqt0,4576
5
+ sct_paz_reader-1.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ sct_paz_reader-1.0.0.dist-info/entry_points.txt,sha256=_5fTUhO0_8dk-8Q4k9Kp880AP09DoJAIKChCVJ9DAD8,69
7
+ sct_paz_reader-1.0.0.dist-info/licenses/LICENSE.txt,sha256=5-eKUp948IoydappLufHc2oAqasNGKhXpIB3qqQvXlY,1082
8
+ sct_paz_reader-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [sct.input_products]
2
+ paz = sct_paz_reader.interface:PAZProductPlugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (C) Aresys S.r.l. <info@aresys.it>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.