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

NIRSpec MOS level 3 spectral combination issues #3918

Closed
stscijgbot opened this issue Aug 14, 2019 · 78 comments
Closed

NIRSpec MOS level 3 spectral combination issues #3918

stscijgbot opened this issue Aug 14, 2019 · 78 comments

Comments

@stscijgbot
Copy link
Collaborator

Issue JP-936 was created by James Muzerolle:

I am testing calwebb_spec3 using a set of simulated MOS exposures, which consists of a 3-shutter nod pattern.  The level 3 products, with source-based files containing 2D unrectified spectra from all exposures and the combined 2D and 1D products, were generated correctly.  However, the combined 2D products appear to have a couple of problems:

  1. Data for the same source on both detectors are not being combined; the NRS2 data are being dropped entirely unless a particular source has no spectrum at all on NRS1.

  2. The combined products tend to appear somewhat jumbled, and the source spectrum from the 3 nods don't seem to overlap (a screen shot of one example is attached).  It's possible I have not included fully correct WCS pointing information in the headers since I wasn't clear on exactly what needs to go where (keyword values need to be added by hand in this case); I essentially cut-and-pasted the SCI headers from a "real" example generated from the nOPs test runs.  Do I also need to make changes to the primary headers?

The input data, level 2b products, and the level 3 products for one source can be found in /grp/jwst/wit4/nirspec/Muzerolle/Files_spec3.

 

@stscijgbot
Copy link
Collaborator Author

Comment by James Davies: Thanks for the report James.

If you are manually changing pointing information in keyword headers, that needs to be done on the _rate.fits file, i.e the input to the spec2 pipeline. This is the only time it is used. It is used in the very first assign_wcs step. After that the spectra are then extracted into 2D cutouts (the _cal.fits file), and at that point, FITS header keywords no longer matter. The spec3 pipeline uses only the GWCS and no keyword headers when doing the resampling, and of course that GWCS is computed at the beginning of the stage 2 pipeline with assign_wcs.

Getting the FITS header keywords for pointing populated correctly for simulated data is tricky, as one has to figure out which change in telescope pointing and roll (translated into RA_REF, DEC_REF and ROLL_REF and the aperture reference) will produce the nod you need in your data. I suspect it is especially tricky in NIRSpec given the angle of the detector relative to spacecraft V2 (that is in the V3I_YANG keyword header).

If you are editing the pointing info after the data has been extracted into cutouts and written to the _cal.fits file, then you'll have to do it before that on the input to the spec2 pipeline.

Of course there could actually be a problem in the resampling code, but it would be good to make sure that the GWCS is being created as intended in assign_wcs first.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: An update on this issue:  I reprocessed this same simulated data after having added the correct (I think) spacecraft pointing information to the rate files (using cal version 0.13.7).  Both problems reported above are still evident.  I have replaced the old files with the new versions in the same directory on central store.

@stscicrawford stscicrawford modified the milestones: Build 7.4, Build 7.5 Dec 4, 2019
@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol]
I am starting to work on this issue. James do you have the association file set up for calspec3 for this data ?
I have not worked with a lot of NIRSPEC MOS nodded data and I am not sure how the association file is set up so that background subtraction is done correctly.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: Yes, both the level 2 and 3 association files I used are now in the same directory as the data (/grp/jwst/wit4/nirspec/Muzerolle/Files_spec3).  Note the background subtraction is done at level 2.  I also updated the fits files to the latest versions processed with b7.4, though I don't think there were any substantial changes from the last version.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~bushouse][~eisenham] [~jdavies]
Since the input data James M provided had so many slits in a single file and running that data through calspec3 took hours and hours just to set up the CRDS data I pulled out 2 slits from each file - Source ID 3161 and 3162. I pulled out the 9 extensions for each slit in the original and wrote them to a new file.
So my new file has 18 extension + asdf extension. I did this for the 6 input files.
When I run calspec3 on this input file it has a problem in exp_to_source when it is reorganizing the data - it is trying to access Source ID 3901 - which in the original file was the next slit. So I still need to remove the
information about all the original slits someplace in my new file - is that information in the asdf. I am not sure where this information is coming from

@stscijgbot
Copy link
Collaborator Author

Comment by Howard Bushouse: Yes, the slit attributes are in the ASDF extension, but it won't work to just do a simple delete of the entire ASDF extension, because you'd also lose the WCS objects for each slit. And you can't simply rerun assign_wcs on the modified cal files (with only 2 slits), because assign_wcs is build to work on the original full 2-D image before the slits have been extracted. So you either need to edit out certain specific parts of the ASDF meta tree or start over completely from the original rate files (if they exist) and redo all of the calwebb_spec2 processing to extract only 2 slits to begin with. [~eisenham] or [~jdavies] might have ideas of how to do specific edits of the ASDF meta tree.

@jemorrison
Copy link
Contributor

@jmuzerolle
I am having difficulty using the cal files you provided because there are so many slits in each file it takes me hours to run cal_spec3 just to get through opening all the files and getting the needed CRDS reference files. I plan for testing to pull out ~2 slits out of the files. I need to do this in
on the file before calspec2 is run so the asdf extension is correct and only contains information on the slits that are actually in the file.. I am using the data in
/grp/jwst/wit4/nirspec/Muzerolle/Files_spec3. Going by the names of the cal files I believe you did not apply the flat is there anything else I should be aware of when I re-run these files through calspec2. I plan to use the l2_asn.json file for the cal spec2 pipeline

@jmuzerolle
Copy link

Hi Jane,

That's right, I skipped the flat_field step because the simulations don't include the major component of that. Otherwise, I ran calspec2 as normal with the json association file. Let me know if you need help in modifying the MSA metafile, I have code that can re-create it with just a few slits instead of the entire set.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol]
I realize I do not know how to reprocess this data through calspec2. The input data is 2048 X 2048. I need an MSA file ?
But I did not see on in the l2_asn.json file and I do not see a MSA file on /grp/jwst/wit4/nirspec/Muzerolle/Files_spec3
Am I looking in the wrong place ?
Could you point me to the MSA and maybe put the code that modifies t the MSA file someplace I can grab too.
I have not worked with NIRSPEC MOS data much so this is new territory for me

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison]

I put both the original MSA metafile ("jw95065006001_msa_full.fits") and a new version with only 2 slits/sources ("jw95065006001_msa.fits") in /grp/jwst/wit4/nirspec/Muzerolle/Files_spec3.  The MSA metafile contains information on all of the shutters that were commanded open to form the slits corresponding to the set of science sources, which is needed by assign_wcs and extract_2d.  The name of the metafile is contained in the primary header keyword "MSAMETFL", and has to be present before calspec2 can be run.  You should be able to rerun the F170LP*correctedWCS.fits files through calspec2 without changing anything else.  If you want to try different slits, you can edit the script "edit_metafile.py" and change the "saveslits" array to whatever slit IDs you want.  Let me know if you have any problems!

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] I grabbed the MSA file and tried to reprocess the data. I looked at the MSA file and it is set up
for SLITLET_ID 6 and 44 I belive. When I trying and run cal spec2 (skipping the flat field step) I get the error below for
F170LP-G235M_MOS_observation-6-c0e0_001_DN_NRS2_mod_correctedWCS.fits
File "/Users/morrison/git/jwst/jwst/pipeline/calwebb_spec2.py", line 193, in process_exposure_product
raise assign_wcs_exception
File "/Users/morrison/git/jwst/jwst/pipeline/calwebb_spec2.py", line 174, in process_exposure_product
input = self.assign_wcs(input)
File "/Users/morrison/git/jwst/jwst/stpipe/step.py", line 392, in run
step_result = self.process(*args)
File "/Users/morrison/git/jwst/jwst/assign_wcs/assign_wcs_step.py", line 84, in process
result = load_wcs(input_model, reference_file_names, slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/assign_wcs.py", line 51, in load_wcs
pipeline = mod.create_pipeline(input_model, reference_files, slit_y_range=nrs_slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 58, in create_pipeline
pipeline = exp_type2transform[exp_type](input_model, reference_files, slit_y_range=slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 275, in slits_wcs
open_slits_id = get_open_slits(input_model, reference_files, slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 380, in get_open_slits
raise NoDataOnDetectorError(log_message)
jwst.assign_wcs.util.NoDataOnDetectorError: No open slits fall on detector NRS2.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Are these slits only on NRS1 ? Or should they be on both detectors.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: Yes, both of those particular slits are only on NRS1.  Sorry about that, I thought I had picked one slit that was on both detectors.  Try slit 31 for an example that should be roughly evenly on both.  I'm surprised the pipeline throws an error in this case, though.  Since there may be programs that don't have any spectra on one detector, we should have spec2 exit more gracefully.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Ok I will try slit 31 and I agree with you we should not get a error - but a clean exit. So I will try and fix that too,
Thanks

@stscijgbot
Copy link
Collaborator Author

Comment by Howard Bushouse: It's supposed to exit more gracefully than that, after issuing the error message about no open slits. Instead of resulting in a traceback it should just say the pipeline is shutting down and then shut down. It can't proceed any further to subsequent steps without any slits to work on.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] I pulled out slit 31 and re-ran spec2 to produce the cal files for NRS1 and NRS2.
I then ran calspec3. Recently we have made many changed to resample_spec so I wanted to see with
the new changes how the s2d images looked. They look pretty good to me.
!NIRSPEC_MOS_combined_s06325_s2d.png|thumbnail!

I put the results of calspec3 for this slit at /grp/jwst/ssb/chartreuse/calspec3/JP-936
Let me know what you think.
I going to try and run all the data through calspec3 but my VPN connect from home drops out frequently so I am not sure that will work.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: The combined product looks like a resampled version of the 1st nod exposure on NRS1, as if the other 2 nods and the data on NRS2 had not been included.  If all nods were being combined, I would expect to see the negative traces on both sides of the combined positive trace.  Including both detectors, the wavelength range should be much larger (roughly 1.8 - 3.2 microns), and there should be a large gap roughly in the middle at the wavelengths where the spectrum lay across the detector gap.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: [~muzerol]
I am starting to work on this issue. James do you have the association file set up for calspec3 for this data ?
I have not worked with a lot of NIRSPEC MOS nodded data and I am not sure how the association file is set up so that background subtraction is done correctly.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: [~bushouse][~eisenham] [~jdavies]
Since the input data James M provided had so many slits in a single file and running that data through calspec3 took hours and hours just to set up the CRDS data I pulled out 2 slits from each file - Source ID 3161 and 3162. I pulled out the 9 extensions for each slit in the original and wrote them to a new file.
So my new file has 18 extension + asdf extension. I did this for the 6 input files.
When I run calspec3 on this input file it has a problem in exp_to_source when it is reorganizing the data - it is trying to access Source ID 3901 - which in the original file was the next slit. So I still need to remove the
information about all the original slits someplace in my new file - is that information in the asdf. I am not sure where this information is coming from

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: [~muzerol]
I realize I do not know how to reprocess this data through calspec2. The input data is 2048 X 2048. I need an MSA file ?
But I did not see on in the l2_asn.json file and I do not see a MSA file on /grp/jwst/wit4/nirspec/Muzerolle/Files_spec3
Am I looking in the wrong place ?
Could you point me to the MSA and maybe put the code that modifies t the MSA file someplace I can grab too.
I have not worked with NIRSPEC MOS data much so this is new territory for me

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: [~muzerol] I grabbed the MSA file and tried to reprocess the data. I looked at the MSA file and it is set up
for SLITLET_ID 6 and 44 I belive. When I trying and run cal spec2 (skipping the flat field step) I get the error below for
F170LP-G235M_MOS_observation-6-c0e0_001_DN_NRS2_mod_correctedWCS.fits
File "/Users/morrison/git/jwst/jwst/pipeline/calwebb_spec2.py", line 193, in process_exposure_product
raise assign_wcs_exception
File "/Users/morrison/git/jwst/jwst/pipeline/calwebb_spec2.py", line 174, in process_exposure_product
input = self.assign_wcs(input)
File "/Users/morrison/git/jwst/jwst/stpipe/step.py", line 392, in run
step_result = self.process(*args)
File "/Users/morrison/git/jwst/jwst/assign_wcs/assign_wcs_step.py", line 84, in process
result = load_wcs(input_model, reference_file_names, slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/assign_wcs.py", line 51, in load_wcs
pipeline = mod.create_pipeline(input_model, reference_files, slit_y_range=nrs_slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 58, in create_pipeline
pipeline = exp_type2transform[exp_type](input_model, reference_files, slit_y_range=slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 275, in slits_wcs
open_slits_id = get_open_slits(input_model, reference_files, slit_y_range)
File "/Users/morrison/git/jwst/jwst/assign_wcs/nirspec.py", line 380, in get_open_slits
raise NoDataOnDetectorError(log_message)
jwst.assign_wcs.util.NoDataOnDetectorError: No open slits fall on detector NRS2.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: Are these slits only on NRS1 ? Or should they be on both detectors.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: Ok I will try slit 31 and I agree with you we should not get a error - but a clean exit. So I will try and fix that too,
Thanks

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison [X]: [~muzerol] I pulled out slit 31 and re-ran spec2 to produce the cal files for NRS1 and NRS2.
I then ran calspec3. Recently we have made many changed to resample_spec so I wanted to see with
the new changes how the s2d images looked. They look pretty good to me.
!NIRSPEC_MOS_combined_s06325_s2d.png|thumbnail!

I put the results of calspec3 for this slit at /grp/jwst/ssb/chartreuse/calspec3/JP-936
Let me know what you think.
I going to try and run all the data through calspec3 but my VPN connect from home drops out frequently so I am not sure that will work.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: The e0 and e1 cutouts on both detectors look about as expected, but e2 looks somewhat blocky with several discontinuities.  Are those from the cal files?

Here's what I got for that exposure, with no background nod subtraction and using extended slit_y limits of +/-1:

!slit31_e2_nrs1_cal.png!

!slit31_e2_nrs2_cal.png!

Note, the signal at the top is from the extended PSF wing of a source in an adjacent slitlet.  The actual source is at the bottom, and is mostly cut off using the default slit_y limits.

 

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison:
I ran calspec2.cfg l2_asn_nobsub.json
Then I just looked at the s2d images resulting from calspec2.
Those images are the s2d images

[~muzerol] The two images that show are those from e2 position ? Are they the s2d images or something else ?

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Ok here are the cal file images - 3 top ones NRS1 and 3 bottom ones NRS2. Now these do not have
the slit expanded I will do that next. But the e2 slit image looks like it is missing ?
!Screen Shot 2020-04-20 at 9.57.38 AM.png|thumbnail!

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: I see, sorry, I thought you were showing unrectified spectra from the cal files.  The pictures I attached are the unrectified spectra for the e2 position (I'm using 0.15.1, so it doesn't include the most recent changes you've made to resample_spec).

The s2d results you show look reasonable, except e2 is missing most of the (intended) source.  Most of what you're seeing in that case is the wings of a source in the adjacent slitlet, resampled into the pixel space of the intended source.  If you extend the slit_y limits like I did above you should see the full source spectrum at the bottom.

I may need to put in a separate ticket to look more closely at how the slit_y limits are applied in assign_wcs, as it seems many source traces are being cut off if the source position is too close to the top/bottom edge of the slitlet.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: Didn't see your last comment until after I posted...  real-time conversations are tricky on confluence! :)

Your unrectified images look as expected.  If you extend the slit_y limits, you should see the source pop out in e2.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Here are the results if I do extend the slit. For e0 it looks like we might be picking up another slit at the bottom when we do this ? These are the cal image (so unrectified)
[~muzerol] what should we do with this data to confirm that resample_spec is putting the NIRSPEC multi slit data together correcting.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: I was not sure if this image attached to last comment
!Screen Shot 2020-04-20 at 9.57.38 AM.png|thumbnail!

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: This looks the same as the previous one?

One thing we could check before running calspec3 combination is to calculate RA and Dec per pixel from the WCS object, and see if the source RA & Dec (as given in the CAL SCI header) is located at the position of the source in the individual spectra.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: I'll take a look at my cal files to do this...

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Here is the correct screen capture (I am having issues attaching images to comments today)

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: !Screen Shot 2020-04-20 at 12.20.21 PM.png|thumbnail!

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] to make more progress on if resample_spec is combining data together correctly is there maybe a different slit we could use. One has the source on the three nods sort of where it is expected. I can then test that the final resample spec image has a positive trace with two negative traces on either side.
Then we can tackle why for this slit - 31 - some step is not doing what is expected.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] The last results you posted for the exposure-level s2d products look reasonably good, at least by-eye.  However, I think I may have found a problem with the WCS that would affect the multi-exposure combination - the RA and Dec values at the source trace in the cal files at each nod is offset by roughly 1 arcsec.  That means that the source traces won't overlap when resampled onto a common grid.  This is only preliminary, though, I need to double-check that I'm calculating the RA and Dec values per pixel correctly.

In the meantime, if you want to try a different slit, 34 might be a good choice.  You won't need to extend the slit_y limits, and there is no contamination from adjacent sources.  Let me know if you need me to send a modified MSA metafile for that.

 

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] There might be a problem with the header keyword values for the spacecraft pointing.  I had to calculate them separately and add them in by hand since we have no way of running the simulations through SDP.  It's the only thing I can think of that would explain the discrepant RA,Dec values.  I'll try to find and correct the offending keywords and send new versions of the fits files asap.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] I did rerun with slit 34 and I think it looks pretty good now.
Here is a portion of the s2d out of resample_spec for calwebb_spec3

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: !Screen Shot 2020-04-22 at 4.07.57 PM.png|thumbnail!

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] I think I found the problem, "ROLL_REF" was off by 180 degrees.  I don't completely understand why, but after making the change the calculated RA, Dec values at the source trace in all nodded exposures are consistent to within a few milliarcsec.  I've copied new versions of the count rate and spec2 product files to /grp/jwst/wit4/nirspec/Muzerolle/Files_spec3/.

@jemorrison
Copy link
Contributor

@jmuzerolle Cool. I will grab the new files and run the new data through calspec3.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] I think this PR is finished. I ran calspec3 using your new data and I put the results of
the combined data in /grp/jwst/ssb/chartreuse/calspec3/JP-936
It looks ok to me but you should double check it and make sure I have not missed something

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] The directory is empty, except for a cfg and association file.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: Sorry about that. I needed to redo it because I used incorrect files. I am re-doing it now. It is taking a while because all the slits are in the cal file. Let you know when it is done.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol] I am copying the results from running calspec3 on all the slits. I looked a sampling of s2d images - I am curious if you think they look ok - it sort of looks like there are 3 negative traces in many of the images ?

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] This is a significant improvement!  In an ideal situation where none of the traces are cut off, I would expect to see a single positive trace surrounded by 2 negative traces on either side.  In the few s2d files I looked at, I see something close to this, though one or two of the negative traces have been cut off.  I think this may be because the output grid spatial range is too small?

Interestingly, the best results with the tightest resampled traces seem to be where there is only data on one detector (e.g., slit 417), which may point to some issue with how the output pixel grid is being constructed.  For the cases I looked at with data from both detectors, the positive trace seems to be more spread out particularly at wavelengths where the unrectified trace has the most curvature.

I also looked at the CON extension for these cases, I don't completely understand the numbers there.  The highest values range from as low as ~7 (slit 417) to as high as ~50 (slit 227).  I know this is supposed to indicate the overlap among all exposures that went into the result, but it seems odd that the numbers would be so different.  I'm just displaying things in fv, perhaps I'm missing some information?  I'll try to look more systematically at the results in python later today.

@stscijgbot
Copy link
Collaborator Author

Comment by Jane Morrison: [~muzerol][~jdavies]
Here is a summary on how resample spec works for the multislit case I am hoping one of you can see where
I might of missed something that results in the effects James is seeing: possible too small output spatial grid and positive grid more spread out at wavelengths where the unrectified trace has the most curvature.

Before the resample step all the input data that a single slit falls on is grouped together
Steps:

  1. all the data for each slit is mapped to ra, dec, lambda using the input models wcs

2 . The spatial sampling is set by the first input in the group. I was assuming that the spatial sampling would
be the same on data from NRS1 and NRS2. In more detail for the first slit in the list the center in the wavelength dimension is found. The ra and dec at this center wavelength is defined as the tangent point.
Using this tangent point the ra, dec for this slit are projected to tangent plane. Using the tangent plane values a linear fits is performed to find the spatial sampling to use for the final output resampled image.
The particular tangent point is only used to define the spatial sampling - the global tangent point of all the
data is found in step 3.

  1. To set the final spatial size. There are global ra and dec arrays. Loop over the groupings of the slit.
    For example if slit # 31 is found on 3 NRS1 input models and 3 NRS2 input models then there are 6 input models this slit is on. The the ra and dec for this slit are determined using the WCS for each input model. While looping over all the input models the slit is on a global ra and dec are appended with each input models ra and dec. At the end there combined array of ra and dec values.
    The min and max of the ra and dec of this combined data is found. The final tangent point to use for
    the entire grouping is defined as ra_center = (ra_max + ra_min)/2 likewise for dec.
    Using the global ra and dec tangent point - the global array of ra and dec is projected to a tangent plane.
    The min and max of the tangent plane values are used to set the spatial size of the final output.

  2. The wavelength is defined by a 1 D table
    The first slit in the group initialized the wavelength array.
    Then for the next slit in the group the min and max limits of this slit are found. If the limits are out side
    the current wavelength array then all those elements that fall outside are appended to the wavelength array. This is contained for each input model the slit falls on.

  3. So in summary
    The final transform is defined by spatial sampling defined by first group (step 1) , tangent plane defined by tangent point found using all ra and dec values (step 3). The wavelength dimension is a table of unique wavelengths (step 3)
    The size of the output is the spatial size found in step 3 and the length of the wavelength array found in step 4.

Do you see anything wrong ? I really hope that all made sense.

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: [~morrison] I don't see anything obviously amiss in your description of how the output grid is determined.  Two things we could look at next: verify that the RA,Dec values in the individual cal.fits files are sufficiently in agreement across the entire trace (I had previously only looked at the mean value), and compare the full range of RA,Dec in each with the output grid to see exactly which values are getting cut off.  I will take a closer look at this next week.  Actually, I could use some help on how to access the RA, Dec, and wavelength values in the level 3 s2d file.  I looked at it yesterday but couldn't figure out how to extract the information from the data model.

One thing I did notice from the above description - you say that the inputs are grouped together according to slit.  This really should be source, because there will be observations that include spectra of the same source taken in different slits; for example, a set of dithered exposures (the simulations we've been using don't have this problem because there is only one set of slits).  If the code is currently keying off of SLITID, would it be straightforward to change to SOURCEID instead?

@jemorrison
Copy link
Contributor

Ok I realize I did use the wrong term to say how the data was grouped together. I am pretty sure it is SOURCE ID - my mistake.
I just think of the groupings as a bunch of slits. So I used sloppy terminology in my description.

@jmuzerolle
Copy link

jmuzerolle commented Apr 30, 2020 via email

@stscijgbot
Copy link
Collaborator Author

Comment by Howard Bushouse: Fixed (at least mostly) in [https://github.com//pull/4766]

@stscijgbot
Copy link
Collaborator Author

Comment by James Muzerolle: Tested with 0.16.1, issues remain.  Closing this and opening a new ticket (JP-1489).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants