Debian Codegraph @

docs/rgb.rst

raw
1 Making RGB images
2 -----------------
3
4 APLpy includes helper functions to generate RGB images from scratch, even
5 for files with initially different projections/resolutions.
6
7 Reprojecting three images to the same projection
8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9
10 If you are starting from three images with different projections/resolutions,
11 the first step is to reproject these to a common projection/resolution. The
12 following code shows how this can be done using the
13 :func:`~aplpy.make_rgb_cube` function::
14
15 aplpy.make_rgb_cube(['2mass_k.fits', '2mass_h.fits',
16 '2mass_j.fits'], '2mass_cube.fits')
17
18 This method makes use of the `reproject
19 <https://reproject.readthedocs.io/en/stable/>`_ package to reproject the images
20 to a common projection. The above example produces a FITS cube named
21 ``2mass_cube.fits`` which contains the three channels in the same projection.
22 This can be used to then produce an RGB image (see next section)
23
24 Producing an RGB image from images in a common projection
25 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26
27 The :func:`~aplpy.make_rgb_image` function can be used to produce an RGB
28 image from either three FITS files in the exact same projection, or a FITS cube
29 containing the three channels (such as that output by
30 :func:`~aplpy.make_rgb_cube`). The following example illustrates how to do
31 this::
32
33 aplpy.make_rgb_image('2mass_cube.fits','2mass_rgb.png')
34
35 In the above example, APLpy will automatically adjust the stretch of the
36 different channels to try and produce a reasonable image, but it is of course
37 possible to specify one or more of the lower/upper limits of the scale to use
38 for each channel. For each lower/upper scale limit, this can be done in two
39 ways. The first is to use the vmin_r/g/b or vmax_r/g/b argument which specifies
40 the pixel value to use for the lower or upper end of the scale respectively. The
41 alternative is to use the pmin_r/g/b or pmax_r/g/b arguments, which specify the
42 percentile value to use instead of an absolute value. The two can of course be
43 mixed, such as in the following example::
44
45 aplpy.make_rgb_image('2mass_cube.fits', '2mass_rgb.png',
46 vmin_r=0., pmax_g=90.)
47
48 Plotting the resulting RGB image
49 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50
51 If `PyAVM <http://astrofrog.github.io/pyavm/>`_ is installed (which is
52 recommended but not required), then if you produce a JPEG or PNG image, you can
53 plot it directly using the :class:`~aplpy.FITSFigure` class with::
54
55 f = aplpy.FITSFigure('2mass_rgb.png')
56 f.show_rgb()
57
58 For more information, see :ref:`howto-avm`.
59
60 On the other hand, if you are not able to use PyAVM, or need to use a format
61 other than JPEG or PNG, then you need to instantiate the
62 :class:`~aplpy.FITSFigure` class with a FITS file with exactly the same
63 dimensions and WCS as the RGB image. The :func:`~aplpy.make_rgb_cube`
64 function will in fact produce a file with the same name as the main output, but
65 including a ``_2d`` suffix, and this can be used to instantiate
66 :class:`~aplpy.FITSFigure`::
67
68 # Reproject the images to a common projection - this will also
69 # produce 2mass_cube_2d.fits
70 aplpy.make_rgb_cube(['2mass_k.fits', '2mass_h.fits',
71 '2mass_j.fits'], '2mass_cube.fits')
72
73 # Make an RGB image
74 aplpy.make_rgb_image('2mass_cube.fits', '2mass_rgb.png')
75
76 # Plot the RGB image using the 2d image to indicate the projection
77 f = aplpy.FITSFigure('2mass_cube_2d.fits')
78 f.show_rgb('2mass_rgb.png')