How to use the astroquery.utils.commons 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 astropy / astroquery / astroquery / casda / core.py View on Github external
def _args_to_payload(self, **kwargs):
        request_payload = dict()

        # Convert the coordinates to FK5
        coordinates = kwargs.get('coordinates')
        c = commons.parse_coordinates(coordinates).transform_to(coord.FK5)

        if kwargs['radius'] is not None:
            radius = u.Quantity(kwargs['radius']).to(u.deg)
            pos = 'CIRCLE {} {} {}'.format(c.ra.degree, c.dec.degree, radius.value)
        elif kwargs['width'] is not None and kwargs['height'] is not None:
            width = u.Quantity(kwargs['width']).to(u.deg).value
            height = u.Quantity(kwargs['height']).to(u.deg).value
            top = c.dec.degree - (height/2)
            bottom = c.dec.degree + (height/2)
            left = c.ra.degree - (width/2)
            right = c.ra.degree + (width/2)
            pos = 'RANGE {} {} {} {}'.format(left, right, top, bottom)
        else:
            raise ValueError("Either 'radius' or both 'height' and 'width' must be supplied.")

        request_payload['POS'] = pos
github astropy / astroquery / astroquery / irsa / core.py View on Github external
def _parse_coordinates(coordinates):
    # borrowed from commons.parse_coordinates as from_name wasn't required in
    # this case
    if isinstance(coordinates, six.string_types):
        try:
            c = coord.SkyCoord(coordinates, frame='icrs')
            warnings.warn("Coordinate string is being interpreted as an "
                          "ICRS coordinate.")
        except u.UnitsError as ex:
            warnings.warn("Only ICRS coordinates can be entered as strings\n"
                          "For other systems please use the appropriate "
                          "astropy.coordinates object")
            raise ex
    elif isinstance(coordinates, commons.CoordClasses):
        c = coordinates
    else:
        raise TypeError("Argument cannot be parsed as a coordinate")
    c_icrs = c.transform_to(coord.ICRS)
    formatted_coords = _format_decimal_coords(c_icrs.ra.degree,
                                              c_icrs.dec.degree)
    return formatted_coords
github astropy / astroquery / astroquery / gaia / tapplus / tap.py View on Github external
async : bool, optional, default 'False'
            executes the query (job) in asynchronous/synchronous mode (default 
            synchronous)
        verbose : bool, optional, default 'False' 
            flag to display information about the process

        Returns
        -------
        The job results (astropy.table).
        """
        coord = self.__getCoordInput(coordinate, "coordinate")
        job = None
        if radius is not None:
            job = self.__cone_search(coord, radius, async=async, verbose=verbose)
        else:
            raHours, dec = commons.coord_to_radec(coord)
            ra = raHours * 15.0 # Converts to degrees
            widthQuantity = self.__getQuantityInput(width, "width")
            heightQuantity = self.__getQuantityInput(height, "height")
            widthDeg = widthQuantity.to(units.deg)
            heightDeg = heightQuantity.to(units.deg)
            query = "SELECT DISTANCE(POINT('ICRS',"+str(MAIN_GAIA_TABLE_RA)+","\
                +str(MAIN_GAIA_TABLE_DEC)+"), \
                POINT('ICRS',"+str(ra)+","+str(dec)+")) AS dist, * \
                FROM "+str(MAIN_GAIA_TABLE)+" WHERE CONTAINS(\
                POINT('ICRS',"+str(MAIN_GAIA_TABLE_RA)+","\
                +str(MAIN_GAIA_TABLE_DEC)+"),\
                BOX('ICRS',"+str(ra)+","+str(dec)+", "+str(widthDeg.value)+", "\
                +str(heightDeg.value)+"))=1 \
                ORDER BY dist ASC"
            if async:
                job = self.launch_job_async(query, verbose=verbose)
github astropy / astroquery / astroquery / gaia / core.py View on Github external
def __getCoordInput(self, value, msg):
        if not (isinstance(value, str) or isinstance(value,
                                                     commons.CoordClasses)):
            raise ValueError(
                str(msg) + " must be either a string or astropy.coordinates")
        if isinstance(value, str):
            c = commons.parse_coordinates(value)
            return c
        else:
            return value
github astropy / astroquery / astroquery / ibe / core.py View on Github external
height=None, intersect='OVERLAPS',
                         most_centered=False):
        """
        Query using simple image access protocol.  See ``query_region`` for
        details.  The returned table will include a list of URLs.
        """
        response = self.query_region_async(
            coordinate=coordinate, mission=mission,
            dataset=dataset, table=table, width=width,
            height=height, intersect=intersect, most_centered=most_centered,
            action='sia')

        # Raise exception, if request failed
        response.raise_for_status()

        return commons.parse_votable(
            response.text).get_first_table().to_table()
github astropy / astroquery / astroquery / gaia / core.py View on Github external
verbose : bool, optional, default 'False'
            flag to display information about the process
        columns: list, optional, default []
            if empty, all columns will be selected

        Returns
        -------
        The job results (astropy.table).
        """
        coord = self.__getCoordInput(coordinate, "coordinate")
        job = None
        if radius is not None:
            job = self.__cone_search(coord, radius,
                                     async_job=async_job, verbose=verbose)
        else:
            raHours, dec = commons.coord_to_radec(coord)
            ra = raHours * 15.0  # Converts to degrees
            widthQuantity = self.__getQuantityInput(width, "width")
            heightQuantity = self.__getQuantityInput(height, "height")
            widthDeg = widthQuantity.to(units.deg)
            heightDeg = heightQuantity.to(units.deg)

            if columns:
                columns = ','.join(map(str, columns))
            else:
                columns = "*"

            query = """
                    SELECT
                      DISTANCE(
                        POINT('ICRS', {ra_column}, {dec_column}),
                        POINT('ICRS', {ra}, {dec})
github astropy / astroquery / astroquery / irsa / core.py View on Github external
    @class_or_instance
    def list_catalogs(self):
        """
        Return a dictionary of the catalogs in the IRSA Gator tool.

        Returns
        -------
        catalogs : dict
            A dictionary of catalogs where the key indicates the catalog name to
            be used in query functions, and the value is the verbose description
            of the catalog.
        """
        response = commons.send_request(Irsa.GATOR_LIST_URL(), dict(mode='xml'), Irsa.TIMEOUT(), request_type="GET")
        root =tree.fromstring(response.content)
        catalogs = {}
        for catalog in root.findall('catalog'):
            catname = catalog.find('catname').text
            desc = catalog.find('desc').text
            catalogs[catname] = desc
        return catalogs