dss_image – Fetch and plot DSS/SDSS images

Download an image from SDSS or DSS and make the plot

Largely copied from hetdexshuffle/visualize.py with some minor modifications

Todo

Improve the documentation.

ifu_centers: plotFocalPlaneQuicklook() and get_image() have a ifu_centers arguments, which is the center of the IFUs in the focal plane. This is confusing as in HETDEX jargon IFUCen refers to the fibers within one IFU.

Write tests.

Use io.StringIO instead of StringIO.StringIO in python2

The CD matrix could be substituted by astropy WCS:

Check if io.StringIO works for python2, if yes, we don’t need it pyhetdex.tools.six

pyhetdex.tools.astro.dss_image.SDSS_coverage(ra, dec)[source]

Check if the position at ra, dec is within the SDSS footprint

Warning

it assumes a radius of 0.02

SDSS coverage talks about RA/Dec in HH:MM:SS / +-DD:MM:SS

Parameters:
ra, dec : float

coordinates to query in degrees.

Returns:
bool

whether the input coordinates are within the SDSS footprint

pyhetdex.tools.astro.dss_image.get_image(ra, dec, pa, size, ifu_centers, yflip, outdir)[source]

Create the SDSS image around the given coordinates

Todo

filename: is hard coded. Instead of the output directory pass the full output name in the function arguments

Rename the function: probably plot_image would be more appropriate

box, size_cut_out: they should not be hard coded

html size should not be hard code

Parameters:
ra, dec : float

coordinates of the plot

pa : ?

??

size : float

??

ifu_centers : list

list of ifu coordinates?

yflip : bool

flip the image around the y axis

outdir : string

output directory

Returns:
outfile : string

full name of the saved plot

pyhetdex.tools.astro.dss_image.plotFocalPlaneQuicklook(dra, ddec, pa, scale, ifu_centers, ra, dec, CD, im_size, color='green', linewidth=0.2)[source]

Patrol circles collection

Plot the region of IFUs and patrol circle and return as a PatchCollection, which can be added to a plot using add_collection().

Todo

ifu_size is hard coded to 0.012. Move to optional argument

Rename the function: function does not plot!

Parameters:
dra, ddec : float

? coordinates

pa : float

?

scale : float

pixel scale

ifu_centers : list

list of ifu coordinates?

ra, dec : flat

reference coordinates

CD : ?

??

im_size : float

size of the image

color : matplotlib color, optional

color of the circles

linewidth : float, optional

width of the line of the circles

Returns:
:class:`~matplotlib.collection.PatchCollection` instance

collection of patrol circles

pyhetdex.tools.astro.dss_image.retrieve_image(ra, dec, size, yflip)[source]

Wrapper function for retrieving image from SDSS. If region outside SDSS converage, it uses DSS image instead.

Todo

either catch errors from urlopen() in retrieve_image_SDSS() and retrieve_image_DSS() or add the notion that it’s raised and do something about it in get_image()

Parameters:
ra, dec : float

center (?) coordinates in degrees

size : float

size in degrees of the patch to retrieve

yflip : bool

flip the image around the y axis

Returns:
imarray : nd array

retrieved image

CD : numpy matrix

??

url : string

url of the request

string

source of the image

pyhetdex.tools.astro.dss_image.retrieve_image_DSS(ra, dec, size, yflip)[source]

Retrieve a fits image from dss server and return the image array, the url, and the CD matrix (there is rotation in DSS images). CD matrix transforms the pixel position (x, y) to world coordinate (ra ,``dec``).

Parameters:
ra, dec, size, yflip : same as retrieve_image()
Returns:
same as :func:`~retrieve_image`
pyhetdex.tools.astro.dss_image.retrieve_image_SDSS(ra, dec, size, yflip, scale=0.396127)[source]

Retrieve image from SDSS-DR9 or dss server (jpeg) and returns the image array and the url. Note that the transformation from world coordinate (ra, dec) to pixel position (x, y) is simple projection without rotation:

x = -scale * (ra - ra0) * cos(dec) + x0
y =  scale * (dec - dec0) + y0

Options for the query are described here

Parameters:
ra, dec, size, yflip : same as retrieve_image()
scale : float, optional

arcsec / pixel (SDSS default); should be 1.698 to match DSS?

Returns:
same as :func:`~retrieve_image`
pyhetdex.tools.astro.dss_image.wcs2pix(ra, dec, ra0, dec0, scale=1.698, im_size=848, CD=None)[source]

Convert world coordinates scale to pixels

Parameters:
ra, dec : float

? coordinates

ra0, dec0 : float

reference coordinates

scale : float, optional

pixel scale

im_size : float, optional

size of the image

CD : numpy.matrix, optional

??

Returns:
x, y : float

pixel corresponding to input coordinates