示例#1
0
def obsid_probabilities():
    per_obsid_two = {-7: [], -11: [], -14: []}
    per_obsid_three = {-7: [], -11: [], -14: []}
    per_obsid_four = {-7: [], -11: [], -14: []}

    target_year = 2018
    acq_stars = np.load("/proj/sot/ska/data/acq_stat_reports/acq_stats_with_temp_and_warmpix.npy")
    warm_threshold = 100

    # acq_mag_limit = {}
    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.0025, 0.005), ("r", "g", "b")):
        # load these from np save files if they exists
        if (
            os.path.exists("acq_two_{}.npy".format(t_ccd_max))
            & os.path.exists("acq_three_{}.npy".format(t_ccd_max))
            & os.path.exists("acq_four_{}.npy".format(t_ccd_max))
        ):
            per_obsid_two[t_ccd_max] = np.load("acq_two_{}.npy".format(t_ccd_max))
            per_obsid_three[t_ccd_max] = np.load("acq_three_{}.npy".format(t_ccd_max))
            per_obsid_four[t_ccd_max] = np.load("acq_four_{}.npy".format(t_ccd_max))
            continue

        dates, t_ccds = dark_models.ccd_temperature_model(
            t_ccd_max, start="{}:001".format(target_year), stop="{}:001".format(target_year), n=1
        )

        warm_frac = dark_models.get_warm_fracs(warm_threshold, date=dates.secs[0], T_ccd=t_ccds[0]) + offset

        for time, t_ccd in izip(dates.secs, t_ccds):
            warm_frac = dark_models.get_warm_fracs(warm_threshold, date=time, T_ccd=t_ccd)
            # mag_limit = optimize.brentq(acq_fail_prob, 6.0, 12.0, args=(warm_frac + offset, 0.5))
            # acq_mag_limit[t_ccd_max] = mag_limit

        obsids = np.unique(acq_stars["obsid"])
        for obsid in np.unique(obsids):
            # ignore cal for the time being
            if obsid > 40000:
                continue
            acq = acq_stars[(acq_stars["obsid"] == obsid)]
            # ignore multi-obi
            if len(np.unique(acq["obi"])) > 1:
                continue
            if len(acq) < 8:
                continue
            acq_probs = [1 - acq_fail_prob(star["mag"], warm_frac) for star in acq]
            prob_n = prob_n_stars(acq_probs)
            cum = np.cumsum(prob_n)
            per_obsid_two[t_ccd_max].append(cum[2])
            per_obsid_three[t_ccd_max].append(cum[3])
            per_obsid_four[t_ccd_max].append(cum[4])
        np.save("acq_two_{}".format(t_ccd_max), per_obsid_two[t_ccd_max])
        np.save("acq_three_{}".format(t_ccd_max), per_obsid_three[t_ccd_max])
        np.save("acq_four_{}".format(t_ccd_max), per_obsid_three[t_ccd_max])

    return per_obsid_two, per_obsid_three, per_obsid_four
def plot_warm_frac_future():
    """
    Plot the future warm pixel fraction from the 2013 baseline dark current model
    for the N100 case.  Include observed fractions from dark current calibrations.
    """
    warm_threshold = 100.
    dates, pred_warm_fracs, obs_warm_fracs = get_warm_frac(warm_thresholds=[warm_threshold])

    plt.close(1)
    plt.figure(1, figsize=(6, 4))
    color = 'g'
    plot_cxctime(dates, obs_warm_fracs[warm_threshold], color + '.')
    plot_cxctime(dates, pred_warm_fracs[warm_threshold], color + '-')

    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.005, 0.01), ('r', 'g', 'b')):
        dates, t_ccds = dark_models.ccd_temperature_model(t_ccd_max, start='2014:001',
                                                          stop='2018:001', n=20)
        warm_fracs = []
        for time, t_ccd in izip(dates.secs, t_ccds):
            warm_frac = dark_models.get_warm_fracs(warm_threshold, date=time, T_ccd=t_ccd)
            warm_fracs.append(warm_frac + offset)
        plot_cxctime(dates.secs, warm_fracs, color + '-',
                     label='T_ccd < {} C'.format(t_ccd_max), linewidth=1.5)

    x0, x1 = plt.xlim()
    dx = (x1 - x0) * 0.03
    plt.xlim(x0 - dx, x1 + dx)
    plt.grid()
    plt.legend(loc='best', fontsize=12)
    plt.title('Warm pixel fraction vs. time')
    plt.ylabel('N > 100 warm pixel fraction')
    plt.tight_layout()
    plt.savefig('warm_frac_future.png')
def get_warm_frac(dateglob='20?????', outroot=None, warm_thresholds=None):
    """
    Get the warm pixel fraction from the 2013 baseline dark current model.
    """
    if warm_thresholds is None:
        warm_thresholds = [50., 100., 200.]

    darkfiles = glob('aca_dark_cal/{}'.format(dateglob))
    pred_warm_fracs = {x: list() for x in warm_thresholds}
    obs_warm_fracs = {x: list() for x in warm_thresholds}
    dates = []

    for darkdir in sorted(darkfiles):
        date = re.search(r'(\d+)', darkdir).group(1)
        if date not in cals_map:
            print '{} not in cals map'.format(date)
            continue

        print 'Processing', darkdir, date
        hdus = fits.open(os.path.join(darkdir, 'imd.fits'))
        dark = hdus[0].data.flatten()
        hdus.close()

        cal = cals_map[date]
        warm_fracs = dark_models.get_warm_fracs(warm_thresholds, date=cal['day'], T_ccd=cal['temp'])

        dates.append(DateTime(cal['day']).secs)
        for warm_threshold, warm_frac in zip(warm_thresholds, warm_fracs):
            pred_warm_fracs[warm_threshold].append(warm_frac)
            obs_warm_fracs[warm_threshold].append(np.sum(dark > warm_threshold) / 1024.0 ** 2)

    return dates, pred_warm_fracs, obs_warm_fracs
示例#4
0
def plot_limiting_mag():
    """
    Plot the future limiting magnitude for three cases of max T_ccd (-14, -11, -7).
    """
    warm_threshold = 100.

    plt.close(1)
    plt.figure(1, figsize=(6, 4))
    color = 'g'

    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.0025, 0.005), ('r', 'g', 'b')):
        dates, t_ccds = dark_models.ccd_temperature_model(t_ccd_max, start='2014:001',
                                                          stop='2018:001', n=20)
        warm_fracs = []
        for time, t_ccd in izip(dates.secs, t_ccds):
            warm_frac = dark_models.get_warm_fracs(warm_threshold, date=time, T_ccd=t_ccd)
            warm_fracs.append(warm_frac + offset)
        n100 = np.array(warm_fracs)
        mag_limit = np.log10(0.5 / n100) / 1.18 + 10.09
        plot_cxctime(dates.secs, mag_limit, color + '-',
                     label='T_ccd < {} C'.format(t_ccd_max), linewidth=1.5)

    x0, x1 = plt.xlim()
    dx = (x1 - x0) * 0.03
    plt.xlim(x0 - dx, x1 + dx)
    plt.grid()
    plt.legend(loc='best', fontsize=12)
    plt.title('ACA Limiting magnitude vs. time')
    plt.ylabel('ACA Mag')
    plt.tight_layout()
    plt.savefig('limiting_mag.png')
示例#5
0
def plot_acq_mag_limit():
    """
    Plot the future acq star limiting magnitude for three cases of
    max T_ccd (-14, -11, -7).
    """
    warm_threshold = 100.

    plt.close(1)
    plt.figure(1, figsize=(6, 4))
    color = 'g'

    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.0025, 0.005), ('r', 'g', 'b')):
        dates, t_ccds = dark_models.ccd_temperature_model(t_ccd_max, start='2014:001',
                                                          stop='2018:001', n=20)
        warm_fracs = []
        for time, t_ccd in izip(dates.secs, t_ccds):
            warm_frac = dark_models.get_warm_fracs(warm_threshold, date=time, T_ccd=t_ccd)
            warm_fracs.append(warm_frac + offset)

        mag_limits = []
        for warm_frac in warm_fracs:
            mag_limit = optimize.brentq(acq_success_prob, 6.0, 12.0, args=(warm_frac, 0.5))
            mag_limits.append(mag_limit)

        plot_cxctime(dates.secs, mag_limits, color + '-',
                     label='T_ccd < {} C'.format(t_ccd_max), linewidth=1.5)

    x0, x1 = plt.xlim()
    dx = (x1 - x0) * 0.03
    plt.xlim(x0 - dx, x1 + dx)
    plt.grid()
    plt.legend(loc='best', fontsize=12)
    plt.title('Acquisition magnitude limit vs. time')
    plt.ylabel('ACA Mag')
    plt.tight_layout()
    plt.savefig('acq_mag_limit.png')
示例#6
0
def save_stars_per_catalog():
    target_year = 2018
    guide_stars = np.load('/proj/sot/ska/data/gui_stat_reports/guide_stats_with_temp_and_warmpix.npy')
    acq_stars = np.load('/proj/sot/ska/data/acq_stat_reports/acq_stats_with_temp_and_warmpix.npy')

    warm_threshold = 100

    # guide stars
    gui_mag_limit = {}
    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.0025, 0.005), ('r', 'g', 'b')):

        dates, t_ccds = dark_models.ccd_temperature_model(t_ccd_max,
                                                          start='{}:001'.format(target_year),
                                                          stop='{}:001'.format(target_year), n=1)
        warm_frac = (dark_models.get_warm_fracs(warm_threshold, date=dates.secs[0], T_ccd=t_ccds[0])
                     + offset)
        gui_mag_limit[t_ccd_max] = np.log10(0.5 / warm_frac) / 1.18 + 10.09

    per_obsid_guide = { -7: [],
                       -11: [],
                       -14: [] }
    obsids = np.unique(guide_stars['obsid'])
    for obsid in obsids:
        # ignore cal for the time being
        if obsid > 40000:
            continue
        gs = guide_stars[(guide_stars['obsid'] == obsid) & (guide_stars['type'] != 'FID') & (guide_stars['type'] != 'MON')]
        # ignore multi-obi
        if len(np.unique(gs['obi'])) > 1:
            continue
        for mag in gui_mag_limit:
            n_bright_stars = len(np.flatnonzero(gs['mag_exp'] < gui_mag_limit[mag]))
            per_obsid_guide[mag].append(n_bright_stars)
            print obsid, mag, n_bright_stars


    per_obsid_acq = { -7: [],
                          -11: [],
                          -14: [] }

    acq_mag_limit = {}
    for t_ccd_max, offset, color in izip((-14, -11, -7), (0, 0.0025, 0.005), ('r', 'g', 'b')):
        dates, t_ccds = dark_models.ccd_temperature_model(t_ccd_max,
                                                          start='{}:001'.format(target_year),
                                                          stop='{}:001'.format(target_year), n=1)

        warm_frac = (dark_models.get_warm_fracs(warm_threshold, date=dates.secs[0], T_ccd=t_ccds[0])
                     + offset)

        for time, t_ccd in izip(dates.secs, t_ccds):
            warm_frac = dark_models.get_warm_fracs(warm_threshold, date=time, T_ccd=t_ccd)
            mag_limit = optimize.brentq(acq_success_prob, 6.0, 12.0, args=(warm_frac + offset, 0.5))
            acq_mag_limit[t_ccd_max] = mag_limit

    obsids = np.unique(acq_stars['obsid'])
    for obsid in obsids:
        # ignore cal for the time being
        if obsid > 40000:
            continue
        acq = acq_stars[(acq_stars['obsid'] == obsid)]
        # ignore multi-obi
        if len(np.unique(acq['obi'])) > 1:
            continue
        if len(acq) < 8:
            continue
        for mag in acq_mag_limit:
            n_bright_stars = len(np.flatnonzero(acq['mag'] < acq_mag_limit[mag]))
            per_obsid_acq[mag].append(n_bright_stars)
            print obsid, mag, n_bright_stars

    for mag in [-7, -11, -14]:
        np.save('guide_{}_bright'.format(mag), per_obsid_guide[mag])
        np.save('acq_{}_bright'.format(mag), per_obsid_acq[mag])