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

Add a check for separation and tolerance in tweakreg #8476

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

mcara
Copy link
Member

@mcara mcara commented May 9, 2024

This PR adds a check that (abs_)separation > sqrt(2) * (abs_)tolerance input parameters to the tweakreg step. It also adds a comment in the docstring about these parameters.

Checklist for PR authors (skip items if you don't have permissions or they are not applicable)

  • added entry in CHANGES.rst within the relevant release section
  • updated or added relevant tests
  • updated relevant documentation
  • added relevant milestone
  • added relevant label(s)
  • ran regression tests, post a link to the Jenkins job below.
    How to run regression tests on a PR
  • All comments are resolved
  • Make sure the JIRA ticket is resolved properly

@mcara mcara requested a review from a team as a code owner May 9, 2024 12:19
@mcara mcara self-assigned this May 9, 2024
@mcara mcara requested review from nden and hbushouse May 9, 2024 12:20
@mcara mcara added this to the Build 10.0.1 milestone May 9, 2024
@hbushouse hbushouse modified the milestones: Build 10.0.1, Build 11.0 May 9, 2024
CHANGES.rst Outdated Show resolved Hide resolved
jwst/tweakreg/tweakreg_step.py Outdated Show resolved Hide resolved
jwst/tweakreg/tweakreg_step.py Outdated Show resolved Hide resolved
@nden
Copy link
Collaborator

nden commented May 15, 2024

Agreed with Howard's comments. These need to be warnings.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

I took into account Howard suggestion as well as (in part) @mairanteodoro suggestion in a different PR about putting common logging and step-skipping code into a single function.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.97%. Comparing base (4179c09) to head (4e69f2e).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8476      +/-   ##
==========================================
- Coverage   57.97%   57.97%   -0.01%     
==========================================
  Files         387      387              
  Lines       38830    38824       -6     
==========================================
- Hits        22513    22507       -6     
  Misses      16317    16317              

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

@mcara
Copy link
Member Author

mcara commented May 16, 2024

Another regression test here: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1447/

Previous test was failing because input models' meta could not be updated with info about step being skipped (models were not yet open)

and https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1448/

@nden
Copy link
Collaborator

nden commented May 16, 2024

@mcara About the common function for logging - #8424 refactors tweakreg to reduce memory. If this function prevents or complicate the refactoring, give preference to #8424 and remove it.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

@mcara About the common function for logging - #8424 refactors tweakreg to reduce memory. If this function prevents or complicate the refactoring, give preference to #8424 and remove it.

@braingram what is your opinion on this change: 56a1108 ?

@braingram
Copy link
Collaborator

@braingram what is your opinion on this change: 56a1108 ?

Thanks for the ping. I will look at this later today. One general question, are these changes required for the check in the title of this PR?

@mcara
Copy link
Member Author

mcara commented May 16, 2024

One general question, are these changes required for the check in the title of this PR?

No. But... @mairanteodoro is right about similar code being used in too many places.

@braingram
Copy link
Collaborator

No. But... @mairanteodoro is right about similar code being used in too many places.

Perhaps a follow-up PR cleaning up the error handling and logging is called for? It could include an update to the tweakwcs pin once a version is released that contains spacetelescope/tweakwcs#203 (and possibly spacetelescope/tweakwcs#204)?

I rebased and reopened #8424 when this PR was only the parameter checks thinking it would have no conflicts. I don't think that's the case if the additional cleanup in 56a1108 is included. Since they're not required for the parameter changes I think they make sense to put in a different cleanup PR.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

OK. I'll remove logging function and simplify this PR.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

@braingram
Copy link
Collaborator

Thanks for updating the PR. I added a few comments.

@mcara
Copy link
Member Author

mcara commented May 16, 2024

@hbushouse @nden regression tests fail with this error:

        # Check the status of the step is set correctly in the files.
        result = TweakRegStep.call(rtdata.input)
    
>       for fi in result._models:
E       AttributeError: 'builtin_function_or_method' object has no attribute '_models'

/data1/jenkins/workspace/RT/JWST-Developers-Pull-Requests/clone/jwst/regtest/test_niriss_image.py:65: AttributeError

Am I returning something incorrect or is this a recently added test that is setup in a different way that we had before. I need help with this. Thanks!

@mcara
Copy link
Member Author

mcara commented May 16, 2024

@mcara
Copy link
Member Author

mcara commented May 16, 2024

I think, @nden, these lines are causing an issue:

# Check the status of the step is set correctly in the files.
result = TweakRegStep.call(rtdata.input)

And since you already run the step above this call, I do not think this is necessary as the step should set skipped flag as @braingram mentioned above. You can just check it (lines below).

@mcara
Copy link
Member Author

mcara commented May 16, 2024

I made a PR that I hope will fix this test: #8489

CHANGES.rst Outdated Show resolved Hide resolved
jwst/tweakreg/tweakreg_step.py Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
jwst/tweakreg/tweakreg_step.py Outdated Show resolved Hide resolved
jwst/tweakreg/tweakreg_step.py Outdated Show resolved Hide resolved
@hbushouse
Copy link
Collaborator

@mcara Still need to address most recent comments and fix conflict that now exists in tweakreg_step.py

@mcara
Copy link
Member Author

mcara commented May 23, 2024

@hbushouse

@mcara Still need to address most recent comments and fix conflict that now exists in tweakreg_step.py

My apologies: somehow I thought I pushed latest changes last Friday.

@braingram
Copy link
Collaborator

Would you add a unit test (or 2) to verify the check. It would be helpful to avoid losing this in a refactor.

Copy link
Collaborator

@braingram braingram left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test. LGTM.

I started regtests with this PR here: https://plwishmaster.stsci.edu:8081/job/RT/job/JWST-Developers-Pull-Requests/1478/

@braingram
Copy link
Collaborator

@mcara the regtest run had 2 failures:

    @pytest.mark.bigdata
    def test_niriss_tweakreg_no_sources(rtdata, fitsdiff_default_kwargs):
        """Make sure tweakreg is skipped when sources are not found.
        """
    
        rtdata.input = "niriss/imaging/jw01537-o003_20240406t164421_image3_00004_asn.json"
        rtdata.get_asn("niriss/imaging/jw01537-o003_20240406t164421_image3_00004_asn.json")
    
        args = [
            "jwst.tweakreg.TweakRegStep",
            rtdata.input,
            "--abs_refcat='GAIADR3'",
            "--save_results=True",
        ]
        result = Step.from_cmdline(args)
        # Check that the step is skipped
>       assert result.skip
E       assert False
E        +  where False = <jwst.tweakreg.tweakreg_step.TweakRegStep object at 0x7fde6dc1e4e0>.skip

Is this second one related to this PR?

@mcara
Copy link
Member Author

mcara commented May 29, 2024

Is this second one related to this PR?

Yes, see #8476 (comment)

@braingram braingram self-requested a review May 29, 2024 10:29
@braingram
Copy link
Collaborator

Thanks. I attempted to dismiss my own review (since the regression test fails with this PR). However I didn't see a button to dismiss my own review so I re-requested myself as a reviewer. I didn't follow the test changes in #8450 #8477 and #8489 close enough to understand why it fails with this PR. If a review is helpful please feel free to ping me.

@hbushouse
Copy link
Collaborator

@mcara the regtest run had 2 failures:

    @pytest.mark.bigdata
    def test_niriss_tweakreg_no_sources(rtdata, fitsdiff_default_kwargs):
        """Make sure tweakreg is skipped when sources are not found.
        """
    
        rtdata.input = "niriss/imaging/jw01537-o003_20240406t164421_image3_00004_asn.json"
        rtdata.get_asn("niriss/imaging/jw01537-o003_20240406t164421_image3_00004_asn.json")
    
        args = [
            "jwst.tweakreg.TweakRegStep",
            rtdata.input,
            "--abs_refcat='GAIADR3'",
            "--save_results=True",
        ]
        result = Step.from_cmdline(args)
        # Check that the step is skipped
>       assert result.skip
E       assert False
E        +  where False = <jwst.tweakreg.tweakreg_step.TweakRegStep object at 0x7fde6dc1e4e0>.skip

Is this second one related to this PR?

That test was likely failing because checking the value of result.skip is not a valid way to determine whether or not a test was skipped. We don't reset the value of the step's skip param on the fly when the code makes its own decision to skip/abort the step. It should only set the value of the cal_step status keyword to "SKIPPED" in the output data model. That's the proper way to test whether a step was skipped. Has this test been updated to account for that?

@hbushouse
Copy link
Collaborator

@mcara Now that this PR has removed the setting of self.skip=True when it decides to skip the step the regression test jwst/regtest/test_niriss_image.py::test_niriss_tweakreg_no_sources needs to be updated so that it no longer calls assert result.skip, because that will no longer be set to True when the step skips. The test should only check the returned values of model.meta.cal_step.tweakreg, as it's already doing.

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.

None yet

4 participants