示例#1
0
def get_ephemeris_file(target, first, last, step_size=4):
    """Returns a file-like object containing the JPL/Horizons response.

    Parameters
    ----------
    target : str

    first : int
        Ephemeris will begin at the beginning of Campaign number `first`.

    last : int
        Ephemeris will end at the end of Campaign number `last`.

    step_size : int
        Resolution of the ephemeris in number of days.

    Returns
    -------
    ephemeris : file-like object.
        Containing the response from JPL/Horizons.
    """
    arg = {
        "target": target.replace(" ", "%20"),
        "start": K2fov.getFieldInfo(first)["start"],
        "stop": K2fov.getFieldInfo(last)["stop"],
        "step_size": "{}%20d".format(step_size)
    }
    if step_size < 1:  # Hack: support step-size in hours
        arg['step_size'] = "{:.0f}%20h".format(step_size * 24)
    print("Obtaining ephemeris for {target} "
          "from JPL/Horizons...".format(**arg))
    url = HORIZONS_URL.format(**arg)
    return urlopen(url)
示例#2
0
def get_ephemeris_file(target, first, last, step_size=4):
    """Returns a file-like object containing the JPL/Horizons response.

    Parameters
    ----------
    target : str

    first : int
        Ephemeris will begin at the beginning of Campaign number `first`.

    last : int
        Ephemeris will end at the end of Campaign number `last`.

    step_size : int
        Resolution of the ephemeris in number of days.

    Returns
    -------
    ephemeris : file-like object.
        Containing the response from JPL/Horizons.
    """
    arg = {
            "target": target.replace(" ", "%20"),
            "start": K2fov.getFieldInfo(first)["start"],
            "stop": K2fov.getFieldInfo(last)["stop"],
            "step_size": "{}%20d".format(step_size)
           }
    if step_size < 1:  # Hack: support step-size in hours
        arg['step_size'] = "{:.0f}%20h".format(step_size * 24)
    print("Obtaining ephemeris for {target} "
          "from JPL/Horizons...".format(**arg))
    url = HORIZONS_URL.format(**arg)
    return urlopen(url)
 def is_obj_in_TPFs(self,ra,dec):
     """
     
     """
     #object must be on silicon first to be within any TPFs!
     if not K2fov.isOnSilicon(ra, dec):
         return False
     
     for TPF in self.TPFs:
         if TPF.is_obj_in_TPF:
             return True
     #if object on silicon but not in any TPFs
     return False
示例#4
0
def get_ephemeris_file(target, first, last, step_size=4):
    """Returns a file-like object containing the JPL/Horizons response.

    Parameters
    ----------
    target : str

    first : int
        Ephemeris will begin at the beginning of Campaign number `first`.

    last : int
        Ephemeris will end at the end of Campaign number `last`.

    step_size : int
        Resolution of the ephemeris in number of days.

    Returns
    -------
    ephemeris : file-like object.
        Containing the response from JPL/Horizons.
    """
    arg = {
        "target": target.replace(" ", "%20"),
        "start": K2fov.getFieldInfo(first)["start"],
        "stop": K2fov.getFieldInfo(last)["stop"],
        "step_size": "{}%20d".format(step_size)
    }
    # If the target is a comet (i.e. name ends with "P"),
    # then we need to add the "CAP" directive to to select
    # the appropriate apparition.
    if target.endswith("P"):
        arg['target'] = "DES={}%3B%20CAP%3B".format(arg['target'])
    if step_size < 1:  # Hack: support step-size in hours
        arg['step_size'] = "{:.0f}%20h".format(step_size * 24)
    print("Obtaining ephemeris for {target} "
          "from JPL/Horizons...".format(**arg))
    url = HORIZONS_URL.format(**arg)
    return urlopen(url)
示例#5
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
示例#6
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