Profiles and spectra#

A profile is the values along a path: a cut across a galaxy, a slice through a star’s wings, or the spectrum along a trace in a two-dimensional spectrum. Draw a line or a box, and its profile is plotted in a pane under the image. A line can be widened into a band, so each point is collapsed across it, and the sky beside the band can be measured and taken off. This page extracts a spectrum, takes a cross section of a galaxy, and plots the color channels of an RGB image side by side.

The examples use spectrum, a long-slit spectrum made up for these pages: one object’s trace, slanted a little across the detector, with emission and absorption lines, over a sky whose own emission lines fill the slit. The rest use the sample star field with its galaxy, image, and the same field in three filters, red, green and blue.

Drawing a profile#

Draw a line (l, or the line tool in the toolbar) and its profile opens under the image at once, plotted against the distance along the line. A box’s profile opens from the Regions panel’s Profile, Plot profile in the box’s right-click menu, or Shift+P with the box selected. While the pane is open it follows whichever line or box you select.

Hover the plot and the point is marked on the image; hover the image to read values as usual. The pane’s buttons copy the profile as TSV or save it as CSV, with every statistic and the position of each point, ready for a spreadsheet or pandas.read_csv.

A spectrum along a slanted trace#

A trace that isn’t quite level is the usual case, and a profile of single pixels along it would be noisy and would wander off the trace’s peak. Widen the line into a band as wide as the trace and each point becomes the mean, median or sum across the band, measured square to the line, so a slanted trace is extracted as it is, without straightening the image first.

In the viewer, select the line and drag the round handle beside it, or type a width in its properties. From Python, give the line as a DS9 projection, which is a line with a width. With profile=True, add_regions opens its profile in the pane:

import pixel_clarity as pc

spec = pc.show(spectrum, scale="asinh", limits="99.5", cmap="inferno", height=560)
spec.add_regions("image; projection(31, 97.05, 2371, 178.95, 9) # text={trace}", profile=True)

The band is drawn dashed on the image. Mean, Median and Sum in the pane choose what each point is: Sum is the flux extracted across the band, Median shrugs off a cosmic ray or a hot pixel in it.

Taking off the sky#

The sky’s emission lines run straight across the slit, so they are in the band too, and show in the spectrum as lines the object doesn’t have. Tick background in the pane: at each point the sky is measured in two strips beside the band, one on each side and a gap away (drawn dotted on the image), as the median of their pixels, and taken off. The median keeps a star or another trace in a strip from raising it. Set the gap and the strips’ width in the pane; each line or box keeps its own.

With the background off, this spectrum is a forest of sky lines; with it on, they go, and the object’s own lines are left: a strong emission line with a weaker one beside it, and absorption lines on either side. The tooltip gives the background at each point, and the CSV has it next to the subtracted values.

A cross section with a box#

A box’s profile collapses the box across its short side: each point is one column of the box (or one row, for a tall box), plotted against the pixel’s coordinate, so a box across a galaxy gives its light profile, averaged over the box’s height. along x and along y in the pane choose the direction. A turned box’s profile runs along its own sides, a point per pixel step, as a widened line’s does.

v = pc.show(image, scale="asinh", limits="99.5", cmap="magma")
v.add_regions("image; box(981, 641, 600, 30, 0) # color=cyan text={cross section}", profile=True)

The pane’s y-axis fits the 1st to 99th percentile of the points, so one bright pixel doesn’t flatten everything else; the link beside the axis shows every point instead.

One curve per color#

On an RGB image, the profile has a curve for each channel, each in its color, read from each channel’s own image (aligned on the sky, so the path is the same place in all three). Here a line runs along the galaxy’s long axis:

v = pc.rgb(red, green, blue, scale="asinh", limits="99.5")
v.add_regions("image; line(717.7, 497.2, 1244.3, 784.8) # text={major axis}", profile=True)

Tick relative to divide each curve by its median (by its peak, with the background on), so the shapes can be compared whatever the brightness in each filter. Here the red curve’s core then stands highest above the disk: the galaxy’s core is redder than its disk.

A color mosaic does the same with one curve per filter, each read across the detectors the path crosses, with their levels matched. A plain mosaic reads each point from the detector on top there.

Statistics, region files and Python#

A widened line is a band everywhere, not only in its profile: its statistics card measures the band, and it is saved in .reg files as DS9’s projection, which loads back as a band. From Python, regions_ds9 writes it the same way. Here is the spectrum’s band, read back from its viewer:

print(spec.regions_ds9)
# Region file format: DS9 version 4.1
global color=green width=1 font="helvetica 10 normal roman"
image
projection(31,97.05,2371,178.95,9) # color=green text={trace}

The regions package doesn’t read projections, so regions gives it as a plain line. See Coordinates and regions for the rest of what add_regions, regions and regions_ds9 do.