astropy / astroquery
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2 1
from __future__ import print_function
3 1
from io import BytesIO
4 1
import astropy.units as u
5 1
import astropy.coordinates as coord
6 1
from astropy.io import fits
7 1
from ..query import BaseQuery
8 1
from ..utils import commons, prepend_docstr_nosections
9 1
from . import conf
10 1
from ..exceptions import InvalidQueryError
11

12 1
__all__ = ['Magpis', 'MagpisClass']
13

14

15 1
class MagpisClass(BaseQuery):
16 1
    URL = conf.server
17 1
    TIMEOUT = conf.timeout
18 1
    surveys = ["gps6",
19
               "gps6epoch2",
20
               "gps6epoch3",
21
               "gps6epoch4",
22
               "gps20",
23
               "gps20new",
24
               "gps90",
25
               "gpsmsx",
26
               "gpsmsx2",
27
               "gpsglimpse36",
28
               "gpsglimpse45",
29
               "gpsglimpse58",
30
               "gpsglimpse80",
31
               "mipsgal",
32
               "atlasgal",
33
               "bolocam"]
34 1
    maximsize = 1024
35

36 1
    def _args_to_payload(self, coordinates, image_size=1 * u.arcmin,
37
                         survey='bolocam', maximsize=None):
38
        """
39
        Fetches image cutouts from MAGPIS surveys.
40

41
        Parameters
42
        ----------
43
        coordinates : str or `astropy.coordinates` object
44
            The target around which to search. It may be specified as a
45
            string in which case it is resolved using online services or as
46
            the appropriate `astropy.coordinates` object. ICRS coordinates
47
            may also be entered as strings as specified in the
48
            `astropy.coordinates` module.
49
        image_size : str or `~astropy.units.Quantity` object, optional
50
           The string must be parsable by `astropy.coordinates.Angle`. The
51
           appropriate `~astropy.units.Quantity` object from `astropy.units`
52
           may also be used. Specifies the symmetric size of the
53
           image. Defaults to 1 arcmin.
54
        survey : str, optional
55
            The MAGPIS survey you want to cut out. Defaults to
56
            'bolocam'. The other surveys that can be used can be listed via
57
            :meth:`~astroquery.magpis.MagpisClass.list_surveys`.
58
        maximsize : int, optional
59
            Specify the maximum image size (in pixels on each dimension) that
60
            will be returned.  Max is 2048.
61
        """
62 1
        request_payload = {}
63 1
        request_payload["Survey"] = survey
64 1
        c = commons.parse_coordinates(coordinates).transform_to('galactic')
65 1
        ra_dec_str = str(c.l.degree) + ' ' + str(c.b.degree)
66 1
        request_payload["RA"] = ra_dec_str
67 1
        request_payload["Equinox"] = "Galactic"
68 1
        request_payload["ImageSize"] = coord.Angle(image_size).arcmin
69 1
        request_payload["ImageType"] = "FITS File"
70 1
        request_payload["MaxImSize"] = self.maximsize if maximsize is None else maximsize
71 1
        return request_payload
72

73 1
    @prepend_docstr_nosections("\n" + _args_to_payload.__doc__)
74 1
    def get_images(self, coordinates, image_size=1 * u.arcmin,
75
                   survey='bolocam', get_query_payload=False):
76
        """
77
        get_query_payload : bool, optional
78
            if set to `True` then returns the dictionary sent as the HTTP
79
            request.  Defaults to `False`
80

81
        Returns
82
        -------
83
        A list of `~astropy.io.fits.HDUList` objects
84
        """
85 1
        response = self.get_images_async(coordinates, image_size=image_size,
86
                                         survey=survey,
87
                                         get_query_payload=get_query_payload)
88 1
        if get_query_payload:
89 0
            return response
90 1
        S = BytesIO(response.content)
91 1
        try:
92 1
            return fits.open(S, ignore_missing_end=True)
93 0
        except IOError:
94 0
            raise InvalidQueryError(response.content)
95

96 1
    @prepend_docstr_nosections("\n" + _args_to_payload.__doc__)
97 1
    def get_images_async(self, coordinates, image_size=1 * u.arcmin,
98
                         survey='bolocam', get_query_payload=False):
99
        """
100
        get_query_payload : bool, optional
101
            if set to `True` then returns the dictionary sent as the HTTP
102
            request.  Defaults to `False`
103

104
        Returns
105
        -------
106
        response : `requests.Response`
107
            The HTTP response returned from the service
108
        """
109 1
        if survey not in self.surveys:
110 1
            raise InvalidQueryError("Survey must be one of " +
111
                                    (",".join(self.list_surveys())))
112 1
        request_payload = self._args_to_payload(
113
            coordinates, image_size=image_size, survey=survey)
114 1
        if get_query_payload:
115 1
            return request_payload
116 1
        response = self._request("POST", url=self.URL, data=request_payload,
117
                                 timeout=self.TIMEOUT, verify=False)
118 1
        return response
119

120 1
    def list_surveys(self):
121
        """Return a list of surveys for MAGPIS"""
122 1
        return self.surveys
123

124

125 1
Magpis = MagpisClass()

Read our documentation on viewing source code .

Loading