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

MIRI and NIRcam PSF photometry with spacephot #173

Merged
merged 22 commits into from
Nov 21, 2024

Conversation

orifox
Copy link
Contributor

@orifox orifox commented Oct 6, 2023

This notebook checklist has been made available to us by the the Notebooks For All team.
Its purpose is to serve as a guide for both the notebook author and the technical reviewer highlighting critical aspects to consider when striving to develop an accessible and effective notebook.

The First Cell

  • The title of the notebook in a first-level heading (eg. <h1> or # in markdown).
  • A brief description of the notebook.
  • A table of contents in an ordered list (1., 2., etc. in Markdown).
  • The author(s) and affiliation(s) (if relevant).
  • The date first published.
  • The date last edited (if relevant).
  • A link to the notebook's source(s) (if relevant).

The Rest of the Cells

  • There is only one H1 (# in Markdown) used in the notebook.
  • The notebook uses other heading tags in order (meaning it does not skip numbers).

Text

  • All link text is descriptive. It tells users where they will be taken if they open the link.
  • All acronyms are defined at least the first time they are used.
  • Field-specific/specialized terms are used when needed, but not excessively.

Code

  • Code sections are introduced and explained before they appear in the notebook. This can be fulfilled with a heading in a prior Markdown cell, a sentence preceding it, or a code comment in the code section.
  • Code has explanatory comments (if relevant). This is most important for long sections of code.
  • If the author has control over the syntax highlighting theme in the notebook, that theme has enough color contrast to be legible.
  • Code and code explanations focus on one task at a time. Unless comparison is the point of the notebook, only one method for completing the task is described at a time.

Images

  • All images (jpg, png, svgs) have an image description. This could be

    • Alt text (an alt property)
    • Empty alt text for decorative images/images meant to be skipped (an alt attribute with no value)
    • Captions
    • If no other options will work, the image is decribed in surrounding paragraphs.
  • Any text present in images exists in a text form outside of the image (this can be alt text, captions, or surrounding text.)

Visualizations

  • All visualizations have an image description. Review the previous section, Images, for more information on how to add it.

  • Visualization descriptions include

    • The type of visualization (like bar chart, scatter plot, etc.)
    • Title
    • Axis labels and range
    • Key or legend
    • An explanation of the visualization's significance to the notebook (like the trend, an outlier in the data, what the author learned from it, etc.)
  • All visualizations and their parts have enough color contrast (color contrast checker) to be legible. Remember that transparent colors have lower contrast than their opaque versions.

  • All visualizations convey information with more visual cues than color coding. Use text labels, patterns, or icons alongside color to achieve this.

  • All visualizations have an additional way for notebook readers to access the information. Linking to the original data, including a table of the data in the same notebook, or sonifying the plot are all options.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:25:59Z
----------------------------------------------------------------

The notebook needs many more comments. It is not clear what has been done and why in many parts.

WebbPSF PSFs are made but no details are provided, so it is hard to evaluate what happened. WebbPSF for MIRI have various issues and they are ignored in the analysis below, making the results not very trustworthy.

There is no indicator of the PSF fit itself. How can a user objectively evaluate the results? Looking at the residuals or the corner plots is only partially useful.


orifox commented on 2023-11-26T18:29:10Z
----------------------------------------------------------------

Thanks. This was an excellent review. Very thorough and you understood a lot of the intricacies. I've tried to address all of your comments, and I think I have to within the scope of this notebook. Particularly how to use the results to determine the goodness of fit. Remaining are a number of Developer Notes (Action Items) to significantly improve the documentation for WebbPSF, Photutils, JDox, and of course, Space_Phot. We'll need to add a lot of that, but I think that is a much larger effort beyond the scope of this notebook. At the current time, users have no examples on how to do PSF photometry. Particularly no examples on how to generate even the most basic JWST PSFs and use them to obtain PSF photometry. So I think if we can confirm the photometry results here are indeed correct and have reliable error bars, we can move forward. Particulary given the PSF notebooks that are currently available. What would be good is to understand within the scope of all of these limitations, what you think the best way to move forward is.

Please remember, the only PSF photometry that users are currently being directed to is by Matteo from 3 years ago:

https://spacetelescope.github.io/jdat_notebooks/notebooks/psf_photometry/NIRCam_PSF_Photometry_Example.html

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:00Z
----------------------------------------------------------------

Please provide clear instructions about how to install the packages. If you install only space_phot, it retrieves the latest versions of all packages but new changes break some parts. The packages I had to change are the following:

  • photutils==1.9.0 -> photutils==1.8.0
  • poppy==1.1.1 -> poppy==1.0.3
  • numexpr==2.8.7 -> numexpr==2.8.3

orifox commented on 2023-11-21T16:51:18Z
----------------------------------------------------------------

Fixed.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:01Z
----------------------------------------------------------------

I would add a variable for the folder given that it might be different from "mast"


orifox commented on 2023-11-22T20:11:28Z
----------------------------------------------------------------

Fixed and hard-coded based on download script now included.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:02Z
----------------------------------------------------------------

Using jwst_download, the name of the json file includes the date. Add a comment to remember to change it


orifox commented on 2023-11-23T15:43:28Z
----------------------------------------------------------------

Good catch. Now automated and fixed.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:03Z
----------------------------------------------------------------

It should be explained what a DQ of 1 means. Also, the DQ flags that should not be used are many more than that. For example, it might be worth to exclude all pixels with a DQ>10, or at least those with a very large number.

I would also mask all pixels related to the 4QPM regions because we want to avoid users to make any science with them.


orifox commented on 2023-11-21T20:43:34Z
----------------------------------------------------------------

Done.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:05Z
----------------------------------------------------------------

Line #4.    ref_fits = fits.open(ref_image)

Why not using the jwst datamodels? Besides that usually we want to push to use products made "in the house", the jwst datamodels offer some advantages, like an easiest access to the header keywords and built-in functions.


orifox commented on 2023-11-23T15:46:06Z
----------------------------------------------------------------

jwst datamodels now used.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:06Z
----------------------------------------------------------------

Line #6.    norm1 = simple_norm(ref_data,stretch='linear',min_cut=-1,max_cut=10)

The scale should highlight the background noise so it is possible to see all faint sources. I would add a comment and change the values between 4 and 5, and/or use a log scale.


orifox commented on 2023-11-23T15:46:26Z
----------------------------------------------------------------

Fixed.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:07Z
----------------------------------------------------------------

Line #10.    plt.show()

I would make the image larger, it is hard to see the details.

This is a "scientific" notebook, so we should make it as such. I would add axis labels and a colorbar. I would add the units (both pixels for the x/y axes and MJy/sr for the colorbar).


orifox commented on 2023-11-21T21:53:41Z
----------------------------------------------------------------

Done.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:08Z
----------------------------------------------------------------

Line #2.    source_location = SkyCoord('17:43:04.4879','+66:55:01.837',unit=(u.hourangle,u.deg))

There is no explanation about this source. Why was it chosen among the rest in the field? Does it have an ID in some catalogs like Gaia?


orifox commented on 2023-11-23T15:55:00Z
----------------------------------------------------------------

Ok, updated. We are using Visit 006, which targets the A5V dwarf 2MASSJ17430448+6655015.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:09Z
----------------------------------------------------------------

Line #10.    plt.show()

Same comments as before: labels, units, scale. I would zoom out a bit to show the wings of the PSF.


orifox commented on 2023-11-21T22:00:28Z
----------------------------------------------------------------

Done.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:10Z
----------------------------------------------------------------

Besides that units and labels are missing, there is no explanation of what we are seeing. This is the PSF made by WebbPSF. How was it made? Did you use a monochromatic PSF or some wavelengths? Was it generated with the spectrum of the source? Is it oversampled and, if so, by how much?

You are analyzing a LVL-2 cal image. Are you using the distorted or the "undistorted" PSF from WebbPSF? It is critical to use the correct one.

WebbPSF PSFs do not include many detector effects. Depending on which version of WebbPSF you are using, there might be only the IPC effect. Also, the cruciform model in WebbPSF is wrong. It has been adjusted in the latest version to match that of my PSFs. Regardless, WebbPSF includes the cruciform artifact ONLY in the distorted PSF.


orifox commented on 2023-11-22T17:09:27Z
----------------------------------------------------------------

# Get PSF from WebbPSF

# The function get_jwst_psf is a space_phot wrapper for the WebbPSF calc_psf function and uses a lot of the same keywords.

# There are more advanced methods for generating your WebbPSF, but those are beyond the scope of this notebook.

# The defaults used by get_jwst_psf in this notebook are:

  # oversample=4

  # normalize='last'

  # Non-distorted PSF

# Useful reference: https://webbpsf.readthedocs.io/en/latest/api/webbpsf.JWInstrument.html#webbpsf.JWInstrument.calc_psf

orifox commented on 2023-11-23T16:51:51Z
----------------------------------------------------------------

Ok, these are all great questions. A DEV note has been added. A DEV note is standard when more work needs to be done, but shouldn't hold up the publishing of the notebook. In this case there are a lot of things to do. First, space_phot needs updated documentation on what get_jwst_psf does. For now, I have added comments into the notebook referencing how it calls WebbPSF's calc_psf function using the defaults. That's sufficient for the purposes of this notebook. Generating more complex PSFs is beyond the scope of this notebook and should be built into the WebbPSF documentation or additional MIRI JDox documentation and/or notebooks. So that is Dev Note #2.

For moving forward, we have added brief comments to temporarily address these issues with details about how the PSF is being generated.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:10Z
----------------------------------------------------------------

The lack of comments makes it hard to understand all outputs here:

  • The first set of plots with Data, Model, Residual shows the target in each image, (I believe) the WebbPSF PSF rescaled and shifted to make the model of the target, and the result of the PSF subtraction. There is a clear systematic trend in the residuals. The PSF is oversubtracted in the centermost pixel and undersubtracted in the wings. What causes this effect? Is it because the source is bright and the brighter-fatter effect that changes the flux distribution of the source or is it the model that is not a good representation of the target? It should be explained to the user what they are looking at. The % value of the median residuals is what it is if not put in a context.

  • There is no explanation of the quantities fit in the corner plots at the bottom. What are the different pairs of coordinates (x0,y0) (x1,y1) (x2,y2) and (x3,y3)?

  • What is the background fitted? Shouldn't it be computed in, e.g., an annulus region far from the source? If the background is estimated taking into account for the PSF wings, it should be explained. There is a correlation between flux and background that is weird if the two are not related.

Why is the table at the bottom showing the results in Equatorial coordinates? You are measuring coordinates of sources on a pixel grid, so the result should be in pixels

How do you get calibrated magnitudes from the PSF fit? Again, more explanations would help.

Why are there errors on the estimate of the position and flux? This is a single measurement of one source in one image, how can you get an error from that? I'm always skeptical about errors computed this way.


orifox commented on 2023-11-23T17:31:58Z
----------------------------------------------------------------

Ok, a lot of comments to respond to here. Let me try my best.

  1. Again, Dev notes are added for improved documentation on the metrics and how to set the parameters. Temporary notes have been added that address many of your questions.
  2. The PSF oversubtraction could be caused by either of your options. I haven't had a chance for either Justin to optimize the fits or have someone help me come up with a better PSF model. To this end, I think finding the perfect PSF model is beyond the scope of this notebook. I agree its important to find a good model, but at this point, I haven't met anyone or read any documentation with the code to do it. So I have added a Dev note and commentary to this point. Nonetheless, the residual value is pretty good so the overall statistical error is relatively small.
  3. The corner plots definitely need more explanation. That is captured in the Dev Note.
  4. More description of the background fitting is needed. That is capture in the Dev Note.
  5. The table shows both equatorial and pixel coordinates, but i think if you look at the table in the cell certain columns are not displayed. We think all values should be displayed to the user. No action has been taken.
  6. The basic answer to the calibrated magnitude question is that the result is baked in. WebbPSF models are normalized (in this case) so that the fitted flux value is the same as the sum o fthe infinite PSF. So a fitted flux is not fitting the observed flux, its fitting TO the flux we see. This is important, but again, something that belongs in the documentation and not the notebook. We really need to beef up our PSF pages. This is captured in the Dev Note.
  7. As for errors, the values areported are just statistical errors. For systematic errors one would need to plant/recover, but that is beyond the scope of this notebook. Nonetheless, we are clear that statistical errors are reported. This is no different than what Astropy's Photutils reports.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:12Z
----------------------------------------------------------------

By averaging directly the magnitudes from the 4 images, you make the implicit assumption that there is no zero-point between the 4 exposures. The zero-point between consecutive exposures should be very small, less than 0.01 mag, but depending on the precision you want to reach it might matter.

You estimate the mag error as the sum in quadrature of the errors of the individual measurements. This: (1) assumes that individual errors are legit, but they might not be (see my comment in the previous cell); (2) does not allow you to detect outliers. If you compute the error as the rms or the standard error of the mean, you can clearly see if the measurements are consistent with each other or not.


orifox commented on 2023-11-23T18:04:14Z
----------------------------------------------------------------

Good catch. The averaging was all a bit old and not supposed to be in there for the exact reasons you give. The whole point to simultaneous fitting is to account for all of this. As a result, the flux and corresponding error take into account a single overall fit. Therefore, there is no need to average the resulting magnitudes or errors. They should all be the same to within their individual zero-point differences (typically <1%).

This is now captured in the documentation, notes, and Dev Notes. I think that addresses all of these concerns.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:13Z
----------------------------------------------------------------

In the followings sections, I have the same comments as in the previous part. I will add only new comments or additional explanations when necessary.


Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:14Z
----------------------------------------------------------------

Why is the pipeline run here?

As I wrote for the corresponding cell in the previous section, details are missing? Is this the WebbPSF PSF corresponding for the LVL-3 image? If so, note that there is the problem of the missing cruciform.

One of the problems I have with doing PSF photometry on the LVL-3 images is that the flux distribution of the stars in the mosaic changes depending on how the mosaic was made. Kernels and weights can result in different flux distributions. So, PSFs might not be a good representation of point-like sources in all mosaics.


orifox commented on 2023-11-23T17:42:13Z
----------------------------------------------------------------

At this point, we are taking several Level2 PSFs and resampling with the pipeline to make a Level2 PSF. We don't know how to turn off the output when that step is run.

Regarding your questions, the Level2 PSFs are generated at the precise location of the source in each Level2 file to account for detector level effects. The resampling uses default resampling paramters. However, users should be aware that if they performed customized resampling for their Level2 data products, they should use similar resampling steps for their PSF below. We added a couple more comments and Dev Notes about these topics and believe that this comment is adequately addressed for the scope of this notebook.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:16Z
----------------------------------------------------------------

Where is the source here?


orifox commented on 2023-11-22T17:30:14Z
----------------------------------------------------------------

The goal is to calculate an upper limit on the blank part of the sky. Additional clarification has been written.

mlibralato commented on 2023-11-27T20:02:33Z
----------------------------------------------------------------

I still do not understand this test and to me it does not make sense.

orifox commented on 2023-11-27T20:34:08Z
----------------------------------------------------------------

I'm not sure how else to say it. The goal is to calculate an upper limit. Let's say you want to try to determine how bright a source is, but you can't see it in a particular filter. Then you need to calculate an upper limit. How do you normally calculate upper limits?

mlibralato commented on 2023-11-27T20:48:33Z
----------------------------------------------------------------

I think you mean lower limit. We add many sources of various brightness across the entire FoV and try to measure them. At a certain threshold, you recover less stars, let's say 50%. Then you go X mag fainter and you recover only 20% and so on. These values tell you what you can measure in an image.

orifox commented on 2023-11-27T20:51:57Z
----------------------------------------------------------------

Right, that's how you would traditionally do it over a field. But in many cases, and supernovae in particular, you have a very complicated background in a very specific region of the detector. Dropping a source at that position is certainly one way to do it. But doing PSF photometry with the "Upper Limit" mode turned on essentially does this for you. And with less systematic error. Also, in general, we call this an "Upper Limit". Because the source could be fainter, but not brighter. If it were brighter, we would have detected it.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:17Z
----------------------------------------------------------------

To me, it seems that you have fitted the background noise.

The result of the fit is a negative flux, which is unphysical. If the fit failed, the code should tell the user.


orifox commented on 2023-11-23T18:06:21Z
----------------------------------------------------------------

These parameters were supposed to be optimized before we submitted the notebook, but that never got done. They are now optimized. In any case, PSF fitting does fit the background noise. That is the whole point to being able to calculate upper limits from PSF fitting. The values returned are the same as in Photutils. Photutils doesn't report a failed fit either. Instead, users need to be able to understand the goodness of fit from their error bars. That is now captured in the text in the notebook.

Copy link

review-notebook-app bot commented Nov 6, 2023

View / edit / reply to this conversation on ReviewNB

mlibralato commented on 2023-11-06T15:26:18Z
----------------------------------------------------------------

There is no source fit here. Whatever it was fitted, it was not a star.


orifox commented on 2023-11-22T17:37:56Z
----------------------------------------------------------------

Need to ask Justin about the "Fix Background" Parameter setting here.

orifox commented on 2023-11-23T18:15:35Z
----------------------------------------------------------------

Thanks. Again we never got to finalizing the optimal paramters. That has now been done.

Copy link
Collaborator

@gibsongreen gibsongreen left a comment

Choose a reason for hiding this comment

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

All execution, validation, and styling checks pass, ready to merge after rebasing and updating to new repository structure

@gibsongreen gibsongreen merged commit 9f8d6e3 into spacetelescope:main Nov 21, 2024
14 checks passed
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.

7 participants