acolite / acolite_ls2

ACOLITE: Atmospheric correction for aquatic applications of Landsat and Sentinel-2 (obsolete)
GNU General Public License v3.0
42 stars 27 forks source link

'float' object cannot be interpreted as an integer #5

Closed lvhengani closed 4 years ago

lvhengani commented 4 years ago

Hi,

When trying to process Sentinel-2 data, I am getting error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/var/acolite/launch_acolite.py", line 30, in <module>
    launch_acolite()
  File "/var/acolite/launch_acolite.py", line 25, in launch_acolite
    ac.acolite.acolite_cli(sys.argv)
  File "/var/acolite/acolite/acolite/acolite_cli.py", line 85, in acolite_cli
    acolite_run(settings=acolite_settings)
  File "/var/acolite/acolite/acolite/acolite_run.py", line 253, in acolite_run
    nc_write_rhorc=nc_write_rhorc
  File "/var/acolite/acolite/acolite/acolite_ac.py", line 309, in acolite_ac
    swaves = pp.shared.sensor_wave(metadata['SATELLITE_SENSOR'])
  File "/var/acolite/acolite/shared/sensor_wave.py", line 16, in sensor_wave
    wave_hyper = linspace(wave_range[0],wave_range[1],((wave_range[1]-wave_range[0])/wave_step)+2)
  File "<__array_function__ internals>", line 6, in linspace
  File "/usr/local/lib/python3.6/dist-packages/numpy/core/function_base.py", line 121, in linspace
    .format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.

I am using Python3.6

acolite commented 4 years ago

Does it help if you change the line:

wave_hyper = linspace(wave_range[0],wave_range[1],((wave_range[1]-wave_range[0])/wave_step)+2)

to:

wave_hyper = linspace(wave_range[0],wave_range[1],ceil(((wave_range[1]-wave_range[0])/wave_step)+2))

You'll also need to import ceil from numpy.

Quinten

acolite commented 4 years ago

It seems this occurs in the most recent Python/numpy distribution. This commit should help: https://github.com/acolite/acolite/commit/650331e634940fe7c9a0d8c6ff0d72855d5ae593

nickselmes commented 4 years ago

Same issue here, despite the updates in that commit. I now have:

Running ACOLITE
Launching ACOLITE Python!
Started ACOLITE Python processing
Wrote run settings file to OUTDIR/acolite_run_20200304_100611_settings.txt
Processing 1 scene...
Processing scene 1 of 1...
Traceback (most recent call last):
  File "CONDADIR/lib/python3.6/site-packages/numpy/core/function_base.py", line 117, in linspace
    num = operator.index(num)
TypeError: 'float' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "launch_acolite.py", line 30, in <module>
    launch_acolite()
  File "launch_acolite.py", line 25, in launch_acolite
    ac.acolite.acolite_cli(sys.argv)
  File "ACOLITEDIR/acolite/acolite/acolite/acolite_cli.py", line 85, in acolite_cli
    acolite_run(settings=acolite_settings)
  File "ACOLITEDIR/acolite/acolite/acolite/acolite_run.py", line 254, in acolite_run
    nc_write_rhorc=nc_write_rhorc
  File "ACOLITEDIR/acolite/acolite/acolite/acolite_ac.py", line 289, in acolite_ac
    metadata,bdata= pp.sentinel.scene_meta(metafile)
  File "ACOLITEDIR/acolite/acolite/sentinel/scene_meta.py", line 75, in scene_meta
    wave = linspace(banddata['Wavelength'][band]['MIN'],banddata['Wavelength'][band]['MAX'], ((banddata['Wavelength'][band]['MAX']-banddata['Wavelength'][band]['MIN'])/step)+1)                                                                                                                                                            
  File "<__array_function__ internals>", line 6, in linspace
  File "CONDADIR/lib/python3.6/site-packages/numpy/core/function_base.py", line 121, in linspace
    .format(type(num)))
TypeError: object of type <class 'float'> cannot be safely interpreted as an integer.
zgcao commented 4 years ago

Hi Quinten,

The 3rd parameter in linespace should be casted as the int type. It seems that the ceil did not work in my macOS because it still generates the float64 number.

I tried this command as follows and it worked.

wave_hyper = linspace(wave_range[0],wave_range[1],int(ceil((wave_range[1]-wave_range[0])/wave_step)+2))

Regards, Zhigang

acolite commented 4 years ago

Thanks Zhigang,

Will update shortly, it seems ceil still returns a float!

Quinten

acolite commented 4 years ago

I have updated the code to pass integers to linspace - my apologies for the long wait!