myimage_analysis module

Module for image analysis in astro applications.

myimage_analysis.bin_image(ndarray, binsize=(1, 1), header=None, origin='lower left', statistic=<function nansum>, return_weights=False, weights=None, quick_bin=False)[source]

Bins an image.

Parameters:

image : array-like

2D image or 3D to be binned. First two axes will be binned.

binsize : tuple

Integer number of pixels to bin in x,y directions

header : astropy.io.Header, optional

Header

origin : string

Location to begin binning.

statistic : function

Function with which to operate on the pixels being binned.

weights : array-like, optional

Weights to be used in the statistic. The statistic must have an argument ‘weights’ if this argument is used.

return_weights : bool, optional

Return weights for image corresponding to the number of valid pixels used to create a binned pixel?

Returns:

image_binned : array-like

Binned image.

header_binned : astropy.io.Header, optional

If header is provided, edited header is returned.

http://stackoverflow.com/questions/8090229/resize-with-averaging-or-rebin-a-numpy-2d-array

myimage_analysis.calc_region_mask(filename, data, header, region_name='')[source]

Masks all pixels which are not within the region.

myimage_analysis.calc_spectrum(cube, statistic=<function nanmedian>, mask=None)[source]

Calculates the spectrum of a cube. Assumes velocity axis is 0th dimension of cube.

myimage_analysis.calculate_moment(data, moment=0, weights=1)[source]

Calculates moment of data. Weights needed for moment of 1 or 2.

myimage_analysis.calculate_nh2(nhi_image=None, av_image=None, dgr=0.11)[source]

Calculates the total gas column density given N(HI), A_v and a dust-to-gas ratio.

myimage_analysis.calculate_nh2_error(nhi_image_error=None, av_image_error=None, dgr=0.11)[source]

Calculates the total gas column density given N(HI), A_v and a dust-to-gas ratio.

myimage_analysis.calculate_nhi(cube=None, velocity_axis=None, velocity_range=None, return_nhi_error=False, noise_cube=None, velocity_noise_range=[90, 100], Tsys=30.0, header=None, fits_filename=None, fits_error_filename=None, verbose=False)[source]

Calculates an N(HI) image given a velocity range within which to include a SpectralGrid’s components.

Parameters:

cube : array-like, optional

Three dimensional array with velocity axis as 0th axis. Must specify a velocity_axis if cube is used. If the cube is two dimensional, assumes the spatial dimension has been raveled into the 1st axis.

velocity_axis : array-like, optional

One dimensional array containing velocities corresponding to

fits_filename : str

If specified, and a header is provided, the N(HI) image will be written as a fits file.

header : pyfits.Header

Header from cube.

velocity_range : tuple, ndarray

If velocity range is a tuple including images of the same shape as the spatial dimensions of the cube, then each velocity range will be applied to individual pixels

velocity_noise_range : tuple

Lower and upper velocities which do not have emission. Used to calculate the N(HI) noise map.

Returns:

nhi_image : array-like

N(HI) in units of 10^20 cm^-2

nhi_image_error : array-like, optional

N(HI) error in units of 10^20 cm^-2

myimage_analysis.calculate_noise(profile, velocity_axis, velocity_range)[source]

Calculates rms noise of Tile profile given velocity ranges.

myimage_analysis.calculate_noise_cube(cube=None, velocity_axis=None, velocity_noise_range=[-110, -90, 90, 110], header=None, Tsys=30.0, filename=None)[source]

Calcuates noise envelopes for each pixel in a cube

myimage_analysis.calculate_noise_scale(Tsys, profile, noise=None)[source]

Creates an array for scaling the noise by (Tsys + Tb) / Tsys

myimage_analysis.calculate_sd(image, sd_factor=0.8)[source]

Calculates a surface density image given a velocity range within which to include a SpectralGrid’s components.

Parameters:

cube : array-like, optional

Three dimensional array with velocity axis as 0th axis. Must specify a velocity_axis if cube is used.

velocity_axis : array-like, optional

One dimensional array containing velocities corresponding to

myimage_analysis.crop_cube(cube, vel_axis, vel_range)[source]

Crops a cube to include only velocities within vel_range.

myimage_analysis.fit_background(av_data, background_mask=None, background_dim=1)[source]
myimage_analysis.get_pix_coords(ra=None, dec=None, header=None)[source]

Ra and dec in (hrs,min,sec) and (deg,arcmin,arcsec).

myimage_analysis.get_radial_profile(image, center=None, stddev=False, binsize=1, mask=None, weights=None)[source]

Calculates radial profiles of an image at the center.

myimage_analysis.hrs2degs(ra=None, dec=None)[source]

Ra and dec tuples in hrs min sec and deg arcmin arcsec.

myimage_analysis.load_ds9_region(filename, header=None, region_name='')[source]
myimage_analysis.read_ds9_region(filename)[source]

Converts DS9 region file into format for plotting region.

Need the following format:
angle : degrees xy : pixels width : pixels height : pixels
Region file provides following format:
# Region file format: DS9 version 4.1 global color=green dashlist=8 3 width=1 font=”helvetica 10 normal roman” select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1 fk5 box(4:17:04.740,+29:20:31.32,5854.33”,11972.7”,130) # text={test}

pyregion module reads DS9 regions: http://leejjoon.github.io/pyregion/users/overview.html

myimage_analysis.subtract_background(image, degree=1, fit_regions=None)[source]

Subtracts a background from an image. Can supply either pixel coordinates of the image or DS9 regions.