jdat_notebooks icon indicating copy to clipboard operation
jdat_notebooks copied to clipboard

ValueError: The image shapes must match.

Open JosephKarpinski opened this issue 2 years ago • 3 comments

Hi,

I'm trying to follow this sample code with real JWST data

/NIRCam_multiband_photometry.ipynb

In the sample F200W, F150W and F090W are all the same shape (1000, 1000)

In JWST data the shapes are different.

ValueError: The image shapes must match. r: (12487, 14593), g: (12375, 14426) b: (12481, 14586)

Is there a way to make this Python code work with real JWST data?

Thank you,

Joseph Karpinski

Screen Shot 2022-07-31 at 9 32 03 AM Screen Shot 2022-07-31 at 9 33 00 AM

JosephKarpinski avatar Jul 31 '22 13:07 JosephKarpinski

Thanks @JosephKarpinski when I get more time I can certainly look into writing a solution, but off the cuff, I have 2 short term answers:

  1. This is just a matter of cropping and aligning your images before entering them into the function. Ideally, a user can figure that out. Like I said, when I get more time, I can help, but it may not be immediately.
  2. This code is making a RGB color image. Ideally, our team would like to replace this snippet with using our Jdaviz tools rather than matplotlib. I have put together a little informal and unofficial tutorial and movie for you if you'd like to try yourself. https://github.com/orifox/jwst_ero

orifox avatar Jul 31 '22 14:07 orifox

Haven’t had a chance to look at this yet. Couldn’t get jdaviz to run under VSCode. Submitted an issue record. Just got the recommended fix today and tested it out.

Re: [spacetelescope/jdaviz] [BUG] Imviz: AttributeError: 'NoneType' object has no attribute 'group' (Issue #1533)

Could you upgrade ipypopout to >= 0.0.11 ? This version prevents this error

Sent from my iPad

On Jul 31, 2022, at 10:46 AM, Ori Fox @.***> wrote:

 Thanks @JosephKarpinski when I get more time I can certainly look into writing a solution, but off the cuff, I have 2 short term answers:

This is just a matter of cropping and aligning your images before entering them into the function. Ideally, a user can figure that out. Like I said, when I get more time, I can help, but it may not be immediately. This code is making a RGB color image. Ideally, our team would like to replace this snippet with using our Jdaviz tools rather than matplotlib. I have put together a little informal and unofficial tutorial and movie for you if you'd like to try yourself. https://github.com/orifox/jwst_ero — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

JosephKarpinski avatar Aug 03 '22 02:08 JosephKarpinski

2. This code is making a RGB color image. Ideally, our team would like to replace this snippet with using our Jdaviz tools rather than matplotlib. I have put together a little informal and unofficial tutorial and movie for you if you'd like to try yourself. https://github.com/orifox/jwst_ero

I'll (unofficially ;-) second this recommendation for a good starting point. To get further towards creating an RGB image, the following steps may be helpful, assuming you have loaded 3 image data sets into the imviz instance:

imviz.link_data(link_type='wcs')     # Align all datasets to matching world coordinates
viewer.state.color_mode = 'One color per layer'

colours = ('#0000ffff', '#00ff00ff', '#ff0000ff')  # Pick pure blue, green, red for the three channels – to be experimented with
for layer, colour in zip(imviz.default_viewer.layers, colours):
    layer.state.color = colour

imviz.show()  # Might want to display in a separate window for maximising size with `imviz.show('popout')`
viewer.save('My_Image')
viewer.figure.save_png('My_Image_upscaled', scale=2)

Exporting images this way the resolution is based on the viewport resolution, so not really suitable for high-resolution pictures. The second option is directly accessing the bqplot.figure instance to use its scale option, but I think this still simply oversamples the viewer data, so is not much of an improvement. Might also be worth looking into make_lupton_rgb for some more sophisticated algorithms for assigning the colour channels.

dhomeier avatar Aug 13 '22 16:08 dhomeier

This is two years old and much has changed since then. Please open another issue if you still have problems. Thank you!

camipacifici avatar Jul 11 '24 13:07 camipacifici