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

11 1
__all__ = ['First', 'FirstClass']
12

13

14 1
class FirstClass(BaseQuery):
15 1
    URL = conf.server
16 1
    TIMEOUT = conf.timeout
17 1
    maximsize = 1024
18

19 1
    def _args_to_payload(self, coordinates, image_size=1 * u.arcmin,
20
                         *, maximsize=None):
21
        """
22
        Fetches image cutouts from FIRST survey.
23

24
        Parameters
25
        ----------
26
        coordinates : str or `astropy.coordinates` object
27
            The target around which to search. It may be specified as a
28
            string in which case it is resolved using online services or as
29
            the appropriate `astropy.coordinates` object. ICRS coordinates
30
            may also be entered as strings as specified in the
31
            `astropy.coordinates` module.
32
        image_size : str or `~astropy.units.Quantity` object, optional
33
           The string must be parsable by `astropy.coordinates.Angle`. The
34
           appropriate `~astropy.units.Quantity` object from `astropy.units`
35
           may also be used. Specifies the symmetric size of the
36
           image. Defaults to 1 arcmin.
37
        maximsize : int, optional
38
            Specify the maximum image size (in pixels on each dimension) that
39
            will be returned.  Max is 2048.
40
        """
41 1
        request_payload = {}
42 1
        c = commons.parse_coordinates(coordinates).transform_to('icrs')
43 1
        ra_dec_str = str(c.ra.hour) + ' ' + str(c.dec.degree)
44 1
        request_payload["RA"] = ra_dec_str
45 1
        request_payload["Equinox"] = "J2000"
46 1
        request_payload["ImageSize"] = coord.Angle(image_size).arcmin
47 1
        request_payload["ImageType"] = "FITS File"
48 1
        request_payload["MaxImSize"] = self.maximsize if maximsize is None else maximsize
49 1
        return request_payload
50

51 1
    @prepend_docstr_nosections("\n" + _args_to_payload.__doc__)
52 1
    def get_images(self, coordinates, image_size=1 * u.arcmin,
53
                   *, get_query_payload=False):
54
        """
55
        get_query_payload : bool, optional
56
            if set to `True` then returns the dictionary sent as the HTTP
57
            request.  Defaults to `False`
58

59
        Returns
60
        -------
61
        A list of `~astropy.io.fits.HDUList` objects
62
        """
63 1
        response = self.get_images_async(coordinates, image_size=image_size,
64
                                         get_query_payload=get_query_payload)
65 1
        if get_query_payload:
66 0
            return response
67 1
        S = BytesIO(response.content)
68 1
        try:
69 1
            return fits.open(S, ignore_missing_end=True)
70 0
        except IOError:
71 0
            raise InvalidQueryError(response.content)
72

73 1
    @prepend_docstr_nosections("\n" + _args_to_payload.__doc__)
74 1
    def get_images_async(self, coordinates, image_size=1 * u.arcmin,
75
                         *, 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
        response : `requests.Response`
84
            The HTTP response returned from the service
85
        """
86 1
        request_payload = self._args_to_payload(
87
            coordinates, image_size=image_size)
88 1
        if get_query_payload:
89 1
            return request_payload
90 1
        response = self._request("POST", url=self.URL, data=request_payload,
91
                                 timeout=self.TIMEOUT, verify=False)
92 1
        return response
93

94

95 1
First = FirstClass()

Read our documentation on viewing source code .

Loading