APLpy

Download and uncompress data


In [1]:
try:
    # import block for Python 3
    from urllib.request import urlopen

except ImportError:
    # if that fails, fall back to Python 2 import block
    from urllib2 import urlopen

import gzip

fits_filenames = ["2MASS_h.fits",
                  "2MASS_j.fits",
                  "2MASS_k.fits"]

template_URL = "https://github.com/aplpy/aplpy-examples/blob/master/data/{0}.gz?raw=true"

for fits_filename in fits_filenames:
    url = template_URL.format(fits_filename)
    url_request = urlopen(url)
    data = url_request.read()
    data_uncompressed = gzip.decompress(data)
    with open(fits_filename, "wb") as f:
        f.write(data_uncompressed)

In [2]:
%matplotlib inline
import aplpy

aplpy.make_rgb_cube(['2MASS_k.fits', 
                     '2MASS_h.fits',
                     '2MASS_j.fits'], '2MASS_cube.fits')

aplpy.make_rgb_image('2MASS_cube.fits', '2MASS_rgb.png', 
                    stretch_r = "log", stretch_g = "log", stretch_b= "log", #change the stretch
                    )


/Users/egentry/anaconda/lib/python3.4/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
INFO:astropy:Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmpm_7xnbhe
INFO: Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmpm_7xnbhe [montage_wrapper.wrappers]
INFO
INFO:astropy:Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmp6y5ibx_g
: Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmp6y5ibx_g [montage_wrapper.wrappers]
INFO
INFO:astropy:Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmp_yrmeu1f
: Deleting work directory /var/folders/07/gl4v7b112z9f8mfg988tlxy40000gn/T/tmp_yrmeu1f [montage_wrapper.wrappers]
INFO
INFO:astropy:Red:
: Red: [aplpy.rgb]
INFO
INFO:astropy:vmin =  4.747e+02 (auto)
INFO:astropy:vmax =  1.669e+03 (auto)
INFO:astropy:Green:
: vmin =  4.747e+02 (auto) [aplpy.rgb]
INFO: vmax =  1.669e+03 (auto) [aplpy.rgb]
INFO: Green: [aplpy.rgb]
INFO
INFO:astropy:vmin =  4.811e+02 (auto)
INFO:astropy:vmax =  1.099e+03 (auto)
INFO:astropy:Blue:
: vmin =  4.811e+02 (auto) [aplpy.rgb]
INFO: vmax =  1.099e+03 (auto) [aplpy.rgb]
INFO: Blue: [aplpy.rgb]
INFO
INFO:astropy:vmin =  1.497e+02 (auto)
INFO:astropy:vmax =  4.592e+02 (auto)
: vmin =  1.497e+02 (auto) [aplpy.rgb]
INFO: vmax =  4.592e+02 (auto) [aplpy.rgb]
/Users/egentry/anaconda/lib/python3.4/site-packages/aplpy/rgb.py:218: UserWarning: PyAVM 0.9.1 or later is not installed, so AVM tags will not be embedded in RGB image
  warnings.warn("PyAVM 0.9.1 or later is not installed, so AVM tags will not be embedded in RGB image")

In [3]:
f = aplpy.FITSFigure('2MASS_h.fits')
f.show_contour(smooth=5, colors="w", levels=3)

f.show_rgb('2MASS_rgb.png' )
f.set_theme("publication")