agpy 0.1 documentation

Adam Ginsburg’s Python Code (agpy)


agpy Package

agpy

The functions included below are the ‘mature’ codes from the agpy package.

agpy.readcol(filename, skipline=0, skipafter=0, names=False, fsep=None, twod=True, fixedformat=None, asdict=False, comment='#', verbose=True, nullval=None, asStruct=False, namecomment=True, removeblanks=False, header_badchars=None)

The default return is a two dimensional float array. If you want a list of columns output instead of a 2D array, pass ‘twod=False’. In this case, each column’s data type will be automatically detected.

Example usage: CASE 1) a table has the format:

X Y Z

0.0 2.4 8.2 1.0 3.4 5.6 0.7 3.2 2.1 ... names,(x,y,z)=readcol(“myfile.tbl”,names=True,twod=False) or x,y,z=readcol(“myfile.tbl”,skipline=1,twod=False) or names,xx = readcol(“myfile.tbl”,names=True) or xxdict = readcol(“myfile.tbl”,asdict=True) or xxstruct = readcol(“myfile.tbl”,asStruct=True)

CASE 2) no title is contained into the table, then there is no need to skipline: x,y,z=readcol(“myfile.tbl”)

CASE 3) there is a names column and then more descriptive text:
X Y Z

(deg) (deg) (km/s) 0.0 2.4 8.2 1.0 3.4. 5.6 ... then use: names,x,y,z=readcol(“myfile.tbl”,names=True,skipline=1,twod=False) or x,y,z=readcol(“myfile.tbl”,skipline=2,twod=False)

INPUTS:

fsep - field separator, e.g. for comma separated value (csv) files skipline - number of lines to ignore at the start of the file names - read / don’t read in the first line as a list of column names

can specify an integer line number too, though it will be the line number after skipping lines

twod - two dimensional or one dimensional output nullval - if specified, all instances of this value will be replaced

with a floating NaN
asdict - zips names with data to create a dict with column headings
tied to column data. If asdict=True, names will be set to True
asStruct - same as asdict, but returns a structure instead of a dictionary
(i.e. you call struct.key instead of struct[‘key’])
fixedformat - if you have a fixed format file, this is a python list of
column lengths. e.g. the first table above would be [3,5,5]. Note that if you specify the wrong fixed format, you will get junk; if your format total is greater than the line length, the last entries will all be blank but readcol will not report an error.
namecomment - assumed that “Name” row is on a comment line. If it is not -
e.g., it is the first non-comment line, change this to False
removeblanks - remove all blank entries from split lines. This can cause lost
data if you have blank entries on some lines.
header_badchars - remove these characters from a header before parsing it
(helpful for IPAC tables that are delimited with | )

If you get this error: “scipy could not be imported. Your table must have full rows.” it means readcol cannot automatically guess which columns contain data. If you have scipy and columns of varying length, readcol will read in all of the rows with length=mode(row lengths).

agpy.kdist(l, b, vin, near=True, r0=8400.0, v0=254.0, dynamical=False, kinematic=True, regular=False, rrgal=False, verbose=False, inverse=False, silent=False, returnvtan=False)
NAME:
KINDIST
PURPOSE:
To return the distance to an object given l,b,v
CALLING SEQUENCE:
dist = KDIST (L, B, V)
INPUTS:
L, B – Galactic Longitude and Latitude (decimal degrees) V - Velocity w.r.t. LSR in km/s
KEYWORD PARAMETERS:
/NEAR, /FAR – Report the near/far kinematic distances for Q1 and
Q4 data.
RO, VO – Force values for galactocentric distance for sun and
velocity of the LSR around the GC. Default to 8.4 kpc and 254 km/s (Reid et al., 2009)

RGAL – Named keyword containing galactocentric radius of sources. rrgal - return galactocentric distance in addition to distance from us /DYNAMICAL – Use the dynamical definition of the LSR /KINEMATIC – Use the kinematic definition of the LSR (default) /REGULAR – Do not apply the rotation correction for High mass

star forming regions.
INVERSE – If set, pass DISTANCE instead of velocity, and output is
velocity
returnvtan - if set, return the tanent velocity and ignore the input
velocity
OUTPUTS:
DIST – the kinematic distance in units of R0 (defaults to pc).

MODIFICATION HISTORY:

Fri Feb 27 00:47:18 2009, Erik <eros@orthanc.local>
Adapted from kindist.pro Translated from IDL to Python by Adam Ginsburg (adam.ginsburg@colorado.edu)
agpy.posang(l1, b1, l2, b2, system='galactic', units='degrees', **kwargs)

Return the position angle between two points assuming a rectilinear coordinate system (I think; at the very least I am making no corrections for wcs).

INPUT: longitude1, latitude1, longitude2, latitude2

Defaults to GALACTIC coordinates. **kwargs are passed to coords.Position

agpy.downsample(myarr, factor, estimator=<function nanmean at 0x10317bcf8>)

Downsample a 2D array by averaging over factor pixels in each axis. Crops upper edge if the shape is not a multiple of factor.

This code is pure numpy and should be fast.

keywords:
estimator - default to mean. You can downsample by summing or
something else if you want a different estimator (e.g., downsampling error: you want to sum & divide by sqrt(n))
agpy.correlate2d(im1, im2, **kwargs)

Cross-correlation of two images of arbitrary size. Returns an image cropped to the largest of each dimension of the input images

Options: return_fft - if true, return fft(im1)*fft(im2[::-1,::-1]), which is the power

spectral density
fftshift - if true, return the shifted psd so that the DC component is in
the center of the image

pad - Default on. Zero-pad image to the nearest 2^n crop - Default on. Return an image of the size of the largest input image.

If the images are asymmetric in opposite directions, will return the largest image in both directions.

WARNING: Normalization may be arbitrary if you use the PSD

agpy.convolve(img, kernel, crop=True, return_fft=False, fftshift=True, fft_pad=True, psf_pad=False, ignore_nan=False, quiet=False, ignore_zeros=True, min_wt=1e-08, force_ignore_zeros_off=False, normalize_kernel=<function sum at 0x1026710c8>, debug=False, nthreads=1)

Convolve an image with a kernel. Returns something the size of an image. Assumes image & kernel are centered

NOTE Order matters; the kernel should be second.

Options: fft_pad - Default on. Zero-pad image to the nearest 2^n psf_pad - Default off. Zero-pad image to be at least the sum of the image

sizes (in order to avoid edge-wrapping when smoothing)
crop - Default on. Return an image of the size of the largest input image.
If the images are asymmetric in opposite directions, will return the largest image in both directions.
return_fft - Return the FFT instead of the convolution. Useful for making
PSDs.
fftshift - If return_fft on, will shift & crop image to appropriate
dimensions
ignore_nan - attempts to re-weight assuming NAN values are meant to be
ignored, not treated as zero.
ignore_zeros - Ignore the zero-pad-created zeros. Desirable if you have
periodic boundaries on a non-2^n grid
force_ignore_zeros_off - You can choose to turn off the ignore-zeros when padding,
but this is only recommended for purely debug purposes
min_wt - If ignoring nans/zeros, force all grid points with a weight less
than this value to NAN (the weight of a grid point with no ignored neighbors is 1.0)

normalize_kernel - if specified, function to divide kernel by to normalize it

nthreads - if fftw3 is installed, can specify the number of threads to
allow FFTs to use. Probably only helpful for large arrays
agpy.convolve(img, kernel, crop=True, return_fft=False, fftshift=True, fft_pad=True, psf_pad=False, ignore_nan=False, quiet=False, ignore_zeros=True, min_wt=1e-08, force_ignore_zeros_off=False, normalize_kernel=<function sum at 0x1026710c8>, debug=False, nthreads=1)

Convolve an image with a kernel. Returns something the size of an image. Assumes image & kernel are centered

NOTE Order matters; the kernel should be second.

Options: fft_pad - Default on. Zero-pad image to the nearest 2^n psf_pad - Default off. Zero-pad image to be at least the sum of the image

sizes (in order to avoid edge-wrapping when smoothing)
crop - Default on. Return an image of the size of the largest input image.
If the images are asymmetric in opposite directions, will return the largest image in both directions.
return_fft - Return the FFT instead of the convolution. Useful for making
PSDs.
fftshift - If return_fft on, will shift & crop image to appropriate
dimensions
ignore_nan - attempts to re-weight assuming NAN values are meant to be
ignored, not treated as zero.
ignore_zeros - Ignore the zero-pad-created zeros. Desirable if you have
periodic boundaries on a non-2^n grid
force_ignore_zeros_off - You can choose to turn off the ignore-zeros when padding,
but this is only recommended for purely debug purposes
min_wt - If ignoring nans/zeros, force all grid points with a weight less
than this value to NAN (the weight of a grid point with no ignored neighbors is 1.0)

normalize_kernel - if specified, function to divide kernel by to normalize it

nthreads - if fftw3 is installed, can specify the number of threads to
allow FFTs to use. Probably only helpful for large arrays
agpy.smooth(image, kernelwidth=3, kerneltype='gaussian', trapslope=None, silent=True, psf_pad=True, interp_nan=False, nwidths='max', min_nwidths=6, return_kernel=False, normalize_kernel=<function sum at 0x1026710c8>, **kwargs)

Returns a smoothed image using a gaussian, boxcar, or tophat kernel

Options: kernelwidth - width of kernel in pixels (see definitions below) kerneltype - gaussian, boxcar, or tophat.

For a gaussian, uses a gaussian with sigma = kernelwidth (in pixels)
out to [nwidths]-sigma

A boxcar is a kernelwidth x kernelwidth square A tophat is a flat circle with radius = kernelwidth

Default options:
psf_pad = True - will pad the input image to be the image size + PSF.
Slows things down but removes edge-wrapping effects (see convolve) This option should be set to false if the edges of your image are symmetric.
interp_nan = False - Will replace NaN points in an image with the
smoothed average of its neighbors (you can still simply ignore NaN values by setting ignore_nan=True but leaving interp_nan=False)
silent = True - turn it off to get verbose statements about kernel
types
return_kernel = False - If set to true, will return the kernel as the
second return value
nwidths = ‘max’ - number of kernel widths wide to make the kernel. Set to
‘max’ to match the image shape, otherwise use any integer
min_nwidths = 6 - minimum number of gaussian widths to make the kernel
(the kernel will be larger than the image if the image size is < min_widths*kernelsize)
normalize_kernel - Should the kernel preserve the map sum (i.e. kernel.sum() = 1)
or the kernel peak (i.e. kernel.max() = 1) ? Must be a function that can operate on a numpy array

Note that the kernel is forced to be even sized on each axis to assure no offset when smoothing.

agpy.azimuthalAverage(image, center=None, stddev=False, returnradii=False, return_nr=False, binsize=0.5, weights=None, steps=False, interpnan=False, left=None, right=None, mask=None)

Calculate the azimuthally averaged radial profile.

image - The 2D image center - The [x,y] pixel coordinates used as the center. The default is

None, which then uses the center of the image (including fractional pixels).

stddev - if specified, return the azimuthal standard deviation instead of the average returnradii - if specified, return (radii_array,radial_profile) return_nr - if specified, return number of pixels per radius and radius binsize - size of the averaging bin. Can lead to strange results if

non-binsize factors are used to specify the center and the binsize is too large
weights - can do a weighted average instead of a simple average if this keyword parameter
is set. weights.shape must = image.shape. weighted stddev is undefined, so don’t set weights and stddev.
steps - if specified, will return a double-length bin array and radial
profile so you can plot a step-form radial profile (which more accurately represents what’s going on)
interpnan - Interpolate over NAN values, i.e. bins where there is no data?
left,right - passed to interpnan; they set the extrapolated values
mask - can supply a mask (boolean array same size as image with True for OK and False for not)
to average over only select data.

If a bin contains NO DATA, it will have a NAN value because of the divide-by-sum-of-weights component. I think this is a useful way to denote lack of data, but users let me know if an alternative is prefered...

agpy.azimuthalAverageBins(image, azbins, symmetric=None, center=None, **kwargs)

Compute the azimuthal average over a limited range of angles kwargs are passed to azimuthalAverage

agpy.kdist(l, b, vin, near=True, r0=8400.0, v0=254.0, dynamical=False, kinematic=True, regular=False, rrgal=False, verbose=False, inverse=False, silent=False, returnvtan=False)
NAME:
KINDIST
PURPOSE:
To return the distance to an object given l,b,v
CALLING SEQUENCE:
dist = KDIST (L, B, V)
INPUTS:
L, B – Galactic Longitude and Latitude (decimal degrees) V - Velocity w.r.t. LSR in km/s
KEYWORD PARAMETERS:
/NEAR, /FAR – Report the near/far kinematic distances for Q1 and
Q4 data.
RO, VO – Force values for galactocentric distance for sun and
velocity of the LSR around the GC. Default to 8.4 kpc and 254 km/s (Reid et al., 2009)

RGAL – Named keyword containing galactocentric radius of sources. rrgal - return galactocentric distance in addition to distance from us /DYNAMICAL – Use the dynamical definition of the LSR /KINEMATIC – Use the kinematic definition of the LSR (default) /REGULAR – Do not apply the rotation correction for High mass

star forming regions.
INVERSE – If set, pass DISTANCE instead of velocity, and output is
velocity
returnvtan - if set, return the tanent velocity and ignore the input
velocity
OUTPUTS:
DIST – the kinematic distance in units of R0 (defaults to pc).

MODIFICATION HISTORY:

Fri Feb 27 00:47:18 2009, Erik <eros@orthanc.local>
Adapted from kindist.pro Translated from IDL to Python by Adam Ginsburg (adam.ginsburg@colorado.edu)
agpy.vector_kdist(x, y, z, **kwargs)
agpy.moments(data, circle, rotate, vheight, estimator=<function median at 0x102ac6b18>, **kwargs)

Returns (height, amplitude, x, y, width_x, width_y, rotation angle) the gaussian parameters of a 2D distribution by calculating its moments. Depending on the input parameters, will only output a subset of the above.

If using masked arrays, pass estimator=numpy.ma.median

agpy.twodgaussian(inpars, circle=False, rotate=True, vheight=True, shape=None)

Returns a 2d gaussian function of the form: x’ = numpy.cos(rota) * x - numpy.sin(rota) * y y’ = numpy.sin(rota) * x + numpy.cos(rota) * y (rota should be in degrees) g = b + a * numpy.exp ( - ( ((x-center_x)/width_x)**2 + ((y-center_y)/width_y)**2 ) / 2 )

inpars = [b,a,center_x,center_y,width_x,width_y,rota]
(b is background height, a is peak amplitude)

where x and y are the input parameters of the returned function, and all other parameters are specified by this function

However, the above values are passed by list. The list should be: inpars = (height,amplitude,center_x,center_y,width_x,width_y,rota)

You can choose to ignore / neglect some of the above input parameters

unumpy.sing the following options: circle=0 - default is an elliptical gaussian (different x, y

widths), but can reduce the input by one parameter if it’s a circular gaussian
rotate=1 - default allows rotation of the gaussian ellipse. Can
remove last parameter by setting rotate=0
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Gaussian function. Can remove first parameter by setting this to 0
shape=None - if shape is set (to a 2-parameter list) then returns
an image with the gaussian defined by inpars
agpy.gaussfit(data, err=None, params=(), autoderiv=True, return_all=False, circle=False, fixed=array([False, False, False, False, False, False, False], dtype=bool), limitedmin=[False, False, False, False, True, True, True], limitedmax=[False, False, False, False, False, False, True], usemoment=array([], dtype=bool), minpars=array([0, 0, 0, 0, 0, 0, 0]), maxpars=[0, 0, 0, 0, 0, 0, 360], rotate=1, vheight=1, quiet=True, returnmp=False, returnfitimage=False, **kwargs)

Gaussian fitter with the ability to fit a variety of different forms of 2-dimensional gaussian.

Input Parameters:

data - 2-dimensional data array err=None - error array with same size as data array params=[] - initial input parameters for Gaussian function.

(height, amplitude, x, y, width_x, width_y, rota) if not input, these will be determined from the moments of the system, assuming no rotation
autoderiv=1 - use the autoderiv provided in the lmder.f function (the
alternative is to us an analytic derivative with lmdif.f: this method is less robust)
return_all=0 - Default is to return only the Gaussian parameters.
1 - fit params, fit error

returnfitimage - returns (best fit params,best fit image) returnmp - returns the full mpfit struct circle=0 - default is an elliptical gaussian (different x, y widths),

but can reduce the input by one parameter if it’s a circular gaussian
rotate=1 - default allows rotation of the gaussian ellipse. Can remove
last parameter by setting rotate=0. numpy.expects angle in DEGREES
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Gaussian function. Can remove first parameter by setting this to 0
usemoment - can choose which parameters to use a moment estimation for.
Other parameters will be taken from params. Needs to be a boolean array.
Output:
Default output is a set of Gaussian parameters with the same shape as
the input parameters
Can also output the covariance matrix, ‘infodict’ that contains a lot
more detail about the fit (see scipy.optimize.leastsq), and a message from leastsq telling what the exit status of the fitting routine was

Warning: Does NOT necessarily output a rotation angle between 0 and 360 degrees.

agpy.onedgaussian(x, H, A, dx, w)

Returns a 1-dimensional gaussian of form H+A*numpy.exp(-(x-dx)**2/(2*w**2))

agpy.onedgaussfit(xax, data, err=None, params=[0, 1, 0, 1], fixed=[False, False, False, False], limitedmin=[False, False, False, True], limitedmax=[False, False, False, False], minpars=[0, 0, 0, 0], maxpars=[0, 0, 0, 0], quiet=True, shh=True, veryverbose=False, vheight=True, negamp=False, usemoments=False)
Inputs:

xax - x axis data - y axis err - error corresponding to data

params - Fit parameters: Height of background, Amplitude, Shift, Width fixed - Is parameter fixed? limitedmin/minpars - set lower limits on each parameter (default: width>0) limitedmax/maxpars - set upper limits on each parameter quiet - should MPFIT output each iteration? shh - output final parameters? usemoments - replace default parameters with moments

Returns:
Fit parameters Model Fit errors chi2

PCA_tools Module

PCA Tools

A set of tools for PCA analysis, singular value decomposition, total least squares, and other linear fitting methods.

Running this code independently tests the fitting functions with different types of random data.

agpy.PCA_tools.PCA_linear_fit(data1, data2, print_results=False, ignore_nans=True)[source]

Use principal component analysis to determine the best linear fit to the data. data1 - x array data2 - y array

returns m,b in the equation y = m x + b

print tells you some information about what fraction of the variance is accounted for

ignore_nans will remove NAN values from BOTH arrays before computing

Although this works well for the tests below, it fails horrifically on some rather well-behaved data sets. I don’t understand why this is, but that’s why I wrote the total_least_squares SVD code below.

agpy.PCA_tools.efuncs(arr, return_others=False)[source]

Determine eigenfunctions of an array for use with PCA cleaning

agpy.PCA_tools.pca_subtract(arr, ncomps)[source]

Compute the eigenfunctions and values of correlated data, then subtract off the ncomps most correlated components, transform back to the original space, and return that.

agpy.PCA_tools.smooth_waterfall(arr, fwhm=4.0, unsharp=False)[source]

Smooth a waterfall plot.

If unsharp set, remove the smoothed component

Input array should have dimensions [timelen, nbolos]

agpy.PCA_tools.total_least_squares(data1, data2, print_results=False, ignore_nans=True, intercept=True)[source]

Use Singular Value Decomposition to determine the Total Least Squares linear fit to the data. (e.g. http://en.wikipedia.org/wiki/Total_least_squares) data1 - x array data2 - y array

if intercept:
returns m,b in the equation y = m x + b
else:
returns m

print tells you some information about what fraction of the variance is accounted for

ignore_nans will remove NAN values from BOTH arrays before computing

agpy.PCA_tools.unpca_subtract(arr, ncomps)[source]

Like pca_subtract, except keep the ncomps most correlated components and reject the others

asinh_norm Module

Arcsinh Colorbar Normalization

For use with, e.g., imshow - imshow(myimage, norm=AsinhNorm())

Some of the ideas used are from aplpy

class agpy.asinh_norm.AsinhNorm(vmin=None, vmax=None, clip=False, vmid=None)[source]
autoscale_None(A)[source]

autoscale only None-valued vmin or vmax

blackbody Module

Simple black-body calculator

Includes both wavelength and frequency blackbody functions. Has flexible units. Also allows for a few varieties of modified blackbody.

agpy.blackbody.blackbody(nu, temperature, scale=1.0, units='cgs', frequency_units='Hz', normalize=<built-in function max>)[source]
agpy.blackbody.blackbody_wavelength(lam, temperature, scale=1.0, units='cgs', wavelength_units='Angstroms', normalize=<built-in function max>)[source]
agpy.blackbody.fit_blackbody(xdata, flux, guesses=(0, 0), err=None, blackbody_function=<function blackbody at 0x103f8a5f0>, quiet=True, **kwargs)[source]

guesses = Temperature, Arbitrary Scale OR Temperature, Beta, Arbitrary Scale

agpy.blackbody.greybody(nu, temperature, beta, A=1.0, logscale=0.0, units='cgs', frequency_units='Hz', kappa0=4.0, nu0=3000000000000.0, normalize=<built-in function max>)[source]
agpy.blackbody.modified_blackbody(nu, temperature, beta=1.75, logscale=0.0, logN=22, muh2=2.8, units='cgs', frequency_units='Hz', kappa0=4.0, nu0=505000000000.0, normalize=<built-in function max>)[source]

Snu = 2hnu^3 c^-2 (e^(hnu/kT) - 1)^-1 (1 - e^(-tau_nu) ) Kappa0 and Nu0 are set as per http://arxiv.org/abs/1101.4654 which uses OH94 values. beta = 1.75 is a reasonable default for Herschel data N = 1e22 is the column density in cm^-2

nu0 and nu must have same units!

agpy.blackbody.modified_blackbody_wavelength(lam, temperature, beta=1.75, logscale=0.0, logN=22, muh2=2.8, units='cgs', wavelength_units='Angstroms', kappa0=4.0, nu0=3000000000000.0, normalize=<built-in function max>)[source]

Snu = 2hnu^3 c^-2 (e^(hnu/kT) - 1)^-1 (1 - e^(-tau_nu) ) Kappa0 and Nu0 are set as per http://arxiv.org/abs/1101.4654 which uses OH94 values. beta = 1.75 is a reasonable default for Herschel data N = 1e22 is the column density in cm^-2

nu0 and nu must have same units!

collapse_gaussfit Module

Collapse Gaussfit

This was an early attempt to automate gaussian fitting over a data cube using (multiple) gaussian decomposition for each spectrum. It’s reasonably effective, but the uses are somewhat minimal. I’ve tried shifting my cube-related work to pyspeckit.

agpy.collapse_gaussfit.adaptive_collapse_gaussfit(cube, axis=2, nsig=3, nrsig=4, prefix='interesting', vconv=<function <lambda> at 0x107ef8398>, xtora=<function <lambda> at 0x107ef8410>, ytodec=<function <lambda> at 0x107ef8488>, doplot=True)[source]

Attempts to fit one or two Gaussians to each spectrum in a data cube and returns the parameters of the fits. Adaptively determines where to fit two Gaussian components based on residuals. Will fit 3 gaussians if a two-gaussian fit is not better than a certain threshold (specified by nsig), and those fits will be output to images with filename prefix+(coordinate).png. The 3-gaussian fit parameters will not be returned because the automated fitting is very unlikely to get that part right.

inputs: cube - a data cube with two spatial and one spectral dimensions axis - the axis of the spectral dimension nsig - number of sigma over the mean residual to trigger double-gaussian fitting

also, cutoff to do any fitting at all

prefix - the prefix (including directory name) of the output images from 3-gaussian fitting doplot - option to turn off plotting of triple-gaussian fits

vconv,xtora,ytodec - functions to convert the axes from pixel coordinates to ra/dec/velocity coordinates

returns: width_arr1,width_arr2,chi2_arr,offset_arr1,offset_arr2,amp_arr1,amp_arr2 The Gaussian widths, line centers (in pixel units), amplitudes, and the chi-squared value, not in that order These returns are identical to the returns from double_gaussian, but all components will be zero for the second gaussian in the case of a single-gaussian fit

the triple gaussian is guessed to be the double gaussian plus a broad, low-amplitude gaussian. Ideally this should fit outflows reasonably well, but who knows if it really will. Another option is to fit a negative-amplitude gaussian to account for self-absorption

agpy.collapse_gaussfit.collapse_double_gaussfit(cube, axis=2)[source]
agpy.collapse_gaussfit.collapse_gaussfit(cube, axis=2, negamp=False)[source]
agpy.collapse_gaussfit.double_gaussian(dx1, dx2, sigma1, sigma2, a1, a2)[source]
agpy.collapse_gaussfit.double_gerr(xarr)[source]
agpy.collapse_gaussfit.gaussian(dx, sigma, a)[source]
agpy.collapse_gaussfit.gerr(xarr)[source]
agpy.collapse_gaussfit.n_gaussian(dx, sigma, a)[source]
agpy.collapse_gaussfit.nanmean(arr)[source]

nanmean - this version is NOT capable of broadcasting (operating along axes)

agpy.collapse_gaussfit.nanmedian(arr)[source]

nanmedian - this version is NOT capable of broadcasting (operating along axes)

agpy.collapse_gaussfit.return_double_param(xarr, params=None)[source]
agpy.collapse_gaussfit.return_param(xarr, params=None, negamp=False)[source]
agpy.collapse_gaussfit.return_triple_param(xarr, params=None)[source]

input parameters: center[1-3],width[1-3],amplitude[1-3]

agpy.collapse_gaussfit.triple_gaussian(dx1, dx2, dx3, sigma1, sigma2, sigma3, a1, a2, a3)[source]
agpy.collapse_gaussfit.triple_gerr(xarr)[source]
agpy.collapse_gaussfit.wrap_collapse_adaptive(filename, outprefix, redo='no', nsig=5, nrsig=2, doplot=True)[source]

redo - if not equal to ‘no’, then... if collapse_gaussfit succeeded (to the extent that the .pysav files were written), but some part of the file writing or successive procedures failed, re-do those procedures without redoing the whole collapse

agpy.collapse_gaussfit.wrap_collapse_gauss(filename, outprefix, redo='no')[source]

redo - if not equal to ‘no’, then... if collapse_gaussfit succeeded (to the extent that the .pysav files were written), but some part of the file writing or successive procedures failed, re-do those procedures without redoing the whole collapse

constants Module

Constants

A simple list of important constants in CGS units

conversationcount Module

Just for fun, histogram up number of conversations & number of messages exchanged with each person on your buddy list. Meant for adium logs.

cubes Module

Cubes

Many tools for cube manipulation.

See pyspeckit for a similar code better incorporated into a package

agpy.cubes.aper_world2pix(ap, wcs, coordsys='galactic', wunit='arcsec')[source]

Converts an elliptical aperture (x,y,width,height,PA) from WCS to pixel coordinates given an input wcs (an instance of the pywcs.WCS class). Must be a 2D WCS header.

agpy.cubes.coords_in_image(fitsfile, lon, lat, system='galactic')[source]

Determine whether the coordinates are inside the image

agpy.cubes.extract_aperture(cube, ap, r_mask=False, wcs=None, coordsys='galactic', wunit='arcsec')[source]

Extract an aperture from a data cube. E.g. to acquire a spectrum of an outflow that is extended.

Cube should have shape [z,y,x], e.g. cube = pyfits.getdata(‘datacube.fits’)

Apertures are specified in PIXEL units with an origin of 0,0 (NOT the 1,1 fits standard!) unless wcs and coordsys are specified

INPUTS:

wcs - a pywcs.WCS instance associated with the data cube coordsys - the coordinate system the aperture is specified in.

Options are ‘celestial’ and ‘galactic’. Default is ‘galactic’

wunit - units of width/height. default ‘arcsec’, options ‘arcmin’ and ‘degree’

For a circular aperture, len(ap)=3:
ap = [xcen,ycen,radius]
For an elliptical aperture, len(ap)=5:
ap = [xcen,ycen,height,width,PA]
Optional inputs:
r_mask - return mask in addition to spectrum (for error checking?)
agpy.cubes.flatten_header(header)[source]

Attempt to turn an N-dimensional fits header into a 2-dimensional header Turns all CRPIX[>2] etc. into new keywords with suffix ‘A’

header must be a pyfits.Header instance

agpy.cubes.getspec(lon, lat, rad, cube, header, r_fits=True, inherit=True, wunit='arcsec')[source]

Given a longitude, latitude, aperture radius (arcsec), and a cube file, return a .fits file or a spectrum.

lon,lat - longitude and latitude center of a circular aperture in WCS coordinates rad - radius (default degrees) of aperture

agpy.cubes.getspec_reg(cubefilename, region, **kwargs)[source]

Aperture extraction from a cube using a pyregion circle region

The region must be in the same coordinate system as the cube header

agpy.cubes.integ(file, vrange, xcen=None, xwidth=None, ycen=None, ywidth=None, **kwargs)[source]

wrapper of subimage_integ that defaults to using the full image

agpy.cubes.rotcrop_cube(x1, y1, x2, y2, cubename, outname, xwidth=25, ywidth=25, in_system='galactic', out_system='equatorial', clobber=True)[source]

Crop a data cube and then rotate it with montage

agpy.cubes.smooth_cube(cube, cubedim=0, parallel=True, numcores=None, **kwargs)[source]

parallel-map the smooth function

parallel - defaults True. Set to false if you want serial (for debug
purposes?)

numcores - pass to parallel_map (None = use all available)

agpy.cubes.speccen_header(header, lon=None, lat=None)[source]

Turn a cube header into a spectrum header, retaining RA/Dec vals where possible (speccen is like flatten; spec-ify would be better but, specify? nah)

Assumes 3rd axis is velocity

agpy.cubes.subcube(cube, xcen, xwidth, ycen, ywidth, header=None, dvmult=False, return_HDU=False, units='pixels', widthunits='pixels')[source]

Crops a data cube

All units assumed to be pixel units

cube has dimensions (velocity, y, x)

xwidth and ywidth are “radius” values, i.e. half the length that will be extracted

if dvmult is set, multiple the average by DV (this is useful if you set average=sum and dvmul=True to get an integrated value)

agpy.cubes.subimage_integ(cube, xcen, xwidth, ycen, ywidth, vrange, header=None, average=<function mean at 0x1026719b0>, dvmult=False, return_HDU=False, units='pixels', zunits=None)[source]

Returns a sub-image from a data cube integrated over the specified velocity range

All units assumed to be pixel units

cube has dimensions (velocity, y, x)

xwidth and ywidth are “radius” values, i.e. half the length that will be extracted

if dvmult is set, multiply the average by DV (this is useful if you set average=sum and dvmul=True to get an integrated value)

cutout Module

Cutout

Generate a cutout image from a .fits file

exception agpy.cutout.DimensionError[source]
agpy.cutout.cutout(filename, xc, yc, xw=25, yw=25, units='pixels', outfile=None, clobber=True, useMontage=False, coordsys='celestial', verbose=False)[source]

Inputs: file - .fits filename or pyfits HDUList (must be 2D) xc,yc - x and y coordinates in the fits files’ coordinate system (CTYPE) xw,yw - x and y width (pixels or wcs) units - specify units to use: either pixels or wcs outfile - optional output file

densitymap Module

Build a density map out of a list of coordinates

agpy.densitymap.densitymap(header, xi, yi, smoothpix=1, outfits=None, clobber=True)[source]

Generates a source-density map given a region file or a list of coordinates

this should be done with np.histogram2d

agpy.densitymap.dmregion(header, region, outfits=None, smoothpix=2, clobber=True)[source]

Given a valid .FITS header with WCS coordinates and a ds9 region file, creates a density map of ds9 objects (doesn’t filter by shape type). Default smoothing is by a sigma=2 pixels gaussian. Specify outfits to write to a fits file, otherwise returns the map

agpy.densitymap.reg_to_xy(region, header)[source]

downsample Module

agpy.downsample.downsample(myarr, factor, estimator=<function nanmean at 0x10317bcf8>)[source]

Downsample a 2D array by averaging over factor pixels in each axis. Crops upper edge if the shape is not a multiple of factor.

This code is pure numpy and should be fast.

keywords:
estimator - default to mean. You can downsample by summing or
something else if you want a different estimator (e.g., downsampling error: you want to sum & divide by sqrt(n))
agpy.downsample.downsample_1d(myarr, factor, estimator=<function nanmean at 0x10317bcf8>)[source]

Downsample a 1D array by averaging over factor pixels. Crops right side if the shape is not a multiple of factor.

This code is pure numpy and should be fast.

keywords:
estimator - default to mean. You can downsample by summing or
something else if you want a different estimator (e.g., downsampling error: you want to sum & divide by sqrt(n))
agpy.downsample.downsample_cube(myarr, factor, ignoredim=0)[source]

Downsample a 3D array by averaging over factor pixels on the last two axes.

ds9_phot Module

agpy.ds9_phot.ds9_photometry(xpapoint)[source]

dust Module

Dust emissivity

nu is in GHz everywhere

agpy.dust.colofsnu(nu, snu, beamomega, temperature=20, **kwargs)[source]
agpy.dust.kappa(nu, nu0=599584916000.0, kappa0=0.005, beta=1.75)[source]
agpy.dust.massofsnu(nu, snu, beamomega, distance=1, temperature=20)[source]
agpy.dust.snu(nu, column, kappa, temperature)[source]
agpy.dust.snudnu(nu, column, kappa, temperature, bandwidth)[source]
agpy.dust.snuofmass(nu, mass, beamomega, distance=1, temperature=20)[source]

nu in Hz snu in Jy

agpy.dust.tauofsnu(nu, snu, beamomega, temperature=20)[source]

nu in GHz snu in Jy

gaussfitter Module

gaussfitter

Latest version available at <http://code.google.com/p/agpy/source/browse/trunk/agpy/gaussfitter.py>

agpy.gaussfitter.collapse_gaussfit(cube, xax=None, axis=2, negamp=False, usemoments=True, nsigcut=1.0, mppsigcut=1.0, return_errors=False, **kwargs)[source]
agpy.gaussfitter.gaussfit(data, err=None, params=(), autoderiv=True, return_all=False, circle=False, fixed=array([False, False, False, False, False, False, False], dtype=bool), limitedmin=[False, False, False, False, True, True, True], limitedmax=[False, False, False, False, False, False, True], usemoment=array([], dtype=bool), minpars=array([0, 0, 0, 0, 0, 0, 0]), maxpars=[0, 0, 0, 0, 0, 0, 360], rotate=1, vheight=1, quiet=True, returnmp=False, returnfitimage=False, **kwargs)[source]

Gaussian fitter with the ability to fit a variety of different forms of 2-dimensional gaussian.

Input Parameters:

data - 2-dimensional data array err=None - error array with same size as data array params=[] - initial input parameters for Gaussian function.

(height, amplitude, x, y, width_x, width_y, rota) if not input, these will be determined from the moments of the system, assuming no rotation
autoderiv=1 - use the autoderiv provided in the lmder.f function (the
alternative is to us an analytic derivative with lmdif.f: this method is less robust)
return_all=0 - Default is to return only the Gaussian parameters.
1 - fit params, fit error

returnfitimage - returns (best fit params,best fit image) returnmp - returns the full mpfit struct circle=0 - default is an elliptical gaussian (different x, y widths),

but can reduce the input by one parameter if it’s a circular gaussian
rotate=1 - default allows rotation of the gaussian ellipse. Can remove
last parameter by setting rotate=0. numpy.expects angle in DEGREES
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Gaussian function. Can remove first parameter by setting this to 0
usemoment - can choose which parameters to use a moment estimation for.
Other parameters will be taken from params. Needs to be a boolean array.
Output:
Default output is a set of Gaussian parameters with the same shape as
the input parameters
Can also output the covariance matrix, ‘infodict’ that contains a lot
more detail about the fit (see scipy.optimize.leastsq), and a message from leastsq telling what the exit status of the fitting routine was

Warning: Does NOT necessarily output a rotation angle between 0 and 360 degrees.

agpy.gaussfitter.moments(data, circle, rotate, vheight, estimator=<function median at 0x102ac6b18>, **kwargs)[source]

Returns (height, amplitude, x, y, width_x, width_y, rotation angle) the gaussian parameters of a 2D distribution by calculating its moments. Depending on the input parameters, will only output a subset of the above.

If using masked arrays, pass estimator=numpy.ma.median

agpy.gaussfitter.multigaussfit(xax, data, ngauss=1, err=None, params=[1, 0, 1], fixed=[False, False, False], limitedmin=[False, False, True], limitedmax=[False, False, False], minpars=[0, 0, 0], maxpars=[0, 0, 0], quiet=True, shh=True, veryverbose=False)[source]

An improvement on onedgaussfit. Lets you fit multiple gaussians.

Inputs:
xax - x axis data - y axis ngauss - How many gaussians to fit? Default 1 (this could supersede onedgaussfit) err - error corresponding to data

These parameters need to have length = 3*ngauss. If ngauss > 1 and length = 3, they will be replicated ngauss times, otherwise they will be reset to defaults:

params - Fit parameters: [amplitude, offset, width] * ngauss
If len(params) % 3 == 0, ngauss will be set to len(params) / 3

fixed - Is parameter fixed? limitedmin/minpars - set lower limits on each parameter (default: width>0) limitedmax/maxpars - set upper limits on each parameter

quiet - should MPFIT output each iteration? shh - output final parameters?

Returns:
Fit parameters Model Fit errors chi2
agpy.gaussfitter.n_gaussian(pars=None, a=None, dx=None, sigma=None)[source]

Returns a function that sums over N gaussians, where N is the length of a,dx,sigma OR N = len(pars) / 3

The background “height” is assumed to be zero (you must “baseline” your spectrum before fitting)

pars - a list with len(pars) = 3n, assuming a,dx,sigma repeated dx - offset (velocity center) values sigma - line widths a - amplitudes

agpy.gaussfitter.onedgaussfit(xax, data, err=None, params=[0, 1, 0, 1], fixed=[False, False, False, False], limitedmin=[False, False, False, True], limitedmax=[False, False, False, False], minpars=[0, 0, 0, 0], maxpars=[0, 0, 0, 0], quiet=True, shh=True, veryverbose=False, vheight=True, negamp=False, usemoments=False)[source]
Inputs:

xax - x axis data - y axis err - error corresponding to data

params - Fit parameters: Height of background, Amplitude, Shift, Width fixed - Is parameter fixed? limitedmin/minpars - set lower limits on each parameter (default: width>0) limitedmax/maxpars - set upper limits on each parameter quiet - should MPFIT output each iteration? shh - output final parameters? usemoments - replace default parameters with moments

Returns:
Fit parameters Model Fit errors chi2
agpy.gaussfitter.onedgaussian(x, H, A, dx, w)[source]

Returns a 1-dimensional gaussian of form H+A*numpy.exp(-(x-dx)**2/(2*w**2))

agpy.gaussfitter.onedmoments(Xax, data, vheight=True, estimator=<function median at 0x102ac6b18>, negamp=None, veryverbose=False, **kwargs)[source]

Returns (height, amplitude, x, width_x) the gaussian parameters of a 1D distribution by calculating its moments. Depending on the input parameters, will only output a subset of the above.

If using masked arrays, pass estimator=numpy.ma.median ‘estimator’ is used to measure the background level (height)

negamp can be used to force the peak negative (True), positive (False), or it will be “autodetected” (negamp=None)

agpy.gaussfitter.twodgaussian(inpars, circle=False, rotate=True, vheight=True, shape=None)[source]

Returns a 2d gaussian function of the form: x’ = numpy.cos(rota) * x - numpy.sin(rota) * y y’ = numpy.sin(rota) * x + numpy.cos(rota) * y (rota should be in degrees) g = b + a * numpy.exp ( - ( ((x-center_x)/width_x)**2 + ((y-center_y)/width_y)**2 ) / 2 )

inpars = [b,a,center_x,center_y,width_x,width_y,rota]
(b is background height, a is peak amplitude)

where x and y are the input parameters of the returned function, and all other parameters are specified by this function

However, the above values are passed by list. The list should be: inpars = (height,amplitude,center_x,center_y,width_x,width_y,rota)

You can choose to ignore / neglect some of the above input parameters

unumpy.sing the following options: circle=0 - default is an elliptical gaussian (different x, y

widths), but can reduce the input by one parameter if it’s a circular gaussian
rotate=1 - default allows rotation of the gaussian ellipse. Can
remove last parameter by setting rotate=0
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Gaussian function. Can remove first parameter by setting this to 0
shape=None - if shape is set (to a 2-parameter list) then returns
an image with the gaussian defined by inpars

get_cutouts Module

Make cutouts with all available data of a given position

agpy.get_cutouts.coords_in_image(xc, yc, header, coordsys='celestial')[source]

Determine whether the coordinates are within the boundaries of the image

grep Module

agpy.grep.grep(string, list)[source]
agpy.grep.grepv(string, list)[source]

grep -v - return elements that do NOT contain the string

h2fit Module

hotwind Module

agpy.hotwind.LofMdot(logdmom, x=1.51, D0=20.69, alphaP=0.66)[source]

Kudritzki 2000 log Dmom - log D0 = x log(L/Lsun); Dmom = Mdot * vinf *R/rsun

returns L in log10(Lsun)

agpy.hotwind.SnuOfMdot(nu, dkpc, mdot=1e-05, mu=1.2, vwind=1000.0, Zbar=1, Te=10000.0)

Panagia and Felli 1975 equation 24

[nu] = GHz [Te] = K [mdot] = msun/yr [vwind] = km/s mu = mean particle mass in AMU (presumably) Zbar = average ionic charge (assumed 1, but not sure that’s good) dkpc = distance in kpc

agpy.hotwind.mdot(snu, nu=10, Te=10000.0, vinf=2000, mue=1.3, d=1)[source]

[snu] = mJy nu = 10 GHz (frequency) Te = 10^4 K (ionized gas temp) vinf = 2000 km/s (maximum wind speed) mue = 1.3 (mean atomic weight per free electron) d = distance (kpc)

return: mdot in Msun/yr

agpy.hotwind.mdotvinfr(snu, nu=10, Te=10000.0, vinf=2000, mue=1.3, d=1, R=25)[source]

[snu] = mJy nu = 10 GHz (frequency) Te = 10^4 K (ionized gas temp) vinf = 2000 km/s (maximum wind speed) mue = 1.3 (mean atomic weight per free electron) d = distance (kpc)

return: Dmom in g*cm/s^2

Sp. type Log D0 x alphaP A I 14.22 2.41 2.64 0.47 0.38 0.07 Mid B I 17.07 1.05 1.95 0.20 0.51 0.05 Early B I 21.24 1.38 1.34 0.25 0.75 0.15 O I 20.69 1.04 1.51 0.18 0.66 0.06 O III, V 19.87 1.21 1.57 0.21 0.64 0.06

imf Module

Various codes to work with the initial mass function

agpy.imf.chabrier(m, integral=False)[source]

Chabrier 2003 IMF http://adsabs.harvard.edu/abs/2003PASP..115..763C (only valid for m < 1 msun)

not sure which of these to use...

integral is NOT IMPLEMENTED

cumint(fn=<function kroupa at 0x1091b7ed8>, bins=array([ 1.00000000e-02, 1.01862899e-02, 1.03760502e-02,
1.05693455e-02, 1.07662418e-02, 1.09668060e-02,
1.11711065e-02, 1.13792129e-02, 1.15911962e-02,
1.18071285e-02, 1.20270833e-02, 1.22511358e-02,
1.24793621e-02, 1.27118400e-02, 1.29486487e-02,
1.31898690e-02, 1.34355829e-02, 1.36858742e-02,
1.39408283e-02, 1.42005318e-02, 1.44650734e-02,
1.47345431e-02, 1.50090328e-02, 1.52886359e-02,
1.55734477e-02, 1.58635653e-02, 1.61590875e-02,
1.64601150e-02, 1.67667503e-02, 1.70790980e-02,
1.73972643e-02, 1.77213578e-02, 1.80514888e-02,
1.83877698e-02, 1.87303154e-02, 1.90792422e-02,
1.94346693e-02, 1.97967175e-02, 2.01655104e-02,
2.05411735e-02, 2.09238348e-02, 2.13136247e-02,
2.17106760e-02, 2.21151240e-02, 2.25271064e-02,
2.29467637e-02, 2.33742387e-02, 2.38096772e-02,
2.42532274e-02, 2.47050406e-02, 2.51652705e-02,
2.56340741e-02, 2.61116110e-02, 2.65980440e-02,
2.70935387e-02, 2.75982639e-02, 2.81123917e-02,
2.86360972e-02, 2.91695588e-02, 2.97129582e-02,
3.02664806e-02, 3.08303146e-02, 3.14046522e-02,
3.19896892e-02, 3.25856248e-02, 3.31926620e-02,
3.38110078e-02, 3.44408728e-02, 3.50824714e-02,
3.57360225e-02, 3.64017485e-02, 3.70798763e-02,
3.77706369e-02, 3.84742658e-02, 3.91910025e-02,
3.99210913e-02, 4.06647809e-02, 4.14223247e-02,
4.21939808e-02, 4.29800121e-02, 4.37806863e-02,
4.45962763e-02, 4.54270599e-02, 4.62733201e-02,
4.71353453e-02, 4.80134292e-02, 4.89078709e-02,
4.98189752e-02, 5.07470524e-02, 5.16924187e-02,
5.26553963e-02, 5.36363132e-02, 5.46355035e-02,
5.56533078e-02, 5.66900727e-02, 5.77461515e-02,
5.88219040e-02, 5.99176967e-02, 6.10339029e-02,
6.21709029e-02, 6.33290840e-02, 6.45088409e-02,
6.57105755e-02, 6.69346971e-02, 6.81816229e-02,
6.94517777e-02, 7.07455942e-02, 7.20635132e-02,
7.34059837e-02, 7.47734631e-02, 7.61664172e-02,
7.75853206e-02, 7.90306568e-02, 8.05029181e-02,
8.20026062e-02, 8.35302320e-02, 8.50863158e-02,
8.66713880e-02, 8.82859884e-02, 8.99306672e-02,
9.16059848e-02, 9.33125118e-02, 9.50508296e-02,
9.68215306e-02, 9.86252179e-02, 1.00462506e-01,
1.02334021e-01, 1.04240401e-01, 1.06182294e-01,
1.08160363e-01, 1.10175281e-01, 1.12227736e-01,
1.14318425e-01, 1.16448062e-01, 1.18617372e-01,
1.20827094e-01, 1.23077980e-01, 1.25370799e-01,
1.27706330e-01, 1.30085370e-01, 1.32508729e-01,
1.34977233e-01, 1.37491723e-01, 1.40053055e-01,
1.42662102e-01, 1.45319752e-01, 1.48026913e-01,
1.50784505e-01, 1.53593468e-01, 1.56454759e-01,
1.59369353e-01, 1.62338243e-01, 1.65362441e-01,
1.68442976e-01, 1.71580899e-01, 1.74777277e-01,
1.78033202e-01, 1.81349780e-01, 1.84728144e-01,
1.88169442e-01, 1.91674849e-01, 1.95245558e-01,
1.98882786e-01, 2.02587771e-01, 2.06361777e-01,
2.10206088e-01, 2.14122015e-01, 2.18110892e-01,
2.22174078e-01, 2.26312957e-01, 2.30528939e-01,
2.34823460e-01, 2.39197984e-01, 2.43654001e-01,
2.48193029e-01, 2.52816614e-01, 2.57526333e-01,
2.62323788e-01, 2.67210616e-01, 2.72188479e-01,
2.77259076e-01, 2.82424133e-01, 2.87685409e-01,
2.93044698e-01, 2.98503825e-01, 3.04064649e-01,
3.09729067e-01, 3.15499006e-01, 3.21376434e-01,
3.27363353e-01, 3.33461802e-01, 3.39673858e-01,
3.46001639e-01, 3.52447300e-01, 3.59013038e-01,
3.65701088e-01, 3.72513730e-01, 3.79453285e-01,
3.86522116e-01, 3.93722633e-01, 4.01057288e-01,
4.08528580e-01, 4.16139055e-01, 4.23891306e-01,
4.31787973e-01, 4.39831747e-01, 4.48025368e-01,
4.56371628e-01, 4.64873371e-01, 4.73533492e-01,
4.82354943e-01, 4.91340729e-01, 5.00493910e-01,
5.09817606e-01, 5.19314994e-01, 5.28989308e-01,
5.38843844e-01, 5.48881961e-01, 5.59107078e-01,
5.69522678e-01, 5.80132310e-01, 5.90939590e-01,
6.01948197e-01, 6.13161884e-01, 6.24584471e-01,
6.36219849e-01, 6.48071983e-01, 6.60144909e-01,
6.72442742e-01, 6.84969672e-01, 6.97729965e-01,
7.10727970e-01, 7.23968114e-01, 7.37454909e-01,
7.51192949e-01, 7.65186915e-01, 7.79441575e-01,
7.93961785e-01, 8.08752491e-01, 8.23818733e-01,
8.39165644e-01, 8.54798453e-01, 8.70722485e-01,
8.86943166e-01, 9.03466021e-01, 9.20296681e-01,
9.37440879e-01, 9.54904456e-01, 9.72693362e-01,
9.90813657e-01, 1.00927151e+00, 1.02807322e+00,
1.04722519e+00, 1.06673394e+00, 1.08660611e+00,
1.10684849e+00, 1.12746796e+00, 1.14847155e+00,
1.16986641e+00, 1.19165984e+00, 1.21385926e+00,
1.23647224e+00, 1.25950646e+00, 1.28296980e+00,
1.30687023e+00, 1.33121590e+00, 1.35601511e+00,
1.38127630e+00, 1.40700809e+00, 1.43321923e+00,
1.45991865e+00, 1.48711546e+00, 1.51481892e+00,
1.54303847e+00, 1.57178372e+00, 1.60106446e+00,
1.63089068e+00, 1.66127252e+00, 1.69222035e+00,
1.72374471e+00, 1.75585633e+00, 1.78856616e+00,
1.82188534e+00, 1.85582523e+00, 1.89039738e+00,
1.92561357e+00, 1.96148581e+00, 1.99802631e+00,
2.03524752e+00, 2.07316213e+00, 2.11178304e+00,
2.15112343e+00, 2.19119669e+00, 2.23201647e+00,
2.27359668e+00, 2.31595149e+00, 2.35909533e+00,
2.40304289e+00, 2.44780916e+00, 2.49340937e+00,
2.53985907e+00, 2.58717408e+00, 2.63537052e+00,
2.68446481e+00, 2.73447368e+00, 2.78541416e+00,
2.83730362e+00, 2.89015972e+00, 2.94400048e+00,
2.99884423e+00, 3.05470967e+00, 3.11161583e+00,
3.16958209e+00, 3.22862820e+00, 3.28877429e+00,
3.35004083e+00, 3.41244871e+00, 3.47601918e+00,
3.54077391e+00, 3.60673495e+00, 3.67392478e+00,
3.74236629e+00, 3.81208280e+00, 3.88309805e+00,
3.95543624e+00, 4.02912203e+00, 4.10418050e+00,
4.18063724e+00, 4.25851829e+00, 4.33785019e+00,
4.41865996e+00, 4.50097513e+00, 4.58482375e+00,
4.67023439e+00, 4.75723614e+00, 4.84585864e+00,
4.93613210e+00, 5.02808725e+00, 5.12175544e+00,
5.21716858e+00, 5.31435916e+00, 5.41336030e+00,
5.51420574e+00, 5.61692982e+00, 5.72156756e+00,
5.82815458e+00, 5.93672722e+00, 6.04732245e+00,
6.15997796e+00, 6.27473213e+00, 6.39162405e+00,
6.51069356e+00, 6.63198120e+00, 6.75552832e+00,
6.88137699e+00, 7.00957009e+00, 7.14015130e+00,
7.27316511e+00, 7.40865683e+00, 7.54667263e+00,
7.68725952e+00, 7.83046540e+00, 7.97633907e+00,
8.12493021e+00, 8.27628946e+00, 8.43046837e+00,
8.58751948e+00, 8.74749630e+00, 8.91045332e+00,
9.07644607e+00, 9.24553110e+00, 9.41776601e+00,
9.59320948e+00, 9.77192128e+00, 9.95396231e+00,
1.01393946e+01, 1.03282813e+01, 1.05206867e+01,
1.07166765e+01, 1.09163173e+01, 1.11196773e+01,
1.13268257e+01, 1.15378330e+01, 1.17527712e+01,
1.19717134e+01, 1.21947344e+01, 1.24219100e+01,
1.26533176e+01, 1.28890361e+01, 1.31291459e+01,
1.33737286e+01, 1.36228676e+01, 1.38766479e+01,
1.41351558e+01, 1.43984795e+01, 1.46667087e+01,
1.49399346e+01, 1.52182505e+01, 1.55017512e+01,
1.57905331e+01, 1.60846948e+01, 1.63843365e+01,
1.66895601e+01, 1.70004698e+01, 1.73171713e+01,
1.76397728e+01, 1.79683839e+01, 1.83031168e+01,
1.86440853e+01, 1.89914058e+01, 1.93451965e+01,
1.97055780e+01, 2.00726730e+01, 2.04466067e+01,
2.08275063e+01, 2.12155017e+01, 2.16107251e+01,
2.20133111e+01, 2.24233968e+01, 2.28411221e+01,
2.32666291e+01, 2.37000629e+01, 2.41415712e+01,
2.45913043e+01, 2.50494154e+01, 2.55160607e+01,
2.59913992e+01, 2.64755927e+01, 2.69688063e+01,
2.74712079e+01, 2.79829688e+01, 2.85042632e+01,
2.90352688e+01, 2.95761666e+01, 3.01271407e+01,
3.06883789e+01, 3.12600724e+01, 3.18424160e+01,
3.24356081e+01, 3.30398507e+01, 3.36553498e+01,
3.42823149e+01, 3.49209598e+01, 3.55715021e+01,
3.62341632e+01, 3.69091691e+01, 3.75967497e+01,
3.82971391e+01, 3.90105762e+01, 3.97373038e+01,
4.04775697e+01, 4.12316259e+01, 4.19997295e+01,
4.27821420e+01, 4.35791301e+01, 4.43909653e+01,
4.52179242e+01, 4.60602884e+01, 4.69183451e+01,
4.77923865e+01, 4.86827104e+01, 4.95896201e+01,
5.05134247e+01, 5.14544388e+01, 5.24129830e+01,
5.33893840e+01, 5.43839743e+01, 5.53970928e+01,
5.64290847e+01, 5.74803016e+01, 5.85511016e+01,
5.96418495e+01, 6.07529169e+01, 6.18846824e+01,
6.30375315e+01, 6.42118571e+01, 6.54080591e+01,
6.66265452e+01, 6.78677305e+01, 6.91320378e+01,
7.04198979e+01, 7.17317494e+01, 7.30680395e+01,
7.44292233e+01, 7.58157646e+01, 7.72281357e+01,
7.86668179e+01, 8.01323013e+01, 8.16250851e+01,
8.31456781e+01, 8.46945981e+01, 8.62723729e+01,
8.78795401e+01, 8.95166472e+01, 9.11842520e+01,
9.28829225e+01, 9.46132376e+01, 9.63757866e+01,
9.81711702e+01, 1.00000000e+02]))
integrate(fn=<function kroupa at 0x1091b7ed8>, bins=array([ 1.00000000e-02, 1.01862899e-02, 1.03760502e-02,
1.05693455e-02, 1.07662418e-02, 1.09668060e-02,
1.11711065e-02, 1.13792129e-02, 1.15911962e-02,
1.18071285e-02, 1.20270833e-02, 1.22511358e-02,
1.24793621e-02, 1.27118400e-02, 1.29486487e-02,
1.31898690e-02, 1.34355829e-02, 1.36858742e-02,
1.39408283e-02, 1.42005318e-02, 1.44650734e-02,
1.47345431e-02, 1.50090328e-02, 1.52886359e-02,
1.55734477e-02, 1.58635653e-02, 1.61590875e-02,
1.64601150e-02, 1.67667503e-02, 1.70790980e-02,
1.73972643e-02, 1.77213578e-02, 1.80514888e-02,
1.83877698e-02, 1.87303154e-02, 1.90792422e-02,
1.94346693e-02, 1.97967175e-02, 2.01655104e-02,
2.05411735e-02, 2.09238348e-02, 2.13136247e-02,
2.17106760e-02, 2.21151240e-02, 2.25271064e-02,
2.29467637e-02, 2.33742387e-02, 2.38096772e-02,
2.42532274e-02, 2.47050406e-02, 2.51652705e-02,
2.56340741e-02, 2.61116110e-02, 2.65980440e-02,
2.70935387e-02, 2.75982639e-02, 2.81123917e-02,
2.86360972e-02, 2.91695588e-02, 2.97129582e-02,
3.02664806e-02, 3.08303146e-02, 3.14046522e-02,
3.19896892e-02, 3.25856248e-02, 3.31926620e-02,
3.38110078e-02, 3.44408728e-02, 3.50824714e-02,
3.57360225e-02, 3.64017485e-02, 3.70798763e-02,
3.77706369e-02, 3.84742658e-02, 3.91910025e-02,
3.99210913e-02, 4.06647809e-02, 4.14223247e-02,
4.21939808e-02, 4.29800121e-02, 4.37806863e-02,
4.45962763e-02, 4.54270599e-02, 4.62733201e-02,
4.71353453e-02, 4.80134292e-02, 4.89078709e-02,
4.98189752e-02, 5.07470524e-02, 5.16924187e-02,
5.26553963e-02, 5.36363132e-02, 5.46355035e-02,
5.56533078e-02, 5.66900727e-02, 5.77461515e-02,
5.88219040e-02, 5.99176967e-02, 6.10339029e-02,
6.21709029e-02, 6.33290840e-02, 6.45088409e-02,
6.57105755e-02, 6.69346971e-02, 6.81816229e-02,
6.94517777e-02, 7.07455942e-02, 7.20635132e-02,
7.34059837e-02, 7.47734631e-02, 7.61664172e-02,
7.75853206e-02, 7.90306568e-02, 8.05029181e-02,
8.20026062e-02, 8.35302320e-02, 8.50863158e-02,
8.66713880e-02, 8.82859884e-02, 8.99306672e-02,
9.16059848e-02, 9.33125118e-02, 9.50508296e-02,
9.68215306e-02, 9.86252179e-02, 1.00462506e-01,
1.02334021e-01, 1.04240401e-01, 1.06182294e-01,
1.08160363e-01, 1.10175281e-01, 1.12227736e-01,
1.14318425e-01, 1.16448062e-01, 1.18617372e-01,
1.20827094e-01, 1.23077980e-01, 1.25370799e-01,
1.27706330e-01, 1.30085370e-01, 1.32508729e-01,
1.34977233e-01, 1.37491723e-01, 1.40053055e-01,
1.42662102e-01, 1.45319752e-01, 1.48026913e-01,
1.50784505e-01, 1.53593468e-01, 1.56454759e-01,
1.59369353e-01, 1.62338243e-01, 1.65362441e-01,
1.68442976e-01, 1.71580899e-01, 1.74777277e-01,
1.78033202e-01, 1.81349780e-01, 1.84728144e-01,
1.88169442e-01, 1.91674849e-01, 1.95245558e-01,
1.98882786e-01, 2.02587771e-01, 2.06361777e-01,
2.10206088e-01, 2.14122015e-01, 2.18110892e-01,
2.22174078e-01, 2.26312957e-01, 2.30528939e-01,
2.34823460e-01, 2.39197984e-01, 2.43654001e-01,
2.48193029e-01, 2.52816614e-01, 2.57526333e-01,
2.62323788e-01, 2.67210616e-01, 2.72188479e-01,
2.77259076e-01, 2.82424133e-01, 2.87685409e-01,
2.93044698e-01, 2.98503825e-01, 3.04064649e-01,
3.09729067e-01, 3.15499006e-01, 3.21376434e-01,
3.27363353e-01, 3.33461802e-01, 3.39673858e-01,
3.46001639e-01, 3.52447300e-01, 3.59013038e-01,
3.65701088e-01, 3.72513730e-01, 3.79453285e-01,
3.86522116e-01, 3.93722633e-01, 4.01057288e-01,
4.08528580e-01, 4.16139055e-01, 4.23891306e-01,
4.31787973e-01, 4.39831747e-01, 4.48025368e-01,
4.56371628e-01, 4.64873371e-01, 4.73533492e-01,
4.82354943e-01, 4.91340729e-01, 5.00493910e-01,
5.09817606e-01, 5.19314994e-01, 5.28989308e-01,
5.38843844e-01, 5.48881961e-01, 5.59107078e-01,
5.69522678e-01, 5.80132310e-01, 5.90939590e-01,
6.01948197e-01, 6.13161884e-01, 6.24584471e-01,
6.36219849e-01, 6.48071983e-01, 6.60144909e-01,
6.72442742e-01, 6.84969672e-01, 6.97729965e-01,
7.10727970e-01, 7.23968114e-01, 7.37454909e-01,
7.51192949e-01, 7.65186915e-01, 7.79441575e-01,
7.93961785e-01, 8.08752491e-01, 8.23818733e-01,
8.39165644e-01, 8.54798453e-01, 8.70722485e-01,
8.86943166e-01, 9.03466021e-01, 9.20296681e-01,
9.37440879e-01, 9.54904456e-01, 9.72693362e-01,
9.90813657e-01, 1.00927151e+00, 1.02807322e+00,
1.04722519e+00, 1.06673394e+00, 1.08660611e+00,
1.10684849e+00, 1.12746796e+00, 1.14847155e+00,
1.16986641e+00, 1.19165984e+00, 1.21385926e+00,
1.23647224e+00, 1.25950646e+00, 1.28296980e+00,
1.30687023e+00, 1.33121590e+00, 1.35601511e+00,
1.38127630e+00, 1.40700809e+00, 1.43321923e+00,
1.45991865e+00, 1.48711546e+00, 1.51481892e+00,
1.54303847e+00, 1.57178372e+00, 1.60106446e+00,
1.63089068e+00, 1.66127252e+00, 1.69222035e+00,
1.72374471e+00, 1.75585633e+00, 1.78856616e+00,
1.82188534e+00, 1.85582523e+00, 1.89039738e+00,
1.92561357e+00, 1.96148581e+00, 1.99802631e+00,
2.03524752e+00, 2.07316213e+00, 2.11178304e+00,
2.15112343e+00, 2.19119669e+00, 2.23201647e+00,
2.27359668e+00, 2.31595149e+00, 2.35909533e+00,
2.40304289e+00, 2.44780916e+00, 2.49340937e+00,
2.53985907e+00, 2.58717408e+00, 2.63537052e+00,
2.68446481e+00, 2.73447368e+00, 2.78541416e+00,
2.83730362e+00, 2.89015972e+00, 2.94400048e+00,
2.99884423e+00, 3.05470967e+00, 3.11161583e+00,
3.16958209e+00, 3.22862820e+00, 3.28877429e+00,
3.35004083e+00, 3.41244871e+00, 3.47601918e+00,
3.54077391e+00, 3.60673495e+00, 3.67392478e+00,
3.74236629e+00, 3.81208280e+00, 3.88309805e+00,
3.95543624e+00, 4.02912203e+00, 4.10418050e+00,
4.18063724e+00, 4.25851829e+00, 4.33785019e+00,
4.41865996e+00, 4.50097513e+00, 4.58482375e+00,
4.67023439e+00, 4.75723614e+00, 4.84585864e+00,
4.93613210e+00, 5.02808725e+00, 5.12175544e+00,
5.21716858e+00, 5.31435916e+00, 5.41336030e+00,
5.51420574e+00, 5.61692982e+00, 5.72156756e+00,
5.82815458e+00, 5.93672722e+00, 6.04732245e+00,
6.15997796e+00, 6.27473213e+00, 6.39162405e+00,
6.51069356e+00, 6.63198120e+00, 6.75552832e+00,
6.88137699e+00, 7.00957009e+00, 7.14015130e+00,
7.27316511e+00, 7.40865683e+00, 7.54667263e+00,
7.68725952e+00, 7.83046540e+00, 7.97633907e+00,
8.12493021e+00, 8.27628946e+00, 8.43046837e+00,
8.58751948e+00, 8.74749630e+00, 8.91045332e+00,
9.07644607e+00, 9.24553110e+00, 9.41776601e+00,
9.59320948e+00, 9.77192128e+00, 9.95396231e+00,
1.01393946e+01, 1.03282813e+01, 1.05206867e+01,
1.07166765e+01, 1.09163173e+01, 1.11196773e+01,
1.13268257e+01, 1.15378330e+01, 1.17527712e+01,
1.19717134e+01, 1.21947344e+01, 1.24219100e+01,
1.26533176e+01, 1.28890361e+01, 1.31291459e+01,
1.33737286e+01, 1.36228676e+01, 1.38766479e+01,
1.41351558e+01, 1.43984795e+01, 1.46667087e+01,
1.49399346e+01, 1.52182505e+01, 1.55017512e+01,
1.57905331e+01, 1.60846948e+01, 1.63843365e+01,
1.66895601e+01, 1.70004698e+01, 1.73171713e+01,
1.76397728e+01, 1.79683839e+01, 1.83031168e+01,
1.86440853e+01, 1.89914058e+01, 1.93451965e+01,
1.97055780e+01, 2.00726730e+01, 2.04466067e+01,
2.08275063e+01, 2.12155017e+01, 2.16107251e+01,
2.20133111e+01, 2.24233968e+01, 2.28411221e+01,
2.32666291e+01, 2.37000629e+01, 2.41415712e+01,
2.45913043e+01, 2.50494154e+01, 2.55160607e+01,
2.59913992e+01, 2.64755927e+01, 2.69688063e+01,
2.74712079e+01, 2.79829688e+01, 2.85042632e+01,
2.90352688e+01, 2.95761666e+01, 3.01271407e+01,
3.06883789e+01, 3.12600724e+01, 3.18424160e+01,
3.24356081e+01, 3.30398507e+01, 3.36553498e+01,
3.42823149e+01, 3.49209598e+01, 3.55715021e+01,
3.62341632e+01, 3.69091691e+01, 3.75967497e+01,
3.82971391e+01, 3.90105762e+01, 3.97373038e+01,
4.04775697e+01, 4.12316259e+01, 4.19997295e+01,
4.27821420e+01, 4.35791301e+01, 4.43909653e+01,
4.52179242e+01, 4.60602884e+01, 4.69183451e+01,
4.77923865e+01, 4.86827104e+01, 4.95896201e+01,
5.05134247e+01, 5.14544388e+01, 5.24129830e+01,
5.33893840e+01, 5.43839743e+01, 5.53970928e+01,
5.64290847e+01, 5.74803016e+01, 5.85511016e+01,
5.96418495e+01, 6.07529169e+01, 6.18846824e+01,
6.30375315e+01, 6.42118571e+01, 6.54080591e+01,
6.66265452e+01, 6.78677305e+01, 6.91320378e+01,
7.04198979e+01, 7.17317494e+01, 7.30680395e+01,
7.44292233e+01, 7.58157646e+01, 7.72281357e+01,
7.86668179e+01, 8.01323013e+01, 8.16250851e+01,
8.31456781e+01, 8.46945981e+01, 8.62723729e+01,
8.78795401e+01, 8.95166472e+01, 9.11842520e+01,
9.28829225e+01, 9.46132376e+01, 9.63757866e+01,
9.81711702e+01, 1.00000000e+02]))
agpy.imf.inverse_imf(p, nbins=1000, mmin=0.03, mmax=120, massfunc='kroupa')[source]

Inverse mass function

massfunc can be ‘kroupa’, ‘chabrier’, ‘salpeter’, ‘schechter’, or a function

agpy.imf.kroupa(m, integral=False)[source]

Kroupa 2001 IMF (http://arxiv.org/abs/astro-ph/0009005, http://adsabs.harvard.edu/abs/2001MNRAS.322..231K)

agpy.imf.lyc_of_cluster(masses)[source]

Determine the log of the integrated lyman continuum luminosity of a cluster Only M>=8msun count

masses is a list or array of masses.

agpy.imf.lyc_of_star(mass)[source]

Determine lyman continuum luminosity of a star given its mass Uses the Vacca, Garmany, Shull 1996 Table 5 Log Q and Mspec parameters

returns LogQ

m_cumint(fn=<function kroupa at 0x1091b7ed8>, bins=array([ 1.00000000e-02, 1.01862899e-02, 1.03760502e-02,
1.05693455e-02, 1.07662418e-02, 1.09668060e-02,
1.11711065e-02, 1.13792129e-02, 1.15911962e-02,
1.18071285e-02, 1.20270833e-02, 1.22511358e-02,
1.24793621e-02, 1.27118400e-02, 1.29486487e-02,
1.31898690e-02, 1.34355829e-02, 1.36858742e-02,
1.39408283e-02, 1.42005318e-02, 1.44650734e-02,
1.47345431e-02, 1.50090328e-02, 1.52886359e-02,
1.55734477e-02, 1.58635653e-02, 1.61590875e-02,
1.64601150e-02, 1.67667503e-02, 1.70790980e-02,
1.73972643e-02, 1.77213578e-02, 1.80514888e-02,
1.83877698e-02, 1.87303154e-02, 1.90792422e-02,
1.94346693e-02, 1.97967175e-02, 2.01655104e-02,
2.05411735e-02, 2.09238348e-02, 2.13136247e-02,
2.17106760e-02, 2.21151240e-02, 2.25271064e-02,
2.29467637e-02, 2.33742387e-02, 2.38096772e-02,
2.42532274e-02, 2.47050406e-02, 2.51652705e-02,
2.56340741e-02, 2.61116110e-02, 2.65980440e-02,
2.70935387e-02, 2.75982639e-02, 2.81123917e-02,
2.86360972e-02, 2.91695588e-02, 2.97129582e-02,
3.02664806e-02, 3.08303146e-02, 3.14046522e-02,
3.19896892e-02, 3.25856248e-02, 3.31926620e-02,
3.38110078e-02, 3.44408728e-02, 3.50824714e-02,
3.57360225e-02, 3.64017485e-02, 3.70798763e-02,
3.77706369e-02, 3.84742658e-02, 3.91910025e-02,
3.99210913e-02, 4.06647809e-02, 4.14223247e-02,
4.21939808e-02, 4.29800121e-02, 4.37806863e-02,
4.45962763e-02, 4.54270599e-02, 4.62733201e-02,
4.71353453e-02, 4.80134292e-02, 4.89078709e-02,
4.98189752e-02, 5.07470524e-02, 5.16924187e-02,
5.26553963e-02, 5.36363132e-02, 5.46355035e-02,
5.56533078e-02, 5.66900727e-02, 5.77461515e-02,
5.88219040e-02, 5.99176967e-02, 6.10339029e-02,
6.21709029e-02, 6.33290840e-02, 6.45088409e-02,
6.57105755e-02, 6.69346971e-02, 6.81816229e-02,
6.94517777e-02, 7.07455942e-02, 7.20635132e-02,
7.34059837e-02, 7.47734631e-02, 7.61664172e-02,
7.75853206e-02, 7.90306568e-02, 8.05029181e-02,
8.20026062e-02, 8.35302320e-02, 8.50863158e-02,
8.66713880e-02, 8.82859884e-02, 8.99306672e-02,
9.16059848e-02, 9.33125118e-02, 9.50508296e-02,
9.68215306e-02, 9.86252179e-02, 1.00462506e-01,
1.02334021e-01, 1.04240401e-01, 1.06182294e-01,
1.08160363e-01, 1.10175281e-01, 1.12227736e-01,
1.14318425e-01, 1.16448062e-01, 1.18617372e-01,
1.20827094e-01, 1.23077980e-01, 1.25370799e-01,
1.27706330e-01, 1.30085370e-01, 1.32508729e-01,
1.34977233e-01, 1.37491723e-01, 1.40053055e-01,
1.42662102e-01, 1.45319752e-01, 1.48026913e-01,
1.50784505e-01, 1.53593468e-01, 1.56454759e-01,
1.59369353e-01, 1.62338243e-01, 1.65362441e-01,
1.68442976e-01, 1.71580899e-01, 1.74777277e-01,
1.78033202e-01, 1.81349780e-01, 1.84728144e-01,
1.88169442e-01, 1.91674849e-01, 1.95245558e-01,
1.98882786e-01, 2.02587771e-01, 2.06361777e-01,
2.10206088e-01, 2.14122015e-01, 2.18110892e-01,
2.22174078e-01, 2.26312957e-01, 2.30528939e-01,
2.34823460e-01, 2.39197984e-01, 2.43654001e-01,
2.48193029e-01, 2.52816614e-01, 2.57526333e-01,
2.62323788e-01, 2.67210616e-01, 2.72188479e-01,
2.77259076e-01, 2.82424133e-01, 2.87685409e-01,
2.93044698e-01, 2.98503825e-01, 3.04064649e-01,
3.09729067e-01, 3.15499006e-01, 3.21376434e-01,
3.27363353e-01, 3.33461802e-01, 3.39673858e-01,
3.46001639e-01, 3.52447300e-01, 3.59013038e-01,
3.65701088e-01, 3.72513730e-01, 3.79453285e-01,
3.86522116e-01, 3.93722633e-01, 4.01057288e-01,
4.08528580e-01, 4.16139055e-01, 4.23891306e-01,
4.31787973e-01, 4.39831747e-01, 4.48025368e-01,
4.56371628e-01, 4.64873371e-01, 4.73533492e-01,
4.82354943e-01, 4.91340729e-01, 5.00493910e-01,
5.09817606e-01, 5.19314994e-01, 5.28989308e-01,
5.38843844e-01, 5.48881961e-01, 5.59107078e-01,
5.69522678e-01, 5.80132310e-01, 5.90939590e-01,
6.01948197e-01, 6.13161884e-01, 6.24584471e-01,
6.36219849e-01, 6.48071983e-01, 6.60144909e-01,
6.72442742e-01, 6.84969672e-01, 6.97729965e-01,
7.10727970e-01, 7.23968114e-01, 7.37454909e-01,
7.51192949e-01, 7.65186915e-01, 7.79441575e-01,
7.93961785e-01, 8.08752491e-01, 8.23818733e-01,
8.39165644e-01, 8.54798453e-01, 8.70722485e-01,
8.86943166e-01, 9.03466021e-01, 9.20296681e-01,
9.37440879e-01, 9.54904456e-01, 9.72693362e-01,
9.90813657e-01, 1.00927151e+00, 1.02807322e+00,
1.04722519e+00, 1.06673394e+00, 1.08660611e+00,
1.10684849e+00, 1.12746796e+00, 1.14847155e+00,
1.16986641e+00, 1.19165984e+00, 1.21385926e+00,
1.23647224e+00, 1.25950646e+00, 1.28296980e+00,
1.30687023e+00, 1.33121590e+00, 1.35601511e+00,
1.38127630e+00, 1.40700809e+00, 1.43321923e+00,
1.45991865e+00, 1.48711546e+00, 1.51481892e+00,
1.54303847e+00, 1.57178372e+00, 1.60106446e+00,
1.63089068e+00, 1.66127252e+00, 1.69222035e+00,
1.72374471e+00, 1.75585633e+00, 1.78856616e+00,
1.82188534e+00, 1.85582523e+00, 1.89039738e+00,
1.92561357e+00, 1.96148581e+00, 1.99802631e+00,
2.03524752e+00, 2.07316213e+00, 2.11178304e+00,
2.15112343e+00, 2.19119669e+00, 2.23201647e+00,
2.27359668e+00, 2.31595149e+00, 2.35909533e+00,
2.40304289e+00, 2.44780916e+00, 2.49340937e+00,
2.53985907e+00, 2.58717408e+00, 2.63537052e+00,
2.68446481e+00, 2.73447368e+00, 2.78541416e+00,
2.83730362e+00, 2.89015972e+00, 2.94400048e+00,
2.99884423e+00, 3.05470967e+00, 3.11161583e+00,
3.16958209e+00, 3.22862820e+00, 3.28877429e+00,
3.35004083e+00, 3.41244871e+00, 3.47601918e+00,
3.54077391e+00, 3.60673495e+00, 3.67392478e+00,
3.74236629e+00, 3.81208280e+00, 3.88309805e+00,
3.95543624e+00, 4.02912203e+00, 4.10418050e+00,
4.18063724e+00, 4.25851829e+00, 4.33785019e+00,
4.41865996e+00, 4.50097513e+00, 4.58482375e+00,
4.67023439e+00, 4.75723614e+00, 4.84585864e+00,
4.93613210e+00, 5.02808725e+00, 5.12175544e+00,
5.21716858e+00, 5.31435916e+00, 5.41336030e+00,
5.51420574e+00, 5.61692982e+00, 5.72156756e+00,
5.82815458e+00, 5.93672722e+00, 6.04732245e+00,
6.15997796e+00, 6.27473213e+00, 6.39162405e+00,
6.51069356e+00, 6.63198120e+00, 6.75552832e+00,
6.88137699e+00, 7.00957009e+00, 7.14015130e+00,
7.27316511e+00, 7.40865683e+00, 7.54667263e+00,
7.68725952e+00, 7.83046540e+00, 7.97633907e+00,
8.12493021e+00, 8.27628946e+00, 8.43046837e+00,
8.58751948e+00, 8.74749630e+00, 8.91045332e+00,
9.07644607e+00, 9.24553110e+00, 9.41776601e+00,
9.59320948e+00, 9.77192128e+00, 9.95396231e+00,
1.01393946e+01, 1.03282813e+01, 1.05206867e+01,
1.07166765e+01, 1.09163173e+01, 1.11196773e+01,
1.13268257e+01, 1.15378330e+01, 1.17527712e+01,
1.19717134e+01, 1.21947344e+01, 1.24219100e+01,
1.26533176e+01, 1.28890361e+01, 1.31291459e+01,
1.33737286e+01, 1.36228676e+01, 1.38766479e+01,
1.41351558e+01, 1.43984795e+01, 1.46667087e+01,
1.49399346e+01, 1.52182505e+01, 1.55017512e+01,
1.57905331e+01, 1.60846948e+01, 1.63843365e+01,
1.66895601e+01, 1.70004698e+01, 1.73171713e+01,
1.76397728e+01, 1.79683839e+01, 1.83031168e+01,
1.86440853e+01, 1.89914058e+01, 1.93451965e+01,
1.97055780e+01, 2.00726730e+01, 2.04466067e+01,
2.08275063e+01, 2.12155017e+01, 2.16107251e+01,
2.20133111e+01, 2.24233968e+01, 2.28411221e+01,
2.32666291e+01, 2.37000629e+01, 2.41415712e+01,
2.45913043e+01, 2.50494154e+01, 2.55160607e+01,
2.59913992e+01, 2.64755927e+01, 2.69688063e+01,
2.74712079e+01, 2.79829688e+01, 2.85042632e+01,
2.90352688e+01, 2.95761666e+01, 3.01271407e+01,
3.06883789e+01, 3.12600724e+01, 3.18424160e+01,
3.24356081e+01, 3.30398507e+01, 3.36553498e+01,
3.42823149e+01, 3.49209598e+01, 3.55715021e+01,
3.62341632e+01, 3.69091691e+01, 3.75967497e+01,
3.82971391e+01, 3.90105762e+01, 3.97373038e+01,
4.04775697e+01, 4.12316259e+01, 4.19997295e+01,
4.27821420e+01, 4.35791301e+01, 4.43909653e+01,
4.52179242e+01, 4.60602884e+01, 4.69183451e+01,
4.77923865e+01, 4.86827104e+01, 4.95896201e+01,
5.05134247e+01, 5.14544388e+01, 5.24129830e+01,
5.33893840e+01, 5.43839743e+01, 5.53970928e+01,
5.64290847e+01, 5.74803016e+01, 5.85511016e+01,
5.96418495e+01, 6.07529169e+01, 6.18846824e+01,
6.30375315e+01, 6.42118571e+01, 6.54080591e+01,
6.66265452e+01, 6.78677305e+01, 6.91320378e+01,
7.04198979e+01, 7.17317494e+01, 7.30680395e+01,
7.44292233e+01, 7.58157646e+01, 7.72281357e+01,
7.86668179e+01, 8.01323013e+01, 8.16250851e+01,
8.31456781e+01, 8.46945981e+01, 8.62723729e+01,
8.78795401e+01, 8.95166472e+01, 9.11842520e+01,
9.28829225e+01, 9.46132376e+01, 9.63757866e+01,
9.81711702e+01, 1.00000000e+02]))
m_integrate(fn=<function kroupa at 0x1091b7ed8>, bins=array([ 1.00000000e-02, 1.01862899e-02, 1.03760502e-02,
1.05693455e-02, 1.07662418e-02, 1.09668060e-02,
1.11711065e-02, 1.13792129e-02, 1.15911962e-02,
1.18071285e-02, 1.20270833e-02, 1.22511358e-02,
1.24793621e-02, 1.27118400e-02, 1.29486487e-02,
1.31898690e-02, 1.34355829e-02, 1.36858742e-02,
1.39408283e-02, 1.42005318e-02, 1.44650734e-02,
1.47345431e-02, 1.50090328e-02, 1.52886359e-02,
1.55734477e-02, 1.58635653e-02, 1.61590875e-02,
1.64601150e-02, 1.67667503e-02, 1.70790980e-02,
1.73972643e-02, 1.77213578e-02, 1.80514888e-02,
1.83877698e-02, 1.87303154e-02, 1.90792422e-02,
1.94346693e-02, 1.97967175e-02, 2.01655104e-02,
2.05411735e-02, 2.09238348e-02, 2.13136247e-02,
2.17106760e-02, 2.21151240e-02, 2.25271064e-02,
2.29467637e-02, 2.33742387e-02, 2.38096772e-02,
2.42532274e-02, 2.47050406e-02, 2.51652705e-02,
2.56340741e-02, 2.61116110e-02, 2.65980440e-02,
2.70935387e-02, 2.75982639e-02, 2.81123917e-02,
2.86360972e-02, 2.91695588e-02, 2.97129582e-02,
3.02664806e-02, 3.08303146e-02, 3.14046522e-02,
3.19896892e-02, 3.25856248e-02, 3.31926620e-02,
3.38110078e-02, 3.44408728e-02, 3.50824714e-02,
3.57360225e-02, 3.64017485e-02, 3.70798763e-02,
3.77706369e-02, 3.84742658e-02, 3.91910025e-02,
3.99210913e-02, 4.06647809e-02, 4.14223247e-02,
4.21939808e-02, 4.29800121e-02, 4.37806863e-02,
4.45962763e-02, 4.54270599e-02, 4.62733201e-02,
4.71353453e-02, 4.80134292e-02, 4.89078709e-02,
4.98189752e-02, 5.07470524e-02, 5.16924187e-02,
5.26553963e-02, 5.36363132e-02, 5.46355035e-02,
5.56533078e-02, 5.66900727e-02, 5.77461515e-02,
5.88219040e-02, 5.99176967e-02, 6.10339029e-02,
6.21709029e-02, 6.33290840e-02, 6.45088409e-02,
6.57105755e-02, 6.69346971e-02, 6.81816229e-02,
6.94517777e-02, 7.07455942e-02, 7.20635132e-02,
7.34059837e-02, 7.47734631e-02, 7.61664172e-02,
7.75853206e-02, 7.90306568e-02, 8.05029181e-02,
8.20026062e-02, 8.35302320e-02, 8.50863158e-02,
8.66713880e-02, 8.82859884e-02, 8.99306672e-02,
9.16059848e-02, 9.33125118e-02, 9.50508296e-02,
9.68215306e-02, 9.86252179e-02, 1.00462506e-01,
1.02334021e-01, 1.04240401e-01, 1.06182294e-01,
1.08160363e-01, 1.10175281e-01, 1.12227736e-01,
1.14318425e-01, 1.16448062e-01, 1.18617372e-01,
1.20827094e-01, 1.23077980e-01, 1.25370799e-01,
1.27706330e-01, 1.30085370e-01, 1.32508729e-01,
1.34977233e-01, 1.37491723e-01, 1.40053055e-01,
1.42662102e-01, 1.45319752e-01, 1.48026913e-01,
1.50784505e-01, 1.53593468e-01, 1.56454759e-01,
1.59369353e-01, 1.62338243e-01, 1.65362441e-01,
1.68442976e-01, 1.71580899e-01, 1.74777277e-01,
1.78033202e-01, 1.81349780e-01, 1.84728144e-01,
1.88169442e-01, 1.91674849e-01, 1.95245558e-01,
1.98882786e-01, 2.02587771e-01, 2.06361777e-01,
2.10206088e-01, 2.14122015e-01, 2.18110892e-01,
2.22174078e-01, 2.26312957e-01, 2.30528939e-01,
2.34823460e-01, 2.39197984e-01, 2.43654001e-01,
2.48193029e-01, 2.52816614e-01, 2.57526333e-01,
2.62323788e-01, 2.67210616e-01, 2.72188479e-01,
2.77259076e-01, 2.82424133e-01, 2.87685409e-01,
2.93044698e-01, 2.98503825e-01, 3.04064649e-01,
3.09729067e-01, 3.15499006e-01, 3.21376434e-01,
3.27363353e-01, 3.33461802e-01, 3.39673858e-01,
3.46001639e-01, 3.52447300e-01, 3.59013038e-01,
3.65701088e-01, 3.72513730e-01, 3.79453285e-01,
3.86522116e-01, 3.93722633e-01, 4.01057288e-01,
4.08528580e-01, 4.16139055e-01, 4.23891306e-01,
4.31787973e-01, 4.39831747e-01, 4.48025368e-01,
4.56371628e-01, 4.64873371e-01, 4.73533492e-01,
4.82354943e-01, 4.91340729e-01, 5.00493910e-01,
5.09817606e-01, 5.19314994e-01, 5.28989308e-01,
5.38843844e-01, 5.48881961e-01, 5.59107078e-01,
5.69522678e-01, 5.80132310e-01, 5.90939590e-01,
6.01948197e-01, 6.13161884e-01, 6.24584471e-01,
6.36219849e-01, 6.48071983e-01, 6.60144909e-01,
6.72442742e-01, 6.84969672e-01, 6.97729965e-01,
7.10727970e-01, 7.23968114e-01, 7.37454909e-01,
7.51192949e-01, 7.65186915e-01, 7.79441575e-01,
7.93961785e-01, 8.08752491e-01, 8.23818733e-01,
8.39165644e-01, 8.54798453e-01, 8.70722485e-01,
8.86943166e-01, 9.03466021e-01, 9.20296681e-01,
9.37440879e-01, 9.54904456e-01, 9.72693362e-01,
9.90813657e-01, 1.00927151e+00, 1.02807322e+00,
1.04722519e+00, 1.06673394e+00, 1.08660611e+00,
1.10684849e+00, 1.12746796e+00, 1.14847155e+00,
1.16986641e+00, 1.19165984e+00, 1.21385926e+00,
1.23647224e+00, 1.25950646e+00, 1.28296980e+00,
1.30687023e+00, 1.33121590e+00, 1.35601511e+00,
1.38127630e+00, 1.40700809e+00, 1.43321923e+00,
1.45991865e+00, 1.48711546e+00, 1.51481892e+00,
1.54303847e+00, 1.57178372e+00, 1.60106446e+00,
1.63089068e+00, 1.66127252e+00, 1.69222035e+00,
1.72374471e+00, 1.75585633e+00, 1.78856616e+00,
1.82188534e+00, 1.85582523e+00, 1.89039738e+00,
1.92561357e+00, 1.96148581e+00, 1.99802631e+00,
2.03524752e+00, 2.07316213e+00, 2.11178304e+00,
2.15112343e+00, 2.19119669e+00, 2.23201647e+00,
2.27359668e+00, 2.31595149e+00, 2.35909533e+00,
2.40304289e+00, 2.44780916e+00, 2.49340937e+00,
2.53985907e+00, 2.58717408e+00, 2.63537052e+00,
2.68446481e+00, 2.73447368e+00, 2.78541416e+00,
2.83730362e+00, 2.89015972e+00, 2.94400048e+00,
2.99884423e+00, 3.05470967e+00, 3.11161583e+00,
3.16958209e+00, 3.22862820e+00, 3.28877429e+00,
3.35004083e+00, 3.41244871e+00, 3.47601918e+00,
3.54077391e+00, 3.60673495e+00, 3.67392478e+00,
3.74236629e+00, 3.81208280e+00, 3.88309805e+00,
3.95543624e+00, 4.02912203e+00, 4.10418050e+00,
4.18063724e+00, 4.25851829e+00, 4.33785019e+00,
4.41865996e+00, 4.50097513e+00, 4.58482375e+00,
4.67023439e+00, 4.75723614e+00, 4.84585864e+00,
4.93613210e+00, 5.02808725e+00, 5.12175544e+00,
5.21716858e+00, 5.31435916e+00, 5.41336030e+00,
5.51420574e+00, 5.61692982e+00, 5.72156756e+00,
5.82815458e+00, 5.93672722e+00, 6.04732245e+00,
6.15997796e+00, 6.27473213e+00, 6.39162405e+00,
6.51069356e+00, 6.63198120e+00, 6.75552832e+00,
6.88137699e+00, 7.00957009e+00, 7.14015130e+00,
7.27316511e+00, 7.40865683e+00, 7.54667263e+00,
7.68725952e+00, 7.83046540e+00, 7.97633907e+00,
8.12493021e+00, 8.27628946e+00, 8.43046837e+00,
8.58751948e+00, 8.74749630e+00, 8.91045332e+00,
9.07644607e+00, 9.24553110e+00, 9.41776601e+00,
9.59320948e+00, 9.77192128e+00, 9.95396231e+00,
1.01393946e+01, 1.03282813e+01, 1.05206867e+01,
1.07166765e+01, 1.09163173e+01, 1.11196773e+01,
1.13268257e+01, 1.15378330e+01, 1.17527712e+01,
1.19717134e+01, 1.21947344e+01, 1.24219100e+01,
1.26533176e+01, 1.28890361e+01, 1.31291459e+01,
1.33737286e+01, 1.36228676e+01, 1.38766479e+01,
1.41351558e+01, 1.43984795e+01, 1.46667087e+01,
1.49399346e+01, 1.52182505e+01, 1.55017512e+01,
1.57905331e+01, 1.60846948e+01, 1.63843365e+01,
1.66895601e+01, 1.70004698e+01, 1.73171713e+01,
1.76397728e+01, 1.79683839e+01, 1.83031168e+01,
1.86440853e+01, 1.89914058e+01, 1.93451965e+01,
1.97055780e+01, 2.00726730e+01, 2.04466067e+01,
2.08275063e+01, 2.12155017e+01, 2.16107251e+01,
2.20133111e+01, 2.24233968e+01, 2.28411221e+01,
2.32666291e+01, 2.37000629e+01, 2.41415712e+01,
2.45913043e+01, 2.50494154e+01, 2.55160607e+01,
2.59913992e+01, 2.64755927e+01, 2.69688063e+01,
2.74712079e+01, 2.79829688e+01, 2.85042632e+01,
2.90352688e+01, 2.95761666e+01, 3.01271407e+01,
3.06883789e+01, 3.12600724e+01, 3.18424160e+01,
3.24356081e+01, 3.30398507e+01, 3.36553498e+01,
3.42823149e+01, 3.49209598e+01, 3.55715021e+01,
3.62341632e+01, 3.69091691e+01, 3.75967497e+01,
3.82971391e+01, 3.90105762e+01, 3.97373038e+01,
4.04775697e+01, 4.12316259e+01, 4.19997295e+01,
4.27821420e+01, 4.35791301e+01, 4.43909653e+01,
4.52179242e+01, 4.60602884e+01, 4.69183451e+01,
4.77923865e+01, 4.86827104e+01, 4.95896201e+01,
5.05134247e+01, 5.14544388e+01, 5.24129830e+01,
5.33893840e+01, 5.43839743e+01, 5.53970928e+01,
5.64290847e+01, 5.74803016e+01, 5.85511016e+01,
5.96418495e+01, 6.07529169e+01, 6.18846824e+01,
6.30375315e+01, 6.42118571e+01, 6.54080591e+01,
6.66265452e+01, 6.78677305e+01, 6.91320378e+01,
7.04198979e+01, 7.17317494e+01, 7.30680395e+01,
7.44292233e+01, 7.58157646e+01, 7.72281357e+01,
7.86668179e+01, 8.01323013e+01, 8.16250851e+01,
8.31456781e+01, 8.46945981e+01, 8.62723729e+01,
8.78795401e+01, 8.95166472e+01, 9.11842520e+01,
9.28829225e+01, 9.46132376e+01, 9.63757866e+01,
9.81711702e+01, 1.00000000e+02]))
agpy.imf.make_cluster(mcluster, massfunc='kroupa', verbose=False, silent=False, tolerance=0.5, **kwargs)[source]

Sample from an IMF to make a cluster. Returns the masses of all stars in the cluster

massfunc must be a string tolerance is how close the cluster mass must be to the requested mass. If the last star is greater than this tolerance, the total mass will not be within tolerance of the requested

kwargs are passed to inverse_imf

agpy.imf.salpeter(m, alpha=2.35, integral=False)[source]

the Salpeter 1955 IMF: dn/dm ~ m^-2.35

agpy.imf.schechter(m, A=1, beta=2, m0=100, integral=False)[source]

A Schechter function with arbitrary defaults (integral may not be correct - exponent hasn’t been dealt with at all)

agpy.imf.schechter_cdf(m, A=1, beta=2, m0=100, mmin=10, mmax=None, npts=10000.0)[source]

Return the CDF value of a given mass for a set mmin,mmax mmax will default to 10 m0 if not specified

Analytic integral of the Schechter function: http://www.wolframalpha.com/input/?i=integral%28x^-a+exp%28-x%2Fm%29+dx%29

agpy.imf.sh_cdf_func(**kwargs)[source]

kdist Module

agpy.kdist.kdist(l, b, vin, near=True, r0=8400.0, v0=254.0, dynamical=False, kinematic=True, regular=False, rrgal=False, verbose=False, inverse=False, silent=False, returnvtan=False)[source]
NAME:
KINDIST
PURPOSE:
To return the distance to an object given l,b,v
CALLING SEQUENCE:
dist = KDIST (L, B, V)
INPUTS:
L, B – Galactic Longitude and Latitude (decimal degrees) V - Velocity w.r.t. LSR in km/s
KEYWORD PARAMETERS:
/NEAR, /FAR – Report the near/far kinematic distances for Q1 and
Q4 data.
RO, VO – Force values for galactocentric distance for sun and
velocity of the LSR around the GC. Default to 8.4 kpc and 254 km/s (Reid et al., 2009)

RGAL – Named keyword containing galactocentric radius of sources. rrgal - return galactocentric distance in addition to distance from us /DYNAMICAL – Use the dynamical definition of the LSR /KINEMATIC – Use the kinematic definition of the LSR (default) /REGULAR – Do not apply the rotation correction for High mass

star forming regions.
INVERSE – If set, pass DISTANCE instead of velocity, and output is
velocity
returnvtan - if set, return the tanent velocity and ignore the input
velocity
OUTPUTS:
DIST – the kinematic distance in units of R0 (defaults to pc).

MODIFICATION HISTORY:

Fri Feb 27 00:47:18 2009, Erik <eros@orthanc.local>
Adapted from kindist.pro Translated from IDL to Python by Adam Ginsburg (adam.ginsburg@colorado.edu)
agpy.kdist.threekpcarm(longitude, radius=3.0, center_distance=8.5)[source]
agpy.kdist.vector_kdist(x, y, z, **kwargs)[source]

lagrange_diff Module

Implementation of the Lagrange differentiation scheme employed by Molinari et al 2010 and Molinari et al 2011 to identify filamentary structures.

How do you compute the lagrange derivative coefficients analytically? This procedure is orders of magnitude too slow

agpy.lagrange_diff.laplace_interp(image, splineimage=None, direction='vertical', splinesmooth=1.0)[source]
agpy.lagrange_diff.max_curvature(image, splinesmooth=2.0)[source]

luminosity Module

class agpy.luminosity.luminosity(nu, fnu, wnu=None, lnu=None, unu=None, efnu=None, dist_pc=None, npoints=100000.0)[source]

Measures luminosity from an SED following the method of Kauffmann et al 2008 http://adsabs.harvard.edu/abs/2008A%26A...487..993K

For frequency, bandwidth, etc. see http://casa.colorado.edu/~ginsbura/filtersets.htm

Units are CGS

nu - frequency (assumed Hz) wnu - [optional/required for non-interpolation] width of frequency bin lnu/unu - lower/upper bounds on frequency bin fnu - flux (assumed Jy) efnu - [optional; currently does nothing] flux error

When interpolation is used, data is added to the luminosity’ classes nu/fnu vectors. If you use, e.g. luminosity.lbol_meas(), it will still work correctly because it sets wnu ~ unu-lnu = 0

fbol_interp(fnu=None, mminterp=True, npoints=100000.0, addpoint=True, mmfreq=None, extrap=True, write=True)[source]

Interpolates between data points to integrate over SED

If mminterp is set, will assume a nu^4 power law (opacity lambda^-2) from the longest wavelength point

Returns int( nuFnu ) in units HzJy

Extrapolate via a constant line at the low/high frequency data point

fbol_meas()[source]

Returns the total integrated flux (int[nu fnu dnu]) measured within the bands. Does not interpolate

The Casoli et al 1986 formula is not used... FIR (10^-13 W m^-2) = 1.75 ( F12 / 0.79 + F25/2 + F60/3.9 + F100/9.9 )

init_interp(npoints)[source]

initializes the interpolation parameters

lbol_interp(**kwargs)[source]

Bolometric luminosity from interpolation in units of solar luminosities

By default, adds a point at 500 microns extrapolated using a nu^4 power law (opacity nu^2) from the longest wavelength data point. Specify addpoint=False to disable this feature.

lbol_interp_llim(**kwargs)[source]

If errors are specified, returns lbol(fnu+efnu)

lbol_interp_ulim(**kwargs)[source]

If errors are specified, returns lbol(fnu+efnu)

lbol_meas(dist_pc=None)[source]

Returned the luminosity within the measured bins. Does not interpolate. A distance must be specified either here or in the initialization

mminterp(freq, lowfreq=599584916000.0, alpha=4.0, addpoint=True)[source]

Creates an interpolated point using an assumed nu^alpha opacity... defaults to alpha=4 (beta=2)

Default point location is 500 microns

plotsed(loglog=True, nufnu=False, interpplot=False, **kwargs)[source]

Plots the SED

tbol(interp=True)[source]

Computes the “bolometric temperature” as specified in the same document. Uses scipy’s zeta function if scipy is available

agpy.luminosity.test_case()[source]

A specific test case using the Klein 2005 luminosity computations

mad Module

agpy.mad.MAD(a, c=0.6745, axis=None)[source]

Median Absolute Deviation along given axis of an array:

median(abs(a - median(a))) / c

c = 0.6745 is the constant to convert from MAD to std; it is used by default

agpy.mad.nanmedian(arr, **kwargs)[source]

Returns median ignoring NAN

mpfit_custom Module

Perform Levenberg-Marquardt least-squares minimization, based on MINPACK-1.

AUTHORS

The original version of this software, called LMFIT, was written in FORTRAN as part of the MINPACK-1 package by XXX.

Craig Markwardt converted the FORTRAN code to IDL. The information for the IDL version is:

Craig B. Markwardt, NASA/GSFC Code 662, Greenbelt, MD 20770 craigm@lheamail.gsfc.nasa.gov UPDATED VERSIONs can be found on my WEB PAGE:

Mark Rivers created this Python version from Craig’s IDL version.
Mark Rivers, University of Chicago Building 434A, Argonne National Laboratory 9700 South Cass Avenue, Argonne, IL 60439 rivers@cars.uchicago.edu Updated versions can be found at http://cars.uchicago.edu/software
Sergey Koposov converted the Mark’s Python version from Numeric to numpy

Sergey Koposov, Max Planck Institute for Astronomy Heidelberg, Germany, D-69117 koposov@mpia.de Updated versions can be found at http://code.google.com/p/astrolibpy/source/browse/trunk/

DESCRIPTION

MPFIT uses the Levenberg-Marquardt technique to solve the least-squares problem. In its typical use, MPFIT will be used to fit a user-supplied function (the “model”) to user-supplied data points (the “data”) by adjusting a set of parameters. MPFIT is based upon MINPACK-1 (LMDIF.F) by More’ and collaborators.

For example, a researcher may think that a set of observed data points is best modelled with a Gaussian curve. A Gaussian curve is parameterized by its mean, standard deviation and normalization. MPFIT will, within certain constraints, find the set of parameters which best fits the data. The fit is “best” in the least-squares sense; that is, the sum of the weighted squared differences between the model and data is minimized.

The Levenberg-Marquardt technique is a particular strategy for iteratively searching for the best fit. This particular implementation is drawn from MINPACK-1 (see NETLIB), and is much faster and more accurate than the version provided in the Scientific Python package in Scientific.Functions.LeastSquares. This version allows upper and lower bounding constraints to be placed on each parameter, or the parameter can be held fixed.

The user-supplied Python function should return an array of weighted deviations between model and data. In a typical scientific problem the residuals should be weighted so that each deviate has a gaussian sigma of 1.0. If X represents values of the independent variable, Y represents a measurement for each value of X, and ERR represents the error in the measurements, then the deviates could be calculated as follows:

DEVIATES = (Y - F(X)) / ERR

where F is the analytical function representing the model. You are recommended to use the convenience functions MPFITFUN and MPFITEXPR, which are driver functions that calculate the deviates for you. If ERR are the 1-sigma uncertainties in Y, then

TOTAL( DEVIATES^2 )

will be the total chi-squared value. MPFIT will minimize the chi-square value. The values of X, Y and ERR are passed through MPFIT to the user-supplied function via the FUNCTKW keyword.

Simple constraints can be placed on parameter values by using the PARINFO keyword to MPFIT. See below for a description of this keyword.

MPFIT does not perform more general optimization tasks. See TNMIN instead. MPFIT is customized, based on MINPACK-1, to the least-squares minimization problem.

USER FUNCTION

The user must define a function which returns the appropriate values as specified above. The function should return the weighted deviations between the model and the data. It should also return a status flag and an optional partial derivative array. For applications which use finite-difference derivatives – the default – the user function should be declared in the following way:

def myfunct(p, fjac=None, x=None, y=None, err=None)
# Parameter values are passed in “p” # If fjac==None then partial derivatives should not be # computed. It will always be None if MPFIT is called with default # flag. model = F(x, p) # Non-negative status value means MPFIT should continue, negative means # stop the calculation. status = 0 return([status, (y-model)/err]

See below for applications with analytical derivatives.

The keyword parameters X, Y, and ERR in the example above are suggestive but not required. Any parameters can be passed to MYFUNCT by using the functkw keyword to MPFIT. Use MPFITFUN and MPFITEXPR if you need ideas on how to do that. The function must accept a parameter list, P.

In general there are no restrictions on the number of dimensions in X, Y or ERR. However the deviates must be returned in a one-dimensional Numeric array of type Float.

User functions may also indicate a fatal error condition using the status return described above. If status is set to a number between -15 and -1 then MPFIT will stop the calculation and return to the caller.

ANALYTIC DERIVATIVES

In the search for the best-fit solution, MPFIT by default calculates derivatives numerically via a finite difference approximation. The user-supplied function need not calculate the derivatives explicitly. However, if you desire to compute them analytically, then the AUTODERIVATIVE=0 keyword must be passed to MPFIT. As a practical matter, it is often sufficient and even faster to allow MPFIT to calculate the derivatives numerically, and so AUTODERIVATIVE=0 is not necessary.

If AUTODERIVATIVE=0 is used then the user function must check the parameter FJAC, and if FJAC!=None then return the partial derivative array in the return list.

def myfunct(p, fjac=None, x=None, y=None, err=None)

# Parameter values are passed in “p” # If FJAC!=None then partial derivatives must be comptuer. # FJAC contains an array of len(p), where each entry # is 1 if that parameter is free and 0 if it is fixed. model = F(x, p) Non-negative status value means MPFIT should continue, negative means # stop the calculation. status = 0 if (dojac):

pderiv = zeros([len(x), len(p)], Float) for j in range(len(p)):

pderiv[:,j] = FGRAD(x, p, j)
else:
pderiv = None

return([status, (y-model)/err, pderiv]

where FGRAD(x, p, i) is a user function which must compute the derivative of the model with respect to parameter P[i] at X. When finite differencing is used for computing derivatives (ie, when AUTODERIVATIVE=1), or when MPFIT needs only the errors but not the derivatives the parameter FJAC=None.

Derivatives should be returned in the PDERIV array. PDERIV should be an m x n array, where m is the number of data points and n is the number of parameters. dp[i,j] is the derivative at the ith point with respect to the jth parameter.

The derivatives with respect to fixed parameters are ignored; zero is an appropriate value to insert for those derivatives. Upon input to the user function, FJAC is set to a vector with the same length as P, with a value of 1 for a parameter which is free, and a value of zero for a parameter which is fixed (and hence no derivative needs to be calculated).

If the data is higher than one dimensional, then the last dimension should be the parameter dimension. Example: fitting a 50x50 image, “dp” should be 50x50xNPAR.

CONSTRAINING PARAMETER VALUES WITH THE PARINFO KEYWORD

The behavior of MPFIT can be modified with respect to each parameter to be fitted. A parameter value can be fixed; simple boundary constraints can be imposed; limitations on the parameter changes can be imposed; properties of the automatic derivative can be modified; and parameters can be tied to one another.

These properties are governed by the PARINFO structure, which is passed as a keyword parameter to MPFIT.

PARINFO should be a list of dictionaries, one list entry for each parameter. Each parameter is associated with one element of the array, in numerical order. The dictionary can have the following keys (none are required, keys are case insensitive):

‘value’ - the starting parameter value (but see the START_PARAMS
parameter for more information).
‘fixed’ - a boolean value, whether the parameter is to be held
fixed or not. Fixed parameters are not varied by MPFIT, but are passed on to MYFUNCT for evaluation.
‘limited’ - a two-element boolean array. If the first/second
element is set, then the parameter is bounded on the lower/upper side. A parameter can be bounded on both sides. Both LIMITED and LIMITS must be given together.
‘limits’ - a two-element float array. Gives the
parameter limits on the lower and upper sides, respectively. Zero, one or two of these values can be set, depending on the values of LIMITED. Both LIMITED and LIMITS must be given together.
‘parname’ - a string, giving the name of the parameter. The
fitting code of MPFIT does not use this tag in any way. However, the default iterfunct will print the parameter name if available.
‘step’ - the step size to be used in calculating the numerical
derivatives. If set to zero, then the step size is computed automatically. Ignored when AUTODERIVATIVE=0.
‘mpside’ - the sidedness of the finite difference when computing

numerical derivatives. This field can take four values:

0 - one-sided derivative computed automatically 1 - one-sided derivative (f(x+h) - f(x) )/h
-1 - one-sided derivative (f(x) - f(x-h))/h
2 - two-sided derivative (f(x+h) - f(x-h))/(2*h)

Where H is the STEP parameter described above. The “automatic” one-sided derivative method will chose a direction for the finite difference which does not violate any constraints. The other methods do not perform this check. The two-sided method is in principle more precise, but requires twice as many function evaluations. Default: 0.

‘mpmaxstep’ - the maximum change to be made in the parameter

value. During the fitting process, the parameter will never be changed by more than this value in one iteration.

A value of 0 indicates no maximum. Default: 0.

‘tied’ - a string expression which “ties” the parameter to other
free or fixed parameters. Any expression involving constants and the parameter array P are permitted. Example: if parameter 2 is always to be twice parameter 1 then use the following: parinfo(2).tied = ‘2 * p(1)’. Since they are totally constrained, tied parameters are considered to be fixed; no errors are computed for them. [ NOTE: the PARNAME can’t be used in expressions. ]
‘mpprint’ - if set to 1, then the default iterfunct will print the
parameter value. If set to 0, the parameter value will not be printed. This tag can be used to selectively print only a few parameter values out of many. Default: 1 (all parameters printed)

Future modifications to the PARINFO structure, if any, will involve adding dictionary tags beginning with the two letters “MP”. Therefore programmers are urged to avoid using tags starting with the same letters; otherwise they are free to include their own fields within the PARINFO structure, and they will be ignored.

PARINFO Example: parinfo = [{‘value’:0., ‘fixed’:0, ‘limited’:[0,0], ‘limits’:[0.,0.]}

for i in range(5)]

parinfo[0][‘fixed’] = 1 parinfo[4][‘limited’][0] = 1 parinfo[4][‘limits’][0] = 50. values = [5.7, 2.2, 500., 1.5, 2000.] for i in range(5): parinfo[i][‘value’]=values[i]

A total of 5 parameters, with starting values of 5.7, 2.2, 500, 1.5, and 2000 are given. The first parameter is fixed at a value of 5.7, and the last parameter is constrained to be above 50.

EXAMPLE

import mpfit import numpy.oldnumeric as Numeric x = arange(100, float) p0 = [5.7, 2.2, 500., 1.5, 2000.] y = ( p[0] + p[1]*[x] + p[2]*[x**2] + p[3]*sqrt(x) +

p[4]*log(x))

fa = {‘x’:x, ‘y’:y, ‘err’:err} m = mpfit(‘myfunct’, p0, functkw=fa) print ‘status = ‘, m.status if (m.status <= 0): print ‘error message = ‘, m.errmsg print ‘parameters = ‘, m.params

Minimizes sum of squares of MYFUNCT. MYFUNCT is called with the X, Y, and ERR keyword parameters that are given by FUNCTKW. The results can be obtained from the returned object m.

THEORY OF OPERATION

There are many specific strategies for function minimization. One very popular technique is to use function gradient information to realize the local structure of the function. Near a local minimum the function value can be taylor expanded about x0 as follows:

f(x) = f(x0) + f’(x0) . (x-x0) + (1/2) (x-x0) . f’‘(x0) . (x-x0)
—– ————— ——————————- (1)

Order 0th 1st 2nd

Here f’(x) is the gradient vector of f at x, and f’‘(x) is the Hessian matrix of second derivatives of f at x. The vector x is the set of function parameters, not the measured data vector. One can find the minimum of f, f(xm) using Newton’s method, and arrives at the following linear equation:

f’‘(x0) . (xm-x0) = - f’(x0) (2)

If an inverse can be found for f’‘(x0) then one can solve for (xm-x0), the step vector from the current position x0 to the new projected minimum. Here the problem has been linearized (ie, the gradient information is known to first order). f’‘(x0) is symmetric n x n matrix, and should be positive definite.

The Levenberg - Marquardt technique is a variation on this theme. It adds an additional diagonal term to the equation which may aid the convergence properties:

(f’‘(x0) + nu I) . (xm-x0) = -f’(x0) (2a)

where I is the identity matrix. When nu is large, the overall matrix is diagonally dominant, and the iterations follow steepest descent. When nu is small, the iterations are quadratically convergent.

In principle, if f’‘(x0) and f’(x0) are known then xm-x0 can be determined. However the Hessian matrix is often difficult or impossible to compute. The gradient f’(x0) may be easier to compute, if even by finite difference techniques. So-called quasi-Newton techniques attempt to successively estimate f’‘(x0) by building up gradient information as the iterations proceed.

In the least squares problem there are further simplifications which assist in solving eqn (2). The function to be minimized is a sum of squares:

f = Sum(hi^2) (3)

where hi is the ith residual out of m residuals as described above. This can be substituted back into eqn (2) after computing the derivatives:

f’ = 2 Sum(hi hi’) f’’ = 2 Sum(hi’ hj’) + 2 Sum(hi hi’‘) (4)

If one assumes that the parameters are already close enough to a minimum, then one typically finds that the second term in f’’ is negligible [or, in any case, is too difficult to compute]. Thus, equation (2) can be solved, at least approximately, using only gradient information.

In matrix notation, the combination of eqns (2) and (4) becomes:

hT’ . h’ . dx = - hT’ . h (5)

Where h is the residual vector (length m), hT is its transpose, h’ is the Jacobian matrix (dimensions n x m), and dx is (xm-x0). The user function supplies the residual vector h, and in some cases h’ when it is not found by finite differences (see MPFIT_FDJAC2, which finds h and hT’). Even if dx is not the best absolute step to take, it does provide a good estimate of the best direction, so often a line minimization will occur along the dx vector direction.

The method of solution employed by MINPACK is to form the Q . R factorization of h’, where Q is an orthogonal matrix such that QT . Q = I, and R is upper right triangular. Using h’ = Q . R and the ortogonality of Q, eqn (5) becomes

(RT . QT) . (Q . R) . dx = - (RT . QT) . h
RT . R . dx = - RT . QT . h (6)
R . dx = - QT . h

where the last statement follows because R is upper triangular. Here, R, QT and h are known so this is a matter of solving for dx. The routine MPFIT_QRFAC provides the QR factorization of h, with pivoting, and MPFIT_QRSOLV provides the solution for dx.

REFERENCES

MINPACK-1, Jorge More’, available from netlib (www.netlib.org). “Optimization Software Guide,” Jorge More’ and Stephen Wright,

SIAM, Frontiers in Applied Mathematics, Number 14.
More’, Jorge J., “The Levenberg-Marquardt Algorithm:

Implementation and Theory,” in Numerical Analysis, ed. Watson, G. A., Lecture Notes in Mathematics 630, Springer-Verlag, 1977.

MODIFICATION HISTORY

Translated from MINPACK-1 in FORTRAN, Apr-Jul 1998, CM

Copyright (C) 1997-2002, Craig Markwardt This software is provided as is without any warranty whatsoever. Permission to use, copy, modify, and distribute modified or unmodified copies is granted, provided this copyright and disclaimer are included unchanged.

Translated from MPFIT (Craig Markwardt’s IDL package) to Python, August, 2002. Mark Rivers Converted from Numeric to numpy (Sergey Koposov, July 2008)
class agpy.mpfit_custom.machar(double=1)[source]
class agpy.mpfit_custom.mpfit(fcn, xall=None, functkw={}, parinfo=None, ftol=1e-10, xtol=1e-10, gtol=1e-10, damp=0.0, maxiter=200, factor=100.0, nprint=1, iterfunct='default', iterkw={}, nocovar=0, fastnorm=0, rescale=0, autoderivative=1, quiet=0, diag=None, epsfcn=None, debug=0)[source]
calc_covar(rr, ipvt=None, tol=1e-14)[source]
call(fcn, x, functkw, fjac=None)[source]
defiter(fcn, x, iter, fnorm=None, functkw=None, quiet=0, iterstop=None, parinfo=None, format=None, pformat='%.10g', dof=1)[source]
enorm(vec)[source]
fdjac2(fcn, x, fvec, step=None, ulimited=None, ulimit=None, dside=None, epsfcn=None, autoderivative=1, functkw=None, xall=None, ifree=None, dstep=None)[source]
lmpar(r, ipvt, diag, qtb, delta, x, sdiag, par=None)[source]
parinfo(parinfo=None, key='a', default=None, n=0)[source]
qrfac(a, pivot=0)[source]
qrsolv(r, ipvt, diag, qtb, sdiag)[source]
tie(p, ptied=None)[source]

posang Module

agpy.posang.posang(l1, b1, l2, b2, system='galactic', units='degrees', **kwargs)[source]

Return the position angle between two points assuming a rectilinear coordinate system (I think; at the very least I am making no corrections for wcs).

INPUT: longitude1, latitude1, longitude2, latitude2

Defaults to GALACTIC coordinates. **kwargs are passed to coords.Position

powerfit Module

agpy.powerfit.brokenpowerfit(xax, data, err=None, alphaguess1=0.0, alphaguess2=-2.0, scaleguess=1.0, breakpoint=None, quiet=True)[source]

Fit a broken power law (a line in log-space) to data as a function of x differs from ‘plfit’ because plfit fits a power law distribution, this code simply fits a power law

This is a lot more intricate than the simple power law fit, since it involves fitting two power laws with different slopes

Parameters: p[0] - scale p[1] - breakpoint p[2] - power 1 (xax < breakpoint) p[3] - power 2 (xax >= breakpoint)

There are 5 parameters (NOT 4) returned because there are two scales that are NOT independent

returns: scale1,scale2,breakpoint,alpha1,alpha2

agpy.powerfit.powerfit(xax, data, err=None, alphaguess=-2.0, scaleguess=1.0, quiet=True)[source]

Fit a power law (a line in log-space) to data as a function of x differs from ‘plfit’ because plfit fits a power law distribution, this code simply fits a power law

psf_fitter Module

agpy.psf_fitter.airy(inpars, circle=True, rotate=False, vheight=True, shape=None, fwhm=False)[source]

Returns a 2d Airy function of the form: x’ = numpy.cos(rota) * x - numpy.sin(rota) * y y’ = numpy.sin(rota) * x + numpy.cos(rota) * y (rota should be in degrees) radius = sqrt( (x’-xcen)^2 + (y’-ycen)^2 ) g = b + a * 2.0*BesselJ1( radius ) / radius

(with a correction for the divide-by-zero in the center)
inpars = [b,a,center_x,center_y,width_x,width_y,rota]
(b is background height, a is peak amplitude)

where x and y are the input parameters of the returned function, and all other parameters are specified by this function

However, the above values are passed by list. The list should be: inpars = (height,amplitude,center_x,center_y,width_x,width_y,rota)

You can choose to ignore / neglect some of the above input parameters

unumpy.sing the following options: circle=1 - default is a circular Airy Disk. An elliptical Airy is

possible, but probably not physically motivated (unless it’s sampled onto a stretched grid?).
rotate=0 - default allows rotation of the gaussian ellipse. Can
remove last parameter by setting rotate=0
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Airy function. Can remove first parameter by setting this to 0
shape=None - if shape is set (to a 2-parameter list) then returns
an image with the gaussian defined by inpars
fwhm - if set, assumes the Width parameters input are FWHM widths, so
they’ll be converted to “Sigma” widths by s = FWHM/2.0/1.61633 (http://en.wikipedia.org/wiki/Airy_disk and http://home.fnal.gov/~neilsen/notebook/astroPSF/astroPSF.html)
agpy.psf_fitter.psffit(data, err=None, params=[], autoderiv=True, return_all=False, circle=True, fixed=array([False, False, False, False, False, False, False], dtype=bool), limitedmin=[False, False, False, False, True, True, True], limitedmax=[False, False, False, False, False, False, True], usemoment=array([], dtype=bool), minpars=array([0, 0, 0, 0, 0, 0, 0]), maxpars=[0, 0, 0, 0, 0, 0, 360], rotate=0, vheight=1, quiet=True, returnmp=False, returnfitimage=False, psffunction=<function airy at 0x109bc3ed8>, extra_pars=None, return_parinfo=False, **kwargs)[source]

PSF fitter with the ability to fit a variety of different forms of 2-dimensional gaussian OR an Airy. This code is mostly directly copied from gaussfitter.py and presents yet another argument for me turning this into a class...

Input Parameters:

data - 2-dimensional data array err=None - error array with same size as data array params=[] - initial input parameters for Gaussian function.

(height, amplitude, x, y, width_x, width_y, rota) if not input, these will be determined from the moments of the system, assuming no rotation
autoderiv=1 - use the autoderiv provided in the lmder.f function (the
alternative is to us an analytic derivative with lmdif.f: this method is less robust)
return_all=0 - Default is to return only the Gaussian parameters.
1 - fit params, fit error

returnfitimage - returns (best fit params,best fit image) returnmp - returns the full mpfit struct circle=0 - default is an elliptical gaussian (different x, y widths),

but can reduce the input by one parameter if it’s a circular gaussian
rotate=1 - default allows rotation of the gaussian ellipse. Can remove
last parameter by setting rotate=0. numpy.expects angle in DEGREES
vheight=1 - default allows a variable height-above-zero, i.e. an
additive constant for the Gaussian function. Can remove first parameter by setting this to 0
usemoment - can choose which parameters to use a moment estimation for.
Other parameters will be taken from params. Needs to be a boolean array.
extra_pars - If your psffunction requires extra parameters, pass their
parinfo dictionaries through this variable
Output:
Default output is a set of Gaussian parameters with the same shape as
the input parameters
Can also output the covariance matrix, ‘infodict’ that contains a lot
more detail about the fit (see scipy.optimize.leastsq), and a message from leastsq telling what the exit status of the fitting routine was

Warning: Does NOT necessarily output a rotation angle between 0 and 360 degrees.

pstopng Module

query_splatalogue Module

agpy.query_splatalogue.query_splatalogue(minwav=0.0026, maxwav=0.00261, waveunits='m', root_url='http://find.nrao.edu/splata-slap/slap', chemical_element=None, NRAO_Recommended=True)[source]

Acquire an atpy table of a splatalogue searched based on wavelength.

Future work will allow queries based on other parameters. I’m waiting on development by the SPLATASLAP database folks to implement these.

ratosexagesimal Module

agpy.ratosexagesimal.dectos(dec)[source]
agpy.ratosexagesimal.ratos(ra)[source]

readcol Module

readcol.py by Adam Ginsburg (keflavich@gmail.com)

readcol is meant to emulate IDL’s readcol.pro, but is more capable and flexible. It is not a particularly “pythonic” program since it is not modular. For a modular ascii table reader, http://cxc.harvard.edu/contrib/asciitable/ is probably better. This single-function code is probably more intuitive to an end-user, though.

class agpy.readcol.Struct(namedict)[source]

Simple struct intended to take a dictionary of column names -> columns and turn it into a struct by removing special characters

add_column(name, data)[source]

Add a new column (attribute) to the struct (will overwrite anything with the same name)

agpy.readcol.get_autotype(arr)[source]

Attempts to return a numpy array converted to the most sensible dtype Value errors will be caught and simply return the original array Tries to make dtype int, then float, then no change

agpy.readcol.make_commentfilter(comment)[source]
agpy.readcol.readcol(filename, skipline=0, skipafter=0, names=False, fsep=None, twod=True, fixedformat=None, asdict=False, comment='#', verbose=True, nullval=None, asStruct=False, namecomment=True, removeblanks=False, header_badchars=None)[source]

The default return is a two dimensional float array. If you want a list of columns output instead of a 2D array, pass ‘twod=False’. In this case, each column’s data type will be automatically detected.

Example usage: CASE 1) a table has the format:

X Y Z

0.0 2.4 8.2 1.0 3.4 5.6 0.7 3.2 2.1 ... names,(x,y,z)=readcol(“myfile.tbl”,names=True,twod=False) or x,y,z=readcol(“myfile.tbl”,skipline=1,twod=False) or names,xx = readcol(“myfile.tbl”,names=True) or xxdict = readcol(“myfile.tbl”,asdict=True) or xxstruct = readcol(“myfile.tbl”,asStruct=True)

CASE 2) no title is contained into the table, then there is no need to skipline: x,y,z=readcol(“myfile.tbl”)

CASE 3) there is a names column and then more descriptive text:
X Y Z

(deg) (deg) (km/s) 0.0 2.4 8.2 1.0 3.4. 5.6 ... then use: names,x,y,z=readcol(“myfile.tbl”,names=True,skipline=1,twod=False) or x,y,z=readcol(“myfile.tbl”,skipline=2,twod=False)

INPUTS:

fsep - field separator, e.g. for comma separated value (csv) files skipline - number of lines to ignore at the start of the file names - read / don’t read in the first line as a list of column names

can specify an integer line number too, though it will be the line number after skipping lines

twod - two dimensional or one dimensional output nullval - if specified, all instances of this value will be replaced

with a floating NaN
asdict - zips names with data to create a dict with column headings
tied to column data. If asdict=True, names will be set to True
asStruct - same as asdict, but returns a structure instead of a dictionary
(i.e. you call struct.key instead of struct[‘key’])
fixedformat - if you have a fixed format file, this is a python list of
column lengths. e.g. the first table above would be [3,5,5]. Note that if you specify the wrong fixed format, you will get junk; if your format total is greater than the line length, the last entries will all be blank but readcol will not report an error.
namecomment - assumed that “Name” row is on a comment line. If it is not -
e.g., it is the first non-comment line, change this to False
removeblanks - remove all blank entries from split lines. This can cause lost
data if you have blank entries on some lines.
header_badchars - remove these characters from a header before parsing it
(helpful for IPAC tables that are delimited with | )

If you get this error: “scipy could not be imported. Your table must have full rows.” it means readcol cannot automatically guess which columns contain data. If you have scipy and columns of varying length, readcol will read in all of the rows with length=mode(row lengths).

agpy.readcol.readff(s, format)[source]

Fixed-format reader Pass in a single line string (s) and a format list, which needs to be a python list of string lengths

reg_gal2cel Module

agpy.reg_gal2cel.gal2cel(regfile)[source]

Converts a region file from galactic to celestial coordinates including position angle reference from the center of the box (right now only works on box regions)

Requires pyregion with the ShapeList.write() function implemented... not clear if that exists in 1.0

regfile_aperture_extract Module

agpy.regfile_aperture_extract.get_fluxes(regfile, outfile, inneraprad=35, outeraprad=60, hdu=None, PPBEAM=1.0, debug=False, print_nulls=False)[source]

Extract fluxes from a region-defined aperture with inner and outer circular apertures specififed

MUST BE IN GALACTIC COORDINATES

region_photometry Module

agpy.region_photometry.region_photometry(regionfile, fitsfilename, outfile='/dev/tty', doprint=True)[source]

region_photometry_files Module

agpy.region_photometry_files.region_photometry_files(regfile, filelist)[source]

region_positions Module

agpy.region_positions.coords_format(format)[source]

Convert from ds9’s ‘fk5’ and ‘icrs’ naming convention to the ‘celestial’/’galactic’ used by coords

agpy.region_positions.pos_to_name(reg)[source]

Given a region, returns a name based on Galactic coordinates

agpy.region_positions.position_region(reg)[source]

small wrapper to get a Position object using the correct coordinate system

reg must by a pyregion Shape instance

regtoapo Module

agpy.regtoapo.regtoapo(regfile, outfile, filtercolor=None)[source]

Take an input ds9 .reg file and create an output file formatted to work with APO’s TUI

filtercolor - if specified, will ignore any regions of this color

regtocima Module

agpy.regtocima.regtocima(regfile, outfile, filtercolor=None)[source]

Take an input ds9 .reg file and create an output file formatted to work with Arecibo’s CIMA [NOT FUNCTIONAL]

filtercolor - if specified, will ignore any regions of this color

agpy.regtocima.regtouptime(regfile, outfile, maxza=15.0)[source]

Converts a region file to a list of target names + how long they are observable @ arecibo

maxza = 15.0 degrees for “broken” Arecibo (2010) or 18-19 for normal Arecibo

subim_gaussfit Module

timer Module

agpy.timer.print_timing(func)[source]

Contents: .. toctree:

:maxdepth: 3
gaussfit
uchii
pyflagger
contributed