Units

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 [github] [bitbucket]

Bases: astropy.units.quantity.Quantity

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, equivalencies=, []velocity_convention=None, refX=None, refX_unit=None, center_frequency=None, center_frequency_unit=None, **kwargs) [github] [bitbucket]

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.

Parameters:

unit : string

What unit do you want to ‘view’ the array as? None returns the x-axis unchanged (NOT a copy!)

frame : string

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: float :

The reference frequency for determining a velocity. Required for conversions between frequency/wavelength/energy and velocity.

center_frequency_unit: 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, approx=False) [github] [bitbucket]

Return the channel spacing if channels are linear

Parameters:

tolerance : float

Tolerance in the difference between pixels that determines how near to linear the xarr must be

approx : bool

Return the mean DX even if it is inaccurate

convert_to_unit(unit, **kwargs) [github] [bitbucket]

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) [github] [bitbucket]

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_unit = GHz xarr.coord_to_x(6000,’GHz’) == 5.1 # GHz

classmethod find_equivalencies(velocity_convention=None, center_frequency=None, equivalencies=[]) [github] [bitbucket]

Utility function to add equivalencies from the velocity_convention and the center_frequency

Parameters:

velocity_convention : str

‘optical’, ‘radio’ or ‘relativistic’

center_frequency : float | astropy.units.Quantity

The reference frequency for determining a velocity. Required for conversions between frequency/wavelength/energy and velocity.

equivalencies : list

astropy equivalencies list containing tuples of the form: (from_unit, to_unit, forward, backward) forward and backward are functions that convert values between those units

in_range(xval) [github] [bitbucket]

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

make_dxarr(coordinate_location='center') [github] [bitbucket]

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

Parameters:

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.

refX_units
set_unit(unit, bad_unit_response='raise') [github] [bitbucket]
umax(unit=None) [github] [bitbucket]

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

umin(unit=None) [github] [bitbucket]

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

units
classmethod validate_unit(unit, bad_unit_response='raise') [github] [bitbucket]
x_to_coord(xval, xunit, verbose=False) [github] [bitbucket]

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

x_to_pix(xval, xval_units=None) [github] [bitbucket]

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

class pyspeckit.spectrum.units.SpectroscopicAxes [github] [bitbucket]

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