Coverage for /home/runner/work/torchcvnn/torchcvnn/src/torchcvnn/datasets/alos2/leader_file.py: 0%
43 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-13 08:53 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-13 08:53 +0000
1# MIT License
3# Copyright (c) 2024 Jeremy Fix
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:
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
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.
23# External imports
24import numpy as np
26# Local imports
27from . import parse_utils
29descriptor_format = [
30 ("file_id", 48, 16, "A", None),
31 ("number_map_projection_record", 192, 6, "I", None),
32]
33descriptor_record_length = 720
35summary_format = [
36 ("scene_id", 20, 32, "A", None),
37 ("number_sar_channels", 388, 4, "I", None),
38 ("sensor_id", 412, 32, "A", None),
39 ("line_content_indicator", 1670, 8, "A", None), # RANGEbbb for L1.1 or OTHERbbb
40 ("line_spacing", 1686, 16, "F16.7", None),
41 ("pixel_spacing", 1702, 16, "F16.7", None),
42 ("doppler_center_frequency_constant_term", 1734, 16, "F16.7", None),
43 ("doppler_center_frequency_linear_term", 1750, 16, "F16.7", None),
44 ("nominal_off_nadir", 1838, 16, "F16.7", None),
45]
46summary_record_length = 4096
48map_projection_format = []
49map_projection_record_length = 1620
51platform_projection_format = []
52platform_projection_record_length = 4680
54altitude_data_format = [
55 ("pitch", 40, 14, "E14.6", None),
56 ("roll", 54, 14, "E14.6", None),
57 ("yaw", 68, 14, "E14.6", None),
58]
59altitude_data_record_length = 16384
61radiometric_data_format = [
62 ("record_number", 0, 4, "B", None),
63 ("calibration_factor", 20, 16, "F16.7", None),
64]
65radiometric_data_record_length = 9860
67data_quality_format = []
68data_quality_record_length = 1620
70facility_format = []
71facility_record_length = 325000 + 511000 + 3072 + 728000 + 5000
74class LeaderFile:
75 r"""
76 Processing of the SAR trailer file.
77 """
79 def __init__(self, filepath):
80 self.descriptor_record = {}
81 self.summary_record = {}
82 self.altitude_record = {}
83 self.radiometric_record = {}
84 with open(filepath, "rb") as fh:
85 fh_offset = 0
86 fh_offset = parse_utils.parse_from_format(
87 fh,
88 self.descriptor_record,
89 descriptor_format,
90 1,
91 descriptor_record_length,
92 fh_offset,
93 )
94 fh_offset = parse_utils.parse_from_format(
95 fh,
96 self.summary_record,
97 summary_format,
98 1,
99 summary_record_length,
100 fh_offset,
101 )
103 # Skip map projection record
104 # Does not exist in L1.1
105 if self.descriptor_record["number_map_projection_record"] == 1:
106 fh_offset += map_projection_record_length
108 # Skip platform projection record
109 fh_offset += platform_projection_record_length
111 # Altitude data record
112 fh_offset = parse_utils.parse_from_format(
113 fh,
114 self.altitude_record,
115 altitude_data_format,
116 1,
117 altitude_data_record_length,
118 fh_offset,
119 )
121 # Radiometric data record
122 fh_offset = parse_utils.parse_from_format(
123 fh,
124 self.radiometric_record,
125 radiometric_data_format,
126 1,
127 radiometric_data_record_length,
128 fh_offset,
129 )
131 @property
132 def calibration_factor(self):
133 cf = self.radiometric_record["calibration_factor"]
134 return np.sqrt(10.0 ** ((cf - 32.0) / 10.0))
136 def __repr__(self):
137 descriptor_txt = parse_utils.format_dictionary(self.descriptor_record, 1)
138 summary_txt = parse_utils.format_dictionary(self.summary_record, 1)
139 altitude_txt = parse_utils.format_dictionary(self.altitude_record, 1)
140 radiometric_txt = parse_utils.format_dictionary(self.radiometric_record, 1)
141 return f"""
142Descriptor:
143{descriptor_txt}
144Summary:
145{summary_txt}
146Altitude:
147{altitude_txt}
148Radiometric:
149{radiometric_txt}
150 """