-
-
Notifications
You must be signed in to change notification settings - Fork 363
Description
Describe the bug
The i.in.spotvgt
module has multiple issues that either break functionality or silently produce invalid (NULL) outputs. The distinct problems encountered during usage and debugging:
1. Incorrect condition: if f < 2:
Present in create_VRT_file()
function
Problematic Line:
if f < 2:
throws a TypeError
because f
is a list.
2. Incorrect SM file name generation
Present inside the -a
flag block
Problematic Line:
qname = spotname.replace("NDV", "SM")
qfile = os.path.join(spotdir, qname)
Error encountered:
ERROR 4: 0001_SM: No such file or directory
This occurred because the code was looking for 0001_SM
but the file was named 0001_SM.HDF
.
3. Incorrect use of list for stdin
in gs.write_command()
Problematic Line:
rules = [
r + "\n"
for r in [
"8 50 50 50",
...
]
]
gs.write_command("r.colors", map=smfile, rules="-", stdin=rules)
Error:
TypeError: can only accept types str and bytes
4. Critical: gs.use_temp_region()
caused all outputs to be NULL
Issue:
gs.use_temp_region()
This created a temporary region, and all operations like r.mapcalc
and g.rename
operated within that temp region, never flushing the result to the main mapset. This led to:
-
r.info
showing metadata -
but
r.univar
showing:n: 0 min: nan
Impact:
This was the root cause of the final map being completely NULL despite all steps succeeding.
To reproduce
-
Use
i.in.spotvgt
on a valid HDF + LOG + SM input. -
Run the module normally (with or without
-a
). -
Check the final raster with:
r.univar test_output
-
Observe that it has
n: 0
and is completely NULL.
Expected behavior
The output raster should contain actual NDVI values remapped from DN using:
NDVI = 0.004 * DN - 0.1
Instead, it silently creates an empty map.
System description
- Operating System: Windows Subsystem for Linux (WSL)
- GRASS GIS version: 8.4
- details about further software components
- GRASS 8.5.0dev
- Python verison: 3.10.12
- wxPython version: 4.2.2
Root Causes
-
Incorrect condition in
create_VRT_file()
,f
should be checked usinglen(f) < 2
to avoid aTypeError
. -
Status map file path was missing the
.HDF
extension, leading to a file not found error. This can be resolved by appending+ ".HDF"
to the filename. -
stdin
was incorrectly passed as a list togs.write_command()
, which expects a single string. Joining the list into a string will fix the issue. -
gs.use_temp_region()
caused output maps to remain in a temporary region, making them effectively NULL. Removing this line will allow the maps to be persisted correctly.
I will be adding the patched code soon, testing all the changes locally.