Utilities: Various constants and methods used by the Toolbox¶
- pdrtpy.pdrutils.addkey(key, value, image)[source]¶
Add a (FITS) keyword,value pair to the image header
- Parameters:
key (str) – The keyword to add to the header
value (any native type) – the value for the keyword
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the key,val to.
- pdrtpy.pdrutils.check_units(input_unit, compare_to)[source]¶
Check if the input unit is equivalent to another.
- Parameters:
input_unit (
astropy.units.Unit
,astropy.units.Quantity
or str) – the unit to check.compare_unit (
astropy.units.Unit
,astropy.units.Quantity
or str) – the unit to check against
- Returns:
True if the input unit is equivalent to compare unit, False otherwise
- pdrtpy.pdrutils.comment(value, image)[source]¶
Add a comment to an image header
- Parameters:
value (str) – the value for the comment
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the comment to
- pdrtpy.pdrutils.convert_if_necessary(image)[source]¶
Helper method to convert integrated intensity units in an image or Measurement from \({\rm K~km~s}^{-1}\) to \({\rm erg~s^{-1}~cm^{-2}~sr^{-1}}\). If a conversion is necessary, the
convert_integrated_intensity()
is called. If not, the image is returned unchanged.- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member or a header BUNIT keyword. It’s units must be \({\rm K~km~s}^{-1}\). It must also have a header RESTFREQ keyword.- Returns:
an image with converted values and units
- pdrtpy.pdrutils.convert_integrated_intensity(image, wavelength=None)[source]¶
Convert integrated intensity from \({\rm K~km~s}^{-1}\) to \({\rm erg~s^{-1}~cm^{-2}~sr^{-1}}\), assuming \(B_\lambda d\lambda = 2kT/\lambda^3 dV\) where \(T dV\) is the integrated intensity in K km/s and \(\lambda\) is the wavelength. The derivation:
\[B_\lambda = 2 h c^2/\lambda^5 {1\over{exp[hc/\lambda k T] - 1}}\]The integrated line is \(B_\lambda d\lambda\) and for \(hc/\lambda k T << 1\):
\[B_\lambda d\lambda = 2c^2/\lambda^5 \times (\lambda kT/hc)~d\lambda\]The relationship between velocity and wavelength, \(dV = \lambda/c~d\lambda\), giving
\[B_\lambda d\lambda = 2\times10^5~kT/\lambda^3~dV,\]with \(\lambda\) in cm, the factor \(10^5\) is to convert \(dV\) in \({\rm km~s}^{-1}\) to \({\rm cm~s}^{-1}\).
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member or header BUNIT keyword. It’s units must be K km/swavelength (
astropy.units.Quantity
) – the wavelength of the observation. The default is to determine wavelength from the image header RESTFREQ keyword
- Returns:
an image with converted values and units
- pdrtpy.pdrutils.dataminmax(image)[source]¶
Set the data maximum and minimum in image header
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the key,val to.
- pdrtpy.pdrutils.draine_unit = Unit("Draine")¶
The Draine radiation field unit
\({\rm 1~Draine = 2.72\times10^{-3}~erg~s^{-1}~cm^{-2}}\)
- pdrtpy.pdrutils.dropaxis(w)[source]¶
Drop the first single dimension axis from a World Coordiante System. Returns the modified WCS if it had a single dimension axis or the original WCS if not.
- Parameters:
w (
astropy.wcs.WCS
) – a WCS- Return type:
- pdrtpy.pdrutils.firstkey(d)[source]¶
Return the “first” key in a dictionary
- Parameters:
d (dict) – the dictionary
- pdrtpy.pdrutils.fliplabel(label)[source]¶
Given a label that has a numerator and a denominator separated by a ‘/’, return the reciprocal label. For example, if the input label is ‘(x+y)/z’ return ‘z/(x+y)’. This method simply looks for the ‘/’ and swaps the substrings before and after it.
- Parameters:
label (str) – the label to flip
- Returns:
the reciprocal label
- Return type:
- Raises:
ValueError – if the input label has no ‘/’
- pdrtpy.pdrutils.get_rad(key)[source]¶
Get radiation field symbol (LaTeX) given radiation field unit. If key is unrecognized, ‘FUV Radiation Field’ is returned.
- Parameters:
key (str or
astropy.units.Unit
) – input field unit name, e.g. ‘Habing’, ‘Draine’ or anastropy.units.Unit
- Returns:
LaTeX string for the radiation field symbol e.g., \(G_0\), \(\chi\)
- Return type:
- pdrtpy.pdrutils.get_table(filename, format='ipac', path=None)[source]¶
Return an astropy Table read from the input filename.
- Parameters:
- Return type:
- pdrtpy.pdrutils.get_testdata(filename)[source]¶
Get fully qualified pathname to FITS test data file.
- Parameters:
filename (str) – input filename, no path
- pdrtpy.pdrutils.get_xy_from_wcs(data, quantity=False, linear=False)[source]¶
Get the x,y axis vectors from the WCS of the input image.
- Parameters:
data (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the input imagequantity (bool) – If True, return the arrays as
astropy.units.Quantity
. If False, the returned arrays arenumpy.ndarray
.linear (bool) – If True, returned arrays are in linear space, if False they are in log space.
- Returns:
The axis values as arrays. Values are center of pixel.
- Return type:
- pdrtpy.pdrutils.habing_unit = Unit("Habing")¶
The Habing radiation field unit
\({\rm 1~Habing = 1.6\times 10^{-3}~erg~s^{-1}~cm^{-2}}\)
- pdrtpy.pdrutils.has_single_axis(w)[source]¶
Check if the input WCS has any single dimension axes
- Parameters:
w (
astropy.wcs.WCS
) – a WCS- Returns:
True if the input WCS has any single dimension axes, False otherwise
- Return type:
- pdrtpy.pdrutils.history(value, image)[source]¶
Add a history record to an image header
- Parameters:
value (str) – the value for the history record
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the HISTORY to
- pdrtpy.pdrutils.is_image(image)[source]¶
Check if a Measurement is an image. The be an image it must have a header with axes keywords and a WCS to be considered an image. This is to distiguish Measurements that have a data array with more than one member from a true image. :param image: the image to check. It must have a
numpy.ndarray
data member andastropy.units.Unit
unit member or a header BUNIT keyword. :type image:astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
. :return: True if it is an image, False otherwise.
- pdrtpy.pdrutils.is_ratio(identifier)[source]¶
Is the identifier a ratio (as opposed to an intensity)
- Return type:
- pdrtpy.pdrutils.mask_union(arrays)[source]¶
Return the union mask (logical OR) of the input masked arrays. This is useful when doing arithmetic on images that don’t have identical masks and you want the most restrictive mask.
- Parameters:
arrays (
numpy.ma.masked_array
) – masked arrays to unionize- Return type:
mask
- pdrtpy.pdrutils.mathis_unit = Unit("Mathis")¶
The Mathis radiation field unit
\({\rm 1~Mathis = 1.81\times10^{-3}~erg~s^{-1}~cm^{-2}}\)
- pdrtpy.pdrutils.now()[source]¶
- Returns:
a string representing the current date and time in ISO format
- pdrtpy.pdrutils.setkey(key, value, image)[source]¶
Set the value of an existing keyword in the image header
- Parameters:
key (str) – The keyword to set in the header
value (any native type) – the value for the keyword
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the key,val to.
- pdrtpy.pdrutils.signature(image)[source]¶
Add AUTHOR and DATE keywords to the image header Author is ‘PDR Toolbox’, date as returned by now()
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – The image which to add the key,val to.
- pdrtpy.pdrutils.squeeze(image)[source]¶
Remove single-dimensional entries from image data and WCS.
- Parameters:
image (
astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.- Returns:
an image with single axes removed
- Return type:
astropy.nddata.CCDData
, orMeasurement
as input
- pdrtpy.pdrutils.table_dir()[source]¶
Project ancillary tables directory, including trailing slash
- Return type:
- pdrtpy.pdrutils.testdata_dir()[source]¶
Project test data directory, including trailing slash
- Return type:
- pdrtpy.pdrutils.to(unit, image)[source]¶
Convert the image values to another unit. While generally this is intended for converting radiation field strength maps between Habing, Draine, cgs, etc, it will work for any image that has a unit member variable. So, e.g., it would work to convert density from \({\rm cm ^{-3}}\) to \({\rm m^{-3}}\). If the input image is a
Measurement
, its uncertainty will also be converted.- Parameters:
unit (string or astropy.units.Unit) – identifying the unit to convert to
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.
- Returns:
an image with converted values and units
- pdrtpy.pdrutils.toDraine(image)[source]¶
Convert a radiation field strength image to Draine units (chi).
\({\rm 1~Draine = 2.72\times10^{-3}~erg~s^{-1}~cm^{-2}}\)
between 6eV and 13.6eV (912-2066 \(\unicode{xC5}\)). See Weingartner and Draine 2001, ApJS, 134, 263, section 4.1
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.- Returns:
an image with converted values and units
- pdrtpy.pdrutils.toHabing(image)[source]¶
Convert a radiation field strength image to Habing units \((G_0)\).
\({\rm G_0 \equiv 1~Habing = 1.6\times10^{-3}~erg~s^{-1}~cm^{-2}}\)
between 6eV and 13.6eV (912-2066 \(\unicode{xC5}\)). See Weingartner and Draine 2001, ApJS, 134, 263, section 4.1
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.- Returns:
an image with converted values and units
- pdrtpy.pdrutils.toMathis(image)[source]¶
Convert a radiation field strength image to Mathis units
\({\rm 1~Mathis = 1.81\times10^{-3}~erg~s^{-1}~cm^{-2}}\)
between 6eV and 13.6eV (912-2066 \(\unicode{xC5}\)). See Weingartner and Draine 2001, ApJS, 134, 263, section 4.1
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.- Returns:
an image with converted values and units
- pdrtpy.pdrutils.tocgs(image)[source]¶
Convert a radiation field strength image to \({\rm erg~s^{-1}~cm^{-2}}\).
- Parameters:
image (
astropy.io.fits.ImageHDU
,astropy.nddata.CCDData
, orMeasurement
.) – the image to convert. It must have anumpy.ndarray
data member andastropy.units.Unit
unit member.- Returns:
an image with converted values and units