NikosAlexandris / i.fusion.hpf

Replication of the High-Pass Filter Addition Image Fusion for GRASS-GIS (Python script)
13 stars 4 forks source link

Worldview-2 data: i.fusion.hpf crash with "ValueError: 9 is not in list" #14

Open neteler opened 4 years ago

neteler commented 4 years ago

Applying the i.fusion.hpf version in https://github.com/OSGeo/grass-addons/tree/master/grass7/imagery/i.fusion.hpf leads to a crash when using it on Worldview-2 data:

# input data
GRASS 7.9.dev (mexico_UTM11): >

PAN=wv2_17OCT08182034_P2AS_058891334010_01_P001
COLORPREFIX=wv2_17OCT08182034_M2AS_058891334010_01_P001

g.list raster pattern="$COLORPREFIX.?" 
wv2_17OCT08182034_M2AS_058891334010_01_P001.1
wv2_17OCT08182034_M2AS_058891334010_01_P001.2
wv2_17OCT08182034_M2AS_058891334010_01_P001.3
wv2_17OCT08182034_M2AS_058891334010_01_P001.4
wv2_17OCT08182034_M2AS_058891334010_01_P001.5
wv2_17OCT08182034_M2AS_058891334010_01_P001.6
wv2_17OCT08182034_M2AS_058891334010_01_P001.7
wv2_17OCT08182034_M2AS_058891334010_01_P001.8

g.list raster pattern="$PAN"
wv2_17OCT08182034_P2AS_058891334010_01_P001

Attempt to pan-sharpen:

i.fusion.hpf pan=$PAN msx=$(g.list raster pattern="$COLORPREFIX.?" sep=comma)
|! Region's resolution matched to Pan's (0.5)

Processing image: wv2_17OCT08182034_M2AS_058891334010_01_P001.1

|1 Determining ratio of low to high resolution
> Retrieving image resolutions
>> Resolution ratio low (2.000) to high (0.500): 4.0

|2 High Pass Filtering the Panchromatic Image
Traceback (most recent call last):
  File "/root/.grass7/addons/scripts/i.fusion.hpf", line 575, in <module>
    sys.exit(main())
  File "/root/.grass7/addons/scripts/i.fusion.hpf", line 378, in main
    hpf = get_high_pass_filter(ratio, center)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 140, in get_high_pass_filter
    kernel = get_kernel(size, level)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 116, in get_kernel
    center = get_center_cell(level, size)
  File "/root/.grass7/addons/etc/i.fusion.hpf/high_pass_filter.py", line 28, in get_center_cell
    kernel_size_idx = [k for ((lo, hi), k) in MATRIX_PROPERTIES].index(kernel_size)
ValueError: 9 is not in list
WARNING: No data base element files found
neteler commented 4 years ago

I think that I got it fixed in https://github.com/OSGeo/grass-addons/pull/49

NikosAlexandris commented 4 years ago

Thank you Markus. I would like to test this too. Can I have a small sample data set? Like 100x100 pixels maybe or similar.

NikosAlexandris commented 4 years ago

Value 9 in the iterator derived by zip() gets consumed and it doesn't exist anymore when a sub-sequent call requests for it. I want to try with your data to confirm how this comes in to play.

neteler commented 4 years ago

I have sent a private link to you with sample data.

NikosAlexandris commented 4 years ago

zip() returns a list of tuples in Python 2 and an iterator in Python 3. Thanks for the fix Markus. See also:

neteler commented 4 years ago

I have now merged https://github.com/OSGeo/grass-addons/pull/49 .

Note: Perhaps this version should be sync'ed to that in grass-addons.