API Reference

class multicolorfits.ControlPanel[source]

This is the control panel where the various parameters for the images are specified in the GUI. (The left-side panel)

class multicolorfits.Header_Editor[source]

FITS image header editor window

ok

The OK, Cancel and Load/Save Header buttons:

class multicolorfits.MPLFigureEditor(*args, **traits)[source]
class multicolorfits.MPLInitHandler[source]
init(info)[source]

This method gets called after the controls have all been created but before they are displayed.

multicolorfits.adjust_gamma(array_in, gamma)[source]

Replacement function for skimage.exposure.adjust_gamma, so that NaNs don’t throw errors

Parameters:
  • array_in (array) – Input image array

  • gamma (float) – Gamma correction value

Returns:

Gamma-adjusted image values

Return type:

array

multicolorfits.beampars_asec_fromhdr(hdrin)[source]

Returns beam parameters [BMAJ (arcsec), BMIN (arcsec), BPA (deg)] from input header

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

[BMAJ_asec, BMIN_asec, BPA_deg]

Return type:

list

multicolorfits.colorize_image(image, colorvals, colorintype='hsv', dtype=<class 'numpy.float64'>, gammacorr_color=1)[source]

### Add color of the given hue to an RGB greyscale image.

Parameters:
  • image (array) – Greyscale RGB image – as would be output from greyRGBize_image()

  • colorvals (str or list or tuple) – color values to apply to image. e.g., ‘#FF0000’ if colorintype=’hex’

  • colorintype (str) – ‘hsv’ for [0..1,0..1,0..1], ‘rgb’ for [0..255,0..255,0..255], or ‘hex’ for ‘#XXXXXX’

  • dtype (dtype) – Defaults to standard numpy float, but may want to lower to e.g. float32 for large images (>~1000x1000)

  • gammacorr_color (float) – To use color as-is, leave as 1 (default). To gamma-correct color at this step (e.g., to match gamma for checking a scaled image), specify a factor

Returns:

Colorized RGB image, shape=[ypixels,xpixels,3]

Return type:

array

multicolorfits.combine_multicolor(im_list_colorized, gamma=2.2, inverse=False)[source]

Combines input colorized RGB images [:,:,3] into one intensity-rescaled RGB image

Parameters:
  • im_list_colorized (list) – List of colorized RGB images. e.g., [ halpha_purple, co21_orange, sio54_teal ]

  • gamma (float) – Value used for gamma correction ^1/gamma. Default=2.2.

  • inverse (bool) – True will invert the scale so that white is the background

Returns:

Colorized RGB image (combined), shape=[ypixels,xpixels,3]

Return type:

array

multicolorfits.comparemulticolorRGB_pureRGB(rgbin, multicolorin, hdrin, ax2title, suptitle, savepath, xaxislabel='RA', yaxislabel='DEC', tickcolor='w', labelcolor='k', facecolor='w', supy=0.8, dpi=150, minorticks=True)[source]

Convenience function to compare a pure RGB image with your multicolor RGB plot, and save to file.

For tick/label colors: Any standard matplotlib color format, such as ‘k’, ‘black’, ‘#000000’, or ‘0.0’

Parameters:
  • rgbin (array) – Input pure RGB image –> e.g., np.dstack( [redframe, gframe, bframe] )

  • multicolorin (array) – Multicolor RGB image – as would be output from combine_multicolor()

  • hdrin (astropy.io.fits.header) – Header to use for WCS information

  • ax2title (str) – String to use for 2nd axis plot title. e.g. “My crazy 5-color image”, or empty quotes “” for nothing.

  • suptitle (str) – String for super title (centered at top of plot, super title applies to whole figure)

  • savepath (str) – Path to save file to. e.g., “./plots/mycrazyimage.pdf”

  • xaxislabel (str) – Label to use for x-axes. Default=’RA’

  • yaxislabel (str) – Label to use for y-axes. Default=’DEC’

  • tickcolor (str) – Color to use for ticks in plot, default = ‘w’.

  • labelcolor (str) – Color to use for ticklabels, default = ‘k’

  • facecolor (str) – Color to use for figure facecolor (border around plot), default =’w’

  • minorticks (bool) – True to use minor ticks

  • dpi (int) – Default=150. Dots per inch value to use for saved plot.

  • supy (float) – Position for suptitle (default = 0.8)

multicolorfits.convpix2sky(headerin, xin, yin, outcoordsys='same', outcoordequinox='J2000.0', forceimagesys=None, originindex=0)[source]

Helper function to convert pixel coordinates to sky coordinates. Now uses SkyCoord.

Allowed SkyCoord frame systems: [‘altaz’, ‘barycentrictrueecliptic’, ‘cirs’, ‘fk4’, ‘fk4noeterms’, ‘fk5’, ‘galactic’, ‘galactocentric’, ‘gcrs’, ‘geocentrictrueecliptic’, ‘hcrs’, ‘heliocentrictrueecliptic’, ‘icrs’, ‘itrs’, ‘precessedgeocentric’, ‘supergalactic’]

Parameters:
  • headerin (astropy.io.fits.header) – Header object

  • xin (float) – Input x-axis pixel position

  • yin (float) – Input y-axis pixel position

  • outcoordsys (str) – ‘same’ for frame in the header, or can alternatively specify a SkyCoord frame system.

  • outcoordequinox (str) – equinox, default = ‘J2000.0’

  • forceimagesys (str) – SkyCoord frame system. User can specify a frame forceimagesys to use (in case no RADESYS in the header, or if it’s known to be wrong…)

  • originindex (int) – Default = 0. Pixel origin to use for calculations (0 or 1)

Returns:

[RA_decimal, DEC_decimal]

Return type:

list

multicolorfits.convsky2pix(headerin, rain, decin, precise=False, checksys=False, incoordsys='fk5', incoordequinox='J2000.0', forceimagesys=None, originindex=0)[source]

Helper function to convert sky coordinates to pixel coordinates. Now uses SkyCoord.

Allowed SkyCoord frame systems: [‘altaz’, ‘barycentrictrueecliptic’, ‘cirs’, ‘fk4’, ‘fk4noeterms’, ‘fk5’, ‘galactic’, ‘galactocentric’, ‘gcrs’, ‘geocentrictrueecliptic’, ‘hcrs’, ‘heliocentrictrueecliptic’, ‘icrs’, ‘itrs’, ‘precessedgeocentric’, ‘supergalactic’]

Parameters:
  • headerin (astropy.io.fits.header) – Header object

  • rain (float) – Input Right Ascension, in decimal

  • decin (float) – Input Declination, in decimal

  • precise (bool) – False (default) to round to nearest integer pixel. True to return fraction of pixel.

  • checksys (bool) – When True, checks that the input coordinate frame is the same as the header frame (e.g., fk5, icrs, etc.)

  • incoordsys (str) – SkyCoord frame system, default = ‘fk5’

  • incoordequinox (str) – equinox, default = ‘J2000.0’

  • forceimagesys (str) – SkyCoord frame system. User can specify a frame forceimagesys to use (in case no RADESYS in the header, or if it’s known to be wrong…)

  • originindex (int) – Default = 0. Pixel origin to use for calculations (0 or 1)

Returns:

[X-pixel, Y-pixel]

Return type:

list

multicolorfits.cropfits2D(datain, hdrin, xbounds, ybounds, newref=None, savenew=False, overwrite=False)[source]

Function to crop a 2D fits image to the specified pixel bounds.

Parameters:
  • datain (array) – Input fits image array

  • hdrin (astropy.io.fits.header) – Input header

  • xbounds (list) – [min,max] x-axis pixel limits to use for new image slice

  • ybounds (list) – [min,max] y-axis pixel limits to use for new image slice

  • newref (None or str) – None, ‘center’, or ‘origin’. None (default) keeps the reference pixel sky coordinate the same. ‘center’ forces the reference pixel to be the new center, ‘origin’ forces it to the new origin.

  • savenew (bool or str) – False (default) does not save, otherwise specify a save path (e.g. savenew=’./mynewfits.fits’) to save the crop to disk

  • overwrite (bool) – Input option to astropy.io.fits.writeto(…, overwrite=False)

Returns:

cropdata, crophdr

Return type:

array, astropy.io.fits.header

multicolorfits.cropfits2D_coords(datain, hdrin, centerRADEC, radius_asec, newref=None, savenew=False, overwrite=False, return_cropcenterpix=False, coords_in='dec', checksys=False, incoordsys='fk5', incoordequinox='J2000.0', forceimagesys=None)[source]

Function to crop a 2D fits image based on sky coordinates and specified width.

Parameters:
  • datain (array) – Input fits image array

  • hdrin (astropy.io.fits.header) – Input header

  • centerRADEC (list) – List of RA,DEC coords. e.g. [12.345678,-10.98765]

  • radius_asec (float) – Radius (box half-width) of new image, in arcseconds

  • newref (str) – None, ‘center’, or ‘origin’. None keeps the reference pixel sky coordinate the same. ‘center’ forces the reference pixel to be the new center, ‘origin’ forces it to the new origin.

  • savenew (bool or str) – False (default) does not save, otherwise specify a save path (e.g. savenew=’./mynewfits.fits’) to save the crop to disk

  • overwrite (bool) – Input option to astropy.io.fits.writeto(…, overwrite=False)

  • return_cropcenterpix (bool) – True will return the cropped image center pixel location.

  • coords_in (str) – ‘dec’ for decimal (default) or ‘sex’ for sexagesimal.

  • checksys (bool) – Passes to convsky2pix(). When True, checks that the input coordinate frame is the same as the header frame (e.g., fk5, icrs, etc.)

  • incoordsys (str) – Passes to convsky2pix(). SkyCoord frame system, default = ‘fk5’

  • incoordequinox (str) – Passes to convsky2pix(). equinox, default = ‘J2000.0’

  • forceimagesys (str) – Passes to convsky2pix(). SkyCoord frame system. User can specify a frame forceimagesys to use (in case no RADESYS in the header, or if it’s known to be wrong…)

Returns:

cropdata, crophdr

Return type:

array, astropy.io.fits.header

multicolorfits.cropfits3D(datain, hdrin, xbounds, ybounds, zbounds=[0, None], newref=None, savenew=False, overwrite=False)[source]

Function to crop a 3D fits cube to the specified pixel bounds.

zbounds (optional) are channel number boundaries [zmin,zmax], 0-indexed

Other arguments the same as for cropfits2D

multicolorfits.cropfits3D_coords(datain, hdrin, centerRADEC, radius_asec, zbounds=[0, None], newref=None, savenew=False, overwrite=False, coords_in='dec', return_cropcenterpix=False)[source]

Function to crop a 3D fits cube based on sky coordinates and specified width.

zbounds (optional) are channel number boundaries [zmin,zmax], 0-indexed

Other arguments the same as for cropfits2D_coords()

multicolorfits.dec2sex(rain, decin, as_string=False, decimal_places=2)[source]

Converts decimal coordinates to sexagesimal.

Parameters:
  • rain (float) – Input Right Ascension in decimal – e.g., 12.34567

  • decin (float) – input Declination in decimal – e.g. -34.56789

  • as_string (bool) – Specifies whether to return output as a string (useful for making tables)

  • decimal_places (int) – Number of decimals places to use when as_string=True

Returns:

[‘HH:MM:SS.ss’, ‘DD:MM:SS.ss’]

Return type:

list

multicolorfits.drawProgressBar(percent, barlength=20, prefix='', suffix='')[source]

This draws a percentage bar of the specified length to stdout

Once you have calculated the compeltion percent in your task, call this function to update the display.

(Alternatively, could use a module like tqdm or termcolor.colored)

multicolorfits.force_hdr_floats(hdrin)[source]

Helper function to force various header values to floats. Sometimes programs save header values as strings, which messes up the WCS…

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Output header

Return type:

astropy.io.fits.header

multicolorfits.force_hdr_to_2D(hdrin)[source]

A simple function to take in a header and remove items related to 3D or 4D structure – such as NAXIS3…

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Output 2D header

Return type:

astropy.io.fits.header

multicolorfits.getasecperpix(hdrin)[source]

Calculates arcseconds per pixel side. Assumes input header CDELTs are in degrees.

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Arcseconds per pixel side

Return type:

float

multicolorfits.getcdelts(hdrin, getrot=False)[source]

Function to calculate CDELT1 and CDELT2 from the input header PCx_x cards.

Parameters:
  • hdrin (astropy.io.fits.header) – Header object

  • getrot (bool) – Specifies whether to return the rotation value crota in the output

Returns:

CDELT1, CDELT2 (, CROTA)

Return type:

float, float (, float)

multicolorfits.getcdmatrix(hdrin, crot=None)[source]

Calculate the CDn_m matrix from CDELTS and CROTA/CROTA2

Parameters:
  • hdrin (astropy.io.fits.header) – Header object

  • crot (float) – Rotation in degrees, if you know it but the header doesn’t correctly have it

Returns:

CD1_1, CD1_2, CD2_1, CD2_2

Return type:

float, float, float, float

multicolorfits.getdegperpix(hdrin)[source]

Calculates degrees per pixel side. Assumes input header CDELTs are in degrees.

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Degrees per pixel side

Return type:

float

multicolorfits.getsteradperpix(hdrin)[source]

Calculates steradians per pixel. Assumes input header CDELTs are in degrees.

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Steradians per pixel

Return type:

float

multicolorfits.greyRGBize_image(datin, rescalefn='linear', scaletype='abs', min_max=[None, None], gamma=2.2, checkscale=False)[source]

### Takes an image and returns 3-frame [R,G,B] (vals from 0…1)

Parameters:
  • datin (array) – Input 2D image data array

  • rescalefn (func) – Function to use for rescaling intensity. imscale.linear/sqrt/squared/log/power/sinh/asinh

  • scaletype (str) – ‘abs’ for absolute values, ‘perc’ for percentiles

  • min_max (list) – [min,max] vals to use in rescale. if scaletype=’perc’, list the percentiles to use, e.g. [1.,95.]

  • gamma (float) – Value for gamma correction. For combining colorized frames, use default gamma=2.2. For inverse, use gamma=(1./2.2)

  • checkscale (bool) – True to bring up plot to check the new image scale.

Returns:

Greyscale RGB image, shape=[ypixels,xpixels,3]

Return type:

array

multicolorfits.gui()[source]

Call this function to run the GUI.

multicolorfits.hex_to_hsv(hexstring)[source]

Convert a hexadecimal string to HSV tuple

Parameters:

hexstring (str) – Hexadecimal string such as ‘#3300FF’

Returns:

HSV tuple such as (0.7,1.,1.)

Return type:

tuple

multicolorfits.hex_to_rgb(hexstring)[source]

Converts a hexadecimal string to RGB tuple

Parameters:

hexstring (str) – Hexadecimal string such as ‘#FFFFFF’

Returns:

RGB tuple such as (256,256,256)

Return type:

tuple

multicolorfits.hexinv(hexstring)[source]

Convenience function to calculate the inverse color (opposite on the color wheel). e.g.: hexinv(‘#FF0000’) = ‘#00FFFF’

Parameters:

hexstring (str) – Hexadecimal string such as ‘#FF0000’

Returns:

Hexadecimal string such as ‘#00FFFF’

Return type:

str

multicolorfits.makesimpleheader(headerin, naxis=2, radesys=None, equinox=None, pywcsdirect=False)[source]

Function to make a new ‘simple header’ from the WCS information in the input header.

Parameters:
  • headerin (astropy.io.fits.header) – Header object

  • naxis (int) – Specifies how many axes the final header should have. Default=2

  • radesys (str) – RA/DEC system to use (valid SkyCoord frame system, e.g. ‘icrs’)

  • equinox (str) – Equinox to use for the output header

  • pywcsdirect (bool) – True to create the header directly with astropy.wcs.WCS

Returns:

Output header

Return type:

astropy.io.fits.header

multicolorfits.mcf_gui()[source]

Call this function to run the GUI. (Keeping as legacy)

class multicolorfits.multicolorfits_viewer[source]

The main window. (Right-side panel.) Has instructions for creating and destroying the app.

multicolorfits.nanpercofscore(array_in, score, **kwargs)[source]

Usage is identical to scipy.stats.stats.percentileofscore(array_in,score), this just corrects for NaNs

Parameters:
  • array_in (array) – input dataset

  • score (float) – score for calculation

  • **kwargs – keyword arguments to pass to scipy.stats.percentileofscore()

Returns:

percentile of the score

Return type:

float, or array the length of score

multicolorfits.pixperbeam_from_hdr(hdrin)[source]

Calculates the number of pixels per beam from the beam parameters (BMAJ,BMIN) in the header. Beam area = 2*PI*sigma_maj*sigma_min = 2*PI*FWHM_maj*FWHM_min/(sqrt(8*ln(2)))**2 = PI*FWHM1*FWHM2/(4*ln(2)) That’s in whatever units the FWHM are in, which is degrees in the case of hdrin[‘BMAJ’], so use CDELTS to get area in pixels Requires valid BMAJ,BMIN header cards, where BMAJ,BMIN are in degrees Note that the scaling factor is 1.13, not 2*pi, because BMAJ/BMIN are FWHM, not sigma

Parameters:

hdrin (astropy.io.fits.header) – Header object

Returns:

Pixels per beam

Return type:

float

multicolorfits.plotsinglemulticolorRGB(multicolorin, hdrin, axtitle, savepath, xaxislabel='RA', yaxislabel='DEC', tickcolor='w', labelcolor='k', facecolor='w', minorticks=True, dpi=150)[source]

Convenience function to plot and save a single multicolor RGB image.

For tick/label colors: Any standard matplotlib color format, such as ‘k’, ‘black’, ‘#000000’, or ‘0.0’

Parameters:
  • multicolorin (array) – Multicolor RGB image – as would be output from combine_multicolor()

  • hdrin (astropy.io.fits.header) – Header to use for WCS information

  • axtitle (str) – String to use for plot title. e.g. “My crazy 5-color image”, or empty quotes “” for nothing.

  • savepath (str) – Path to save file to. e.g., “./plots/mycrazyimage.pdf”

  • xaxislabel (str) – Label to use for x-axis. Default=’RA’

  • yaxislabel (str) – Label to use for y-axis. Default=’DEC’

  • tickcolor (str) – Color to use for ticks in plot, default = ‘w’.

  • labelcolor (str) – Color to use for ticklabels, default = ‘k’

  • facecolor (str) – Color to use for figure facecolor (border around plot), default =’w’

  • minorticks (bool) – True to use minor ticks

  • dpi (int) – Default=150. Dots per inch value to use for saved plot.

multicolorfits.reproject2D(mapin, hdrfrom, hdrto, scale=False, method='interp', interpdict={'cval': nan, 'mode': 'constant', 'order': 1}, returnfootprint=False, parallel=True)[source]

Function that reprojects a 2D map from the parameters in one header to the parameters in another header.

Parameters:
  • mapin (array) – Input map / data array (np.ndarray). Usually would get this from astropy.io.fits.getdata(…)

  • hdrfrom (astropy.io.fits.header) – Header for the original image, specifying the original pixel size, etc.

  • hdrto (astropy.io.fits.header) – Header to reproject to (usually just a second image’s header)

  • scale (bool) – True if units are Flux [W/m^2, Jy, or similar]. False for brightness [W/m^2/sr, Jy/sr, or similar] –> Note that when convolving maps in beam units [e.g., Jy/beam], the reprojection will need scale=True because the beam sizes change.

  • method (str) – One of ‘kapteyn’ (kapteyn package, interpolation), ‘interp’ (reproject.py), or ‘spi’ (reproject package, spherical polygon intersection). Drizzle not yet implemented

  • interpdict (dict) – For method=’kapteyn’. Sets the interpol_dict (interpolation). interpdict={order:<>,mode:<>,cval:<>} –> order = spline order, 0 to 5; mode=’constant’,’nearest’,’reflect’,’wrap’; cval = value outside bounds (NaN)

  • returnfootprint (bool) – True to also return the footprint of which reprojected pixels fell on original image grid

  • parallel (bool) – True to use parallel processing (method=’spi’ only)

Returns:

Reprojected map (, optional footprint)

Return type:

array (, array)

multicolorfits.reproject3D(mapin, hdrfrom, hdrto, scale=False, method='kapteyn', parallel=True, returnfootprint=False, print_progress=False)[source]

Function that reprojects a 3D cube from the parameters in one header to the parameters in another header.

Calls reproject2D for each slice in the cube.

See reproject2D for argument desscriptions.

multicolorfits.rgb_to_hex(rgb)[source]

Converts RGB tuple to a hexadecimal string

Parameters:

rgb (tuple) – RGB tuple such as (256,256,256)

Returns:

Hexadecimal string such as ‘#FFFFFF’

Return type:

str

multicolorfits.saveRGBfits(savepath, multicolorRGBdat, commonhdr, overwrite=True)[source]

Convenience function to save out the multicolorRGB image to a fits file.

Parameters:
  • savepath (str) – Path to save file to. e.g., “./fits/mycrazy5colr.fits”

  • multicolorRGBdat (array) – Multicolor RGB image – as would be output from combine_multicolor()

  • commonhdr (astropy.io.fits.header) – The common header with the WCS information for the output images

  • overwrite (bool) – Passed to astropy.io.fits.writeto()

multicolorfits.sex2dec(rain, decin)[source]

Converts sexagesimal coordinates to decimal. HMS and DMS separated by colons (:)

Parameters:
  • rain (str) – input Right Ascension as a sexagesimal string – e.g., ‘03:45:6789’

  • decin (str) – input Declination as a sexagesimal string – e.g., ‘-12:34:5678998765’

Returns:

[12.345678, -10.987654]

Return type:

list

multicolorfits.smooth_image(datain, sigma=3)[source]

Simple wrapper to call skimage.filters.gaussian(), to perform simple image smoothing. This can be useful for e.g., matching another image resolution, smoothing over noise to boost apparent dynamic range, etc.

Parameters:
  • datain (array) – Input fits image array. Can either be a 2D image or a 3D (multichannel) set of images.

  • sigma (int or float) – The sigma value (in pixels) for Gaussian smoothing

Returns:

smoothed_image

Return type:

array