Esempio n. 1
0
File: catalog.py Progetto: sot/mica
def plot(obsid, mp_dir=None):
    sc = get_starcheck_catalog(obsid, mp_dir)
    quat = Quaternion.Quat((sc['obs']['point_ra'],
                            sc['obs']['point_dec'],
                            sc['obs']['point_roll']))
    field = agasc.get_agasc_cone(sc['obs']['point_ra'], sc['obs']['point_dec'],
                                 radius=1.5,
                                 date=DateTime(sc['obs']['mp_starcat_time']).date)
    fig = plot_stars(catalog=sc['cat'], attitude=quat, stars=field,
                    title="RA %.2f Dec %.2f" % (sc['obs']['point_ra'],
                                                sc['obs']['point_dec']))
    return fig, sc['cat'], sc['obs']
Esempio n. 2
0
def plot(obsid, mp_dir=None):
    sc = get_starcheck_catalog(obsid, mp_dir)
    quat = Quaternion.Quat((sc['obs']['point_ra'], sc['obs']['point_dec'],
                            sc['obs']['point_roll']))
    field = agasc.get_agasc_cone(sc['obs']['point_ra'],
                                 sc['obs']['point_dec'],
                                 radius=1.5,
                                 date=DateTime(
                                     sc['obs']['mp_starcat_time']).date)
    fig = plot_stars(catalog=sc['cat'],
                     attitude=quat,
                     stars=field,
                     title="RA %.2f Dec %.2f" %
                     (sc['obs']['point_ra'], sc['obs']['point_dec']))
    return fig, sc['cat'], sc['obs']
Esempio n. 3
0
def get_catalog(obsid, obstime):
    idx = np.searchsorted(load_segments['datestart'], obstime) - 1
    # if the start of the dwell isn't captured in this load segment, skip the dwell
    if not ((load_segments[idx]['datestart'] < obstime)
            & (load_segments[idx]['datestop'] > obstime)):
        print "Skipping {} {}".format(obstime, obsid)
    if load_segments[idx]['load_segment'] == 'CL344:1903_1':
        load_segments[idx]['load_segment'] = 'CL344:1903'
    if load_segments[idx]['load_segment'] == 'CL208:1800_1':
        load_segments[idx]['load_segment'] = 'CL208:1800'
    if load_segments[idx]['load_segment'] == 'CL344:2303_2':
        load_segments[idx]['load_segment'] = 'CL344:2303'
    load_match = (
        (loads['year'] == load_segments[idx]['year'])
        & (loads['load_segment'] == load_segments[idx]['load_segment']))

    load = loads[load_match][0]
    summary = summaries[summaries['file'] == load['file']][0]
    mp_dir = summary['mp_dir']
    if summary['bcf_cmd_count'] != 0:
        if (summary['processing_tstart'] > obstime):
            re_match = re.match("C(\d{3}):(\d{4})", summary['replan_cmds'])
            if re_match:
                sum_match = summaries[
                    summaries['shortfile'] == "C{}_{}.sum".format(
                        re_match.group(1), re_match.group(2))]
                if len(sum_match):
                    mp_dir = sum_match[0]['mp_dir']
                else:
                    raise ValueEarror
    cat = get_starcheck_catalog(obsid, mp_dir="/{}/".format(mp_dir))
    if not len(cat['cat']):
        raise ValueError
    targdelta = DateTime(obstime).secs - DateTime(
        cat['manvr'][-1]['mp_targquat_time']).secs
    return cat
Esempio n. 4
0
def calc_stats(obsid):
    obspar = mica.archive.obspar.get_obspar(obsid, version='last')
    if not obspar:
        raise ValueError("No obspar for {}".format(obsid))
    manvr = None
    dwell = None
    try:
        manvrs = events.manvrs.filter(obsid=obsid, n_dwell__gt=0)
        if len(manvrs) == 0:
            raise ValueError
        dwells = events.dwells.filter(obsid=obsid)
        # Use the last manvr and the first dwell
        manvr = manvrs[manvrs.count() - 1]
        dwell = dwells[0]
    except ValueError:
        multi_manvr = events.manvrs.filter(start=obspar['tstart'] - 10000,
                                           stop=obspar['tstart'] + 10000)
        multi = multi_manvr.select_overlapping(events.obsids(obsid=obsid))
        deltas = [np.abs(m.tstart - obspar['tstart']) for m in multi]
        manvr = multi[np.argmin(deltas)]
        dwell = manvr.dwell_set.first()

    if not manvr or not dwell:
        raise ValueError("No manvr or dwell for {}".format(obsid))

    logger.info("Found obsid manvr at {}".format(manvr.start))
    logger.info("Found dwell at {}".format(dwell.start))
    acq_start = manvr.acq_start
    guide_start = manvr.guide_start
    try:
        starcheck = get_starcheck_catalog_at_date(manvr.acq_start)
    except:
        # bad timelines for these observations, skip the tstart
        # input for get_starcheck_catalog
        if obsid in [1966]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/JAN1202/oflsa')
        elif obsid in [3105, 2741, 61334, 61333, 61332, 61331, 3358, 3357]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/JAN2802/oflsd/')
        elif obsid in [61261]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAR1902/oflsa/')
        elif obsid in [
                3471, 3086, 61250, 61249, 3094, 3066, 3115, 2833, 3464, 3175
        ]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAR2502/oflsb/')
        elif obsid in [3663, 61185, 61184, 3392, 61183]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAY2402/oflsa/')
        elif obsid in [60983]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/OCT2102/oflsc/')
        elif obsid in [60640, 60639, 60638, 60637, 60636, 60635, 60634, 60633]:
            raise ValueError("Starcheck not available for PCHECK_JUL2003")
        elif obsid in [60616, 60615]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/JUL2103/oflsc/')
        elif obsid in [3911]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/JUL2803/oflsc/')
        elif obsid in [4162]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/SEP2903/oflsa/')
        elif obsid in [60401]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2004/JAN1904/oflsb/')
        elif obsid in [59921, 5035]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2004/DEC1404/oflsc/')
        elif obsid in [58548, 58547, 58546, 7753]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2007/JAN2907/oflsb/')
        elif obsid in [7936, 7463]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2007/MAY2807/oflsb/')
        else:
            raise ValueError(
                "Problem looking up starcheck for {}".format(obsid))
    if starcheck is None or 'cat' not in starcheck or not len(
            starcheck['cat']):
        raise ValueError('No starcheck catalog found for {}'.format(
            manvr.get_obsid()))
    starcat_time = DateTime(starcheck['cat']['mp_starcat_time'][0]).secs
    starcat_dtime = starcat_time - DateTime(manvr.start).secs
    # If it looks like the wrong starcheck by time, give up
    if abs(starcat_dtime) > 300:
        raise ValueError(
            "Starcheck cat time delta is {}".format(starcat_dtime))
    if abs(starcat_dtime) > 30:
        logger.warning("Starcheck cat time delta of {} is > 30 sec".format(
            abs(starcat_dtime)))
    vals, times, one_shot, star_info = get_modern_data(manvr, dwell, starcheck)

    acq_stats = calc_acq_stats(manvr, vals, times)
    obsid_info = {
        'obsid': obsid,
        'obi': obspar['obi_num'],
        'acq_start': acq_start,
        'guide_start': guide_start,
        'guide_tstart': DateTime(guide_start).secs,
        'one_shot_length': one_shot,
        'revision': '1.0'
    }
    catalog = Table(starcheck['cat'])
    catalog.sort('idx')
    # Filter the catalog to be just acquisition stars
    catalog = catalog[(catalog['type'] == 'ACQ') | (catalog['type'] == 'BOT')]
    time = DateTime(guide_start).secs
    ccd_temp = np.mean(fetch_sci.MSID('AACCCDPT', time - 250, time + 250).vals)
    warm_threshold = 100.0
    warm_frac = dark_model.get_warm_fracs(warm_threshold, time, ccd_temp)
    temps = {'ccd_temp': ccd_temp, 'n100_warm_frac': warm_frac}
    return obsid_info, acq_stats, star_info, catalog, temps
Esempio n. 5
0
        kadi_one_shot = []
        aoatter1 = []
        aoatter2 = []
        aoatter3 = []

        for d in dwells:
            obsid = d.get_obsid()
            if obsid is None:
                continue
            if DateTime(d.stop).secs > mstable['TIME'][-1]:
                continue
            # Get one shot and maneuver to for *next* obsid
            n = d.get_next()
            if not n:
                continue
            starcheck = get_starcheck_catalog(n.get_obsid())
            if not starcheck or not len(starcheck['manvr']):
                continue
            manvr_angle.append(starcheck['manvr'][-1]['angle_deg'])
            manvr_slew_err.append(starcheck['manvr'][-1]['slew_err_arcsec'])
            next_obsids.append(n.get_obsid())

            date.append(d.manvr.kalman_start)
            datestop.append(d.stop)
            time.append(DateTime(d.manvr.kalman_start).secs)
            timestop.append(DateTime(d.stop).secs)
            kadi_one_shot.append(n.manvr.one_shot)

            obsids.append(obsid)

            # for data earlier than the chunk of pcad data I have
Esempio n. 6
0
def calc_stats(obsid):
    obspar = mica.archive.obspar.get_obspar(obsid)
    if not obspar:
        raise ValueError("No obspar for {}".format(obsid))
    manvr = None
    dwell = None
    try:
        manvrs = events.manvrs.filter(obsid=obsid, n_dwell__gt=0)
        dwells = events.dwells.filter(obsid=obsid)
        if manvrs.count() and dwells.count() == 1:
            manvr = manvrs[0]
            dwell = dwells[0]
    except ValueError:
        multi_manvr = events.manvrs.filter(start=obspar['tstart'] - 10000,
                                           stop=obspar['tstart'] + 10000)
        multi = multi_manvr.select_overlapping(events.obsids(obsid=obsid))
        deltas = [np.abs(m.tstart - obspar['tstart']) for m in multi]
        manvr = multi[np.argmin(deltas)]
        dwell = manvr.dwell_set.first()

    if not manvr or not dwell:
        raise ValueError("No manvr or dwell for {}".format(obsid))

    logger.info("Found obsid manvr at {}".format(manvr.start))
    logger.info("Found dwell at {}".format(dwell.start))
    acq_start = manvr.acq_start
    guide_start = manvr.guide_start
    try:
        starcheck = get_starcheck_catalog(obsid,
                                          tstart=manvr.start)
    except:
        # bad timelines for these observations, skip the tstart
        # input for get_starcheck_catalog
        if obsid in [1966]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/JAN1202/oflsa')
        elif obsid in [3105, 2741, 61334, 61333, 61332, 61331, 3358, 3357]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/JAN2802/oflsd/')
        elif obsid in [61261]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAR1902/oflsa/')
        elif obsid in [3471, 3086, 61250, 61249, 3094, 3066, 3115, 2833, 3464, 3175]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAR2502/oflsb/')
        elif obsid in [3663, 61185, 61184, 3392, 61183]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/MAY2402/oflsa/')
        elif obsid in [60983]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2002/OCT2102/oflsc/')
        elif obsid in [60640, 60639, 60638, 60637, 60636, 60635, 60634, 60633]:
            raise ValueError("Starcheck not available for PCHECK_JUL2003")
        elif obsid in [60616, 60615]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/JUL2103/oflsc/')
        elif obsid in [3911]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/JUL2803/oflsc/')
        elif obsid in [4162]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2003/SEP2903/oflsa/')
        elif obsid in [60401]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2004/JAN1904/oflsb/')
        elif obsid in [59921, 5035]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2004/DEC1404/oflsc/')
        elif obsid in [58548, 58547, 58546, 7753]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2007/JAN2907/oflsb/')
        elif obsid in [7936, 7463]:
            starcheck = get_starcheck_catalog(obsid,
                                              mp_dir='/2007/MAY2807/oflsb/')
        else:
            raise ValueError("Problem looking up starcheck for {}".format(obsid))
    if 'cat' not in starcheck or not len(starcheck['cat']):
        raise ValueError('No starcheck catalog found for {}'.format(
                manvr.get_obsid()))
    starcat_time = DateTime(starcheck['cat']['mp_starcat_time'][0]).secs
    starcat_dtime = starcat_time - DateTime(manvr.start).secs
    # If it looks like the wrong starcheck by time, give up
    if abs(starcat_dtime) > 300:
        raise ValueError("Starcheck cat time delta is {}".format(starcat_dtime))
    if abs(starcat_dtime) > 30:
        logger.warn("Starcheck cat time delta of {} is > 30 sec".format(abs(starcat_dtime)))
    vals, times, one_shot, star_info = get_modern_data(manvr, dwell, starcheck)

    acq_stats = calc_acq_stats(manvr, vals, times)
    obsid_info = {'obsid': obsid,
                  'obi': obspar['obi_num'],
                  'acq_start': acq_start,
                  'guide_start':  guide_start,
                  'guide_tstart': DateTime(guide_start).secs,
                  'one_shot_length': one_shot,
                  'revision': '1.0'}
    catalog = Table(starcheck['cat'])
    catalog.sort('idx')
    # Filter the catalog to be just acquisition stars
    catalog = catalog[(catalog['type'] == 'ACQ') | (catalog['type'] == 'BOT')]
    time = DateTime(guide_start).secs
    ccd_temp = np.mean(fetch_sci.MSID('AACCCDPT',
                                      time-250,
                                      time+250).vals)
    warm_threshold = 100.0
    warm_frac = mica.archive.aca_dark.dark_model.get_warm_fracs(
        warm_threshold, time, ccd_temp)
    temps = {'ccd_temp': ccd_temp, 'n100_warm_frac': warm_frac}
    return obsid_info, acq_stats, star_info, catalog, temps