jdaviz icon indicating copy to clipboard operation
jdaviz copied to clipboard

Aperture photometry plugin reflects display unit selection

Open cshanahan1 opened this issue 1 year ago • 11 comments

Update all display and outputs of aperture photometry app to reflect selected display unit in cubeviz. The output photometry table now has a separate column for Unit.

cshanahan1 avatar Jul 25 '24 18:07 cshanahan1

Codecov Report

Attention: Patch coverage is 89.43089% with 13 lines in your changes missing coverage. Please review.

Project coverage is 88.82%. Comparing base (7826a99) to head (8385dcf). Report is 125 commits behind head on main.

Files with missing lines Patch % Lines
...imviz/plugins/aper_phot_simple/aper_phot_simple.py 89.43% 13 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3118      +/-   ##
==========================================
+ Coverage   88.78%   88.82%   +0.03%     
==========================================
  Files         112      112              
  Lines       17446    17550     +104     
==========================================
+ Hits        15489    15588      +99     
- Misses       1957     1962       +5     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 31 '24 14:07 codecov[bot]

Looks good! I just noticed a couple of things:

  • with some units the numbers can be very large or very small. Can you please use scientific notation for the min/max/ave/etc in the table? They all come out as zeros with very small/big numbers now.
  • at the end of the table, the flux_scaling is not updating to follow the unit change.
  • i created a subset and run aperture photometry. the plot is labeled x/y. rerunning it, the plot gets the correct units.
  • then I changed units and rerun aperture photometry without changing anything else and the plot kept the points from before and updated only the line Screenshot 2024-07-31 at 2 50 08 PM Screenshot 2024-07-31 at 2 50 16 PM Screenshot 2024-07-31 at 2 50 56 PM

camipacifici avatar Jul 31 '24 18:07 camipacifici

Just noticed that the problem about not showing the units right away is also in the released version.

camipacifici avatar Jul 31 '24 19:07 camipacifici

Now that you mention the radial plot, I wonder how the Gaussian1D fit would behave as well.

pllim avatar Jul 31 '24 19:07 pllim

I tested the gaussian fit and the plotting and it was working for me, but maybe something is getting out of sync. looking into it

cshanahan1 avatar Jul 31 '24 19:07 cshanahan1

I think the raw profile is not updating and only the label is updating. After changing the units, there is a big difference between the raw and average although they should be comparable. Screenshot 2024-07-31 at 4 18 36 PM Screenshot 2024-07-31 at 4 18 44 PM

camipacifici avatar Jul 31 '24 20:07 camipacifici

the latest commit should fix the issue with the raw radial profile plot

cshanahan1 avatar Jul 31 '24 21:07 cshanahan1

The fix worked, thank you!

camipacifici avatar Aug 01 '24 20:08 camipacifici

  1. Please add a change log.
  2. Please fix the test failure in devdeps job.
>       row = cubeviz_helper.get_aperture_photometry_results()[0]
E       TypeError: 'NoneType' object is not subscriptable

jdaviz/configs/cubeviz/plugins/tests/test_cubeviz_aperphot.py:102: TypeError

pllim avatar Aug 01 '24 21:08 pllim

I still see the error in devdeps job. I suspect the photometry failed somewhere but it was swallowed by try-except block. Please run that test case manually and instead of swallowing the exception, raise it. Then you will see what is really going on. My bet is on either astropy-dev or photutils-dev.

pllim avatar Aug 02 '24 18:08 pllim

still working on figuring out that failure, will update with a fix once i figure it out

cshanahan1 avatar Aug 02 '24 19:08 cshanahan1

a few things:

  1. There is no current test coverage for batch mode in cubeviz. I have run into occasional errors testing the unit conversion with batch mode, but also sometimes it does work. I started working on adding some test coverage for batch mode specifically (both generally and testing before/after unit conversion) but there are some existing issues making this complicated. For example, an error is thrown when you try to toggle on batch mode by setting plugin.multiselect to True (which works in imviz), which then doesn't allow you to select multiple apertures or use the 'unpack_batch_options' method. I think that validating that batch mode works and is covered in tests warrants its own ticket outside of this work, and that not testing batch mode + unit conversion shouldn't hold up merging this PR.

  2. Similarly, there is no current test coverage for radial profile or curve of growth plots in the plugin. I looked at the markers plugin to get the syntax to access points directly from a figure to test what is happening in the UI (rather than just calling _curve_of_growth, which wouldn't pick up things in the plugin like unit changes, and is already tested on its own in the imviz tests), and that is not working here. Even if I can get it to work, I think that this goes out of scope since those basic tests don't exist already. I propose addressing this in the same followup that adds test coverage for batch mode, and adding a test there that covers unit conversion.

cshanahan1 avatar Aug 06 '24 13:08 cshanahan1

~I thought we agree to disallow magnitude in aperture photometry? This is probably wrong and should not be allowed.~ (Kyle said this is now a separate ticket because we're going to disable mag app-wide.)

pllim avatar Aug 06 '24 19:08 pllim

  1. I don't know what the flux scaling mean in unit that isn't a variant of Jy. The original ask from user was to hardcode 3631 Jy (ref: https://en.wikipedia.org/wiki/AB_magnitude) as a convenient shortcut to quickly get AB mag for JWST data. Maybe it is cleaner to set it to 1 for something that isn't Jy (or some prefix of it)?
  2. ~Not sure what is going on with the Curve of Growth JSON message.~ Never mind. I introduced that bug. I fixed it in a second commit that I pushed.

pllim avatar Aug 06 '24 19:08 pllim

@kecnry also said we should disable multi-select for aperture photometry in Cubeviz. Is that part of this PR or a different ticket?

pllim avatar Aug 06 '24 20:08 pllim

@kecnry also said we should disable multi-select for aperture photometry in Cubeviz. Is that part of this PR or a different ticket?

This is already a separate ticket, and I just said disabling could be an option if it isn't an easy fix (but that we probably should try to get it working and covered in tests if there aren't too many roadblocks).

kecnry avatar Aug 07 '24 11:08 kecnry

As it is, background and flux_scaling is going to crash whenever you try to convert from per-wavelength to per-frequency because that conversion needs u.spectral_density that needs a wavelength/frequency as input. Example traceback:

File aper_phot_simple.py:184, in SimpleAperturePhotometry._on_display_units_changed(self, event)
    181     new_unit = u.Unit(self.display_flux_or_sb_unit)
    183     bg = self.background_value * prev_unit
--> 184     self.background_value = bg.to_value(new_unit)
    186 # convert flux scaling to new unit
    187 if self.flux_scaling is not None:

UnitConversionError: 'MJy / sr' (surface brightness) and 'erg / (Angstrom s sr cm2)' (surface brightness wav) are not convertible

For Cubeviz, you can probably grab this value from slice. But this is going to be much trickier if you ever want to enable the same functionality for Imviz because then you need to infer that value from some bandpass information that might or might not be available.

pllim avatar Aug 08 '24 15:08 pllim

oh, i was working on adding the equivalencies but it looks like you just committed those changes?

cshanahan1 avatar Aug 09 '24 14:08 cshanahan1

Re: https://github.com/spacetelescope/jdaviz/pull/3118#issuecomment-2278044827

Oh ooops... Feel free to drop my commits then if you want to push yours out.

pllim avatar Aug 09 '24 14:08 pllim

Noooo... I think I broke it.

pllim avatar Aug 09 '24 14:08 pllim

Actually maybe the difference is caused by https://github.com/spacetelescope/jdaviz/pull/3133

(Yes, I confirmed it locally by comparing test result before/after rebase. So I updated the test result.)

pllim avatar Aug 09 '24 15:08 pllim