def run_test(campaign):
     """Are entries in the target list of a given campaign on silicon?"""
     fov = getKeplerFov(campaign)
     targetlist_fn = os.path.join(TESTDIR,
                                  "data",
                                  "K2Campaign{0}targets.csv".format(campaign))
     targetlist = np.genfromtxt(targetlist_fn,
                                delimiter=",", dtype=None, names=True)
     ra, dec = targetlist["RA_J2000_deg"], targetlist["Dec_J2000_deg"]
     mask = ~np.isnan(ra) & ~np.isnan(dec)
     for idx in np.where(mask)[0][::500]:  # Speed-up: check every 500th
         # All the sources in the target list should be on silicon
         assert(onSiliconCheck(ra[idx], dec[idx], fov))
         # A source +20 deg away should not be on silicon
         assert(not onSiliconCheck(ra[idx] + 20, dec[idx], fov))
Esempio n. 2
0
def check_target(target,
                 first=0,
                 last=LAST_CAMPAIGN,
                 verbose=True,
                 create_plot=False,
                 print_speed=True):
    """
    Returns
    -------
    visible_campaigns : list of int
        List of campaign numbers in which the object is visible.
    """
    K2fov.logger.disabled = True  # Disable warnings about prelim fields
    ephem = get_ephemeris_dataframe(target, first, last)
    visible_campaigns = []
    for c in range(first, last + 1):
        visible = False
        fovobj = K2fov.getKeplerFov(c)
        campaign_ephem = ephem.loc[K2fov.getFieldInfo(c)["start"]:K2fov.
                                   getFieldInfo(c)["stop"]]
        if create_plot:
            import matplotlib.pyplot as pl
            from K2fov import projection
            ph = projection.PlateCaree()
            pl.figure()
            fovobj.plotPointing(ph, showOuts=False)
            pl.plot(campaign_ephem["ra"],
                    campaign_ephem["dec"],
                    color="black",
                    lw=3)
            #plot_padding = 5
            #pl.xlim([campaign_ephem["ra"].max() + plot_padding,
            #         campaign_ephem["ra"].min() - plot_padding])
            #pl.ylim([campaign_ephem["dec"].min() - plot_padding,
            #         campaign_ephem["dec"].max() + plot_padding])
            pl.xlabel('R.A. [degrees]')
            pl.ylabel('Declination [degrees]')
            pl.gca().invert_xaxis()
            pl.minorticks_on()
            pl.title("Visibility of {0} in K2 C{1}".format(target, c))
            plot_fn = "{}-c{}.png".format(target.replace("/", "_"), c)
            print("Writing {}".format(plot_fn))
            pl.savefig(plot_fn)
            pl.close()
        for idx, row in campaign_ephem.iterrows():
            if onSiliconCheck(row["ra"], row["dec"], fovobj):
                logging.debug("{} is visible in C{}.".format(target, c))
                logging.debug(campaign_ephem[["dra", "ddec"]])
                visible = True
                break
        if visible:
            visible_campaigns.append(c)
            if verbose:
                mag = campaign_ephem['mag']
                if mag.dtype == float:  # can also be the string "n/a"
                    min_mag, max_mag = mag.min(), mag.max()
                else:
                    min_mag, max_mag = -99.9, -99.9
                print("Object '{}' is visible in C{} ("
                      "mag {:.1f}..{:.1f}; "
                      "{:.1f}..{:.1f}\"/h; "
                      "ra {:.3f}..{:.3f}; "
                      "dec {:.3f}..{:.3f}).".format(
                          target, c, min_mag, max_mag,
                          campaign_ephem['motion'].min(),
                          campaign_ephem['motion'].max(),
                          campaign_ephem['ra'].min(),
                          campaign_ephem['ra'].max(),
                          campaign_ephem['dec'].min(),
                          campaign_ephem['dec'].max()))
            continue
    K2fov.logger.disabled = False
    return visible_campaigns
Esempio n. 3
0
def check_target(target, first=0, last=LAST_CAMPAIGN, verbose=True,
                 create_plot=False, print_speed=True):
    """
    Returns
    -------
    visible_campaigns : list of int
        List of campaign numbers in which the object is visible.
    """
    K2fov.logger.disabled = True  # Disable warnings about prelim fields
    ephem = get_ephemeris_dataframe(target, first, last)
    visible_campaigns = []
    for c in range(first, last + 1):
        visible = False
        fovobj = K2fov.getKeplerFov(c)
        campaign_ephem = ephem.loc[K2fov.getFieldInfo(c)["start"]:K2fov.getFieldInfo(c)["stop"]]
        if create_plot:
            import matplotlib.pyplot as pl
            from K2fov import projection
            ph = projection.PlateCaree()
            pl.figure()
            fovobj.plotPointing(ph, showOuts=False)
            pl.plot(campaign_ephem["ra"], campaign_ephem["dec"],
                    color="black", lw=3)
            #plot_padding = 5
            #pl.xlim([campaign_ephem["ra"].max() + plot_padding,
            #         campaign_ephem["ra"].min() - plot_padding])
            #pl.ylim([campaign_ephem["dec"].min() - plot_padding,
            #         campaign_ephem["dec"].max() + plot_padding])
            pl.xlabel('R.A. [degrees]')
            pl.ylabel('Declination [degrees]')
            pl.gca().invert_xaxis()
            pl.minorticks_on()
            pl.title("Visibility of {0} in K2 C{1}".format(target, c))
            plot_fn = "{}-c{}.png".format(target.replace("/", "_"), c)
            print("Writing {}".format(plot_fn))
            pl.savefig(plot_fn)
            pl.close()
        for idx, row in campaign_ephem.iterrows():
            if onSiliconCheck(row["ra"], row["dec"], fovobj):
                logging.debug("{} is visible in C{}.".format(target, c))
                logging.debug(campaign_ephem[["dra", "ddec"]])
                visible = True
                break
        if visible:
            visible_campaigns.append(c)
            if verbose:
                mag = campaign_ephem['mag']
                if mag.dtype == float:  # can also be the string "n/a"
                    min_mag, max_mag = mag.min(), mag.max()
                else:
                    min_mag, max_mag = -99.9, -99.9
                print("Object '{}' is visible in C{} ("
                      "mag {:.1f}..{:.1f}; "
                      "{:.1f}..{:.1f}\"/h; "
                      "ra {:.3f}..{:.3f}; "
                      "dec {:.3f}..{:.3f}).".format(
                          target,
                          c,
                          min_mag,
                          max_mag,
                          campaign_ephem['motion'].min(),
                          campaign_ephem['motion'].max(),
                          campaign_ephem['ra'].min(),
                          campaign_ephem['ra'].max(),
                          campaign_ephem['dec'].min(),
                          campaign_ephem['dec'].max())
                      )
            continue
    K2fov.logger.disabled = False
    return visible_campaigns