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

BlackBody and units support within modeling plugin #953

Merged
merged 13 commits into from
Nov 30, 2021

Conversation

kecnry
Copy link
Member

@kecnry kecnry commented Nov 2, 2021

Description

This pull request adds support for a BlackBody model in the modeling plugin (which in turn requires proper unit support for models in both jdaviz and specutils). Note that this PR is dependent on astropy/specutils#891 (now merged, but not yet released). Logic for Polynomial1D has been refactored to avoid duplicating code for the new support of units. Since astropy's BlackBody model does not (yet) support flux units, this uses a custom implementation until a proper solution is adopted in astropy.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Are two approvals required? Branch protection rule does not check for the second approval. If a second approval is not necessary, please apply the trivial label.
  • Do the proposed changes actually accomplish desired goals? Also manually run the affected example notebooks, if necessary.
  • Do the proposed changes follow the STScI Style Guides?
  • Are tests added/updated as required? If so, do they follow the STScI Style Guides?
  • Are docs added/updated as required? If so, do they follow the STScI Style Guides?
  • Did the CI pass? If not, are the failures related?
  • Is a change log needed? If yes, is it added to CHANGES.rst?
  • Is a milestone set? Milestone is only currently required for PRs related to Imviz MVP.
  • After merge, any internal documentations need updating (e.g., JIRA, Innerspace)?

@kecnry kecnry added this to the 2.1 milestone Nov 2, 2021
@codecov
Copy link

codecov bot commented Nov 2, 2021

Codecov Report

Merging #953 (bfe2be7) into main (381e715) will increase coverage by 1.29%.
The diff coverage is 70.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #953      +/-   ##
==========================================
+ Coverage   69.09%   70.39%   +1.29%     
==========================================
  Files          69       73       +4     
  Lines        4935     5256     +321     
==========================================
+ Hits         3410     3700     +290     
- Misses       1525     1556      +31     
Impacted Files Coverage Δ
...igs/default/plugins/model_fitting/model_fitting.py 28.28% <11.11%> (-0.77%) ⬇️
...figs/default/plugins/model_fitting/initializers.py 42.35% <61.90%> (+6.53%) ⬆️
jdaviz/models/physical_models.py 91.66% <91.66%> (ø)
jdaviz/models/__init__.py 100.00% <100.00%> (ø)
jdaviz/configs/imviz/plugins/parsers.py 100.00% <0.00%> (ø)
jdaviz/configs/imviz/plugins/__init__.py 100.00% <0.00%> (ø)
...configs/imviz/plugins/aper_phot_simple/__init__.py 100.00% <0.00%> (ø)
...imviz/plugins/aper_phot_simple/aper_phot_simple.py 95.37% <0.00%> (ø)
jdaviz/configs/imviz/helper.py 98.31% <0.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 381e715...bfe2be7. Read the comment docs.

@kecnry kecnry marked this pull request as ready for review November 3, 2021 14:49
@kecnry kecnry marked this pull request as draft November 9, 2021 19:23
@kecnry kecnry force-pushed the modeling-bb-and-units-support branch 2 times, most recently from 613acc3 to 5ae04b9 Compare November 10, 2021 20:43
@kecnry kecnry marked this pull request as ready for review November 16, 2021 17:19
* currently uses custom "fork" of BlackBody model with support for flux units.  Will likely want to update this to the eventual support for flux units in astropy
* to update to new changes to models with units but without having to duplicate too much code logic
* but remove deprecation tests
@kecnry kecnry force-pushed the modeling-bb-and-units-support branch from 5ae04b9 to cc2a84d Compare November 23, 2021 16:41
* BlackBody now passes unitless scale with output_units assigned from the y-axis of the spectrum
* BlackBody.output_units now supports passing units as strings (as it needs to be serializable within jdaviz)
* the unitless scale is estimated from the maximum value of the spectrum converted into the native blackbody units (to handle cases where the y-unit contains 1e-17, etc)
* automatic limits of (0, None) are placed on the scale to try to prevent the optimization from getting stuck at 0 if overshooting, but can still be somewhat sensitive to the initial guess.
* fixes bug (likely introduced earlier in this PR) where overridden values from initializers were not being set correctly in the plugin.  This does currently require looping over parameters twice and might be able to be simplified in the future.
@kecnry kecnry force-pushed the modeling-bb-and-units-support branch from cc2a84d to 3dd2ef5 Compare November 23, 2021 16:45
@orifox
Copy link
Contributor

orifox commented Nov 23, 2021

Ok, this passes all of my tests. I approve to merge!

@orifox orifox self-assigned this Nov 23, 2021
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a general review. I don't know how to use the plugin properly, so if @orifox et al. are happy with the usability, it is fine by me.

CHANGES.rst Outdated Show resolved Hide resolved
"""
Initialization that is specific to the BlackBody model.

Notes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to comment on the Sphinx stuff here because a hidden class will not make it to public API doc. FYI.

jdaviz/models/physical_models.py Show resolved Hide resolved
@pllim

This comment has been minimized.

@kecnry kecnry force-pushed the modeling-bb-and-units-support branch from ce18253 to ad97141 Compare November 23, 2021 21:35
@kecnry kecnry force-pushed the modeling-bb-and-units-support branch from c85fb35 to 67d8eb5 Compare November 24, 2021 19:46
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve by proxy since @orifox is happy and my comments are addressed.

One other approval would be nice.

Thanks!

Copy link
Collaborator

@rosteen rosteen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I was able to fit a blackbody and get the model and model parameters back out into the notebook.

Screen Shot 2021-11-30 at 1 06 27 PM

@rosteen rosteen merged commit 0b3da0a into spacetelescope:main Nov 30, 2021
@kecnry kecnry deleted the modeling-bb-and-units-support branch November 30, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants