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

Adding synphot #424

Merged
merged 15 commits into from
Apr 1, 2021
Merged

Adding synphot #424

merged 15 commits into from
Apr 1, 2021

Conversation

shanosborne
Copy link
Contributor

This PR aims to work with spacetelescope/poppy#388 to replace pysynphot with stsynphot.

After discussion with @mperrin, we decided that completely replacing pysynphot in webbpsf would cause problems for our dev users (especially ote sim mirage users) if they have mismatched webbpsf and poppy versions. So instead, we decided to add a check for the user's poppy version inside webbpsf. If poppy > 0.9.2 (the latest release), the code would use stsynphot, if poppy <= 0.9.2, the code would use pysynphot. We will remove this check for the next release of webbpsf, but this will help users in the meantime.

Testing Note: Because of the version check above, since the poppy PR with the stsynphot changes isn't merged yet, in order to test this you'll need to change the > to < in line 57 in webbpsf_core.py. That or we'll need to rebase the poppy PR to appear that the change is after 0.9.2

@shanosborne
Copy link
Contributor Author

@pllim I've tried running this branch with your branch in poppy and I'm getting some errors from the stsynphot calls in poppy. Would you be able to look this over and see if you understand the errors? Thanks!

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.

pysynphot and stsynphot are not 100% interchangable, especially when it comes to Quantity support and underlying machinery.

Comment on lines 18 to 21
if package_version.parse(poppy_ver) > package_version.parse("0.9.2"):
import stsynphot
else:
import pysynphot
Copy link
Contributor

@pllim pllim Mar 1, 2021

Choose a reason for hiding this comment

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

I wouldn't do this: This looks like a maintenance nightmare. Much easier to cut the next major release and not use pysynphot at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed in the long run, yes. This is intentional and needed in the short term transitional period however. We plan to take it out after this next release.

@codecov
Copy link

codecov bot commented Mar 1, 2021

Codecov Report

Merging #424 (2692bbf) into develop (ce518be) will decrease coverage by 0.00%.
The diff coverage is 50.45%.

❗ Current head 2692bbf differs from pull request most recent head 9ac51a9. Consider uploading reports for the commit 9ac51a9 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #424      +/-   ##
===========================================
- Coverage    48.39%   48.39%   -0.01%     
===========================================
  Files           14       14              
  Lines         5837     5912      +75     
===========================================
+ Hits          2825     2861      +36     
- Misses        3012     3051      +39     
Impacted Files Coverage Δ
webbpsf/obssim.py 0.00% <0.00%> (ø)
webbpsf/jupyter_gui.py 7.97% <38.46%> (+2.32%) ⬆️
webbpsf/utils.py 61.56% <57.89%> (-0.23%) ⬇️
webbpsf/distortion.py 81.81% <60.00%> (-13.42%) ⬇️
webbpsf/webbpsf_core.py 80.58% <63.63%> (+0.69%) ⬆️
webbpsf/roman.py 90.00% <0.00%> (+0.22%) ⬆️

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 ad9c2de...9ac51a9. Read the comment docs.

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

The tests passed here. I don't understand where are the errors you need help with. Can you please clarify? Thanks!

@shanosborne
Copy link
Contributor Author

@pllim, the errors come from running this branch of webbpsf with your pysyn-stsyn-port branch of poppy, in an environment where stsynphot is installed

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

@shanosborne , can you please have this branch call that branch here, so we can all see the log in CI? Thanks!

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

I waited a while for https://travis-ci.org/github/spacetelescope/webbpsf/jobs/760994800 to run but it passed. 🤷 (I cancelled the irrelevant jobs.)

@shanosborne
Copy link
Contributor Author

Oh shoot you're right. I messed up the test and didn't add an stsynphot installation to it, so it passed because it never called any of the stsynphot code (which is optional and is only called if you have the package installed). I've just updated the test and hopefully it actually tests what we want it to now. Sorry about that!

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

Seems like Travis CI has a very long queue time now. Still waiting for it to start. 🤞

@shanosborne
Copy link
Contributor Author

Right, so now we have the case where the fact that the poppy PR isn't merged yet has become a problem. So I'm going to add a commit to flip the sign of the version check in webbpsf_core.py which we will need to undo before merging the PR, but is necessary for testing.

@mperrin
Copy link
Collaborator

mperrin commented Mar 1, 2021

@shanosborne for the version check - how about instead of looking at the version number we try looking at just what poppy is using directly. Something like this:

try:
   import poppy.instrument.stsynphot
   # poppy is using sysynphot so webbpsf should too
   import stsynphot
except ImportError:
   import pysynphot

And, optional, but I wonder if it's worth consolidating these if/else statements into one place in the code, so there's less to undo later when we can take out all the pysynphot refs eventually.

This all would indeed be easier if we could afford a case of temporary breakage of dependencies if we don't merge both PRs at the exact same time, but alas from past experience that way lies confusion and hassle...

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

I still think it is less maintenance burden to branch out 0.9.x that only uses pysynphot and only support stsynphot going forward. People who want to use pysynphot can use your 0.9.x releases and you can backport things into it from develop as needed. But I am not the one who has to maintain this package.

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

I guess we finally got it? Are the errors in https://travis-ci.org/github/spacetelescope/webbpsf/jobs/761016058 what you also see locally, @shanosborne ?

@pllim
Copy link
Contributor

pllim commented Mar 1, 2021

Most of the failures are caused by your source and bandpass "waveset" not overlapping completely or at all. This usually means either one of them have wavelength in existing values but now in wrong unit or some assumptions you made with PySynphot no longer makes sense. I'll see if I can sniff it out with your test cases.

There is one error where somehow you are passing in zero or negative for wavelength, which is not allowed.

@pllim

This comment has been minimized.

@pllim
Copy link
Contributor

pllim commented Mar 4, 2021

After discussions with @shanosborne , I have created this gist to explain why you are seeing failures, and provide workarounds, where possible. Many thanks to Shannon who patiently provided me with the necessary info.

tl;dr

  1. No overlap and partial overlap -- Your bandpass is too far from the blackbody peak, resulting in useless observation. You can force the observation to happen in stsynphot by resampling the blackbody (as shown in the gist above) but don't expect the observation to give you anything useful.
  2. Negative wavelength -- Your bandpass is unphysical. Do not create such a bandpass. After the bandpass typo is fixed, this is also a partial overlap case, as above.

@shanosborne shanosborne requested a review from mperrin March 9, 2021 20:55
@shanosborne shanosborne marked this pull request as ready for review March 29, 2021 14:52
@mperrin
Copy link
Collaborator

mperrin commented Apr 1, 2021

@shanosborne FYI the PR in poppy is now merged, so here we can take out the temporary parts (extra tox test case etc) and hopefully merge this shortly. Can you take care of the few updates needed in this, please? I'm not sure if anything's needed besides just the changes in the test setup?

Copy link
Collaborator

@mperrin mperrin left a comment

Choose a reason for hiding this comment

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

As discussed this should have the temporary test case revised out before we merge.

Looking at this now I'm starting to have second thoughts about the back compatibility approach, but probably not enough to revise. I still want to make sure we take zero chance of breaking any dependencies in any of the team practices etc; but I'm not sure we want all the switching code around in the long run. We probably should consider pysynphot deprecated and remove this before some later release I suppose.

One minor change requested, plus the test case stuff, and then this should be good to merge. Thanks!

Comment on lines 136 to 139
Pysynphot CDBS files used for the development version of the JWST Exposure Time Calculators (ETCs),
Stsynphot CDBS files used for the development version of the JWST Exposure Time Calculators (ETCs),
normalized to peak transmission = 1.0 (because absolute throughput is not
relevant for PSF calculations). Not all filters are yet supported in Pysynphot,
relevant for PSF calculations). Not all filters are yet supported in Stsynphot,
however.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: This text can be updated, as it's outdated in ways besides just the py/stsynphot change. Let's say the following:

Instrumental relative spectral responses are derived from the reference data files used by the Pandeia engine <https://jwst-docs.stsci.edu/jwst-exposure-time-calculator-overview/jwst-etc-pandeia-engine-tutorial/installing-pandeia#InstallingPandeia-DataFiles>_ for the JWST Exposure Time Calculator<https://jwst.etc.stsci.edu>_, normalized to peak transmission=1.0 (because absolute throughput is not relevant for PSF calculations).

@pllim
Copy link
Contributor

pllim commented Apr 1, 2021

Re: tox -- You still want a new job to test against stsynphot (unless you want to swap it out with pysynphot in existing jobs) but maybe not call it "poppydev".

@mperrin mperrin changed the title Adding stsynphot Adding synphot Apr 1, 2021
@mperrin
Copy link
Collaborator

mperrin commented Apr 1, 2021

Travis passes, codecov is "failing" but irrelevant (-0.01% delta), I'm going ahead with this since it's needed with the current dev poppy.

@mperrin mperrin merged commit 7ac2b7c into spacetelescope:develop Apr 1, 2021
@shanosborne shanosborne deleted the stsynphot branch July 4, 2021 21:55
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

Successfully merging this pull request may close these issues.

3 participants