Skip to content

Commit

Permalink
Merge pull request #382 from sot/add-acq-model-info
Browse files Browse the repository at this point in the history
Add acq prob model info dict as a new pickled attribute
  • Loading branch information
jeanconn authored Jul 11, 2023
2 parents 4e2d19c + ab1532f commit d52f347
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.3.0
hooks:
- id: black
language_version: python3.8
language_version: python3.10

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (python)
language_version: python3.10
10 changes: 9 additions & 1 deletion proseco/acq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from pathlib import Path

import numpy as np
from chandra_aca.star_probs import acq_success_prob, prob_n_acq
from chandra_aca.star_probs import (
acq_success_prob,
get_default_acq_prob_model_info,
prob_n_acq,
)
from chandra_aca.transform import mag_to_count_rate, pixels_to_yagzag, snr_mag_for_t_ccd
from scipy import ndimage, stats
from scipy.interpolate import interp1d
Expand Down Expand Up @@ -210,6 +214,9 @@ def get_acq_catalog(obsid=0, **kwargs):
warning=True,
)

# Get the acq prob model info and add to the table.
acqs.acq_prob_model_info = get_default_acq_prob_model_info(verbose=False)

return acqs


Expand Down Expand Up @@ -252,6 +259,7 @@ class AcqTable(ACACatalogTable):
p_safe = MetaAttribute(is_kwarg=False)
_fid_set = MetaAttribute(is_kwarg=False, default=())
imposters_mag_limit = MetaAttribute(is_kwarg=False, default=20.0)
acq_prob_model_info = MetaAttribute(is_kwarg=False)

@classmethod
def empty(cls):
Expand Down
28 changes: 27 additions & 1 deletion proseco/tests/test_acq.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import agasc
import numpy as np
import pytest
from chandra_aca import star_probs
from chandra_aca.aca_image import AcaPsfLibrary
from chandra_aca.transform import mag_to_count_rate, yagzag_to_pixels
from Quaternion import Quat
from ska_helpers import chandra_models

from .. import characteristics as ACA
from .. import characteristics_acq as ACQ
Expand Down Expand Up @@ -467,6 +469,8 @@ def test_get_acq_catalog_19387():
def test_get_acq_catalog_21007():
"""Put it all together. Regression test for selected stars.
Also test that the acq prob model info dict is correctly set.
From ipython::
>>> from proseco.acq import AcqTable
Expand All @@ -475,7 +479,9 @@ def test_get_acq_catalog_21007():
>>> repr(acqs.cand_acqs[TEST_COLS]).splitlines()
"""
acqs = get_acq_catalog(**OBS_INFO[21007])
# Force default acq prob model to be grid-* for checking the info dict later
with star_probs.conf.set_temp("default_model", "grid-*"):
acqs = get_acq_catalog(**OBS_INFO[21007])

exp = [
"<AcqTable length=14>",
Expand Down Expand Up @@ -517,6 +523,26 @@ def test_get_acq_catalog_21007():

assert repr(acqs[TEST_COLS]).splitlines() == exp

# Check the acq prob model info dict
info = acqs.acq_prob_model_info

# These can change with each run or on different machines
del info["data_file_path"]
del info["repo_path"]

exp = {
"default_model": "grid-*",
"version": "3.48",
"commit": "68a58099a9b51bef52ef14fbd0f1971f950e6ba3",
"md5": "3a47774392beeca2921b705e137338f4",
}
# For acqs info with verbose=False only non-None env vars are included
for name in chandra_models.ENV_VAR_NAMES:
if val := os.environ.get(name):
exp[name] = val

assert info == exp


def test_box_strategy_20603():
"""Test for PR #32 that doesn't allow p_acq to be reduced below 0.1.
Expand Down

0 comments on commit d52f347

Please sign in to comment.