guiwitz / napari-sediment

https://guiwitz.github.io/napari-sediment/napari_sediment.html
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Convert: wrong claim that image is not in BIL format #44

Open aloboa opened 6 months ago

aloboa commented 6 months ago

Convert aborts with the message "Image is not in bil format, cannot convert" , even though the image is actually in BIL format. (in any case, Convert should work with either BIL, BSQ or PIL).

ENVI description = {Data recorded with Specim IQ} samples = 512 lines = 512 bands = 204 header offset = 0 file type = ENVI data type = 12 interleave = BIL sensor type = SPECIM IQ byte order = 0

Traceback:


ValueError                                Traceback (most recent call last)
~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari_sediment/convert_widget.py in _on_click_convert(self=<napari_sediment.convert_widget.ConvertWidget object>, event=False)
     79         """Convert .hdr to .zarr"""
     80         
---> 81         convert_bil_raw_to_zarr(self.imhdr_path, self.export_folder)
        global convert_bil_raw_to_zarr = <function convert_bil_raw_to_zarr at 0x75a11d1abe50>
        self.imhdr_path = PosixPath('/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/capture/297.hdr')
        self.export_folder = PosixPath('/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari')
     82         self.save_params()
     83 

~/miniconda3/envs/sediment2/lib/python3.9/site-packages/napari_sediment/sediproc.py in convert_bil_raw_to_zarr(hdr_path=PosixPath('/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/capture/297.hdr'), export_folder=PosixPath('/media/alobo/SP PHD U3/CERTEC/20240430_erica2/HSI/IQ_Prefire/297/napari'), num_rows_chunk=2000, force=False)
    541     img = open_image(hdr_path)
    542     if (not img.metadata['interleave'] == 'bil') and (not force):
--> 543         raise ValueError('Image is not in bil format, cannot convert')
        global ValueError = undefined
    544     
    545     #num_rows_chunk = 2000

ValueError: Image is not in bil format, cannot convert
aloboa commented 5 months ago

this issue should be solved by adding .lower() in

if (not img.metadata['interleave'].lower() == 'BIL') and (not force):
        raise ValueError('Image is not in bil format, cannot convert')

Note 'BIL' is very frequent (more than 'bil' in hdr files