Photometric Module

class tshirt.pipeline.phot_pipeline.phot(paramFile='/home/docs/checkouts/', directParam=None)[source]

Uses fits header cards to list the files This clutters up the header, so I have now moved the fileName list to a separate structure


Adjust apertures, if scaling by FWHM


ind (int) – the index of self.fileList.


Check the file structure for plotting/saving data


Does photometry using the centroids found in get_allimg_cen

fix_centroids(diagnostics=False, nsigma=10.0)[source]

Fix the centroids for outlier positions for stars


Load an image from a given path and extensions

get_allcen_img(ind, showStamp=False)[source]

Gets the centroids for all sources in one image

get_allimg_cen(recenter=False, useMultiprocessing=False)[source]

Get all image centroids If self.param[‘doCentering’] is False, it will just use the input aperture positions :param recenter: Recenter the apertures again? Especially after changing the sources in photometry parameters :type recenter: bool :param useMultiprocessing: Use multiprocessing for faster computation?s :type useMultiprocessing: bool


A function go get the area of apertures This accommodates different versions of photutils

get_centroid(img, xGuess, yGuess)[source]

Get the centroid of a source given an x and y guess Takes the self.param[‘boxFindSize’] to define the search box

get_default_cen(custPos=None, ind=0)[source]

Get the default centroids for postage stamps or star identification maps

  • custPos (numpy array) – Array of custom positions for the apertures. Otherwise it uses the guess position

  • ind (int) – Image index. This is used to guess the position if a drift file is given

get_default_im(img=None, head=None)[source]

Get the default image for postage stamps or star identification maps


Get the default index from the file list

get_fwhm(subimg, xCen, yCen)[source]

Get the FWHM of the source in a subarray surrounding it


Get the reference-corrected time series


excludeSrc (list or None) – Numbers of the reference stars to exclude


  • t (numpy array) – time (JD - reference)

  • yCorr (numpy array) – Reference-corrected time series

  • yCorr_err (numpy array) – Reference-corrected time series error


Get the source X and Y pixel positions from coordinates


Get a simple table of the photometry after extraction


  • t1 (astropy.table object) – A table of fluxes and time

  • t2 (astropy.table object) – A table of flux errors and time

interactive_refSeries(excludeSrc=None, refCorrect=True, srcInd=0)[source]

Plot a bokeh interactive plot of the photometry This lets you see which images are outliers

  • refCorrect (bool) – Reference correct the time series?

  • excludeSrc (list or None) – Which sources to exclude from reference series

  • srcInd (int) – Which source index to plot if refCorrect is False

make_drift_file(srcInd=0, refIndex=0)[source]

Use the centroids in photometry to generate a drift file of X/Y offsets

  • srcInd (int) – The source index used for drifts

  • refIndex (int) – Which file index corresponds to 0.0 drift


Makes a Header data unit (binary FITS table) for filenames


Calculate aperture photometry using photutils


ind (int) – index of the file list on which to read in and do photometry


Plot flux versus centroid to look for flat fielding effects

plot_phot(offset=0.0, refCorrect=False, ax=None, fig=None, showLegend=True, normReg=None, doBin=None, doNorm=True, yLim=[None, None], excludeSrc=None, errBar=None, showPlot=False)[source]

Plots previously calculated photometry

  • offset (float) – y displacement for overlaying time series

  • refCorrect (bool) – Use reference star-corrected photometry?

  • ax (matplotlib axis object) – If the axis was created separately, use the input axis object

  • fig (matplotlib figure object) – If the figure was created separately, use the input axis object

  • showLegend (bool) – Show a legend?

  • normReg (list with two items or None) – Relative region over which to fit a baseline and re-normalize. This only works on reference-corrected photometry for now

  • doBin (float or None) – The bin size if showing binned data.

  • doNorm (bool) – Normalize the individual time series?

  • yLim (List) – List of Y limit to show

  • errBar (string or None) – Describes how error bars will be displayed. None=none, ‘all’=every point,’one’=representative

  • excludeSrc (List or None) – Custom sources to exclude in the averaging (to exclude specific sources in the reference time series). For example, for 5 sources, excludeSrc = [2] will use [1,3,4] for the reference

  • showPlot (bool) – Show the plot? Otherwise, it saves it to a file

poly_sub_phot(img, head, err, ind, showEach=False, saveFits=False)[source]

Do a polynomial background subtraction use robust polynomials

This is instead of using the mean or another statistic of the background aperture

print_phot_statistics(refCorrect=True, excludeSrc=None, shorten=False, returnOnly=False, removeLinear=True, startInd=0, endInd=15)[source]

Print the calculated and theoretical noise as a table

  • refCorrect (bool) – Use reference stars to correct target? If True, there is only one row in the table for the target. If False, there is a row for each star’s absolute noise

  • excludeSrc (list, or None) – A list of sources (or None) to exclude as reference stars Given by index number

  • shorten (bool) – Shorten the number of points used the time series? Useful if analyzing the baseline befor transit, for example.

  • returnOnly (bool) – If True, a table is returned. If False, a table is printed and another is returned

  • removeLinear (bool) – Remove a linear trend from the data first?

  • startInd (int) – If shorten is True, only uses a subset of the data starting with StartInd

  • endInd (int) – If shorten is True, only uses a subset of the data ending with endInd

refSeries(photArr, errPhot, reNorm=False, excludeSrc=None, sigRej=5.0)[source]

Average together the reference stars

  • reNorm (bool) – Re-normalize all stars before averaging? If set all stars have equal weight. Otherwise, the stars are summed together, which weights by flux

  • excludeSrc (arr) – Custom sources to use in the averaging (to exclude specific sources in the reference time series. For example, for 5 sources, excludeSrc = [2] will use [1,3,4] for the reference

  • sigRej (int) – Sigma rejection threshold


Reset the photometry

A reminder to myself to write a script to clear the positions. Sometimes, if you get bad positions from a previous file, they will wind up being used again. Need to reset the srcAperture.positions!

rowamp_sub_phot(img, head, err, ind)[source]

Do a row-by-row, amplifier-by-amplifier background subtraction

This is instead of using the mean or another statistic of the background aperture

save_centroids(cenArr, fwhmArr, fixesApplied=True, origCen=None, origFWHM=None)[source]

Saves the image centroid data :param cenArr: 3d array of centroids (nImg x nsrc x 2 for x/y) :type cenArr: numpy array :param fwhmArr: 3d array of fwhm (nImg x nsrc x 2 for x/y) :type fwhmArr: numpy array :param fixesApplied: Are fixes applied to the centroids? :type fixesApplied: bool :param origCen: Original array of centroids :type origCen: None or numpy array :param origFWHM: Original array of FWHMs :type origFWHM: None or numpy array


Save a reference-corrected time series

shift_centroids_from_other_file(refPhotFile, SWLW=True)[source]

Creates a centroid array where shifts are applied from another file. For example, Imaging data from another camera can be used to provide shifts to the apertures for grism data

showCustSet(index=None, ptype='Stamps', defaultCen=False, vmin=None, vmax=None, boxsize=None, showPlot=False)[source]

Show a custom stamp or star identification plot for a given image index

  • index (int) – Index of the image/centroid to show

  • ptype (str) –

    Plot type - ‘Stamps’ for postage stamps

    ’Map’ for star identification map

  • defaultCen (bool) –

    Use the default centroid? If True, it will use the guess centroids to

    show the guess before centering.

  • boxsize (int or None) – The size of the box to cut out for plotting postage stamps. If None, will use defaults. Only use when ptype is ‘Stamps’

  • showPlot (bool) – Show the plot in notebook or iPython session? If True, it will show the plot. If False, it will save the plot in the default directory.

showStamps(img=None, head=None, custPos=None, custFWHM=None, vmin=None, vmax=None, showPlot=False, boxsize=None, index=None)[source]

Shows the fixed apertures on the image with postage stamps surrounding sources


index (int) – Index of the file list. This is needed if scaling apertures

showStarChoices(img=None, head=None, custPos=None, showAps=False, srcLabel=None, figSize=None, showPlot=False, allLabels=None, apColor='black', backColor='black', vmin=None, vmax=None, index=None, labelColor='white', xLim=None, yLim=None, txtOffset=20, diffImgIndex=None)[source]

Show the star choices for photometry

  • img (numpy 2D array, optional) – An image to plot

  • head (astropy FITS header, optional) – header for image

  • custPos (numpy 2D array or list of tuple coordinates, optional) – Custom positions

  • showAps (bool, optional) – Show apertures rather than circle stars

  • srcLabel (str or None, optional) – What should the source label be? The default is “src”

  • allLabels (list of str) – Names for all aperture labels. Must be the same length as the number of sources

  • figSize (list or None, optional) – Specify the size of the plot. This is useful for looking at high/lower resolution

  • showPlot (bool) – Show the plot? If True, it will show, otherwise it is saved as a file

  • apColor (str) – The color for the source apertures

  • backColor (str) – The color for the background apertures

  • vmin (float or None) – A value for the matplotlib.pyplot.plot.imshow vmin parameter

  • vmax (float or None) – A value for the matplotlib.pyplot.plot.imshow vmax parameter

  • index (int or None) – The index of the file name. If None, it uses the default

  • labelColor (str) – Color for the text label for sources

  • xLim (None or two element list) – Specify the minimum and maximum X for the plot. For example xLim=[40,60]

  • yLim (None or two element list) – Specify the minimum and maximum Y for the plot. For example yLim=[40,60]

  • txtOffset (float) – The X and Y offset to place the text label for a source

  • diffImgIndex (int) – Choose a file index from which to subtract a reference image

show_cutout(img, aps=None, name='', percentScaling=False, src=None, ind=None)[source]

Plot the cutout around the source for diagnostic purposes


Is the source within an image? Return ‘unknown’ if no sky positions specified

tshirt.pipeline.phot_pipeline.allTser(refCorrect=False, showBestFit=False)[source]

Plot all time series for KIC 1255

  • refCorrect (bool) – Do the reference correction?

  • showBestFit (bool) – Show the best fit? If true, shows the best fit. If false, it shows the average Kepler light curve. This only works after the best fits have been previously calculated.

tshirt.pipeline.phot_pipeline.allan_variance(x, y, yerr=None, removeLinear=False, yLim=[None, None], binMin=50, binMax=2000, customShortName=None, logPlot=True, clip=False, xUnit='min', yUnit='ppm', showPlot=False, custTitle=None, nBinSequence=20, sequenceLabels=None, skipLegend=False)[source]

Make an Allan Variance plot for a time series to see if it bins as sqrt(N) statistics

  • x (numpy array) – Independent variable

  • y (numpy array or list of numpy arrays.) – Dependent variable like flux. If y is a list, loop through the y for comparison

  • keywords) ((optional)

  • yerr (numpy array or list of numpy arrays) – Theoretical error

  • customShortName (str) – Name for file

  • yLim (2 element list) – Specify custom Y values for the plot

  • binMin (int) – Bin size for the smallest # of bins

  • binMax (int) – Bin size for the largest # of bins

  • nBinSequence (int) – Number of bins to cycle through in sequence

  • removeLinear (bool) – Remove a linear trend from the time series first?

  • clip (bool) – Clip the first few points?

  • xUnit (str) – Name of units for X axis of input series

  • yUnit (str) – Name of units for Y axis to be binned

  • custTitle (str or None) – Custom title name. If None, will generate one automatically

  • showPlot (bool) – Render the plot with matplotlib? If False, it is saved instead.

  • sequenceLabels (list of strings) – If y is a list of different data sets, they can be labeled with sequenceLabels

  • skipLegend (bool) – Skip the Legend?

class tshirt.pipeline.phot_pipeline.batchPhot(batchFile='parameters/phot_params/example_batch_phot.yaml')[source]

Create several photometry objects and run phot over all of them

batch_run(method, **kwargs)[source]

Run any method of the photometry class by name. This will cycle through all parameter lists and run the method

  • method (str) – Photometry method to run in batch mode

  • **kwargs (keywords or dict) – Arguments to be passed to this method


batch_result – A list of results from the photometry method. If all results are None, then batch_run returns None

Return type:

list or None


Make a photometry pipeline object that will be executed in batch


Return a photometry object so other methods and attributes can be explored

tshirt.pipeline.phot_pipeline.do_binning(x, y, nBin=20, yerr=None, returnXwidth=False)[source]

A function that uses scipy binned_statistic to bin data

It also calculates the standard error in each bin, which can be used as an error estimate

  • x (numpy array) – Independent variable for use in assigning data to bins

  • y (numpy array) – Dependent variable to be binned

  • yerr (numpy array (optional)) – The error on the y points

  • nBin (int or numpy array) – The number of bins or else the bin array

  • returnXwidth (bool) – Return the X widths?


  • 3 item tuple

  • xBin, yBin, yStd

  • xBin (numpy array) – Middles of the bins

  • yBin (numpy array) – mean value in bin

  • yStd (numpy array) – If yerr supplied,standard error of each bin If yerr not supplied, the standard deviation of each bin

  • xWidth (numpy array) – The x widths? If returnXwidth is True

tshirt.pipeline.phot_pipeline.ensure_coordinates_are_within_bounds(xCoord, yCoord, img)[source]

Check if x and y coordinates are inside an image If they are are, spit them back. Otherwise, give the coordinates at the closest x/y edge


Takes a name of a file and makes sure the directories are there to save the file

tshirt.pipeline.phot_pipeline.exists_and_equal(dict1, key1, val1)[source]

Simple test to see if


Download all example tshirt data. This is needed to run tests and the default parameter files

class tshirt.pipeline.phot_pipeline.prevPhot(photFile='tser_data/phot/phot_kic1255_UT2016_06_12.fits')[source]

Loads in previous photometry from FITS data. Inherits functions from the phot class


photFile (str) – Directory of the photometry file

tshirt.pipeline.phot_pipeline.run_multiprocessing_phot(photObj, fileIndices, method='phot_for_one_file')[source]

Run photometry/spectroscopy methods on all files using multiprocessing Awkward workaround because multiprocessing doesn’t work on object methods

  • photObj (Photometry object) – A photometry Object instance

  • fileIndices (list) – List of file indices

  • method (str) – Method on which to apply multiprocessing


Do a photometry/spectroscopy method on one file For example, do aperture photometry on one file This is a slightly awkward workaround because multiprocessing doesn’t work on object methods So it’s a separate function that takes an object and runs the method


allInput (3 part tuple (object, int, string)) – This contains the object, file index to run (0-based) and name of the method to run


Saves the reference-corrected time series for all nights


Makes a summary of the seeing for a given night

Spectroscopic Module

class tshirt.pipeline.spec_pipeline.spec(paramFile='/home/docs/checkouts/', directParam=None)[source]
adjacent_bin_ratio(nbins=10, bin1=2, bin2=3, binMin=10, binMax=250, srcInd=0)[source]

Examine the time series for adjacent bins

  • nbins (int) – Number of bins

  • bin1 (int) – Index of the first bin

  • bin2 (int) – Index of the second bin

  • binMin (int) – start bin for allan variance

  • binMax (int) – end bin for allan variance

  • srcInd (int) – Index for the source. For a single source, the index is 0.

align_dynamic_spectra(alignStars=True, starAlignDiagnostics=False, skipIndividualDynamic=False, **kwargs)[source]

Align the dynamic spectra for multi-object spectroscopy? This method uses the mosOffsets to get the gross alignments of the dynamic spectra.

  • alignStars (bool) – Cross-correlate to find the individual star’s offsets?

  • starAlignDiagnostics (bool) – Show the diagnostics for aligning average aspectra

  • skipIndividualDynamic (bool) –

    Skip the individual dynamic spectra. Use this when trying to run

    quickly many times and use the saved versions only.

backsub_oneDir(img, head, oneDirection, saveFits=False, showEach=False, ind=None, custPrefix=None)[source]

Do the background subtraction in a specified direction Either row-by-row or column-by-column

  • img (np.array) – 2D image to be subtracted

  • head (astropy fits header) – Header of file

  • oneDirection (str) – ‘X’ does row-by-row subtraction ‘Y’ does column-by-column subtraction

  • saveFits (bool) – Save a fits file of the subtraction model?

  • showEach (bool) – Show each polynomial fit?

  • ind (int or None) – The ind in the fileL. This is mainly used for naming files, if files are being saved.

  • custPrefix (str or None) – A custom prefix for saved file names of the subtraction. If None and ind is None, it saves the prefix as unnamed If None and ind is an int, it uses the original file name


imgSub, model, head – ‘imgSub’ is a background-subtracted image ‘model’ is a background model image ‘head’ is a header for the background-subtracted image

Return type:

tuple of (numpy array, numpy array, astropy.fits.header)


from tshirt.pipeline import spec_pipeline
img, head = spec.get_default_im()
img2, bkmodel2, head2 = spec.backsub_oneDir(img,head,'X')

Calculate the source aperture (where to start/end)


Some requirements for the trace code to work

do_backsub(img, head, ind=None, saveFits=False, directions=['Y', 'X'], custPrefix=None)[source]

Do all background subtractions

  • img (numpy array) – The image do to background subtraction on

  • head (astropy.fits.header object) – The header of the image

  • ind (int, or NOne) – The index of the file list. This is used to name diagnostic images, if requested

  • saveFits (bool) – Save diagnostic FITS images of the background subtracted steps?

  • directions (list of str) – The directions to extract, such as [‘Y’,’X’] to subtract along Y and then X

  • custPrefix (str or None) – A prefix for the output file name if saving diagnostic files


  • subImg (numpy array) – Background subtracted image

  • bkgModelTotal (numpy array) – The background model

  • subHead (astropy.fits.header object) – A header for the background-subtracted image


Extract all spectroscopy

eval_trace(dispArray, src=0)[source]

Evaluate the trace function


dispArray (numpy array) – Dispersion array in pixels

find_profile(img, head, ind=None, saveFits=False, showEach=False, masterProfile=False)[source]

Find the spectroscopic profile using splines along the spectrum This assumes an inherently smooth continuum (like a stellar source)

img: numpy array

The 2D Science image

head: header object

Header from the science file

ind: int

Index of the file list (which image is begin analyzed)

saveFits: bool (optional)

Save the profile to a fits file?

showEach: bool

Show each step of the profile fitting

masterProfile: bool

Is this a master profile fit?

find_px_bins_from_waves(waveMid, waveWidth)[source]

Given a set of wavelengths centers and widths, find the pixels that will approximately give you those wavelengths, but with no pixels repeated or skipped.

find_trace(recalculateTrace=False, recalculateTraceData=False, showPlot=False)[source]

Find the trace either from saved file or trace data

  • recalculateTrace (bool) – Recalculate the trace?

  • recalculateTraceData (bool) – Recalculate the trace data?

  • showPlot (bool) – Show plot of fitting the trace?

fit_trace(img, head, showEach=False, fitMethod='astropy')[source]

Use Gaussian to fit trace and FWHM

  • img (numpy array) – 2D image to fit trace for

  • head (astropy header) – FITS header to do fitting on

  • showEach (bool) – Show each line fit?

  • fitMethod (str) – ‘astropy’ : will use models Gaussian2D + linear ‘sckpyQuick’ : will fit w/ scipy.stats.norm

get_avg_spec(src=0, redoDynamic=True, align=False)[source]

Get the average spectrum across all of the time series

  • src (int) – The index number for the source (0 for the first source’s spectrum)

  • redoDynamic (bool) – Re-run the plot_dynamic_spec method to save the average spectrum

  • align (bool) – Pass this to the plot_dynamic_spec method


  • x (numpy array) – the Wavelength dispersion values (in pixels)

  • y (numpy array) – The Flux values of the average spectrum

  • yerr (numpy array) – The error in the average flux


Calculate the median image fron n images


nImg (int) – Number of images to use for the profile

get_spec(specType='Optimal', ind=None, src=0)[source]

Get a spectrum from the saved FITS file

  • specType (str) – The type of spectrum ‘Optimal” for optimal extraction. ‘Sum’ for sum extraction

  • ind (int or None) – The index from the file list. If None, it will use the default.

  • src (int) – The source index


  • x (numpy array) – The spectral pixel numbers

  • y (numpy array) – the extracted flux

  • yerr (numpy array) – the error in the extracted flux

get_wavebin_series(nbins=10, recalculate=False, specType='Optimal', srcInd=0, binStarts=None, binEnds=None)[source]

Get a table of the the wavelength-binned time series

  • nbins (int) – The number of wavelength bins

  • recalculate (bool, optional) – Recalculate the dynamic spectrum? This is good to set as True when there is an update to the parameter file.

  • specType (str, optional) – The type of spectral extraction routine Eg. “Sum” for sum extraction, “Optimal” for optimal extraction This will be skipped over if recalculate=False and a file already exists

  • srcInd (int, optional) – The index of the source. For single objects it is 0.

  • binStarts (int, optional or None) – Pixel starting positions (or None). If None, it will be calculated as a linear spacing

  • binEnds (int, optional) – Pixel ending positions (or None). If None, it will be calculated as a linear spacing


  • t1 (astropy table) – A table of wavelength-binned flux values

  • t2 (astropy table) – A table of wavelength-binned error values


>>> from tshirt.pipeline import spec_pipeline
>>> spec = spec_pipeline.spec()
>>> t1, t2 = spec.get_wavebin_series()

Calculate the pixel location for a given wavelength Uses 1D interpolation of wavelength vs pixel

make_constant_Rgrid(wStart=None, wEnd=None, Rfixed=100, plotBins=True)[source]

Make an approximately constant R grid rounded to whole pixels

  • wStart (float) – The wavelength start for bin edges

  • wEnd (float) – The wavelength end for bin edges

  • Rfixed (float) – The spectral resolution

  • plotBins (bool) – Plot the bins over a stellar spectrum?

make_wavebin_series(specType='Optimal', src=0, nbins=10, dispIndices=None, recalculate=False, align=False, refCorrect=False, binStarts=None, binEnds=None)[source]

Bin wavelengths together and generate a time series from the dynamic spectrum

  • specType (str) – Type of extraction ‘Optimal’ vs ‘Sum’

  • src (int) – Which source index is this for

  • nbins (int) – Number of wavelength bins

  • dispIndices (list of ints) – The detector pixel indices over which to create the wavelength bins

  • recalculate (bool) – Re-caalculate the dynamic spectrum?

  • align (bool) – Automatically align all the spectra? This is passed to plot_dynamic_spec

  • refCorrect (bool) – Use the reference corrected photometry?

  • binStarts (numpy array or None) – Specify starting points for the bins. If None, binStarts are calculated automatically

  • binEnds (numpy array or None) – Specify starting points for the bins w/ Python, so the last point is binEnds - 1. If None, binEnds are calculated automatically.

norm_spec(x, y, numSplineKnots=None, srcInd=0)[source]

Normalize spec

periodogram(src=0, ind=None, specType='Optimal', showPlot=True, transform=None, trim=False, logY=True, align=False)[source]

Plot a periodogram of the spectrum to search for periodicities


showPlot (bool) – If True, a plot is rendered in matplotlib widget If False, a plot is saved to file

plot_dynamic_spec(src=0, saveFits=True, specAtTop=True, align=False, alignDiagnostics=False, extraFF=False, specType='Optimal', showPlot=False, vmin=None, vmax=None, flipX=False, waveCal=False, topYlabel='', interpolation=None, smooth2D=None)[source]

Plots a dynamic spectrum of the data

  • showPlot (bool) – Show the plot in addition to saving?

  • saveFits (bool) – Save a FITS file of the dynamic spectrum?

  • specAtTop (bool) – Plot the average spectrum at the top of the dynamic spectrum?

  • align (bool) – Automatically align all the spectra?

  • alignDiagnostics (bool) – Show diagnostics of the alignment process?

  • extraFF (bool) – Apply an extra flattening step?

  • specType (str) – Spectrum type - ‘Optimal’ or ‘Sum’

  • showPlot – Show a plot with the spectrum?

  • vmin (float or None) – Value minimum for dynamic spectrum image

  • vmax (float or None) – Value maximum for dynamic spectrum image

  • flipX (bool) – Flip the X axis?

  • interpolation (None or str) – plot interpolation to use for matplotlib imshow()

  • topYlabel (str) – The label for the top Y axis

  • waveCal (bool) – Calibrate the dispersion to wavelength?

  • smooth2D (None or 2 element list) – If None, no smoothing. If a 2 element list [x_std,y_std], astropy convolve with 2D Gaussian kernel

plot_noise_spectrum(src=0, showPlot=True, yLim=None, startInd=0, endInd=None, waveCal=False, waveBin=False, nbins=10, returnNoiseSpec=False)[source]

Plot the Noise Spectrum from the Dynamic Spectrum

  • src (int) – Index number for the source

  • showPlot (bool) – Show a plot in backend?

  • yLim (list or None) – Specify the y limits

  • startInd (int) – Starting time index to use

  • endInd (int or None) – Ending index to use. None will use all

  • waveCal (bool) – Wavelength calibrate the dispersion pixel

  • waveBin (bool) – Bin the wavelengths ?

  • nbins (int) – How many wavelength bins should be used?

  • returnNoiseSpec (bool) – Return the noise spectrum? If True, an astropy table is returned

plot_one_spec(src=0, ind=None, specTypes=['Sum', 'Optimal'], normalize=False, numSplineKnots=None, showPlot=True, waveCal=False)[source]

Plot one example spectrum after extraction has been run

  • src (int, optional) – The number of the source to plot

  • ind (int or None, optional) – An index number to pass to get_spec(). It tells which spectrum to plot. Defaults to number of images //2

  • specTypes (list of strings, optional) – List of which spectra to show ‘Sum’ for sum extraction ‘Optimal’ for optimal extraction

  • normalize (bool, optional) – Normalize and/or flatten spectrum using self.norm_spec

  • numSplitKnots (int or None, optional) – Number of spline knots to pass to self.norm_spec for flattening

  • showPlot (bool) – Show the plot in widget? If True, it renders the image with If False, saves an image

  • waveCal (bool) – Wavelength calibrate the X axis? If False, gives dispersion pixels

plot_wavebin_series(nbins=10, offset=0.005, showPlot=False, yLim=None, xLim=None, recalculate=False, dispIndices=None, differential=False, interactive=False, unit='fraction', align=False, specType='Optimal', src=0, refCorrect=False, binStarts=None, binEnds=None, timeBin=False, nTimeBin=150, waveLabels=False)[source]

Plot a normalized lightcurve for wavelength-binned data one wavelength at a time with an offset between the lightcurves.

  • nbins (int) – The number of wavelength bins to use

  • offset (float) – The normalized flux offset between wavelengths

  • showPlot (bool) – Show the plot widget? The result also depends on the interactive keyword. If interactive is True, showPlot is ignored and it saves an html file in plots/spectra/interactive/. If False (and interactive is False), it is saved in plots/spectra/wavebin_tseries/. If True (and interactive is False), no plot is saved and instead the plot is displayed in the matplotlib framework.

  • yLim (list of 2 elements or None) – If None, it will automatically set the Y axis. If a list [y_min,y_max], it will make the Y axis limits y_min to y_max

  • xLim (list of 2 elements or None) – If None, it will automatically set the X axis. If a list [x_min,x_max], it will make the X axis limits x_min to x_max

  • recalculate (bool) – If True, it will calculate the values from the dynamic spectrum. If False, it will used cached results from a previous set of lightcurves.

  • dispIndices (list of 2 elements or None) – If None, it will use the dispIndices from the parameter file. If a 2 element list of [disp_min,disp_max], it will use those coordinates

  • differential (bool) – If True, it will first divide each wavelength’s lightcurve by the lightcurve average of all wavelengths. This means that it shows the differential time series from average. If False, no division is applied (other than normalization)

  • interactive (bool) – If True, it will use bokeh to create an interactive HTML javascript plot where you can hover over data points to find out the file name for them. It saves the html plot in plots/spectra/interactive/. If False, it will create a regular matplotlib plot.

  • unit (str) – Flux unit. ‘fraction’ or ‘ppm’

  • specType (str) – Type of extraction ‘Optimal’ vs ‘Sum’

  • align (bool) – Automatically align all the spectra? This is passed to plot_dynamic_spec

  • src (int) – Index number for which spectrum to look at (used for Multi-object spectroscopy)

  • refCorrect (bool) – Correct by reference stars for MOS?

  • timeBin (bool) – Bin the points in time?

  • nTimeBin – Number of points to bin in time

print_noise_wavebin(nbins=10, shorten=False, recalculate=False, align=False, specType='Optimal', npoints=15, srcInd=0, startInd=0, endInd=None)[source]

Get a table of noise measurements for all wavelength bins

  • nbins (int) – The number of wavelength bins

  • shorten (bool) – Use a short segment of the full time series? This could be useful for avoiding bad data or a deep transit. This overrides startInd and endInd so choose either shorten or specify the start and end indices

  • npoints (int) – Number of points to include in the calculation (only if shorten is True) This will only use the first npoints.

  • startInd (int) – Starting time index to use (for specifying a time interval via indices) Shorten will supercede this so keep it False to use startInd.

  • endInd (int) – Ending time index to use (for specifying a time interval via indices). Shorten will supercede this so keep it False to use endInd.

  • recalculate (bool) – Recalculate the wavebin series and dynamic spectrum?

  • specType (str) – Type of extraction ‘Optimal’ vs ‘Sum’

  • align (bool) – Automatically align all the spectra? This is passed to plot_dynamic_spec

  • srcInd (int) – Index for the source. For a single object, the index is 0.


t – A table of wavelength bins, with theoretical noise and measured standard deviation across time

Return type:

an astropy.table object

profile_normalize(img, method='sum')[source]

Renormalize a profile along the spatial direction


img (numpy array) – The input profile image to be normalized


Read the covariance-weights for a fixed profile through the time series


Read in the master profile for each source if using a single profile for all images


Divide the (aligned) dynamic spectra of one source by another for MOS


mainSrcIndex (int) – The main source that will be divided by references


Save all background-subtracted images


Save a background-subtracted

showStarChoices(img=None, head=None, showBack=True, srcLabel=None, figSize=None, vmin=None, vmax=None, xlim=None, ylim=None, showPlot=False)[source]

Show the star choices for spectroscopy

  • img (numpy 2D array, optional) – An image to plot

  • head (astropy FITS header, optional) – header for image

  • showBack (bool, optional) – Show the background subtraction regions?

  • srcLabel (str or None, optional) – What should the source label be? The default is “src”

  • vmin (float, optional) – Minimum value for imshow

  • vmax (float) – (optional) Maximum value for imshow

  • figSize (2 element list) – (optional) Specify the size of the plot This is useful for looking at high/lower resolution

  • xlim (list or None) – (optional) Set the x limit of plot

  • ylim (list or None) – (optional) Set the y limit of plot

  • showPlot (bool) – Make the plot visible?

spec_for_one_file(ind, saveFits=False, diagnoseCovariance=False)[source]

Get spectroscopy for one file Calculate the optimal and sum extractions

If saveRefRow is True, the reference pixel row will be saved

  • ind (int) – File index

  • saveFits (bool) – Save the background subtraction and profile fits?

  • diagnoseCovariance (bool) – Diagnostic information for the covariance profile weighting

wavebin_specFile(nbins=10, srcInd=0)[source]

The name of the wavelength-binned time series file

  • nbins (int) – The number of wavelength bins

  • srcInd (int) – The index for the source. For a single source the index is 0.

wavecal(dispIndicesInput, waveCalMethod=None, head=None, dispShift=None, **kwargs)[source]

Wavelength calibration to turn the dispersion pixels into wavelengths

  • dispIndices (numpy array) – Dispersion Middle X-axis values

  • waveCalMethod (str, optional) – Corresponds to instrumentation used. Use ‘NIRCamTS’ for the NIRCam time series mode (jwst_inst_funcs.ts_wavecal). Use ‘wfc3Dispersion’ for the HST WFC3 grism (ts_wavecal).

  • head (astropy FITS header, optional) – header for image

  • dispShift (None or float) – Value by which to shift the disp indices before evaluating the wavelengths (for example a star is shifted). If None, it will use the value from the parameter ‘waveCalPxOffset’

class tshirt.pipeline.spec_pipeline.batch_spec(batchFile='parameters/spec_params/example_batch_spec_parameters.yaml')[source]

Make a spectroscopy pipeline object that will be executed in batch


Return a photometry object so other methods and attributes can be explored


Return a photometry object so other methods and attributes can be explored

tshirt.pipeline.spec_pipeline.compare_spectra(fileNames=[], specType='Optimal', showPlot=False, normalize=False)[source]

Compare multiple spectra

  • specType (str) – Which spectrum extension to read? (eg. ‘Optimal’ vs ‘Sum’)

  • showPlot (bool) – Render the matplotlib plot? If True, it is rendered as a matplotlib widget, not saved. If False, the plot is saved to file only

  • normalize (bool) – Normalize all the spectra by dividing by the median first?

tshirt.pipeline.spec_pipeline.make_const_R_grid(wStart=2.45, wEnd=3.96, Rfixed=100)[source]

Make a constant-resolution grid

for F444W NIRCam at R=100, I used wStart=3.911238, wEnd=5.0,Rfixed=100

  • wStart (float) – The wavelength start for bin edges

  • wEnd (float) – The wavelength end for bin edges

  • Rfixed (float) – The spectral resolution

Instrument-Specific Modules

tshirt.pipeline.instrument_specific.hst_inst_funcs.hstwfc3_wavecal(dispIndices, xc0=75.0, yc0=75.0, DirIm_x_appeture=522, DirIm_y_appeture=522, SpecIm_x_appeture=410, SpecIm_y_appeture=522, subarray=128)[source]

Wavelength calibration to turn the dispersion pixels into wavelengths

  • dispIndices (numpy array) – Dispersion Middle X-axis values

  • xc0 (float) – Initial X coordinate of direct image centroid

  • yc0 (float) – Initial Y coordinate of direct image centroid

  • DirIm_x_appeture (float) – Chip Reference X-Pixel dependent upon direct image centroid apeture

  • DirIm_y_appeture (float) – Chip Reference Y-Pixel dependent upon direct image centroid apeture

  • SpecIm_x_appeture (float) – Chip Reference X-Pixel dependent upon spectral image centroid apeture

  • SpecIm_y_appeture (float) – Chip Reference Y-Pixel dependent upon spectral image centroid apeture

  • subarray – Length of detector array


Note that direct image and spectral image should be taken with the same aperture. If not, please adjust the centroid measurement according to table in:

tshirt.pipeline.instrument_specific.jwst_inst_funcs.flight_poly_grismr_nc(pixels, obsFilter='F322W2', detectorPixels=False)[source]

Flight polynomials for NIRCam GRISMR grism time series

  • obsFilter (str) – NIRCam Observation filter: F322W2 or F444W

  • detectorPixels (bool) – Are the pixels in detector pixels from raw fitswriter output? This should be False for the MAST products in DMS format


Polynomial fit to transformed Y coordinate

## See this file /Users/~/Documents/jwst/flight_data/proc/01185/wasp69b_proc/miri_lrs_rate/lrs_wavecal.ipynb I ran wcs_step = assign_wcs.AssignWcsStep() Then calculated wavelengths with: xcor,ycor,wavearr = wcs_res.meta.wcs(37 * np.ones(NY),y_array)


Simple Polynomial fit to the NIRSpec prism Uses the jwst pipeline evaluated at Y=16 on 2022-07-15


Simple analytic wavelength calibration for Simulated GRISMC data

tshirt.pipeline.instrument_specific.jwst_inst_funcs.ts_wavecal(pixels, tserSim=False, obsFilter='F444W', subarray='SUBGRISM64', grism='GRISM0')[source]

Simple analytic wavelength calibration for NIRCam grism time series

tshirt.pipeline.instrument_specific.jwst_inst_funcs.ts_wavecal_quick_nonlin(pixels, obsFilter='F322W2')[source]

Simple inefficient polynomial


Do a column-by-column slow read correction instead of an even/odd correction

tshirt.pipeline.instrument_specific.rowamp_sub.do_backsub(img, photObj=None, amplifiers=4, saveDiagnostics=False, evenOdd=True, activePixMask=None, backgMask=None, grismr=False, returnFastSlow=False, colByCol=False, smoothSlowDir=None, badRowsAllowed=0, GROEBA=False, GPnsmoothKern=None, showGP1D=False)[source]

Do background subtraction amplifier-by-amplifier, row-by-row around the sources

  • img (numpy 2D array) – The input uncorrected image

  • photObj ((optional) a tshirt photometry pipeline object) – If supplied, it will use the background apertures to mask out sources

  • amplifiers (int) – How many outputamplifiers are used? 4 for NIRCam stripe mode and 1 is for 1 output amplifier

  • evenOdd (bool) – Remove the even and odd offsets before doing row-by-row medians?

  • colByCol (bool) – Do column-by-column subtraction. This will supercede the even/odd correction.

  • saveDiagnostics (bool) – Save diagnostic files?

  • activePixMask (numpy 2D array or None) –

    Mask of reference pixels to ignore (optionally). Pixels that are False

    will be ignored in the background estimation, and pixels that are true will be kept in the background estimation. If refpixMask is None no extra points will be masked

  • badRowsAllowed (int) –

    Number of bad rows to accept and still do fast-read correction

    (ie. if not enough background and/or ref pixels, no fast-read correction can be done)

  • backgMask (numpy 2D array or None) –

    Mask for the background. Pixels that are False will be ignored in

    row-by-row background estimation. Pixels that are true will be kept for the background estimation.

  • grismr (bool) –

    Is this NIRCam GRISMR data? Special treatment is needed for NIRCam

    GRISMR, where the spectra run through multiple amplifiers

  • returnFastSlow (bool) – Return both the fast and slow read models?

  • smoothSlowDir (None or float) – Length of the smoothing kernel to apply along the fast read direction If None, no smoothing is applied

  • GROEBA (bool) – Use Gaussian-Process row-by-row, odd/even by amplifier subtraction? This will use a Gaussian process to do 1/f noise interpolation

  • GPnsmoothKern (int or None) – (only if GROEBA==True). Specify the window length for a Savgol smoothing filter for the GP. Otherwise it is chosen automatically

  • showGP1D (bool) – (only if GROEBA==True). Plot the GP prediction in 1D


Do an even-odd correction for a given amplifier If only one amplifier is used, it can be the whole image


Make a Gaussian Process Kernel for 1/f corrections


sigma_w (float) – White noise error in DN


Show the power spectral density function for the Gaussian process

Image Preparation Module

tshirt.pipeline.prep_images.lbt_luci2_lincor(img, dataUnit=Unit('adu'), ndit=1.0, k2=2.767e-06)[source]

LUCI2 linearity correction from

Input image should be in ADU

  • img (numpy array) – An input image to do linearity correction on

  • dataUnit (astropy unit) – Unit of the image, such as astropy.units.adu

  • ndit (float) – The number of the detection integration time in LUCI2’s readout system This has to be updated for the science observations in question

  • k2 (float) – Quadratic coefficient in non-linearity correction


ADUlin * ndit – A new image that has been linearity-corrected

Return type:

numpy array

class tshirt.pipeline.prep_images.prep(paramFile='parameters/reduction_parameters/example_reduction_parameters.yaml', testMode=False, rawIndex=0)[source]

Class for reducing images Parameters are located in parameters/reduction_parameters


Check if non-linearity correction should be applied

fix_pix_line(img, direction='row')[source]

Fix pixels

getData(fileName, normalize=False)[source]

Gets the data and converts to CCDData type


normalize (bool) – Normalize by the median? Useful for sky flats

get_fileL(fileSearchInfo, searchType='generic')[source]

Search for a list of files Tests out if the user put in a string w/ wildcard or a list of files


Makes the master calibration files


Process the science images


Reduce all files listed in reduction parameters

Pipeline Utilities

tshirt.pipeline.utils.crosscor_offset(x, y1, y2, Noffset=150, diagnostics=False, flatteningMethod='filter', highPassFreq=0.01, lowPassFreq=None, subPixel=False)[source]

Cross correlate two arrays to find the offset

First, a filter is applied to each array to remove low frequency stuff

  • x (numpy array) – Array for the x values

  • y1 (numpy array) – The first signal assumed to be the reference

  • y2 (numpy array) – The second signal where the shift is desired to the reference

  • Noffset (int) – number of offset points to explore

  • diagnostics (bool) – Show diagnostic plots?

  • flatteningMethod (str) –

    What kind of flattening method should be used on the arrays?

    ’filter’ will apply a filter ‘polynomial’ will divide by a polynomial

  • highpassFreq (float) – The frequency (on a scale from Nyquist to 1) to pass information

  • subPixel (bool) – Fit the cross-correlation at the subpixel level?

tshirt.pipeline.utils.flatten(x, y, flatteningMethod='filter', polyOrd=2, highPassFreq=0.01, normalize=True, lowPassFreq=None)[source]

Flatten a time series/array

tshirt.pipeline.utils.robust_poly(x, y, polyord, sigreject=3.0, iteration=3, useSpline=False, knots=None, preScreen=False, plotEachStep=False)[source]

Fit a function (with sigma rejection) to a curve

  • x (numpy array) – Independent variable

  • y (numpy array) – Dependent variable

  • polyord (int) – order of the fit (number of terms). polyord=1 is a linear fit, 2 is a quadratic, etc.

  • sigreject (float) – The ‘sigma’ rejection level in terms of median absolute deviations

  • useSpline (bool) – Do a spline fit?

  • knots (int or None) – How many knots to use if doing a spline fit

  • preScreen (bool) – Pre-screen by removing outliers from the median (which might fail for large slopes)

  • plotEachStep (bool) – Plot each step of the fitting?


import numpy as np
from tshirt.pipeline import phot_pipeline
import matplotlib.pyplot as plt

x = np.arange(30)
y = np.random.randn(30) + x
y[2] = 80 ## an outlier
polyfit = phot_pipeline.robust_poly(x,y,1)
ymodel = np.polyval(polyfit,x)
tshirt.pipeline.utils.roll_pad(y, pixShift, pad_value=nan, order=1)[source]

Similar as numpy roll (shifting) but make sure the wrap-arounds are NaN Converts to floating point since the Nans are weird for integer arrays

If pixShift is an integer, it does whole-pixel shifts Otherwise, it will do linear interpolation to do the subpixel shift


Test the rolling function

Pipeline Analysis Module

tshirt.pipeline.analysis.adjust_aperture_set(phot_obj, param, srcSize, backStart, backEnd, showPlot=False, plotHeight=None)[source]

Takes a photometry or spectroscopy object and sets the aperture parameters

  • phot_obj (a tshirt phot or spec object) – Input object to be adjusted

  • param (dictionary) – A parameter dictionary for a phot or spec object

  • showPlot (bool) – Show a plot of the aperture set?

  • plotHeight (float) – A size of the photometry plot (only works for photometry)


new_phot – Spec or phot object w/ modified parameters

Return type:

a tshirt phot or spec object

tshirt.pipeline.analysis.aperture_size_sweep(phot_obj, stepSize=5, srcRange=[5, 20], backRange=[5, 28], minBackground=2, stepSizeSrc=None, stepSizeBack=None, shorten=False)[source]

Calculate the Noise Statistics for a “Sweep” of Aperture Sizes Loops through a series of source sizes and background sizes in a grid search

  • stepSize (float) – The step size. It will be superseded by stepSize_bck or stepSizeSrc if used.

  • srcRange (two element list) – The minimum and maximum src radii to explore

  • backRange (two element list) – The minimum and maximum aperture radii to explore (both for the inner & outer)

  • minBackground (float) – The minimum thickness for the background annulus or rectangle width

  • stepSizeSrc (float) – (optional) Specify the step size for the source that will supersed the general stepSize

  • stepSizeBack (float) – (optional) Specify the step size for the background that will supersed the general stepSize

  • shorten (bool) – Shorten the time series? (This is passed to print_phot_statistics)

tshirt.pipeline.analysis.backsub_list(specObj, outDirectory='tmp')[source]

Save all the background-subtracted images


specObj (a any::tshirt.pipeline.spec_pipeline.spec object)

tshirt.pipeline.analysis.plot_apsizes(apertureSweepFile, showPlot=True)[source]

Plot the aperture sizes calculated from aperture_size_sweep

  • apertureSweepFile (str) – A .csv file created by aperture_size_sweep

  • showPlot (bool) – Show the plot w/ matplotlib? otherwise, it saves to file