How to use the astroquery.mast.Observations function in astroquery

To help you get started, we’ve selected a few astroquery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github afeinstein20 / eleanor / eleanor / source.py View on Github external
closest_x, closest_y = np.argmin(np.abs(post_cens['x'] - col)), np.argmin(np.abs(post_cens['y'] - row))
        self.postcard = postcard_fmt.format(post_cens['x'].data[closest_x],
                                            post_cens['y'].data[closest_y])
        
        # Keeps track of all postcards that the star falls on
        all_postcards = []
        for i in range(len(post_cens)):
            name = postcard_fmt.format(post_cens['x'].data[i],
                                       post_cens['y'].data[i])
            all_postcards.append(name)
        self.all_postcards = np.array(all_postcards)
        
        
        if local == False:
        
            postcard_obs = Observations.query_criteria(provenance_name="ELEANOR",
                                                       target_name=self.postcard,
                                                       obs_collection="HLSP")

            if len(postcard_obs) > 0:
                product_list = Observations.get_product_list(postcard_obs)
                self.pointing = check_pointing(self.sector, self.camera, self.chip, self.pm_dir)

                if self.pointing is None:
                    extension = ["pc.fits", "bkg.fits", "pm.txt"]
                else:
                    extension = ["pc.fits", "bkg.fits"]

                results = Observations.download_products(product_list, extension=extension,
                                                         download_dir=self.fn_dir)
                postcard_path = results['Local Path'][0]
                self.postcard_path = '/'.join(e for e in postcard_path.split('/')[:-1])
github KeplerGO / lightkurve / lightkurve / mast.py View on Github external
"""
    # If passed a SkyCoord, convert it to an RA and Dec
    if isinstance(target, SkyCoord):
        target = '{}, {}'.format(target.ra.deg, target.dec.deg)

    try:
        # If `target` looks like a KIC or EPIC ID, we will pass the exact
        # `target_name` under which MAST will know the object.
        target = int(target)
        if (target > 0) and (target < 200000000):
            target_name = 'kplr{:09d}'.format(target)
        elif (target > 200000000) and (target < 300000000):
            target_name = 'ktwo{:09d}'.format(target)
        else:
            raise ValueError("{:09d}: not in the KIC or EPIC ID range".format(target))
        obs = Observations.query_criteria(target_name=target_name,
                                          project=["Kepler", "K2"],
                                          obs_collection=["Kepler", "K2"])
    except ValueError:
        # If `target` did not look like a KIC or EPIC ID, then we let MAST
        # resolve the target name to a sky position.
        try:
            obs = Observations.query_criteria(objectname=target,
                                              radius='{} arcsec'.format(radius),
                                              project=["Kepler", "K2"],
                                              obs_collection=["Kepler", "K2"])
            # Make sure the final table is in DISTANCE order
            obs.sort('distance')
        except ResolverError as exc:
            raise ArchiveError(exc)

    obsids = np.asarray(obs['obsid'])
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
return obs
    except ValueError:
        pass

    # If `target` did not look like a KIC or EPIC ID, then we let MAST
    # resolve the target name to a sky position. Convert radius from arcsec
    # to degrees for query_criteria().
    from astroquery.exceptions import ResolverError
    try:
        with warnings.catch_warnings():
            # suppress misleading AstropyWarning
            warnings.simplefilter('ignore', AstropyWarning)
            from astroquery.mast import Observations
            log.debug("Started querying MAST for observations within {} of objectname='{}'."
                      "".format(radius.to(u.arcsec), target))
            obs = Observations.query_criteria(objectname=target,
                                              radius=str(radius.to(u.deg)),
                                              project=project,
                                              obs_collection=project)
        obs.sort('distance')
        return obs
    except ResolverError as exc:
        raise SearchError(exc)
github KeplerGO / lightkurve / lightkurve / mast.py View on Github external
obs_collection=["Kepler", "K2"])
    except ValueError:
        # If `target` did not look like a KIC or EPIC ID, then we let MAST
        # resolve the target name to a sky position.
        try:
            obs = Observations.query_criteria(objectname=target,
                                              radius='{} arcsec'.format(radius),
                                              project=["Kepler", "K2"],
                                              obs_collection=["Kepler", "K2"])
            # Make sure the final table is in DISTANCE order
            obs.sort('distance')
        except ResolverError as exc:
            raise ArchiveError(exc)

    obsids = np.asarray(obs['obsid'])
    products = Observations.get_product_list(obs)
    order = [np.where(products['parent_obsid'] == o)[0] for o in obsids]
    order = [item for sublist in order for item in sublist]
    products = products[order]
    return products
github waqasbhatti / astrobase / astrobase / services / tesslightcurves.py View on Github external
)
        return None

    lcfiles = []

    for hlsp in hlsp_products:

        obs_table = Observations.query_criteria(
            target_name=tic_id, provenance_name=hlsp
        )

        if verbose:
            LOGINFO('Found {} {} light-curves.'.format(len(obs_table), hlsp))

        # Get list of available products for this Observation.
        cdips_products = Observations.get_product_list(obs_table)

        # Download the products for this Observation.
        manifest = Observations.download_products(cdips_products,
                                                  download_dir=download_dir)
        if verbose:
            LOGINFO("Done")

        if len(manifest) >= 1:
            lcfiles.append(list(manifest['Local Path']))

    #
    # flatten lcfiles list
    #
    if len(lcfiles) >= 1:
        return_lcfiles = [item for sublist in lcfiles for item in sublist]
    else:
github KeplerGO / lightkurve / lightkurve / search.py View on Github external
elif (0 < 200000000) and (target < 251813739):
            log.warning("Warning: {} may refer to a different K2 or TESS target. "
                        "Please add the prefix 'EPIC' or 'TIC' to disambiguate."
                        "".format(target))

    observations = _query_mast(target, project=mission, radius=radius)
    log.debug("MAST found {} observations. "
              "Now querying MAST for the corresponding data products."
              "".format(len(observations)))
    if len(observations) == 0:
        raise SearchError('No data found for target "{}".'.format(target))

    # Light curves and target pixel files
    if filetype.lower() != 'ffi':
        from astroquery.mast import Observations
        products = Observations.get_product_list(observations)
        result = join(products, observations, keys="obs_id", join_type='left',
                      uniq_col_name='{col_name}{table_name}', table_names=['', '_2'])
        result.sort(['distance', 'obs_id'])

        masked_result = _filter_products(result, filetype=filetype,
                                         campaign=campaign, quarter=quarter,
                                         cadence=cadence, project=mission,
                                         month=month, sector=sector, limit=limit)
        log.debug("MAST found {} matching data products.".format(len(masked_result)))
        return SearchResult(masked_result)

    # Full Frame Images
    else:
        cutouts = []
        for idx in np.where(['TESS FFI' in t for t in observations['target_name']])[0]:
            # if target passed in is a SkyCoord object, convert to RA, dec pair
github astropy / astroquery / docs / gallery-examples / example10_mast.py View on Github external
"""
Example 10
++++++++++
Retrieve Hubble archival data of M83 and make a figure
"""
from astroquery.mast import Mast, Observations
from astropy.visualization import make_lupton_rgb, ImageNormalize
import matplotlib.pyplot as plt
import reproject

result = Observations.query_object('M83')
selected_bands = result[(result['obs_collection'] == 'HST') &
                        (result['instrument_name'] == 'WFC3/UVIS') &
                        ((result['filters'] == 'F657N') |
                         (result['filters'] == 'F487N') |
                         (result['filters'] == 'F336W')) &
                        (result['target_name'] == 'MESSIER-083')]
prodlist = Observations.get_product_list(selected_bands)
filtered_prodlist = Observations.filter_products(prodlist)

downloaded = Observations.download_products(filtered_prodlist)

blue = fits.open(downloaded['Local Path'][2])
red = fits.open(downloaded['Local Path'][5])
green = fits.open(downloaded['Local Path'][8])

target_header = red['SCI'].header
github waqasbhatti / astrobase / astrobase / services / tesslightcurves.py View on Github external
lcfiles : list or None
        List of light-curve file paths. None if none are found and downloaded.

    """

    if not astroquery_dependency:
        LOGERROR(
            "The astroquery package is required for this function to work."
        )
        return None

    lcfiles = []

    for hlsp in hlsp_products:

        obs_table = Observations.query_criteria(
            target_name=tic_id, provenance_name=hlsp
        )

        if verbose:
            LOGINFO('Found {} {} light-curves.'.format(len(obs_table), hlsp))

        # Get list of available products for this Observation.
        cdips_products = Observations.get_product_list(obs_table)

        # Download the products for this Observation.
        manifest = Observations.download_products(cdips_products,
                                                  download_dir=download_dir)
        if verbose:
            LOGINFO("Done")

        if len(manifest) >= 1: