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

extract1d for IFU data version 2- JP 1736 #5506

Conversation

jemorrison
Copy link
Collaborator

@jemorrison jemorrison commented Dec 2, 2020

This is just a copy of #5383. Somehow that PR got confused on my system and I could not resolve conflicts.
This is just a clean copy.

Fixes JP-1615
Fixes JP-1633
Fixes JP-1730

…rrison/jwst into jemorrison-extract1d_datamodel_JP_1736_v2

Problem with branch conflicts
@jemorrison jemorrison changed the title Jemorrison extract1d datamodel jp 1736 v2 extract1d for IFU data version 2- JP 1736 Dec 2, 2020
@codecov
Copy link

codecov bot commented Dec 2, 2020

Codecov Report

Merging #5506 (c55ca7c) into master (53dc5e2) will decrease coverage by 3.19%.
The diff coverage is 64.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5506      +/-   ##
==========================================
- Coverage   74.41%   71.21%   -3.20%     
==========================================
  Files         417      415       -2     
  Lines       38115    41147    +3032     
  Branches     5636     5891     +255     
==========================================
+ Hits        28362    29303     +941     
- Misses       9753    11001    +1248     
- Partials        0      843     +843     
Flag Coverage Δ *Carryforward flag
nightly 71.10% <84.73%> (-4.85%) ⬇️ Carriedforward from 5712155
unit 54.20% <16.66%> (-0.06%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Impacted Files Coverage Δ
jwst/extract_1d/apply_apcorr.py 77.77% <50.00%> (-17.99%) ⬇️
jwst/extract_1d/extract.py 43.85% <53.84%> (-24.43%) ⬇️
jwst/extract_1d/ifu.py 63.17% <70.70%> (-16.65%) ⬇️
jwst/extract_1d/extract_1d_step.py 49.60% <87.50%> (-31.93%) ⬇️
jwst/datamodels/__init__.py 100.00% <100.00%> (ø)
jwst/datamodels/apcorr.py 100.00% <100.00%> (ø)
jwst/datamodels/extract1d_spec.py 100.00% <100.00%> (ø)
jwst/reset/reset_step.py 25.92% <0.00%> (-40.75%) ⬇️
jwst/pipeline/calwebb_ami3.py 61.90% <0.00%> (-32.00%) ⬇️
jwst/reset/reset_sub.py 70.00% <0.00%> (-30.00%) ⬇️
... and 129 more

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 53dc5e2...c55ca7c. Read the comment docs.

@drlaw1558
Copy link
Collaborator

@jemorrison This is meant to be a copy of PR-5383, but it looks like they each have different numbers of files changed? (14 here, 23 there) E.g., PR-5383 modified CHANGES.rst but this PR-5506 does not?

Trying to figure out the best way to compare the relevant code between these two PRs, and if it's best to just check out this new PR and rerun my various tests again.

@jemorrison
Copy link
Collaborator Author

jemorrison commented Dec 2, 2020 via email

@jemorrison
Copy link
Collaborator Author

jemorrison commented Dec 2, 2020

Yes I just do not understand why the old PR had files changes related to associations. I did not touch code related to associations. I must of created the branch in a non-standard way. I just wanted the PR to include the extract1d changes. I think this is a clean pr how. I need to update the change log and I will do that and push that change over.
To create this new branch I did this:
git fetch jwst
git checkout -b jemorrison-extract1d_datamodel_JP_1736_v2 jwst/master
git pull https://github.com/jemorrison/jwst.git extract1d_datamodel_JP_1736
It only grabbed the extract1d code not the association related code.

@drlaw1558
Copy link
Collaborator

Ok, I think I see now. I will see if it's possible to check everything just by comparing the line-by-line diffs for the non-association related files rather than by rerunning various simulations/tests.

@drlaw1558
Copy link
Collaborator

What are all of the warnings (e.g., Added lines #L399 - L400 were not covered by tests) in apply_apcorr.py in the diff file about? They make it hard to scan the actual diffs as they break up the page so much.

@jemorrison
Copy link
Collaborator Author

@drlaw1558 I think the warnings are that I have added code but I do not have a unit test that tests these new lines.

@hbushouse hbushouse added this to the Build 7.7 milestone Dec 3, 2020
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.

Wow, this represents a LOT of work! Just a few comments and questions here and there. Can't really properly review the actual new functionality for IFU data, since I'm not completely sure how it's supposed to work.

@@ -21,6 +21,7 @@
from .drizpars import DrizParsModel
from .drizproduct import DrizProductModel
from .extract1dimage import Extract1dImageModel
from .extract1d_spec import IFUExtract1dModel
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose it would throw a big wrench into things at this late stage to rename this new model class to Extract1dIFUModel just for consistency in naming with the existing Extract1dImageModel? If so, it's not a big deal.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is fine I can change the names of models to be more consistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I think that means I'll have to change some things about my generation code as well. Are the 'datamodl' keywords still meant to be MirMrsExtract1dModel and MirMrsApcorrModel ? If so I should only need to change the names of the schema files.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes @drlaw1558 that does imply that the actual class name of the data model used for the extract1d reference file will be changing from IFUExtract1dModel to Extract1dIFUModel. That's only for the extract1d reference file model. The apcorr ref files models remain unchanged. I don't see MirMrsExtract1dModel referenced anywhere, or am I just missing it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, it looks like this was the name Jane used in creating a test asdf file back in October; maybe that's now been superseded by MirMrsExtract1dModel -> IFUExtract1dModel -> Extract1dIFUModel. In this case I'll need to change both my code and the reference file to make sure the data model keyword is up to date.

It doesn't look like the update has been made in the schema for this branch yet though? @jemorrison your comment above said that it had been changed, but the relevant branch still seems to have the old names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just pushed over the new code. It is Extract1DIFUModel now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I see it. If we're now using schemas/extract1difu.schema.yaml should we remove the old schemas/mirmrs_extract1d.schema.yaml ?

@@ -0,0 +1,48 @@
%YAML 1.1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again in terms of file naming consistency, could this new schema file be renamed to extract1difu.schema.yaml, in keeping with the existing extract1dimage.schema.yaml file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed

type: string
wavelength:
datatype: float32
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are some data type attributes named type while others are datatype? Does it make a difference? My inner hob goblin of foolish consistency suggests having them all the same.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was trial and error to get this to work. This worked that is all I know

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So from trial and error I have found that when I create the asdf reference files, write them to disk and then read them in
using asdf.open and test them using asdf validate - all values that are strings that are called datatype in the schema fail in the validate. The error message says they are not arrays. So I am guessing that 'datatype' is for arrays and 'type' is for single values.

datatype: float32
apcorr_err:
datatype: float32
apcorr_table_f070lp_g140h:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it'd be a huge pain to do at this late stage of the development, but having cal data for all the filter+grating combinations in a single ref file forces the pipeline to do the selection of the proper data, while having them split into separate ref files would put the selection in CRDS, which is what it was built for.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So at one point we thought about pulling out filter/grating and having a different reference file for each. We ended up just leaving it in the code mainly because I was not sure how CRDS would handle the cases of multiple bands, channels, gratings or filters. After testing I think 'MULTIPLE' is set if that is the case - so we can go ahead and break then up into separate reference files. NOTHING has been loaded into CRDS.


def apply(self, spec_table: fits.FITS_rec):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that the apcorr ref files have been migrated to ASDF format, does the fits.FITS_rec still work properly? Or is the spec_table object the spectral data that've already been extracted and are still stored as a FITS table?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the spec_table is still stored as a FITS table.

@@ -115,13 +116,23 @@ def open_extract1d_ref(refname: str) -> dict:
If the extract1d reference file is in JSON format, ref_dict will be the
dictionary returned by json.load(), except that the file type
('JSON') will also be included with key 'ref_file_type'.
If the extract1d reference file is in asdf format, the ref_dict will
be a containing two keys: ref_dict['ref_file_type'] = 'ASDF'
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like a typo here: "will be a containing two ..." will be a what?

if refname == "N/A":
ref_dict = None
elif exptype == 'MIR_MRS' or exptype == 'NRS_IFU':
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't affect functionality, but you could condense this to:
elif exptype in ['MIR_MRS', 'NRS_IFU']:

@@ -5,12 +5,12 @@
from astropy.io import fits
from astropy.table import Table

from jwst.datamodels import JwstDataModel
from jwst.extract_1d.apply_apcorr import ApCorr, ApCorrRadial, ApCorrPhase, select_apcorr
from jwst.datamodels import DataModel
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, this might need to be JwstDataModel, because I think DataModel went away with the migration to using the new stdatamodels package. Need to confirm.

@@ -35,7 +33,7 @@ def inputs(request):

instrument, exptype = request.param

dm = JwstDataModel()
dm = DataModel()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment here about JwstDataModel

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.

Looks good to me. I recreated new reference files using the updated schema names, and reran some of my tests just to make sure.

@hbushouse
Copy link
Collaborator

flake8 issues need fixing before we merge

Fix flake8 whitespace issues.
@hbushouse hbushouse merged commit 31a1c5f into spacetelescope:master Jan 7, 2021
@jemorrison jemorrison deleted the jemorrison-extract1d_datamodel_JP_1736_v2 branch February 24, 2021 19:23
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.

3 participants