Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open Carina Nebula JWST image from napari-nasa-samples #3

Open
lgan-czi opened this issue Jul 14, 2022 · 2 comments
Open

Can't open Carina Nebula JWST image from napari-nasa-samples #3

lgan-czi opened this issue Jul 14, 2022 · 2 comments

Comments

@lgan-czi
Copy link

lgan-czi commented Jul 14, 2022

Hi @royerloic!

I was playing around with your plugin, and I tried to look at the Carina Nebula image from File > Open Sample > napari-nasa-samples > Cosmic Cliffs, Carina Nebula, NIRCam Image, JWST, but I got the error below. All the other images worked fine, just this one didn't work.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/tifffile/tifffile.py:3609, in TiffFile.__init__(self=<tifffile.TiffFile 'STScI-01G7ETNMR8…64R4CVA1E6T.tif'>, file='/Library/Caches/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif', mode=None, name=None, offset=None, size=None, _multifile=None, _useframes=None, _parent=None, **kwargs={})
   3608 try:
-> 3609     byteorder = {b'II': '<', b'MM': '>', b'EP': '<'}[header[:2]]
        header = b'<?xm'
        header[:2] = b'<?'
   3610 except KeyError:

KeyError: b'<?'

During handling of the above exception, another exception occurred:

TiffFileError                             Traceback (most recent call last)
File ~/Desktop/napari/napari/_qt/menus/file_menu.py:239, in FileMenu._rebuild_samples_menu.<locals>._add_sample(plg='napari-nasa-samples', smp='cosmic_cliffs', *args=(False,))
    237 def _add_sample(*args, plg=plugin_name, smp=samp_name):
    238     try:
--> 239         self._win._qt_viewer.viewer.open_sample(plg, smp)
        plg = 'napari-nasa-samples'
        smp = 'cosmic_cliffs'
        self._win = <napari._qt.qt_main_window.Window object at 0x1866ffd00>
        self = <napari._qt.menus.file_menu.FileMenu object at 0x1890d9820>
    240     except MultipleReaderError as e:
    241         handle_gui_reading(
    242             e.paths,
    243             self._win._qt_viewer,
    244             plugin_name=plugin_name,
    245             stack=False,
    246         )

File ~/Desktop/napari/napari/components/viewer_model.py:861, in ViewerModel.open_sample(self=Viewer(axes=Axes(visible=False, labels=True, col...indings._transform_active_layer at 0x187eede50>}), plugin='napari-nasa-samples', sample='cosmic_cliffs', reader_plugin=None, **kwargs={})
    859 if callable(data):
    860     added = []
--> 861     for datum in data(**kwargs):
        data = <bound method SampleDataGenerator.open of SampleDataGenerator(key='cosmic_cliffs', display_name='Cosmic Cliffs, Carina Nebula, NIRCam Image, JWST', command='napari-nasa-samples.cosmic_cliffs')>
        kwargs = {}
    862         added.extend(self._add_layer_from_data(*datum))
    863     return added

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/npe2/manifest/contributions/_sample_data.py:44, in SampleDataGenerator.open(self=SampleDataGenerator(key='cosmic_cliffs', display...ST', command='napari-nasa-samples.cosmic_cliffs'), _registry=None, *args=(), **kwargs={})
     41 def open(
     42     self, *args, _registry: Optional["CommandRegistry"] = None, **kwargs
     43 ) -> List[LayerData]:
---> 44     return self.exec(args, kwargs, _registry=_registry)
        args = ()
        kwargs = {}
        self = SampleDataGenerator(key='cosmic_cliffs', display_name='Cosmic Cliffs, Carina Nebula, NIRCam Image, JWST', command='napari-nasa-samples.cosmic_cliffs')
        _registry = None

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/npe2/manifest/utils.py:65, in Executable.exec(self=SampleDataGenerator(key='cosmic_cliffs', display...ST', command='napari-nasa-samples.cosmic_cliffs'), args=(), kwargs={}, _registry=None)
     63 if kwargs is None:
     64     kwargs = {}
---> 65 return self.get_callable(_registry)(*args, **kwargs)
        kwargs = {}
        _registry = None
        args = ()
        self = SampleDataGenerator(key='cosmic_cliffs', display_name='Cosmic Cliffs, Carina Nebula, NIRCam Image, JWST', command='napari-nasa-samples.cosmic_cliffs')

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/napari_nasa_samples/_jwst_cosmic_cliffs.py:10, in make_sample_data()
      8 def make_sample_data():
      9     """Generates an image"""
---> 10     array = get_array("https://stsci-opo.org/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif")
     11     return [(array, {'name':'Cosmic Cliffs, Carina Nebula, JWST'})]

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/napari_nasa_samples/utils.py:18, in get_array(url='https://stsci-opo.org/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif')
     16 if file_path.endswith('tif'):
     17     from tifffile import tifffile
---> 18     array = tifffile.imread(file_path)
        file_path = '/Library/Caches/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif'
        tifffile = <module 'tifffile.tifffile' from '/Users/lgan/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/tifffile/tifffile.py'>
     19 else:
     20     import imageio

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/tifffile/tifffile.py:973, in imread(files='/Library/Caches/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif', aszarr=False, key=None, series=None, level=None, squeeze=None, maxworkers=None, name=None, offset=None, size=None, pattern=None, axesorder=None, categories=None, imread=None, sort=None, container=None, axestiled=None, ioworkers=1, chunkmode=None, fillvalue=None, zattrs=None, _multifile=None, _useframes=None, **kwargs={})
    968     files = files[0]
    970 if isinstance(files, str) or not isinstance(
    971     files, collections.abc.Sequence
    972 ):
--> 973     with TiffFile(
        files = '/Library/Caches/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif'
        name = None
        offset = None
        size = None
        _multifile = None
        _useframes = None
        is_flags = {}
    974         files,
    975         name=name,
    976         offset=offset,
    977         size=size,
    978         _multifile=_multifile,
    979         _useframes=_useframes,
    980         **is_flags,
    981     ) as tif:
    982         if aszarr:
    983             assert key is None or isinstance(key, int)

File ~/opt/anaconda3/envs/napari-dev-env/lib/python3.9/site-packages/tifffile/tifffile.py:3611, in TiffFile.__init__(self=<tifffile.TiffFile 'STScI-01G7ETNMR8…64R4CVA1E6T.tif'>, file='/Library/Caches/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif', mode=None, name=None, offset=None, size=None, _multifile=None, _useframes=None, _parent=None, **kwargs={})
   3609     byteorder = {b'II': '<', b'MM': '>', b'EP': '<'}[header[:2]]
   3610 except KeyError:
-> 3611     raise TiffFileError(f'not a TIFF file {header!r}')
   3613 version = struct.unpack(byteorder + 'H', header[2:4])[0]
   3614 if version == 43:
   3615     # BigTiff

TiffFileError: not a TIFF file b'<?xm'


I tried going to https://stsci-opo.org/STScI-01G7ETNMR8CBHQQ64R4CVA1E6T.tif and got this message:
Screen Shot 2022-07-14 at 12 12 01 PM

@royerloic
Copy link
Owner

Ok, seems NASA is not happy with the traffic and so I may need to find some fallback hosting solution...
I can add code so we can provide a list of URLs and it will try them all.

@royerloic
Copy link
Owner

royerloic commented Jul 14, 2022

This link works:
https://stsci-opo.org/STScI-01G7WCH0VH9RK7YBFAMM07S2TB.tif

they seem to be changing the links...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants