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

Rcal 596 Add association processing to the pipeline code #802

Merged
merged 25 commits into from
Aug 7, 2023

Conversation

ddavis-stsci
Copy link
Collaborator

@ddavis-stsci ddavis-stsci commented Aug 1, 2023

Resolves RCAL-596

Closes #755

This PR adds the initial association processing to the pipeline. This is an initial implementation and once rcal-620 and rcal-621 are done we will use ModelContainer and the open function to load the association.
The current usage requires the use of disable-crds-steppar option but should be relaxed on the two Jira issues above are
addressed. To run the pipeline with an association the command is,
strun --disable-crds-steppar roman_elp r90001-a3001_image_001_asn.json

2023-08-01 13:51:57,520 - stpipe.ExposurePipeline - INFO - ExposurePipeline instance created.
2023-08-01 13:51:57,521 - stpipe.ExposurePipeline.dq_init - INFO - DQInitStep instance created.
2023-08-01 13:51:57,522 - stpipe.ExposurePipeline.saturation - INFO - SaturationStep instance created.
...
2023-08-01 14:11:21,769 - stpipe.ExposurePipeline.source_detection - INFO - Found 3869 sources.
2023-08-01 14:11:21,802 - stpipe.ExposurePipeline.source_detection - INFO - Step source_detection done
2023-08-01 14:11:21,803 - stpipe.ExposurePipeline - INFO - Roman exposure calibration pipeline ending...
2023-08-01 14:11:23,380 - stpipe.ExposurePipeline - INFO - Saved model in r0000101001001001001_01101_0001_WFI01_cal.asdf
2023-08-01 14:11:24,925 - stpipe.ExposurePipeline - INFO - Saved model in r0000101001001001001_01101_0001_WFI02_cal.asdf
2023-08-01 14:11:26,485 - stpipe.ExposurePipeline - INFO - Saved model in r0000101001001001001_01101_0001_WFI03_cal.asdf
2023-08-01 14:11:28,130 - stpipe.ExposurePipeline - INFO - Saved model in r0000101001001001001_01101_0001_WFI04_cal.asdf
2023-08-01 14:11:28,130 - stpipe.ExposurePipeline - INFO - Step ExposurePipeline done

Checklist

  • added entry in CHANGES.rst under the corresponding subsection
  • updated relevant tests
  • updated relevant documentation
  • updated relevant milestone(s)
  • added relevant label(s)

pytest romancal/tests/
=============================================================== test session starts ================================================================
platform darwin -- Python 3.11.0, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/ddavis/src/Roman/romancal
configfile: pyproject.toml
plugins: remotedata-0.4.0, asdf-2.15.0, hypothesis-6.82.0, doctestplus-0.13.0, cov-4.1.0, filter-subpackage-0.1.2, mock-3.11.1, astropy-header-0.2.2, astropy-0.10.0, ci-watson-0.6.1, openfiles-0.5.0, env-0.8.2, arraydiff-0.5.0
collected 92 items

romancal/tests/test_import.py ............................................................................................ [100%]

================================================================ 92 passed in 1.59s ================================================================
(rcal_dev) bash>pytest romancal/datamodels/tests/
=============================================================== test session starts ================================================================
platform darwin -- Python 3.11.0, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/ddavis/src/Roman/romancal
configfile: pyproject.toml
plugins: remotedata-0.4.0, asdf-2.15.0, hypothesis-6.82.0, doctestplus-0.13.0, cov-4.1.0, filter-subpackage-0.1.2, mock-3.11.1, astropy-header-0.2.2, astropy-0.10.0, ci-watson-0.6.1, openfiles-0.5.0, env-0.8.2, arraydiff-0.5.0
collected 42 items

romancal/datamodels/tests/test_datamodels.py ......................................... [ 97%]
romancal/datamodels/tests/test_filetype.py . [100%]

=============================================================== 42 passed in 23.78s

Since plwishmaster is down I ran the regression tests locally,
platform darwin -- Python 3.11.0, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/ddavis/src/Roman/romancal
configfile: pyproject.toml
plugins: remotedata-0.4.0, asdf-2.15.0, hypothesis-6.82.0, doctestplus-0.13.0, cov-4.1.0, filter-subpackage-0.1.2, mock-3.11.1, astropy-header-0.2.2, astropy-0.10.0, ci-watson-0.6.1, openfiles-0.5.0, env-0.8.2, arraydiff-0.5.0
collected 21 items

../../../romancal/romancal/regtest/test_dark_current.py .... [ 19%]
../../../romancal/romancal/regtest/test_jump_det.py . [ 23%]
../../../romancal/romancal/regtest/test_linearity.py .. [ 33%]
../../../romancal/romancal/regtest/test_ramp_fitting.py . [ 38%]
../../../romancal/romancal/regtest/test_refpix.py . [ 42%]
../../../romancal/romancal/regtest/test_tweakreg.py . [ 47%]
../../../romancal/romancal/regtest/test_wfi_dq_init.py .. [ 57%]
../../../romancal/romancal/regtest/test_wfi_flat_field.py ... [ 71%]
../../../romancal/romancal/regtest/test_wfi_photom.py . [ 76%]
../../../romancal/romancal/regtest/test_wfi_pipeline.py ... [ 90%]
../../../romancal/romancal/regtest/test_wfi_saturation.py .. [100%]
...
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================= 21 passed, 19 warnings in 7665.81s (2:07:45)

@ddavis-stsci ddavis-stsci added this to the 23Q4_B11 milestone Aug 1, 2023
@ddavis-stsci ddavis-stsci self-assigned this Aug 1, 2023
@ddavis-stsci ddavis-stsci force-pushed the rcal-596_dsd branch 2 times, most recently from f872848 to e965b24 Compare August 1, 2023 18:41
@braingram
Copy link
Collaborator

FYI: doc failure appears related to an old theme version, similar to: https://github.com/spacetelescope/jwst/pull/7787/files

@codecov
Copy link

codecov bot commented Aug 1, 2023

Codecov Report

Patch coverage: 35.21% and project coverage change: -1.00% ⚠️

Comparison is base (0489537) 76.95% compared to head (7ba47e9) 75.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #802      +/-   ##
==========================================
- Coverage   76.95%   75.96%   -1.00%     
==========================================
  Files          94       96       +2     
  Lines        5690     5799     +109     
==========================================
+ Hits         4379     4405      +26     
- Misses       1311     1394      +83     
Flag Coverage Δ *Carryforward flag
nightly 63.95% <ø> (-0.18%) ⬇️ Carriedforward from 0489537

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

Files Changed Coverage Δ
romancal/pipeline/exposure_pipeline.py 40.36% <6.06%> (-43.85%) ⬇️
romancal/associations/load_as_asn.py 39.58% <39.58%> (ø)
romancal/datamodels/filetype.py 96.42% <96.42%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 1, 2023
@ddavis-stsci
Copy link
Collaborator Author

Thanks Brett, that fixed the problem!

@ddavis-stsci ddavis-stsci marked this pull request as ready for review August 2, 2023 13:57
@ddavis-stsci ddavis-stsci requested a review from a team as a code owner August 2, 2023 13:57
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Aug 2, 2023
Copy link
Collaborator

@schlafly schlafly 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 left a few comments in line in the pipeline stage where I didn't understand the logic.

Do the regression tests really take 2 hours to run on your system? Is that just the difference between your system and plwishmaster (~20 min, IIRC?)?

Yes, Mostly downloading lots of large files.

else:
log.info("Flat Field step is being SKIPPED")
result.meta.cal_step.flat_field = "SKIPPED"
return results
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused about this. The old version had this line under the is_fully_saturated condition; here this is outside that condition, so if there is ' groupdq' in result.keys() we stop the pipeline? I think I would have guessed that this should be indented one block, and that rather than returning, we continue to the next SCA?

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 looks like a rebase/merge issue and I'll fix that.


if result.meta.exposure.type == "WFI_IMAGE":
result = self.photom(result)
result = self.source_detection(result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be a merge / rebase issue or something, but I think we want to keep this "only do source detection for images" condition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes that must have been wiped out.
The check is also in the steps so it doesn't matter too much. The logic is here to avoid extra setup.

self.setup_output(result)
log.info("Roman exposure calibration pipeline ending...")

self.output_use_model = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't see where this was used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is used in stpipe to set the output file names.

@ddavis-stsci ddavis-stsci force-pushed the rcal-596_dsd branch 2 times, most recently from d98fd5c to 9dae67e Compare August 3, 2023 18:23
@ddavis-stsci
Copy link
Collaborator Author

ddavis-stsci commented Aug 3, 2023

Updates for logging and step skips for non WFI_IMAGE data. The pipeline now produces with imaging and spectral data,

2023-08-03 14:21:13,575 - stpipe.ExposurePipeline - INFO - Flat Field step is being SKIPPED
2023-08-03 14:21:13,576 - stpipe.ExposurePipeline - INFO - Photom and source detection steps are being SKIPPED
2023-08-03 14:21:13,576 - stpipe.ExposurePipeline - INFO - Roman exposure calibration pipeline ending...
2023-08-03 14:21:15,180 - stpipe.ExposurePipeline - INFO - Saved model in r0000101001001001001_01101_0001_WFI01_cal.asdf
2023-08-03 14:21:16,635 - stpipe.ExposurePipeline - INFO - Saved model in r0000201001001001003_01101_0001_WFI01_cal.asdf
2023-08-03 14:21:16,635 - stpipe.ExposurePipeline - INFO - Step ExposurePipeline done

and for the spectral data file

          assign_wcs	COMPLETE
          flat_field	SKIPPED
                dark	COMPLETE
             dq_init	COMPLETE
                jump	COMPLETE
           linearity	COMPLETE
              photom	SKIPPED
    source_detection	SKIPPED
            ramp_fit	COMPLETE
          saturation	COMPLETE


Returns
-------
association : DMSLevel2bBase
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we get away from JWST names and levels, since there's noLevel 2b for Roman?

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's fine. I did this for expediency and when the associations were much more poorly defined. Can this be a separate ticket to clean this up?

if isinstance(obj, str):
file_name, file_ext = os_path.splitext(obj)

if file_ext == ".fits":
Copy link
Collaborator

Choose a reason for hiding this comment

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

And what about not using FITS files or do you see this code being combined in the future with the code for JWST?

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 kept this to cover a case if/when someone will give romancal a fits file. We can just give a warning and gracefully exit.
There is also the type error in roman_datamodels (TypeError: Roman datamodels does not accept FITS files or objects) should we stick with that?

try:
input = rdm.open(input)
except TypeError:
log.debug("Error opening file:")
Copy link
Collaborator

Choose a reason for hiding this comment

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

What should happen in the case of one asdf file which cannot be opened? Should it return?

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 guess the question is, if any of the inputs in the association fail for any reason will the end user still want the results?
My choice would be to stop and let the user know. They can fix the error and rerun the pipeline. That way they make the decision if the results are valid without all the inputs. Not very pythonic of me.

try:
asn = LoadAsLevel2Asn.load(input, basename=self.output_file)
except AssociationNotValidError:
log.debug("Error opening file:")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly here - if an association is invalid shouldn't the code exit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to make sure it's a Level 2 asn, to prevent running the code on L2 products? Even if this is desirable I'm not asking to be done in this PR.

Copy link
Collaborator Author

@ddavis-stsci ddavis-stsci Aug 4, 2023

Choose a reason for hiding this comment

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

I left all that out. I'd like to address that once rcal-620 and 621 are in. I think that would be a better place to enforce validity.
But yes here the code should just exit.

@ddavis-stsci
Copy link
Collaborator Author

ddavis-stsci commented Aug 4, 2023 via email

Copy link
Collaborator

@schlafly schlafly left a comment

Choose a reason for hiding this comment

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

I'm still confused about the intended behavior in the fully saturated case. I've added code suggestions below and am approving. Thanks!

log.info("Roman exposure calibration pipeline ending...")

return result
return results
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return results
continue

Indenting and changing return -> continue so other detectors will still process.


# Set suffix for proper output naming
self.suffix = "cal"
results.append(result)

# Return fully saturated image file (stopping pipeline)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Return fully saturated image file (stopping pipeline)
# Skip remaining steps on this detector.

Indenting this to go under the saturation check, and updating the comment.

@ddavis-stsci
Copy link
Collaborator Author

ddavis-stsci commented Aug 7, 2023 via email

@schlafly
Copy link
Collaborator

schlafly commented Aug 7, 2023

Okay, I guess I'm misunderstanding the code, go ahead.

@ddavis-stsci ddavis-stsci merged commit df09aa5 into spacetelescope:main Aug 7, 2023
19 of 21 checks passed
@ddavis-stsci ddavis-stsci deleted the rcal-596_dsd branch August 7, 2023 15:37
@ddavis-stsci
Copy link
Collaborator Author

ddavis-stsci commented Aug 7, 2023 via email

'rad @ git+https://github.com/spacetelescope/rad.git@main',
# 'roman_datamodels >=0.15.0',
'roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git@main',
'rad == 0.17.0',
Copy link
Collaborator

@braingram braingram Aug 7, 2023

Choose a reason for hiding this comment

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

The devdeps job on plwishmaster is currently installing rad and roman_datamodels 0.17.0 instead of the dev versions:
https://plwishmaster.stsci.edu:8081/blue/organizations/jenkins/RT%2FRoman-devdeps/detail/Roman-devdeps/361/pipeline/176

I think this pin is causing the devdeps job on plwishmaster to pull the older, 0.17.0 rad (and similar for roman_datamodels) instead of testing against the 0.17.1 (or development version, which I think is the same at the moment).

@ddavis-stsci was this a requirement for this PR? If so, is there a follow-up PR or tracking issue to remove the pin?

@ddavis-stsci
Copy link
Collaborator Author

ddavis-stsci commented Aug 7, 2023 via email

@braingram
Copy link
Collaborator

Thanks! That explains why 22 of the 23 failing tests fixed themselves :)

Comment on lines +25 to +29
'rad == 0.17.0',
# 'rad >= 0.16.0, < 0.17.1',
# 'rad @ git+https://github.com/spacetelescope/rad.git@main',
'roman_datamodels ==0.17.0',
# 'roman_datamodels @ git+https://github.com/spacetelescope/roman_datamodels.git@main',
Copy link
Collaborator

Choose a reason for hiding this comment

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

There absolutely should not be exact pins for these dependencies. This will cause us major headaches in development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
associations dependencies Pull requests that update a dependency file pipeline testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add association processing to exposure pipeline
5 participants