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(xarr, unit=None, refX=None, redshift=None, refX_unit=None, velocity_convention=None, use128bits=False, bad_unit_response='raise', equivalencies=[(Unit("m"), Unit("Hz"), <function spectral.<locals>.<lambda>>), (Unit("m"), Unit("J"), <function spectral.<locals>.<lambda>>), (Unit("Hz"), Unit("J"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>), (Unit("m"), Unit("1 / m"), <function spectral.<locals>.<lambda>>), (Unit("Hz"), Unit("1 / m"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>), (Unit("J"), Unit("1 / m"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>), (Unit("1 / m"), Unit("rad / m"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>), (Unit("m"), Unit("rad / m"), <function spectral.<locals>.<lambda>>), (Unit("Hz"), Unit("rad / m"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>), (Unit("J"), Unit("rad / m"), <function spectral.<locals>.<lambda>>, <function spectral.<locals>.<lambda>>)], center_frequency=None, center_frequency_unit=None)[source] [github] [bitbucket]¶
Bases:
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
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
- property 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.
- property refX¶
- property refX_unit¶
- property 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
- property 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(axislist, frame='rest', xtype=None, refX=None, redshift=None)[source] [github] [bitbucket]¶
Bases:
SpectroscopicAxis
Counterpart to Spectra: takes a list of SpectroscopicAxis’s and concatenates them while checking for consistency and maintaining header parameter
Make a new spectroscopic axis instance Default units Hz