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

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

Make a new spectroscopic axis instance Default units Hz

as_unit(unit, equivalencies=[], velocity_convention=None, refX=None, refX_unit=None, center_frequency=None, center_frequency_unit=None, **kwargs)[source] [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.

cdelt(tolerance=1e-08, approx=False)[source] [github] [bitbucket]

Return the channel spacing if channels are linear

convert_to_unit(unit, make_dxarr=True, **kwargs)[source] [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)[source] [github] [bitbucket]

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

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

Utility function to add equivalencies from the velocity_convention and the center_frequency

in_range(xval)[source] [github] [bitbucket]

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

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

Create a “delta-x” array corresponding to the X array. It will have the same length as the input array, which is achieved by concatenating an extra pixel somewhere.

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

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

umin(unit=None)[source] [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')[source] [github] [bitbucket]
x_to_coord(xval, xunit, verbose=False)[source] [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_unit=None, xval_units=None, equivalencies=None)[source] [github] [bitbucket]

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

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

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