Skip to content

i.spectral: fix text output to write band values#7488

Open
Valyrian-Code wants to merge 1 commit into
OSGeo:mainfrom
Valyrian-Code:i.spectral-text-output
Open

i.spectral: fix text output to write band values#7488
Valyrian-Code wants to merge 1 commit into
OSGeo:mainfrom
Valyrian-Code:i.spectral-text-output

Conversation

@Valyrian-Code

Copy link
Copy Markdown
Contributor

Description

write2textf iterated with for row in enumerate(what), which binds row to
the (index, row) tuple. As a result the -t text output wrote a Python tuple
repr — including a redundant index and the easting/northing/label columns —
instead of the band values:

1, (0, [5.0, 5.0, 0, 10.0, 20.0, 30.0])

This unpacks the index and writes row[3:] (the band DN values), matching what
draw_gnuplot and draw_linegraph already do, so the output becomes:

1, [10.0, 20.0, 30.0]

Motivation and context

The text export silently produced unusable data (a Python repr rather than the
spectral values shown in the plots). The exit code was still 0, so nothing
flagged it.

How has this been tested?

Reproduced locally before and after the change. Added a regression test
(scripts/i.spectral/tests/i_spectral_test.py) that runs i.spectral -t on
three constant-value rasters and asserts the output line is
1, [10.0, 20.0, 30.0]; it fails on the previous code and passes on the fix.
ruff format and ruff check are clean.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Tests

Copilot AI review requested due to automatic review settings June 3, 2026 06:29
@github-actions github-actions Bot added Python Related code is in Python module imagery tests Related to Test Suite labels Jun 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes the i.spectral -t text output regression where tuple representations were written instead of band values, and adds a regression test to prevent recurrence.

Changes:

  • Update write2textf() to write only band values (and correct pick numbering) for text output.
  • Add a pytest regression test validating the expected text output format for a simple 3-band case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/i.spectral/i.spectral.py Fixes text output writing logic to avoid (index, row) tuple output and emit band values instead.
scripts/i.spectral/tests/i_spectral_test.py Adds regression test covering the corrected -t text output formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/i.spectral/i.spectral.py
Comment thread scripts/i.spectral/i.spectral.py
Comment thread scripts/i.spectral/tests/i_spectral_test.py Outdated
write2textf iterated with 'for row in enumerate(what)', binding row to the (index, row) tuple, so the -t text output wrote a Python tuple repr (a redundant index plus the easting/northing/label columns) instead of the band values. Unpack the index and write row[3:], matching draw_gnuplot and draw_linegraph, via writelines.

Add a regression test for the -t output.
@Valyrian-Code Valyrian-Code force-pushed the i.spectral-text-output branch from bf27a7b to bf2a48a Compare June 3, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

imagery module Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants