<jupyter_start><jupyter_text>Acquisition success yearly trendingTo run this standalone on the HEAD or GRETA networks:``` Get into Ska3 environmentgit clone https://github.com/sot/aca_stats.gitcd aca_statsjupyter nbconvert --to notebook --execute acq-success-trend-yearly.ipynbls -lrt```This will create the png and csv output files.<jupyter_code>import numpy as np
from agasc import get_supplement_table
%matplotlib inline
from astropy.table import Table
from mica.stats.acq_stats import get_stats
from cxotime import CxoTime
import matplotlib.pyplot as plt
from chandra_aca.star_probs import binom_ppf
stats = Table(get_stats())
len(stats)
# Make truncated year column for doing grouping. If current time is less than
# half way through the year then slosh that data into the previous year.
curr_year = CxoTime.now().decimalyear
curr_year_trunc = np.trunc(curr_year)
obs_year = CxoTime(stats['guide_tstart']).decimalyear
if curr_year - curr_year_trunc < 0.5:
    obs_year = obs_year.clip(None, curr_year_trunc - 1)
stats['iyear'] = np.trunc(obs_year)
# Correct ACA mags using AGASC supplement
obs_mags = get_supplement_table('mags', as_dict=True)
n_match = 0
for row in stats:
    try:
        row['mag'] = obs_mags[row['agasc_id']]['mag_aca']
        n_match += 1
    except KeyError:
        pass
print(n_match)
# Select only faint stars.
# Original version of notebook filtered on stats['halfw'] >= 120 but don't do that here.
ok = (stats['mag'] >= 9.6) & (stats['mag'] < 10.6)
sok = stats[ok]
len(sok)
n_match
sok['imag'] = np.trunc(sok['mag'] * 5) / 5
sg = sok.group_by(keys=['imag', 'iyear'])['imag', 'iyear', 'star_tracked']
len(sg.groups)
for grp in sg.groups:
    print(grp['imag'][0], grp['iyear'][0], np.sum(grp['star_tracked']), len(grp), 
          '{:.2f}'.format(np.sum(grp['star_tracked']) / len(grp)))
# This is the way to plot error bars, but they end up being too messy anyway.
binom_ppf(7, 13, [0.16, 0.5, 0.84])
# The mean of the star_tracked 0's and 1's is the tracking fraction.
sga = sg.groups.aggregate(np.mean)
print(sga)
# Make the plot
fig, ax = plt.subplots()
imags = sorted(set(sga['imag']))
for imag in imags:
    ok = sga['imag'] == imag
    ax.plot(sga['iyear'][ok], sga['star_tracked'][ok], '-o', ms=3,
            label=f'{imag:.1f} - {imag+0.2:.1f} mag')
ax.legend()
ax.grid()
ax.set_title('Acquisition success rate trend')
ax.set_ylabel('Success fraction')
ax.set_xlabel('Year')
ax.set_ylim(0, 1);
plt.savefig('acq_success_yearly.png', dpi=150)

sga.write('acq_success_yearly.csv', overwrite=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14307992202729045, 'fraction_numerical': 0.016374269005847954, 'mean_word_length': 4.939814814814815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '15492', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 993, 'n_tokens_neox': 944, 'n_words': 251, 'path': 'acq-success-trend-yearly.ipynb', 'repo_name': 'sot/aca_stats', 'size': '2565'}