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

Plot IR flag fraction in monitor_win_perigee + style improvements #12

Merged
merged 5 commits into from
May 1, 2024

Conversation

taldcroft
Copy link
Member

@taldcroft taldcroft commented Apr 28, 2024

Description

monitor_win_perigee.py is the trending code that makes the composite plot reflecting ionizing radiation near perigee using ACA / OBC telemetry in NPNT and ACA monitor window image data in NMAN.

Previously the code was taking a short-cut and using 8 - AOKALSTR as a proxy for the count of IR flags, but this is distorted by times when a slot is not tracked and can also reflect other flags or problems.

Instead the new code directly counts the IR flags in telemetry to give an apples-to-apples comparison between NPNT and NMAN data. In addition the code is more careful now about normalization and the quantity that gets plotted is the fraction of available images that have the IR flag set. In the case of NPNT this requires both AOACASEQ == "KALM" and that the image tracking flag is set.

An unrelated change was just tidying a few style issue that ruff highlighted in kalman_perigee_mon.py. There is one slightly non-trivial change using lines.extend. I wasn't 100% sure of this behavior but it works and I did functional testing:

In [2]: a = [10]
In [3]: a.extend(x for x in range(5))
In [4]: a
Out[4]: [10, 0, 1, 2, 3, 4]

Functional testing

monitor_win_perigee.py

Ran the following from with the repo in Ska3:

python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2023:290 --stop 2023:325
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2023:320 --stop 2023:355
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2023:350 --stop 2024:005
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2024:001 --stop 2024:035
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2024:030 --stop 2024:065
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2024:060 --stop 2024:095
python -m kalman_watch.monitor_win_perigee --n-cache 300 --start 2024:090 --stop 2024:115

This gave the expected results for instance:
image

kalman_perigee_mon.py

Expected outputs:

(ska3) ➜  kalman_watch git:(use-ir-flag-in-mon-win-perigee) python -m kalman_watch.kalman_perigee_mon --stop 2022:165 --email=TEST --data-dir=play
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions.
2024-04-29 06:38:24,869 log_run_info: ******************************************
2024-04-29 06:38:24,869 log_run_info: Running: /Users/aldcroft/git/kalman_watch/kalman_watch/kalman_perigee_mon.py
2024-04-29 06:38:24,869 log_run_info: Version: 0.3.1.dev3+g0da5648
2024-04-29 06:38:24,869 log_run_info: Time: Mon Apr 29 06:38:24 2024
2024-04-29 06:38:24,869 log_run_info: User: root
2024-04-29 06:38:24,869 log_run_info: Machine: saos-MBP
2024-04-29 06:38:24,869 log_run_info: Processing args:
2024-04-29 06:38:24,869 log_run_info: {'data_dir': 'play',
2024-04-29 06:38:24,869 log_run_info:  'emails': ['TEST'],
2024-04-29 06:38:24,869 log_run_info:  'lookback': 14,
2024-04-29 06:38:24,869 log_run_info:  'make_html': False,
2024-04-29 06:38:24,869 log_run_info:  'stop': '2022:165'}
2024-04-29 06:38:24,869 log_run_info: ******************************************
2024-04-29 06:38:24,870 read_kalman_stats: No kalman perigee stats data found at play/perigees/kalman_perigees.ecsv
2024-04-29 06:38:24,870 read_kalman_stats: Creating new table from 0 info files
2024-04-29 06:38:24,870 get_evts_perigee: Getting perigee events between 2022:151:00:00:00.000 and 2022:165:00:00:00.000
2024-04-29 06:38:25,218 _get_tlm: Getting telemetry for 2022:152:04:14:24.365
2024-04-29 06:38:25,415 _get_tlm: Getting telemetry for 2022:154:19:43:59.552
2024-04-29 06:38:25,553 _get_tlm: Getting telemetry for 2022:157:11:13:15.204
2024-04-29 06:38:25,693 _get_tlm: Getting telemetry for 2022:160:02:41:36.780
2024-04-29 06:38:25,833 _get_tlm: Getting telemetry for 2022:162:18:09:01.633
2024-04-29 06:38:25,971 get_evts_perigee: Found 5 new perigee event(s)
2024-04-29 06:38:25,972 obss: Getting observations from kadi commands for 2022/Jun-01
2024-04-29 06:38:28,489 write_data: Writing perigee data to play/perigees/2022/Jun-01/data.npz
2024-04-29 06:38:28,493 write_info: Writing info to play/perigees/2022/Jun-01/info.json
2024-04-29 06:38:28,498 obss: Getting observations from kadi commands for 2022/Jun-03
2024-04-29 06:38:28,500 write_data: Writing perigee data to play/perigees/2022/Jun-03/data.npz
2024-04-29 06:38:28,503 write_info: Writing info to play/perigees/2022/Jun-03/info.json
2024-04-29 06:38:28,508 obss: Getting observations from kadi commands for 2022/Jun-06
2024-04-29 06:38:28,510 write_data: Writing perigee data to play/perigees/2022/Jun-06/data.npz
2024-04-29 06:38:28,513 write_info: Writing info to play/perigees/2022/Jun-06/info.json
2024-04-29 06:38:28,517 obss: Getting observations from kadi commands for 2022/Jun-09
2024-04-29 06:38:28,519 write_data: Writing perigee data to play/perigees/2022/Jun-09/data.npz
2024-04-29 06:38:28,523 write_info: Writing info to play/perigees/2022/Jun-09/info.json
2024-04-29 06:38:28,527 obss: Getting observations from kadi commands for 2022/Jun-11
2024-04-29 06:38:28,529 write_data: Writing perigee data to play/perigees/2022/Jun-11/data.npz
2024-04-29 06:38:28,532 write_info: Writing info to play/perigees/2022/Jun-11/info.json
2024-04-29 06:38:28,543 main: Writing perigee data play/perigees/kalman_perigees.ecsv
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: kalman_watch: long drop interval(s)
From: aldcroft@head.cfa.harvard.edu
To: TEST

******************************************
Running /Users/aldcroft/git/kalman_watch/kalman_watch/kalman_perigee_mon.py
acdc version: 4.13.2
Time: Mon Apr 29 06:38:28 2024
User: root
Machine: saos-MBP
Processing args:
{'data_dir': 'play',
 'emails': ['TEST'],
 'lookback': 14,
 'make_html': False,
 'stop': '2022:165'}
******************************************

Long drop interval(s) found for the following perigee events:
2022/Jun-11 2022:162:18:09:01.633

Validation of IR fraction compared to Kalman drops

From https://gist.github.com/taldcroft/524136904910254ff3eed0bd224764b5 there is this plot:
image

From the new code for the same month of 2022-Jan we get:
image

For an IR flag fraction of 0.1 we would expect the above plot to show about 48 Kalman drops / minute (0.1 * 8 * 60), but instead we see rates 2 to 3 times higher. The answer is that if you look at the raw data many/most of the Kalman drops come from a star being not tracked (the red X's below).

From https://cxc.cfa.harvard.edu/mta/ASPECT/kalman_watch3/perigees/2022/Jan-12/index.html there is this plot:
image

The new code only considers readouts when a star is being tracked and the IR flag could be set. So the two quantities are telling us different things:

  • IR flag fraction: best estimate of actual radiation environment and best comparison to monitor window data
  • Kalman drops: proxy for the overall impact of high radiation on star tracking and PCAD control

@taldcroft taldcroft requested review from javierggt and jeanconn April 29, 2024 11:58
@jeanconn
Copy link
Contributor

jeanconn commented Apr 29, 2024

I'm getting this now on head ska from fido,

ska3-jeanconn-fido> git rev-parse HEAD
0da5648758682b62798da8684e07b2a13e74a9c5
ska3-jeanconn-fido> git clean -fxd
ska3-jeanconn-fido> git status
On branch use-ir-flag-in-mon-win-perigee
Your branch is up to date with 'origin/use-ir-flag-in-mon-win-perigee'.

nothing to commit, working tree clean
ska3-jeanconn-fido> python -m kalman_watch.monitor_win_perigee
2024-04-29 15:55:33,455 get_manvrs_perigee: Getting maneuvers from 2024:075:19:55:33.454 to 2024:119:19:55:33.455
2024-04-29 15:55:37,819 get_manvrs_perigee: Getting intervals of Earth blocks from 2024:075:19:55:33.454 to 2024:119:19:55:33.455
/proj/sot/ska3/flight/lib/python3.11/site-packages/Quaternion/Quaternion.py:1084: UserWarning: Normalizing quaternion with zero norm
  warnings.warn("Normalizing quaternion with zero norm")
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/proj/sot/ska/jeanproj/git/kalman_watch/kalman_watch/monitor_win_perigee.py", line 831, in <module>
    main()
  File "/proj/sot/ska/jeanproj/git/kalman_watch/kalman_watch/monitor_win_perigee.py", line 791, in main
    manvrs_perigee = get_manvrs_perigee(start, stop)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj/sot/ska/jeanproj/git/kalman_watch/kalman_watch/monitor_win_perigee.py", line 145, in get_manvrs_perigee
    blocks = get_earth_blocks(start, stop)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj/sot/ska3/flight/lib/python3.11/site-packages/chandra_aca/planets.py", line 737, in get_earth_blocks
    eba = get_earth_boresight_angle(start, stop)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj/sot/ska3/flight/lib/python3.11/site-packages/chandra_aca/planets.py", line 685, in get_earth_boresight_angle
    p_earth_body = np.einsum("ijk,ik->ij", q_att_inv, -p_chandra_eci)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/proj/sot/ska3/flight/lib/python3.11/site-packages/numpy/core/einsumfunc.py", line 1371, in einsum
    return c_einsum(*operands, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (3708878,3,3)->(3708878,3,3) (3708876,3)->(3708876,newaxis,3) 

ipdb> start
<CxoTime object: scale='utc' format='date' value=2024:075:20:15:37.177>
ipdb> stop
<CxoTime object: scale='utc' format='date' value=2024:119:20:15:37.179>

@jeanconn
Copy link
Contributor

It looks like I'm seeing this because the fetch of quat_aoattqt results in an Msid object with different length vals and times.

In [1]: from cxotime import CxoTime

In [2]: start = CxoTime('2024:075:20:15:37.177')

In [3]: stop = CxoTime('2024:119:20:15:37.179')

In [4]: from cheta import fetch

In [5]: msid_q_att = fetch.Msid("quat_aoattqt", start, stop)
/proj/sot/ska3/flight/lib/python3.11/site-packages/Quaternion/Quaternion.py:1084: UserWarning: Normalizing quaternion with zero norm
  warnings.warn("Normalizing quaternion with zero norm")

In [6]: len(msid_q_att.times)
Out[6]: 3708876

In [7]: len(msid_q_att.vals)
Out[7]: 3708878

@jeanconn
Copy link
Contributor

Oh, I probably need sot/cheta#260

@taldcroft
Copy link
Member Author

@jeanconn - I think I have addressed your review comments. I changed a few docstrings to make things a bit less confusing, but overall it is not worth the effort to entirely excise the whole Kalman drops concept. This is addressed with a note at the top of the code.

I re-ran the functional testing with the seven time ranges and confirmed that the plots are still as expected.

@taldcroft taldcroft merged commit 976f109 into master May 1, 2024
@taldcroft taldcroft deleted the use-ir-flag-in-mon-win-perigee branch May 1, 2024 15:46
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