-
Notifications
You must be signed in to change notification settings - Fork 167
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
JP-3784 Fix Pixel replace and cube_build output file names #8979
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8979 +/- ##
==========================================
+ Coverage 76.81% 76.82% +0.01%
==========================================
Files 496 496
Lines 45610 45612 +2
==========================================
+ Hits 35034 35043 +9
+ Misses 10576 10569 -7
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@melanieclarke @emolter 024-11-27 07:10:50,422 - stpipe.PixelReplaceStep - INFO - Saved model in jw01267003001_02105_00001_mirifushort_pixelreplacestep.fits So the step is working just fine but I can not seem to access the output filenames when it is called from a container. |
85fa531
to
5756f31
Compare
@melanieclarke I got this step to work by including the 'invariant_filenames' routine that is from cal spec3 and it manages filenames. I just copied the routine and suck in pixel_replace_step.py. I tried to import it from: But that gets circular and I get an error because calwebb_spec3 is importing pixel_replace. |
The I didn't review this in detail yet but I don't see anything wrong with the current solution. For unit testing, instead of checking the |
We could move that function to a library and import it in both places - maybe in lib/pipe_utils.py. I'm not sure I understand why that's working, though. |
At risk of nit-picking, since |
Testing locally, it looks like this solution does work for the case we were trying to fix, where container is made from a list of filenames: But it now un-fixes the calwebb_spec3 case. Calling like this: |
@melanieclarke @emolter I do have a question about a unit test that saves the output to disk. Is that allowed ? It writes out files to the test directory ? @melanieclarke I need to understand your test better. In your s3.json file what is the output name set to ? I have a set of tests (in a Jupyter notebook) that I have developed to test the various filenames of pixel_replace and cube_build. When I run calspec3 and save the pixel_replace output. ALL the filenames have the correct format. spec3_asn = 'test.json' in the association the name is set to 'test_miri' and there are 4 input files. and the output from cube_build is: |
@melanieclarke Forget last message. I was on a wrong branch. Let me check what is going on with cube_build and I will update |
If you're passing in e.g. the |
@emolter @melanieclarke for example: |
@emolter @melanieclarke |
@jemorrison It appears this is working the way I intended it to, but I do see why this could be confusing. It wasn't obvious to me how else to set a default output filename in cases like this, where there is no association metadata passed in. We could attempt to parse the filename strings and remove the exposure number, but then what happens if someone renamed their files to a custom name? or if the list includes files from multiple programs/observations/visits? Do you have a suggestion for a better way to do this? |
I think Melanie and I already made some suggestions |
5756f31
to
ddcab09
Compare
@emolter the reason I find it confusing is it it seems like cube build only included 1 file and not both files. There really is no way to know because that information is not written to the header. So you just have to look at the log message and know that both files were included in creating the IFU cubes. Not that I think this is much of an issue - I do not think most people will create a model container and run cube_build on that container. It is really set up to run using an association that sets up the correct product name. But since this ticket all started from running pixel_replace and cube build on containers I thought I would raise this issue. |
@emolter @melanieclarke I should have been clearer on invariant_filenames. I am checking what is better. Melanie did not seem convinced. Are we agreed to move it to jwst.stpipe ? |
Yep, works for me! |
@emolter I move the invariant_filename to stpipe.utiltites and import it as follows: good with you ? |
yeah seems great |
c8f6688
to
d51601f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great Jane, just one question about the test setup and a (low priority, but I hope easy) request for a unit test of invariant_filename
@@ -211,3 +212,23 @@ def query_step_status(datamodel, cal_step): | |||
return getattr(datamodel[0].meta.cal_step, cal_step, NOT_SET) | |||
else: | |||
return getattr(datamodel.meta.cal_step, cal_step, NOT_SET) | |||
|
|||
|
|||
def invariant_filename(save_model_func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not crucial, but it would be helpful to write a unit test for this function. I think it could be pretty simple. Writing some pseudocode on-the-fly, I'm thinking something like
def mock_save_func(model):
model.meta.filename = "changed"
return model
def test_invariant_filename(input_model):
input_model.meta.filename = "initial_name"
invariant_save_func = invariant_filename(mock_save_func)
output_model = invariant_save_func(input_model)
assert output_model.meta.filename == "initial_name"
|
||
# for this simple case, the results from either algorithm should | ||
# be the same | ||
result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm) | ||
result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm,save_results=True) | |
result = PixelReplaceStep.call(input_model, skip=False, algorithm=algorithm, save_results=True) |
return_files = [] | ||
# for this simple case, the results from either algorithm should | ||
# be the same | ||
result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) | |
result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm, save_results=True) |
# for this simple case, the results from either algorithm should | ||
# be the same | ||
result = PixelReplaceStep.call(container, skip=False, algorithm=algorithm,save_results=True) | ||
for dirname in [output_dir, tmp_cwd]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to check both the cwd and the output dir here? I would have thought we would know beforehand which files went to which directories, and part of the test would be to ensure those are as expected.
ec6e261
to
0069f17
Compare
@emolter I added a unit test for invariant filenames. Is this good enough ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All my questions / comments have been answered, thanks Jane!
@melanieclarke There are some regression test failures. |
Some of them might, but it does look like many are because the S_PXREPL is present and set to COMPLETE in the truth file, but not in the test output. I forgot you are out - I can take over for this issue and see if we can sort that out and get this settled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some issues with output cal_step status in the regression tests - this needs to be resoved before this PR can be merged.
Resolves JP-3784
Closes #8904
This PR addresses fixes the names of the output from pixel_replacement when called using a ModelContainer. In addition, it fixes the output names of cube_build when a single file is input to cube_build.
Tasks
Build 11.3
(use the latest build if not sure)no-changelog-entry-needed
)changes/
:echo "changed something" > changes/<PR#>.<changetype>.rst
(see below for change types)docs/
pagehttps://github.com/spacetelescope/RegressionTests/actions/runs/12359349881
okify_regtests
to update the truth filesnews fragment change types...
changes/<PR#>.general.rst
: infrastructure or miscellaneous changechanges/<PR#>.docs.rst
changes/<PR#>.stpipe.rst
changes/<PR#>.datamodels.rst
changes/<PR#>.scripts.rst
changes/<PR#>.fits_generator.rst
changes/<PR#>.set_telescope_pointing.rst
changes/<PR#>.pipeline.rst
stage 1
changes/<PR#>.group_scale.rst
changes/<PR#>.dq_init.rst
changes/<PR#>.emicorr.rst
changes/<PR#>.saturation.rst
changes/<PR#>.ipc.rst
changes/<PR#>.firstframe.rst
changes/<PR#>.lastframe.rst
changes/<PR#>.reset.rst
changes/<PR#>.superbias.rst
changes/<PR#>.refpix.rst
changes/<PR#>.linearity.rst
changes/<PR#>.rscd.rst
changes/<PR#>.persistence.rst
changes/<PR#>.dark_current.rst
changes/<PR#>.charge_migration.rst
changes/<PR#>.jump.rst
changes/<PR#>.clean_flicker_noise.rst
changes/<PR#>.ramp_fitting.rst
changes/<PR#>.gain_scale.rst
stage 2
changes/<PR#>.assign_wcs.rst
changes/<PR#>.badpix_selfcal.rst
changes/<PR#>.msaflagopen.rst
changes/<PR#>.nsclean.rst
changes/<PR#>.imprint.rst
changes/<PR#>.background.rst
changes/<PR#>.extract_2d.rst
changes/<PR#>.master_background.rst
changes/<PR#>.wavecorr.rst
changes/<PR#>.srctype.rst
changes/<PR#>.straylight.rst
changes/<PR#>.wfss_contam.rst
changes/<PR#>.flatfield.rst
changes/<PR#>.fringe.rst
changes/<PR#>.pathloss.rst
changes/<PR#>.barshadow.rst
changes/<PR#>.photom.rst
changes/<PR#>.pixel_replace.rst
changes/<PR#>.resample_spec.rst
changes/<PR#>.residual_fringe.rst
changes/<PR#>.cube_build.rst
changes/<PR#>.extract_1d.rst
changes/<PR#>.resample.rst
stage 3
changes/<PR#>.assign_mtwcs.rst
changes/<PR#>.mrs_imatch.rst
changes/<PR#>.tweakreg.rst
changes/<PR#>.skymatch.rst
changes/<PR#>.exp_to_source.rst
changes/<PR#>.outlier_detection.rst
changes/<PR#>.tso_photometry.rst
changes/<PR#>.stack_refs.rst
changes/<PR#>.align_refs.rst
changes/<PR#>.klip.rst
changes/<PR#>.spectral_leak.rst
changes/<PR#>.source_catalog.rst
changes/<PR#>.combine_1d.rst
changes/<PR#>.ami.rst
other
changes/<PR#>.wfs_combine.rst
changes/<PR#>.white_light.rst
changes/<PR#>.cube_skymatch.rst
changes/<PR#>.engdb_tools.rst
changes/<PR#>.guider_cds.rst