pyspeckit 0.1 documentation

Units

Units and SpectroscopicAxes

Unit parsing and conversion tool. The SpectroscopicAxis class is meant to deal with unit conversion internally

Open Questions: Are there other FITS-valid projection types, unit types, etc.
that should be included? What about for other fields (e.g., wavenumber?)
class pyspeckit.spectrum.units.SpectroscopicAxis

Bases: numpy.ndarray

A Spectroscopic Axis object to store the current units of the spectrum and allow conversion to other units and frames. Typically, units are velocity, wavelength, frequency, or redshift. Wavenumber is also hypothetically possible.

WARNING: If you index a SpectroscopicAxis, the resulting array will be a SpectroscopicAxis without a dxarr attribute! This can result in major problems; a workaround is being sought but subclassing numpy arrays is harder than I thought

as_unit(unit, frame=None, quiet=True, center_frequency=None, center_frequency_units=None, **kwargs)

Convert the spectrum to the specified units. This is a wrapper function to convert between frequency/velocity/wavelength and simply change the units of the X axis. Frame conversion is... not necessarily implemented.

unit [ string ]
What unit do you want to ‘view’ the array as?
frame [ None ]
NOT IMPLEMENTED. When it is, it will allow you to convert between LSR, topocentric, heliocentric, rest, redshifted, and whatever other frames we can come up with. Right now the main holdup is finding a nice python interface to an LSR velocity calculator... and motivation.

center_frequency [ None | float ] center_frequency_units [ None | string ]

If converting between velocity and any other spectroscopic type, need to specify the central frequency around which that velocity is calculated. I think this can also accept wavelengths....
cdelt(tolerance=1e-08)

Return the channel spacing if channels are linear

change_frame(frame)

Change velocity frame

convert_to_unit(unit, **kwargs)

Return the X-array in the specified units without changing it Uses as_unit for the conversion, but changes internal values rather than returning them.

coord_to_x(xval, xunit)

Given an X-value assumed to be in the coordinate axes, return that value converted to xunit e.g.: xarr.units = ‘km/s’ xarr.refX = 5.0 xarr.refX_units = GHz xarr.coord_to_x(6000,’GHz’) == 5.1 # GHz

in_frame(frame)

Return a shifted xaxis

in_range(xval)

Given an X coordinate in SpectroscopicAxis’ units, return whether the pixel is in range

make_dxarr(coordinate_location='center')

Create a “delta-x” array corresponding to the X array.

coordinate_location [ ‘left’, ‘center’, ‘right’ ]
Does the coordinate mark the left, center, or right edge of the pixel? If ‘center’ or ‘left’, the last pixel will have the same dx as the second to last pixel. If right, the first pixel will have the same dx as the second pixel.
umax(units=None)

Return the maximum value of the SpectroscopicAxis. If units specified, convert to those units first

umin(units=None)

Return the minimum value of the SpectroscopicAxis. If units specified, convert to those units first

x_in_frame(xx, frame)

Return the value ‘x’ shifted to the target frame

x_to_coord(xval, xunit, verbose=False)

Given a wavelength/frequency/velocity, return the value in the SpectroscopicAxis’s units e.g.: xarr.units = ‘km/s’ xarr.refX = 5.0 xarr.refX_units = GHz xarr.x_to_coord(5.1,’GHz’) == 6000 # km/s

x_to_pix(xval)

Given an X coordinate in SpectroscopicAxis’ units, return the corresponding pixel number

class pyspeckit.spectrum.units.SpectroscopicAxes

Bases: pyspeckit.spectrum.units.SpectroscopicAxis

Counterpart to Spectra: takes a list of SpectroscopicAxis’s and concatenates them while checking for consistency and maintaining header parameters