Skip to content

Conversation

@jemorrison
Copy link
Collaborator

@jemorrison jemorrison commented Sep 11, 2023

Resolves JP-3355 and Resolves JP-3340

Closes #7846 and #7815

This PR allows the user to override the srctype and perform POINT source extraction for IFU data.

Checklist for maintainers

@jemorrison jemorrison requested a review from a team as a code owner September 11, 2023 22:06
@jemorrison
Copy link
Collaborator Author

Will update documentation next

@jemorrison
Copy link
Collaborator Author

I am going to add the work needed for JP-3340 since it is so similar to is needed for this ticket.

@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Patch coverage is 11.76% of modified lines.

Files Changed Coverage
jwst/extract_1d/extract_1d_step.py 0.00%
jwst/extract_1d/ifu.py 20.00%
jwst/extract_1d/extract.py 33.33%

📢 Thoughts on this report? Let us know!.

@jemorrison jemorrison added this to the Build 10.0 milestone Sep 11, 2023
@tapastro
Copy link
Contributor

Is this worth including over recommending reprocessing spec2 with a srctype step parameter, or having a user modify the header value prior to running extract_1d? I feel like this is an overreach for extract_1d parameters, which is already a bloated list.

@drlaw1558
Copy link
Collaborator

This modification is based on a number of user interactions and their frustration with it being so hard to change the spectral extraction behaviour; it's also helpful from a testing perspective.

@jemorrison
Copy link
Collaborator Author

I have had to modify the SRCTYPE to POINT for all the data I have worked with and then set up a specialized extract 1d reference file with a scaled radius. IT IS A PAIN! Having 2 options to extract1d would be so much easier

@jemorrison
Copy link
Collaborator Author

@jmuzerolle @melanieclarke @leonardoubeda I am making these changes to extract1d for MIRI MRS data(option to change to POINT Source, option to scale extraction radius). The NIRSpec aperture correction has multiple radii to use so it could also handle having a scaling radius. But this code change is focused on MIRI because of how the default extraction radii is set. Looking at the NIRSpec App corr files they are still marked as DUMMY and there are 3 fix radius extractions (0.3, 0.5, 1.0). I don't know if the team has done enough study to want to scale the extraction radii. Unless I hear otherwise I will keep these options as only MIRI MRS options

@jemorrison
Copy link
Collaborator Author

This is really an issue with how the data is extracted. If we change it in SRC type step then if there are point source specific steps applied that would happened and we may not want that. I am thinking of NIRSpec pathloss mostly. At least that is my take on it. We just want to have an extraction radius and that is only possible in extract 1d with a POINT source type of data.

@hbushouse
Copy link
Collaborator

So given all the commentary regarding how everyone has to rerun extract_1d on their MRS cubes to have the extraction done as a point source, why are we ever setting SRCTYPE='EXTENDED' to begin with? How much would it affect upstream processing if the srctype step were just hardwired to always set it to point source for every MRS exposure? Alternatively, if the extended source version of IFU extraction in extract_1d is totally worthless, then we should consider removing it, or at least changing the logic in the step so that it just always uses point source extraction for MRS, period.

@drlaw1558
Copy link
Collaborator

I realize I should clarify; it's not that everyone has to rerun extract_1d. Many programs can use the extended source extraction just fine, or at least it's as good as possible given their scene geometry of fuzzy stuff. It's just that in a number of cases there is a complex extended-type scene with multiple point sources within it, or a single source that turns out to be only slightly extended and can for most purposes be treated as a point source. In those cases it's helpful to be able to use the pipeline to run point-source like extractions at specific locations in the scene rather than users rebuilding the wheel trying to figure out how to use the aperture correction file outside the pipeline.

@jemorrison jemorrison force-pushed the JP-3355_extract1d_override_src_type branch from 7fb5b07 to c6f2c5d Compare September 13, 2023 17:05
@jemorrison
Copy link
Collaborator Author

@hbushouse @drlaw1558 I made all the suggested changes. I tested it some. David you might want to test it more.
I will see about getting this run through the regression tests today

Copy link
Collaborator

@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

Still needs a change log entry

@jemorrison jemorrison force-pushed the JP-3355_extract1d_override_src_type branch from 85d1799 to 32bd697 Compare September 14, 2023 17:31
@jemorrison
Copy link
Collaborator Author

@leonardoubeda @jmuzerolle @bethanjames
I have made a few changes to extract1d to support MIRI MRS extraction changes.

This pr allows the user for IFU to change from EXTENDED to POINT source (or vice versa). Is this a feature NIRSpec IFU should allow ?

@jemorrison jemorrison force-pushed the JP-3355_extract1d_override_src_type branch from df7db3f to 4859bc6 Compare September 18, 2023 19:41
@leonardoubeda
Copy link

@jemorrison With regards to the comment:
"This pr allows the user for IFU to change from EXTENDED to POINT source (or vice versa). Is this a feature NIRSpec IFU should allow ?"
I was thinking about the fact that NIRSpec IFU treats EXTENDED and POINT differently when calculating fluxes (#7569) and may be allowing users to select the source type might result in wrong fluxes without intention to do so.

@jemorrison
Copy link
Collaborator Author

@leonardoubeda Yeah I was concerned about that as well. This option to switch to POINT to EXTENDed or vice versa is probably just something MIRI MRS people would want to try. But it is only changing the fact that the extraction can be done using a radius and not the entire FOV of the s3d cube. But since an aperture correction would then also be applied which is
more for POINT like data (unless that is turned off), it might be less confusing to people working with NIRSpec data to just go back and change the SRCTYPE in the calspec2 pipeline. So I will leave this PR as it is and only allowed for MIRI MRS data

@jemorrison jemorrison force-pushed the JP-3355_extract1d_override_src_type branch from 6da57ce to 6d6ca15 Compare September 19, 2023 16:15
Copy link
Collaborator

@drlaw1558 drlaw1558 left a comment

Choose a reason for hiding this comment

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

LGTM. Tested the pt/extended swap and also that various choices of scaling radius give results that match what I get when overriding the relevant reference file to implement the change by hand. Seems to all be working as expected.

@jemorrison
Copy link
Collaborator Author

@hbushouse Here are the results of the regression tests. The two failures do not seem related to this PR- NIRSpec MSA tests that can not find the msa meta file. https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/958/

@hbushouse
Copy link
Collaborator

@jemorrison There are EIGHT failures in your regtest run, not just 2. The first 2 are unrelated, as you say, but the remaining 6 are coming from the new extract_1d code trying to work on WFSS data:

                # --------------------------------------------------------------
                # Data is WFSS
                if input_model[0].meta.exposure.type in extract.WFSS_EXPTYPES:
    
                    # For WFSS level-3, the input is a single entry of a
                    # SourceContainer, which contains a list of multiple
                    # SlitModels for a single source. Send the whole list
                    # into extract1d and put all results in a single product.
                    apcorr_ref = (
                        self.get_reference_file(input_model[0], 'apcorr') if self.apply_apcorr is True else 'N/A'
                    )
    
                    if apcorr_ref == 'N/A':
                        self.log.info('APCORR reference file name is "N/A"')
                        self.log.info('APCORR will NOT be applied')
                    else:
                        self.log.info(f'Using APCORR file {apcorr_ref}')
    
                    extract_ref = 'N/A'
                    self.log.info('No EXTRACT1D reference file will be used')
    
                    result = extract.run_extract1d(
                        input_model,
                        extract_ref,
                        apcorr_ref,
                        self.smoothing_length,
                        self.bkg_fit,
                        self.bkg_order,
                        self.bkg_sigma_clip,
                        self.log_increment,
                        self.subtract_background,
                        self.use_source_posn,
                        self.center_xy,
                        self.ifu_autocen,
                        self.ifu_rfcorr,
                        self.ifu_set_srctype,
>                       self.ifu_rscsale,
                        was_source_model=was_source_model
                    )
E                   AttributeError: 'Extract1dStep' object has no attribute 'ifu_rscsale'

I guess the new ifu_rscale attribute hasn't been added to the step object properly?

@jemorrison
Copy link
Collaborator Author

@hbushouse Ok now there are only 2 failures:
https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/962/

And those failures are because the MSA file can not be found.

Copy link
Collaborator

@hbushouse hbushouse left a comment

Choose a reason for hiding this comment

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

All looks good now. So I guess the final consensus on whether or not to make the srctype option available for NRS_IFU was no?

@drlaw1558
Copy link
Collaborator

I'm getting some major crashes after this merge that I hadn't seen in testing. Extract1d runs in a standalone manner, but not as part of the spec3 pipeline; crashing at
232 if self.ifu_rfcorr:
--> 233 if input_model.meta.exposure.type != "MIR_MRS":
with
AttributeError: No attribute 'exposure'

Was this exposure type test introduced for the first time here?

@hbushouse
Copy link
Collaborator

I'm getting some major crashes after this merge that I hadn't seen in testing. Extract1d runs in a standalone manner, but not as part of the spec3 pipeline; crashing at 232 if self.ifu_rfcorr: --> 233 if input_model.meta.exposure.type != "MIR_MRS": with AttributeError: No attribute 'exposure'

Was this exposure type test introduced for the first time here?

It might be due to the fact that the combined s3d file created during level-3 processing doesn't have the exposure attribute carried over into the meta of the data model? It should have all original meta copied over, but that's my guess.

@drlaw1558
Copy link
Collaborator

Looks like the issue is that, when called on a single cube, the input is a single Model with all the associated keywords. When called from spec3 the input is a ModelContainer, which presumably needs to access keywords in a different way (and could conceivably change between items in the container?)

@tapastro
Copy link
Contributor

If the input is a ModelContainer, you may need to access a model in the container to check meta properties. Wouldn't this be seen in regression testing?

@hbushouse
Copy link
Collaborator

If the input is a ModelContainer, you may need to access a model in the container to check meta properties. Wouldn't this be seen in regression testing?

Those new params are set to None by default, so the if block wouldn't be executed in normal tests. Obviously need a test that exercises the new params.

@jemorrison
Copy link
Collaborator Author

Dang. Ok I will add a test and make figure out what is needed when the s3d is created from multiple channels.

@hbushouse
Copy link
Collaborator

But by the time the combined s3d cube gets fed to extract_1d during calwebb_spec3 processing, shouldn't it be just a single model, as opposed to a model container? The original input to calwebb_spec3 will be a model container, loaded from the list of exposures in the ASN file. But I would assume that the output of cube_build is a single model, because the exposures have been combined. Or does it create multiple cubes, one for each channel/band combination? If the input to extract_1d during level-3 is a container, then you just need something like input_model[0].meta.exposure.type, i.e. just pick the first one. They'd better all be the same EXP_TYPE!

@jemorrison
Copy link
Collaborator Author

Working on this now to understand the error. In all cases whether calspec2 or calspec3 the output from cube_build is an IFU model. But it could pass a Container of IFU models if the association contains multiple Channel cubes.

@jemorrison
Copy link
Collaborator Author

jemorrison commented Sep 21, 2023 via email

@jemorrison jemorrison deleted the JP-3355_extract1d_override_src_type branch November 19, 2024 15:24
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.

Allow extract_1d to override POINT vs EXTENDED

5 participants