opengeos / HyperCoast

A Python Package for Visualizing and Analyzing Hyperspectral Data in Coastal Environments
https://hypercoast.org
MIT License
151 stars 26 forks source link

Incompatible connection to leafmap #102

Closed ohadshapira closed 2 months ago

ohadshapira commented 3 months ago

Environment Information

Description

Trying to save AVIRIS HSI file as an image. Have been failing due to an incompatible connection to leafmap

>> ds_pyramid= hypercoast.read_aviris(filepath)
>> hypercoast.aviris_to_image(ds_pyramid,None,'nearest',"test")

Traceback (most recent call last):
  File "C:\Users\Home\PycharmProjects\hsi\.venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-15-1bb334ad2f28>", line 1, in <module>
    hypercoast.aviris_to_image(ds_pyramid,None,'nearest',"test")
  File "C:\Users\Home\PycharmProjects\hsi\.venv\Lib\site-packages\hypercoast\aviris.py", line 148, in aviris_to_image
    return array_to_image(
           ^^^^^^^^^^^^^^^
  File "C:\Users\Home\PycharmProjects\hsi\.venv\Lib\site-packages\leafmap\common.py", line 10641, in array_to_image
    raise ValueError("resolution must be provided if source is not provided")
ValueError: resolution must be provided if source is not provided
giswqs commented 3 months ago

The array_to_image function uses rio.to_raster under the hood. You can try converting the xarray.DataArray to rioxarray by setting crs and transform. https://corteva.github.io/rioxarray/html/examples/convert_to_raster.html#Converting-DataArray-to-raster

ohadshapira commented 3 months ago

It seems like the missing part was: hypercoast.aviris_to_image(ds,output="test4"**,cellsize=32,crs="EPSG:3857"**)

It is mandatory input for 'leafmap.array_to_image' (in both aviris_to_image and pace_to_image).

The only issue now is that when reading and immediately saving the ds, I get different file sizes (original vs. saved)

giswqs commented 2 months ago

This issue has been fixed in the upstream leafmap package. See https://github.com/opengeos/leafmap/pull/869

Once the package is updated, you should be able to use the following to save the DataArray as an image.

hypercoast.aviris_to_image(dataset, wavelengths=[400, 500, 600], output="aviris.tif")
giswqs commented 2 months ago

Leafmap v0.36.6 has been released. Please update it using pip install -U leafmap and try the aviris_to_image() function again.