Coverage for sloancone/image.py : 23%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/local/bin/python
2# encoding: utf-8
3"""
4*Given a location and some other parameters, download an SDSS image of that location in the sky*
6:Author:
7 David Young
9:Date Created:
10 July 18, 2016
11"""
12from __future__ import print_function
13from __future__ import absolute_import
14from __future__ import division
15################# GLOBAL IMPORTS ####################
16from builtins import object
17from past.utils import old_div
18import sys
19import os
20os.environ['TERM'] = 'vt100'
21from fundamentals import tools
22from astrocalc.coords import unit_conversion
25class image(object):
26 """
27 *The worker class for the image module*
29 **Key Arguments:**
30 - ``log`` -- logger
31 - ``settings`` -- the settings dictionary
32 - ``ra`` -- right-ascension of the sky-location
33 - ``dec`` -- declination of the sky-location
34 - ``downloadDirectory`` -- directory to download the image stamp to. Default *./*
35 - ``filename`` -- path to download the image stamp to. Default *"sdss_stamp.jpeg"*
36 - ``grid`` -- include grid and scale in stamp. Default *True*
37 - ``label`` -- label. Default *False*
38 - ``photocat`` -- mark photometrical catalogued sources. Default *False*
39 - ``speccat`` -- mark spectrscopical catalogued objects. Default *False*
40 - ``invertColors`` -- invert the image stamp colors. Default *False*
41 - ``arcminWidth`` -- the width of the image stamp in arcmin. Default *5*
42 - ``pixelWidth`` -- the width of the image stamp in pixels. Default *500*
44 **Return:**
45 - ``covered`` -- the coverage result. True | False | 999 (i.e. not sure)
47 **Usage:**
49 Here's an example where we turn on all options before we download the image:
51 .. code-block:: python
53 from sloancone import image
54 imagestamp = image(
55 log=log,
56 settings=settings,
57 ra="179.689293428354",
58 dec="-0.454379056007667",
59 downloadDirectory="/tmp",
60 filename="sdss_stamp.jpeg",
61 grid=True,
62 label=True,
63 photocat=True,
64 speccat=True,
65 invertColors=True,
66 arcminWidth=5,
67 pixelWidth=500
68 )
69 # covered = True | False | 999 (i.e. not sure)
70 covered = imagestamp.get()
72 This produces a stamp at ``/tmp/sdss_stamp.jpeg`` that looks like this:
74 .. image:: https://i.imgur.com/2w4ipqr.png
75 :width: 800px
76 :alt: SDSS image stamp with all options turned on
77 """
78 # Initialisation
80 def __init__(
81 self,
82 log,
83 ra,
84 dec,
85 downloadDirectory="./",
86 filename="sdss_stamp.jpeg",
87 settings=False,
88 grid=True,
89 label=False,
90 photocat=False,
91 speccat=False,
92 invertColors=False,
93 arcminWidth=5,
94 pixelWidth=500
95 ):
96 self.log = log
97 log.debug("instansiating a new 'image' object")
98 self.settings = settings
99 self.ra = ra
100 self.dec = dec
101 self.filename = filename
102 self.downloadDirectory = downloadDirectory
103 self.grid = grid
104 self.label = label
105 self.photocat = photocat
106 self.speccat = speccat
107 self.invertColors = invertColors
108 self.arcminWidth = arcminWidth
109 self.pixelWidth = pixelWidth
111 # xt-self-arg-tmpx
113 # INITIAL ACTIONS
114 # CHECK SDSS COVERAGE BEFORE DOWNLOAD ATTEMPT
115 from .check_coverage import check_coverage
116 # covered = True | False | 999 (i.e. not sure)
117 self.covered = check_coverage(
118 log=log,
119 ra=self.ra,
120 dec=self.dec
121 ).get()
123 return None
125 def get(self):
126 """
127 *download the image*
128 """
129 self.log.debug('starting the ``get`` method')
131 ra = self.ra
132 dec = self.dec
133 if self.covered == False or self.covered == 999 or self.covered == "999":
134 return self.covered
136 self._download_sdss_image()
138 self.log.debug('completed the ``get`` method')
139 return self.covered
141 def _download_sdss_image(
142 self):
143 """*download sdss image*
144 """
145 self.log.debug('starting the ``_download_sdss_image`` method')
147 opt = ""
148 if self.grid:
149 opt += "G"
151 if self.label:
152 opt += "L"
154 if self.photocat:
155 opt += "P"
157 if self.speccat:
158 opt += "S"
160 if self.invertColors:
161 opt += "I"
163 if len(opt):
164 opt = "opt=%(opt)s&" % locals()
166 width = self.pixelWidth
168 scale = old_div((self.arcminWidth * 60.), width)
170 converter = unit_conversion(
171 log=self.log
172 )
173 ra = converter.ra_sexegesimal_to_decimal(
174 ra=self.ra
175 )
176 dec = converter.dec_sexegesimal_to_decimal(
177 dec=self.dec
178 )
179 url = """http://skyservice.pha.jhu.edu/DR12/ImgCutout/getjpeg.aspx?ra=%(ra)s&dec=%(dec)s&scale=%(scale)s&%(opt)sPhotoObjs=on&width=%(width)s&height=%(width)s""" % locals(
180 )
182 from fundamentals.download import multiobject_download
183 localUrls = multiobject_download(
184 urlList=[url],
185 downloadDirectory=self.downloadDirectory,
186 log=self.log,
187 timeStamp=False,
188 timeout=180,
189 concurrentDownloads=10,
190 resetFilename=[self.filename],
191 credentials=False, # { 'username' : "...", "password", "..." }
192 longTime=True,
193 indexFilenames=False
194 )
196 print(url)
198 self.log.debug('completed the ``_download_sdss_image`` method')
199 return None
201 # use the tab-trigger below for new method
202 # xt-class-method