Skip to content

Commit 9daf06b

Browse files
michaelayeclaude
andcommitted
fix: normalize PVL sidecar longitudes to declared [0, 360) domain
The PVL sidecar declares LongitudeDomain=360 but the lon values written could be outside [0, 360) — e.g. _derive_ground_range returns lon_max=181.5 for an antimeridian-crossing strip. ISIS tools reading the sidecar expect values consistent with the declared domain. Now lon_min, lon_max, and CenterLongitude are all normalized via mod 360 before writing. If wraparound makes max < min (e.g. 359 to 1), that's correct for the 360 domain — ISIS interprets it as crossing 0°. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c20610 commit 9daf06b

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

src/isistools/processing/writers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ def write_mapping_pvl(
146146

147147
pvl_path = output_path.with_suffix(".pvl")
148148

149+
# Normalize longitudes to the declared domain [0, 360) so the PVL
150+
# is self-consistent. _derive_ground_range may return values outside
151+
# [-180, +180] for antimeridian-crossing strips (e.g. lon_min=179.5,
152+
# lon_max=181.5); ISIS tools expect the values to match the domain.
153+
lon_min_pvl = grid.lon_min % 360.0
154+
lon_max_pvl = grid.lon_max % 360.0
155+
center_lon_pvl = center_lon % 360.0
156+
# If wraparound made max < min (e.g. 359° to 1°), that's correct
157+
# for the 360 domain — ISIS interprets it as crossing 0°.
158+
149159
lines = [
150160
"Group = Mapping",
151161
f" ProjectionName = {isis_proj_name}",
@@ -156,11 +166,11 @@ def write_mapping_pvl(
156166
" LongitudeDirection = PositiveEast",
157167
" LongitudeDomain = 360",
158168
f" CenterLatitude = {center_lat}",
159-
f" CenterLongitude = {center_lon}",
169+
f" CenterLongitude = {center_lon_pvl}",
160170
f" MinimumLatitude = {grid.lat_min}",
161171
f" MaximumLatitude = {grid.lat_max}",
162-
f" MinimumLongitude = {grid.lon_min}",
163-
f" MaximumLongitude = {grid.lon_max}",
172+
f" MinimumLongitude = {lon_min_pvl}",
173+
f" MaximumLongitude = {lon_max_pvl}",
164174
f" PixelResolution = {grid.resolution} <meters/pixel>",
165175
f" UpperLeftCornerX = {grid.transform.c} <meters>",
166176
f" UpperLeftCornerY = {grid.transform.f} <meters>",

0 commit comments

Comments
 (0)