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:
pdrtpy.pdrutils.check_nb()[source]
pdrtpy.pdrutils.check_units(input_unit, compare_to)[source]

Check if the input unit is equivalent to another.

Parameters:
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:
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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.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:
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, or Measurement.) – 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:

astropy.wcs.WCS

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:

str

Raises:

ValueError – if the input label has no ‘/’

pdrtpy.pdrutils.float_formatter(quantity, precision)[source]
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 an astropy.units.Unit

Returns:

LaTeX string for the radiation field symbol e.g., \(G_0\), \(\chi\)

Return type:

str

pdrtpy.pdrutils.get_table(filename, format='ipac', path=None)[source]

Return an astropy Table read from the input filename.

Parameters:
  • filename (str) – input filename, no path

  • format (str) – file format, Default: “ipac”

  • path (str) – path to filename relative to models directory. Default of None means look in “tables” directory

Return type:

astropy.table.Table

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

The axis values as arrays. Values are center of pixel.

Return type:

numpy.ndarray or astropy.units.Quantity

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:

bool

pdrtpy.pdrutils.history(value, image)[source]

Add a history record to an image header

Parameters:
pdrtpy.pdrutils.is_even(number)[source]

Check if number is even

Parameters:

number (float) – a number

Returns:

True if even, False otherwise

Return type:

bool

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 and astropy.units.Unit unit member or a header BUNIT keyword. :type image: astropy.io.fits.ImageHDU, astropy.nddata.CCDData, or Measurement. :return: True if it is an image, False otherwise.

pdrtpy.pdrutils.is_odd(number)[source]

Check if number is odd

Parameters:

number (float) – a number

Returns:

True if odd, False otherwise

Return type:

bool

pdrtpy.pdrutils.is_rad(input_unit)[source]
pdrtpy.pdrutils.is_ratio(identifier)[source]

Is the identifier a ratio (as opposed to an intensity)

Return type:

bool

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.model_dir()[source]

Project model directory, including trailing slash

Return type:

str

pdrtpy.pdrutils.now()[source]
Returns:

a string representing the current date and time in ISO format

pdrtpy.pdrutils.rescale_axis_units(x, from_unit, from_ctype, to_unit, loglabel=True)[source]
pdrtpy.pdrutils.root_dir()[source]

Project root directory, including trailing slash

Return type:

str

pdrtpy.pdrutils.root_path()[source]

Project root directory as path

Return type:

Path

pdrtpy.pdrutils.setkey(key, value, image)[source]

Set the value of an existing keyword in the image header

Parameters:
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, or Measurement.) – 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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.units.Unit unit member.

Returns:

an image with single axes removed

Return type:

astropy.nddata.CCDData, or Measurement as input

pdrtpy.pdrutils.table_dir()[source]

Project ancillary tables directory, including trailing slash

Return type:

str

pdrtpy.pdrutils.testdata_dir()[source]

Project test data directory, including trailing slash

Return type:

str

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:
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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.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, or Measurement.) – the image to convert. It must have a numpy.ndarray data member and astropy.units.Unit unit member.

Returns:

an image with converted values and units

pdrtpy.pdrutils.warn(cls, msg)[source]

Issue a warning

Parameters:
  • cls (Class) – The calling Class

  • msg (str) – The warning message