python - make subplots from an astronomical fits image -


i have set of rgb images , made rgb fits image aplpy , overlaid contours on image cut image , make small fits images see peaks of contour.

import aplpy import atpy pyavm import avm import asciitable import matplotlib import matplotlib.pyplot plt matplotlib.colors import lognorm,boundarynorm import montage_wrapper astropy.io import fits import pyfits astropy import wcs fitsfile = 'rgb.fits' fitsfile_2d = 'rgb_2d.fits' pngfile = 'rgb_arcsinh_contour.png'  figfile = 'rgb.png' w = wcs.wcs(naxis=2)  # set "airy's zenithal" projection # vector properties may set python lists, or numpy arrays w.wcs.crpix = [5.70000000e+03, 3.05000000e+03] w.wcs.cdelt = np.array([-6.611111263e-05, 6.611111263e-05]) w.wcs.crval = [23.166667, -7.666667] w.wcs.ctype = ["ra---tan", "dec--tan"] w.wcs.cunit =["deg","deg"]  # print out of contents of wcs object w.wcs.print_contents()  # pixel coordinates of interest. pixcrd = np.array([[0,0],[24,38],[45,98]], np.float_)  # convert pixel coordinates world coordinates world = w.wcs_pix2world(pixcrd, 1) print world  # convert same coordinates pixel coordinates. pixcrd2 = w.wcs_world2pix(world, 1) print pixcrd2  # these should same original pixel coordinates, modulo # floating-point error. assert np.max(np.abs(pixcrd - pixcrd2)) < 1e-6  # now, write out wcs object fits header header = w.to_header() hdu = pyfits.open(fitsfile) # header astropy.io.fits.header object.  can use create new # primaryhdu , write file. hdu = fits.primaryhdu(header=header)   # make rgb image aplpy.make_rgb_image(fitsfile, pngfile,                      vmin_r=-0.005, vmax_r=0.2,                      vmin_g=-0.02, vmax_g=0.1,                      vmin_b=-0.02,vmax_b=0.04,                      embed_avm_tags=false)  # make figure img = aplpy.fitsfigure(fitsfile_2d) img.show_rgb(pngfile) img.set_nan_color('white') standard_setup(img)   

how produce subplots given coordinates of image given size ?

according aplpy documentation, can make subplots:

by default, fitsfigure creates figure single subplot occupies entire figure. however, aplpy can used place subplot in existing matplotlib figure instance. this, fitsfigure should called figure= argument follows:

import aplpy import matplotlib.pyplot mpl  fig = mpl.figure() f = aplpy.fitsfigure('some_image.fits', figure=fig) 

and recenter figures:

the figure can interactively explored zooming , panning. recenter on specific region programmatically, use following method, specifying either radius:

fig.recenter(33.23, 55.33, radius=0.3) # degrees

or separate width , height:

fig.recenter(33.23, 55.33, width=0.3, height=0.2) # degrees

i have tested because use aplpy , works nice me.

hth,

germán.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -