Esempio n. 1
0
def acq_success_prob(date=None, t_ccd=-19.0, mag=10.0, color=0.6, spoiler=False):
    """
    Return probability of acquisition success for given date, temperature and mag.

    Any of the inputs can be scalars or arrays, with the output being the result of
    the broadcasted dimension of the inputs.

    This is based on the dark model and acquisition success model presented
    in the State of the ACA 2013, and subsequently updated to use a Probit
    transform and separately fit B-V=1.5 stars.  This is available in the
    state_of_aca repo as fit_sota_model_probit.ipynb.

    :param date: Date(s) (scalar or np.ndarray, default=NOW)
    :param t_ccd: CD temperature(s) (degC, scalar or np.ndarray, default=-19C)
    :param mag: Star magnitude(s) (scalar or np.ndarray, default=10.0)
    :param color: Star color(s) (scalar or np.ndarray, default=0.6)
    :param spoil: Star spoiled (boolean or np.ndarray, default=False)

    :returns: Acquisition success probability(s)
    """
    from mica.archive.aca_dark.dark_model import get_warm_fracs

    date = DateTime(date).secs

    is_scalar, dates, t_ccds, mags, colors, spoilers = broadcast_arrays(date, t_ccd, mag,
                                                                        color, spoiler)
    spoilers = spoilers.astype(bool)

    warm_fracs = []
    for date, t_ccd in zip(dates.ravel(), t_ccds.ravel()):
        warm_frac = get_warm_fracs(WARM_THRESHOLD, date=date, T_ccd=t_ccd)
        warm_fracs.append(warm_frac)
    warm_frac = np.array(warm_fracs).reshape(dates.shape)

    probs = model_acq_success_prob(mags, warm_fracs, colors)

    p_0p7color = .4294  # probability multiplier for a B-V = 0.700 star (REF?)
    p_spoiler = .9241  # probability multiplier for a search-spoiled star (REF?)

    # If the star is brighter than 8.5 or has a calculated probability
    # higher than the max_star_prob, clip it at that value
    max_star_prob = .985
    probs[mags < 8.5] = max_star_prob
    probs[colors == 0.7] *= p_0p7color
    probs[spoilers] *= p_spoiler
    probs = probs.clip(1e-6, max_star_prob)

    # Return probabilities.  The [()] getitem at the end will flatten a
    # scalar array down to a pure scalar.
    return probs[0] if is_scalar else probs
Esempio n. 2
0
def get_interval_data(intervals, times, ccd_temp, obsreqs=None):
    """
    Determine the max temperature and mean offsets over each interval.

    If the OR list is supplied (in the obsreqs dictionary) the ACA offsets will
    also be calculated for each interval and included in the returned data.

    :param intervals: list of dictionaries describing obsid/catalog intervals
    :param times: times of the temperature samples
    :param ccd_temp: ccd temperature values
    :param obsreqs: optional dictionary of OR list from parse_cm.or_list

    :returns: dictionary (keyed by obsid) of intervals with max ccd_temps
    """
    obstemps = {}
    for interval in intervals:
        # treat the model samples as temperature intervals
        # and find the max during each obsid npnt interval
        obs = {'ccd_temp': None}
        obs.update(interval)
        stop_idx = 1 + np.searchsorted(times, interval['tstop'])
        start_idx = -1 + np.searchsorted(times, interval['tstart'])
        ok_temps = ccd_temp[start_idx:stop_idx]
        ok_times = times[start_idx:stop_idx]
        # If there are no good samples, put the times in the output dict and go to the next interval
        if len(ok_temps) == 0:
            obstemps[str(interval['obsid'])] = obs
            continue
        obs['ccd_temp'] = np.max(ok_temps)
        obs['n100_warm_frac'] = dark_model.get_warm_fracs(
            100, interval['tstart'], np.max(ok_temps))
        # If we have an OR list, the obsid is in that list, and the OR list has zero-offset keys
        if (obsreqs is not None and interval['obsid'] in obsreqs
                and 'chip_id' in obsreqs[interval['obsid']]):
            obsreq = obsreqs[interval['obsid']]
            ddy, ddz = get_aca_offsets(obsreq['detector'],
                                       obsreq['chip_id'],
                                       obsreq['chipx'],
                                       obsreq['chipy'],
                                       time=ok_times,
                                       t_ccd=ok_temps)
            obs['aca_offset_y'] = np.mean(ddy)
            obs['aca_offset_z'] = np.mean(ddz)
        obstemps[str(interval['obsid'])] = obs
    return obstemps