utilities module¶
-
utilities.
Jy2mag
(band, jy, jy_unc, filter_dict='')¶
-
utilities.
blackbody
(lam, T, Flam=False, radius=1, dist=10, emitted=False)¶ Given a wavelength array [um] and temperature [K], returns an array of Planck function values in [erg s-1 cm-2 A-1]
-
utilities.
contour_plot
(x, y, z, best=False, figsize=(8, 8), levels=20, cmap=<matplotlib.colors.LinearSegmentedColormap object>)¶
-
utilities.
deg2sxg
(ra='', dec='')¶
-
utilities.
dict2txt
(DICT, writefile, column1='-', delim='\t', digits='', order='', colsort='', row2='', preamble='', postamble='', empties=True, append=False, all_str=False, literal=False, blanks='\\\\nodata', LaTeX=False)¶ Given a nested dictionary DICT, writes a .txt file with keys as columns.
-
utilities.
distance
(coord1, coord2)¶ Given n-dimensional coordinates of two points, returns the distance between them
-
utilities.
filter_info
(band)¶ Effective, min, and max wavelengths in [um] and zeropoint in [erg s-1 cm-2 A-1] and [photon s-1 cm-2 A-1] for SDSS, Bessel, 2MASS, IRAC and WISE filters IN THE VEGA SYSTEM. Values from SVO filter profile service.
- band
- Name of filter band (e.g. ‘J’ from 2MASS, ‘W1’ from WISE, etc.) or list of filter systems (e.g. [‘SDSS’,‘2MASS’,’WISE’])
-
utilities.
find
(filename, tree)¶ For given filename and directory tree, returns the path to the file. For only file extension given as filename, returns list of paths to all files with that extnsion in that directory tree.
- filename
- Filename or file extension to search for (e.g. ‘my_file.txt’ or just ‘.txt’)
- tree
- Directory tree base to start the walk (e.g. ‘/Users/Joe/Documents/’)
-
utilities.
flux2mag
(band, f, sig_f='', photon=False, filter_dict='')¶ For given band and flux returns the magnitude value (and uncertainty if sig_f)
-
utilities.
flux_calibrate
(mag, dist, sig_m='', sig_d='', scale_to=<Quantity 10.0 pc>)¶
-
utilities.
get_filters
(filter_directories=['/Users/Joe/Documents/Python/Filters/2MASS/', '/Users/Joe/Documents/Python/Filters/SDSS/', '/Users/Joe/Documents/Python/Filters/WISE/', '/Users/Joe/Documents/Python/Filters/IRAC/', '/Users/Joe/Documents/Python/Filters/MIPS/', '/Users/Joe/Documents/Python/Filters/HST/', '/Users/Joe/Documents/Python/Filters/Bessel/', '/Users/Joe/Documents/Python/Filters/MKO/', '/Users/Joe/Documents/Python/Filters/GALEX/', '/Users/Joe/Documents/Python/Filters/DENIS/', '/Users/Joe/Documents/Python/Filters/GAIA/', '/Users/Joe/Documents/Python/Filters/DES/'], systems=['2MASS', 'SDSS', 'WISE', 'IRAC', 'MIPS', 'HST', 'Bessel', 'MKO', 'GALEX', 'DENIS', 'GAIA', 'DES'])¶ Grabs all the .txt spectral response curves and returns a dictionary of wavelength array [um], filter response [unitless], effective, min and max wavelengths [um], and zeropoint [erg s-1 cm-2 A-1].
-
utilities.
goodness
(spec1, spec2, array=False, exclude=[], filt_dict=None, weighting=True, verbose=False)¶
-
utilities.
group
(lst, n)¶
-
utilities.
group_spectra
(spectra)¶ Puts a list of spectra into groups with overlapping wavelength arrays
-
utilities.
idx_exclude
(x, exclude)¶
-
utilities.
idx_include
(x, include)¶
-
utilities.
inject_average
(spectrum, position, direction, n=10)¶ Used to smooth edges after trimming a spectrum. Injects a new data point into a spectrum at given position with flux value equal to the average of the n elements in the given direction.
-
utilities.
mag2flux
(band, mag, sig_m='', photon=False, filter_dict='')¶ For given band and magnitude returns the flux value (and uncertainty if sig_m) in [ergs][s-1][cm-2][A-1]
-
utilities.
make_composite
(spectra)¶ Creates a composite spectrum from a list of overlapping spectra
-
utilities.
manual_legend
(labels, colors, markers='', edges='', sizes='', errors='', styles='', text_colors='', fontsize=14, overplot='', bbox_to_anchor='', loc=0, ncol=1, figlegend=False)¶ Add manually created legends to plots and subplots labels
A list of strings to appear as legend text, e.g. [‘Foo’,’Bar’,’Baz’]- colors
- A list of colors for the legend markers, e.g. [‘r’,’g’,’b’]
- markers
- A list of markers or linestyles to use in the legend, e.g. [‘o’,’^’,’–’]
- edges
- A list of colors to use as marker edge colors, e.g. [‘m’,’None’,’k’]
- sizes
- A list of integers to specify the marker size of points or the linewidth of lines, e.g. [8,12,2]
- errors
- A list of boolean statements to indicate whether markers should display error bars of not, e.g. [True,False,False]
- styles
- A list indicating whether each legend item should display a point ‘p’ or a line ‘l’, e.g. [‘p’,’p’,’l’]
- overplot
- The axes to draw the legend on (defaults to the active axes)
- fontsize
- The fontsize of the legend text
- loc
- The 0-8 integer location of the legend
- ncol
- The integer number of columns to divide the legend markers into
-
utilities.
marginalized_distribution
(data, figure='', xunits='', yunits='', xy='', color='b', marker='o', markersize=8, contour=True, save='')¶
-
utilities.
modelFit
(fit, spectrum, photometry, photDict, specDict, filtDict, d='', sig_d='', exclude=[], plot=False, Rlim=(0, 100), Tlim=(700, 3000), title='', weighting=True, verbose=False, save='')¶ For given spectrum [W,F,E] or dictionary of photometry, returns the best fit synthetic spectrum by varying surface gravity and effective temperature.
-
utilities.
modelInterp
(params, model_dict, filt_dict=None, plot=False)¶ Returns the interpolated model atmosphere spectrum (if model_dict==spec_dict) or photometry (if model_dict==phot_dict and filt_dict provided)
-
utilities.
modelReplace
(spectrum, model, replace=[], tails=False, plot=False)¶ Returns the given spectrum with the tuple termranges in replace replaced by the given model.
-
utilities.
montecarlo
(spectrum, modelDict, N=100, exclude=[], save='')¶ For given spectrum and dictionary of models modelDict, runs a Monte Carlo simulation N times on each model
-
utilities.
multiplot
(rows, columns, ylabel='', xlabel='', xlabelpad='', ylabelpad='', hspace=0, wspace=0, figsize=(15, 7), fontsize=22, sharey=True, sharex=True)¶ Creates subplots with given number or rows and columns.
-
utilities.
norm_spec
(spectrum, template, exclude=[], include=[])¶ Parameters: - spectrum (sequence) – The [w,f] or [w,f,e] astropy quantities spectrum to normalize
- template (sequence) – The [w,f] or [w,f,e] astropy quantities spectrum to be normalized to
- exclude (sequence (optional)) – A sequence of tuples defining the wavelength ranges to exclude in the normalization
- include (sequence (optional)) – A sequence of tuples defining the wavelength ranges to include in the normalization
Returns: spectrum – The normalized [w,f] or [w,f,e] astropy quantities spectrum
Return type: sequence
-
utilities.
norm_to_mag
(spectrum, magnitude, band)¶ Returns the flux of a given spectrum [W,F] normalized to the given magnitude in the specified photometric band
-
utilities.
normalize
(spectra, template, composite=True, plot=False, SNR=50, exclude=[], trim=[], replace=[], D_Flam=None)¶ Normalizes a list of spectra with [W,F,E] or [W,F] to a template spectrum. Returns one normalized, composite spectrum if composite, else returns the list of spectra normalized to the template.
-
utilities.
pi2pc
(parallax, parallax_unc=0, pc2pi=False)¶
-
utilities.
poly_print
(coeff_list, x='x', y='y')¶
-
utilities.
polynomial
(n, m, sig='', x='x', y='y', title='', degree=1, c='k', ls='--', lw=2, legend=True, ax='', output_data=False, plot_rms='0.9')¶
-
utilities.
printer
(labels, values, format='', truncate=150, to_txt=None, highlight=[], skip=[], empties=True, title=False)¶ Prints a nice table of values with labels with auto widths else maximum width if same else col_len if specified.
-
utilities.
random
() → x in the interval [0, 1).¶
-
utilities.
read_spec
(specFiles, errors=True, atomicron=False, negtonan=False, plot=False, linear=False, wlog=False, verbose=True)¶ (by Alejandro N |uacute| |ntilde| ez, Jocelyn Ferrara)
Read spectral data from fits or ascii files. It returns a list of numpy arrays with wavelength in position 0, flux in position 1 and error values (if requested) in position 2. More than one file name can be provided simultaneously.
Limitations: Due to a lack of set framework for ascii file headers, this function assumes ascii files to have wavelength in column 1, flux in column 2, and (optional) error in column 3. Ascii spectra are assumed to be linear, so the kwarg linear is disabled for ascii files. Fits files that have multiple spectral orders will not be interpreted correctly with this function.
- specFiles
- String with fits file name (with full path); it can also be a python list of file names.
- errors
- Boolean, whether to return error values for the flux data; return nans if unavailable.
- atomicron
- Boolean, if wavelength units are in Angstrom, whether to convert them to microns.
- negtonan
- Boolean, whether to set negative flux values equal to zero.
- plot
- Boolean, whether to plot the spectral data, including error bars when available.
- linear
- Boolean, whether to return spectrum only if it is linear. If it cannot verify linearity, it will assume linearity.
- verbose
- Boolean, whether to print warning messages.
-
utilities.
rebin_spec
(spec, wavnew, waveunits='um')¶
-
utilities.
rgb_image
(images, save='')¶ Saves an RGB false color image at save made from a stack of three images From the APLpy (Apple Pie) module (http://aplpy.readthedocs.org/en/latest/howto_rgb.html)
-
utilities.
sameName
(name1, name2, chars=4)¶ Boolean: Given names of two objects, checks that they have a certain number of name characters in common Note: discounts ‘2’ in object names with ‘2MASS’ or ‘2m’
- chars
- Number of consecutive characters to match, 4 by default. (e.g ‘2m0355’ and ‘2MASSJ0355+1234’ have ‘0355’ in common with chars=4)
-
utilities.
scrub
(data)¶ For input data [w,f,e] or [w,f] returns the list with NaN, negative, and zero flux (and corresponsing wavelengths and errors) removed.
-
utilities.
separation
(ra1, dec1, ra2, dec2)¶ Given coordinates ra1, dec1, ra2, dec2 of two objects, returns the angular separation in arcseconds.
-
utilities.
smooth
(x, beta)¶ Smooths a spectrum x using a Kaiser-Bessel smoothing window of narrowness beta (~1 => very smooth, ~100 => not smooth)
-
utilities.
specType
(SpT)¶ (By Joe Filippazzo)
Converts between float and letter/number M, L, T and Y spectral types (e.g. 14.5 => ‘L4.5’ and ‘T3’ => 23).
- SpT
- Float spectral type between 0.0 and 39.9 or letter/number spectral type between M0.0 and Y9.9
-
utilities.
squaredError
(a, b, c)¶ Computes the squared error of two arrays. Pass to scipy.optimize.fmin() to find least square or use scipy.optimize.leastsq()
-
utilities.
str2Q
(x, target='')¶ Given a string of units unconnected to a number, returns the units as a quantity to be multiplied with the number. Inverse units must be represented by a forward-slash prefix or negative power suffix, e.g. inverse square seconds may be “/s2” or “s-2”
- x
- The units as a string, e.g. str2Q(‘W/m2/um’) => np.array(1.0) * W/(m**2*um)
- target
- The target units as a string if rescaling is necessary, e.g. str2Q(‘Wm-2um-1’,target=’erg/s/cm2/cm’) => np.array(10000000.0) * erg/(cm**3*s)
-
utilities.
sxg2deg
(ra='', dec='')¶
-
utilities.
tails
(spectrum, model, plot=False)¶ Appends the Wein and Rayleigh-Jeans tails of the model to the given spectrum
-
utilities.
trim_spectrum
(spectrum, regions, smooth_edges=False)¶
-
utilities.
try_except
(success, failure, exceptions)¶ Replaces the multi-line try/except statement with a function
-
utilities.
txt2dict
(txtfile, delim='', skip=[], ignore=[], to_list=False, all_str=False, obj_col=0, key_row=0, start=1)¶ For given txtfile returns a parent dictionary with keys from obj_col and child dictionaries with keys from key_row, delimited by delim character. Characters to ignore, entire lines to skip, and the data row to start at can all be specified. Floats and integers are returned as numbers unless all_str is set True.
-
utilities.
unc
(spectrum, SNR=20)¶ Removes NaNs negatives and zeroes from spectrum arrays of form [W,F] or [W,F,E]. Generates E at signal to noise SNR for [W,F] and replaces NaNs with the same for [W,F,E].
-
utilities.
xl2dict
(filepath, sheet=1, obj_col=0, key_row=0, start=1, manual_keys='')¶