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

Apply temperature-dependent drift model offset to fid positions #388

Merged
merged 38 commits into from
Dec 17, 2023

Conversation

jeanconn
Copy link
Contributor

@jeanconn jeanconn commented Oct 17, 2023

Description

Update proseco to apply the time and temperature-dependent fid position offsets to the fid positions in proseco constructed catalogs. This code relies on chandra_aca.drift.get_fid_offset and the aimpoint drift model in chandra_models.

Interface impacts

Changes default behavior in proseco to apply offsets in y and z to expected fid positions via chandra_aca.drift.get_fid_offset. Respects new environment variable PROSECO_ENABLE_FID_OFFSET .

Testing

Requires sot/chandra_aca#157

Unit tests

  • Mac

Independent check of unit tests by @taldcroft

  • Mac

Functional tests

Added a unit test.
Reselected ~900 catalogs in two aca aimpoint drift model epochs and since the last safe modes (2023:044 and 2023:047) and confirmed proseco fid positions with the PR are overall reasonable compared to observed positions and that there are small mean offests since the last safe mode (expected). Also reviewed reselected star catalogs with critical warnings (with and without fid offsets applied) and confirmed proseco catalogs are reasonable (one new critical warning on an hrc fid light in a field with many spoiler stars).

Functional review notebook is part of the PR in the analysis directory https://github.com/sot/proseco/blob/5595c4c002814b82ccee2f20f4f084bd14850770/analysis/reselect_fid_offset.ipynb

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

I know this is a WIP but it looks really good and just needs a few changes and some testing. We should go ahead with this soon!

proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
@taldcroft
Copy link
Member

There is a slight complication here:
https://github.com/sot/kadi/blob/76b7d0b6b79102ab60c53df302eab1eb42c65b0e/kadi/commands/observations.py#L85

The current code will break this because t_ccd is not known. This supports a thought I was having independently, which is that if t_ccd and date are both None then that should imply not adding the offset. That also leads to a 3-state value for PROSECO_ENABLE_FID_OFFSET:

  • "True": always apply and require that t_ccd and date are supplied
  • "False": never apply
  • None (undefined, which will be the default): apply if t_ccd and date are both supplied.

@jeanconn
Copy link
Contributor Author

Those kadi observations are an interesting use case. Thanks for bringing that up.

@jeanconn jeanconn changed the title WIP: Apply offset to fid positions Apply offset to fid positions Oct 29, 2023
@jeanconn jeanconn marked this pull request as ready for review October 29, 2023 16:18
@jeanconn
Copy link
Contributor Author

I forgot -- I need to document the functional testing in here so that's still to-do.

@jeanconn
Copy link
Contributor Author

jeanconn commented Nov 1, 2023

We probably also need to handle dates < 2012 explicitly (perhaps with a warning instead of rethrowing the valueerror from chandra_aca) if we want to leave this turned on and run old schedules in matlab regression for example.

@taldcroft
Copy link
Member

Good point about the 2012 cutoff from this code in chandra_aca.drift:

        if times[0] < DateTime("2012:001:12:00:00").secs:
            raise ValueError("model is not applicable before 2012")

One idea is to just change the drift model to extrapolate back from 2012 with a constant via:

        times = times.clip(DateTime("2012:001:12:00:00").secs, None)

@jeanconn jeanconn marked this pull request as draft November 1, 2023 17:36
@jeanconn jeanconn marked this pull request as ready for review November 1, 2023 17:38
@jeanconn jeanconn requested a review from taldcroft November 30, 2023 18:04
@taldcroft
Copy link
Member

One more thing, can you make the notebook names more descriptive. I'd suggest:

  • pr388-backstop-vs-proseco-star-positions.ipynb
  • pr388-validate-drift-model-fid-positions.ipynb

@taldcroft taldcroft changed the title Apply offset to fid positions Apply temperature dependent drift model offset to fid positions Dec 5, 2023
@taldcroft taldcroft changed the title Apply temperature dependent drift model offset to fid positions Apply temperature-dependent drift model offset to fid positions Dec 5, 2023
docs/index.rst Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Outdated Show resolved Hide resolved
proseco/tests/test_fid.py Outdated Show resolved Hide resolved
proseco/tests/test_fid.py Outdated Show resolved Hide resolved
proseco/tests/test_fid.py Outdated Show resolved Hide resolved
proseco/tests/test_fid.py Show resolved Hide resolved
proseco/tests/test_fid.py Show resolved Hide resolved
proseco/core.py Outdated
@@ -1487,7 +1487,8 @@ def add_fake_stars_from_fid(
detector=detector,
sim_offset=sim_offset,
focus_offset=0,
t_ccd=-10.0,
t_ccd_guide=-10.0,
t_ccd_acq=-10.0,
Copy link
Contributor Author

@jeanconn jeanconn Dec 8, 2023

Choose a reason for hiding this comment

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

This may be controversial, but it seems to be in the context of use in a test function that is in proseco.core (maybe should be somewhere in tests?).

Copy link
Member

Choose a reason for hiding this comment

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

Can reverting this count as the test of changing the t_ccd setter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just un-done this (makes sense at this point), though did your comment mean that you wanted me to remove some of my gratuitous t_ccd tests?

@jeanconn jeanconn requested a review from taldcroft December 8, 2023 19:58
proseco/fid.py Outdated Show resolved Hide resolved
proseco/fid.py Show resolved Hide resolved
@@ -128,6 +131,7 @@ def t_ccd(self):
@t_ccd.setter
def t_ccd(self, value):
self.t_ccd_guide = value
self.t_ccd_acq = value
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In more detailed review and testing, this was the change needed so that "get_fid_catalog" will mostly do the right thing if just a t_ccd is supplied. In that case the temperature is assigned to both t_ccd_guide and t_ccd_acq and fid offsets will be applied based on t_ccd_acq by default. This was already the default behavior for get_aca_catalog, but not for get_fid_catalog.

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable.

@taldcroft
Copy link
Member

Is this ready again for review? BTW I put this as Squash and Merge, unless you are adamant that all 36 commits should go in the permanent history.

@jeanconn jeanconn requested review from taldcroft and removed request for taldcroft December 13, 2023 15:18
@jeanconn
Copy link
Contributor Author

Sure. I just made that change to add_fake_stars_from_fid and reran unit tests (did not re-run functional/notebook). This is ready for review again. And sure I don't care if we keep all the commits if this is approved.

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

@jeanconn - I pushed a final commit with some cleanup. I re-reviewed the key validation notebook and code. It all looks good now, thanks for this important fix!


aca_args = STD_INFO.copy()
for kw in ["t_ccd", "t_ccd_acq", "t_ccd_guide"]:
if kw in aca_args:
Copy link
Member

Choose a reason for hiding this comment

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

For future reference, a one-line way to do this is aca_args.pop(kw, None).

Copy link
Member

Choose a reason for hiding this comment

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

And if it ever comes up again, we could update mod_info() (or whatever is that function) to allow for deleting kwargs via mod_info(delete_kwargs=("t_ccd", "t_ccd_acq", "t_ccd_guide")).

}


def test_t_ccd_attr():
Copy link
Member

Choose a reason for hiding this comment

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

I like the new tests!

@jeanconn jeanconn merged commit e1c1d0f into master Dec 17, 2023
2 checks passed
@jeanconn jeanconn deleted the fid-offset branch December 17, 2023 20:31
@javierggt javierggt mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants