Data Preparation (photometry.prepare)

Preparation for Photometry extraction.

Code author: Rasmus Handberg <>

photometry.prepare.prepare_photometry(input_folder=None, sectors=None, cameras=None, ccds=None, calc_movement_kernel=False, backgrounds_pixels_threshold=0.5, output_file=None)[source]

Restructure individual FFI images (in FITS format) into a combined HDF5 file which is used in the photometry pipeline.

In this process the background flux in each FFI is estimated using the backgrounds.fit_background() function.

  • input_folder (str) – Input folder to create TODO list for. If None, the input directory in the environment variable TESSPHOT_INPUT is used.

  • sectors (iterable of int, optional) – TESS Sectors. If None, all sectors will be processed.

  • cameras (iterable of int, optional) – TESS camera number (1-4). If None, all cameras will be processed.

  • ccds (iterable of int, optional) – TESS CCD number (1-4). If None, all cameras will be processed.

  • calc_movement_kernel (bool, optional) – Should Image Movement Kernels be calculated for each image? If it is not calculated, only the default WCS movement kernel will be available when doing the folllowing photometry. Default=False.

  • backgrounds_pixels_threshold (float) – Percentage of times a pixel has to use used in background calculation in order to be included in the final list of contributing pixels. Default=0.5.

  • output_file (str, optional) – The file path where the output file should be saved. If not specified, the file will be saved into the input directory. Should only be used for testing, since the file would (proberly) otherwise end up with a wrong file name for running with the rest of the pipeline.


NotADirectoryError – If the specified input_folder is not an existing directory or if settings table could not be loaded from the catalog SQLite file.

Code author: Rasmus Handberg <>

photometry.prepare.quality_from_tpf(tpffile, time_start, time_end)[source]

Transfer quality flags from Target Pixel File to FFIs.

Only quality flags in TESSQualityFlags.FFI_RELEVANT_BITMASK are transfered.

  • tpffile (string) – Path to Target Pixel File to load quality flags from.

  • time_start (ndarray) – Array of start-timestamps for FFIs.

  • time_end (ndarray) – Array of end-timestamps for FFIs.


Quality flags for FFIs coming from Target Pixel File.

Return type:


Code author: Rasmus Handberg <>

Background estimation (photometry.backgrounds)

Estimation of sky background in TESS Full Frame Images.

Code author: Rasmus Handberg <>

class photometry.backgrounds.ModeBackground(sigma_clip=SigmaClip(sigma=3.0, sigma_lower=3.0, sigma_upper=3.0, maxiters=10, cenfunc='median', stdfunc='std', grow=False))[source]

Bases: BackgroundBase

calc_background(data, axis=None)[source]

Calculate the background value.

  • data (array_like or – The array for which to calculate the background value.

  • axis (int or None, optional) – The array axis along which the background is calculated. If None, then the entire array is used.

  • masked (bool, optional) – If True, then a is returned. If False, then a ~numpy.ndarray is returned, where masked values have a value of NaN. The default is False.


result – The calculated background value. If masked is False, then a ~numpy.ndarray is returned, otherwise a is returned. A scalar result is always returned as a float.

Return type:

float, ~numpy.ndarray, or

photometry.backgrounds.fit_background(image, catalog=None, flux_cutoff=80000.0, bkgiters=3, radial_cutoff=2400, radial_pixel_step=15, radial_smooth=3)[source]

Estimate background in Full Frame Image.

The background is estimated using a combination of a 2D estimate of the mode of the images (using background estimator from SExtractor), and a radial component to account for the corner-glow that is present in TESS FFIs.

  • image (ndarray or str) – Either the image as 2D ndarray or a path to FITS or NPY file where to load image from.

  • catalog (astropy.table.Table) – Catalog of stars in the image. Is currently not yet being used for anything.

  • flux_cutoff (float) – Flux value at which any pixel above will be masked out of the background estimation.

  • bkgiters (int) – Number of times to iterate the background components. Default=3.

  • radial_cutoff (float) – Radial distance in pixels from camera centre to start using radial component. Default=2400.

  • radial_pixel_step (int) – Step sizes to use in radial component. Default=15.

  • radial_smooth (int) – Width of median smoothing on radial profile. Default=3.


  • ndarray: Estimated background with the same size as the input image.

  • ndarray: Boolean array specifying which pixels was used to estimate the background

    (True if pixel was not used).

Return type:


Code author: Rasmus Handberg <>