API Package

exowirc.calib_utils module

exowirc.fit_utils module

exowirc.io_utils module

exowirc.io_utils.get_bkg_file_name(direc, bkg_num, style='wirc')
exowirc.io_utils.get_calib_file_names(direc, dark_num, flat_num, style='wirc')
exowirc.io_utils.get_img_name(direc, number, style='wirc', img_type='')

Gets the image name in WIRC convention

This function will take an image directory and number and gives the image name. :param number: The image number. :type number: int :param direc: The directory in which the image is stored. :type direc: str :param style: Either ‘wirc’ or ‘image’ to precede the number. :type style: str :param img_type: For instance ‘master_dark’, etc. :type img_type: str

Returns

The correct path to the required file.

Return type

str

exowirc.io_utils.get_science_img_list(science_ranges)
exowirc.io_utils.init_output_direcs(path, test_name)

Initializes all output directories

exowirc.io_utils.init_phot_dirs(dump_dir, img_dir, rads)
exowirc.io_utils.load_bkgs(dump_dir)
exowirc.io_utils.load_calib_files(flat, dark, bp, hp, nonlinearity_fname=None)
exowirc.io_utils.load_calib_img(calib_dir, img_number, style='wirc', img_type='')
exowirc.io_utils.load_multicomponent_frame(dump_dir)
exowirc.io_utils.load_phot_data(dump_dir, aperture)
exowirc.io_utils.save_covariates(dump_dir, covariate_dict)
exowirc.io_utils.save_image(data, imname)
exowirc.io_utils.save_multicomponent_frame(mcf, dump_dir)
exowirc.io_utils.save_phot_data(dump_dir, xpos, ypos, widths, raw_phot, errs, tag='')

exowirc.photo_utils module

exowirc.photo_utils.accurate_cent(data, xc, yc, radius=3.0, max_iter=100, max_pos_error=0.01)

Iterative flux-weighted centroiding for getting the apertures placed precisely.

Parameters
  • data (array_like, shape(N, N)) – The cutout on which the centroiding will be performed

  • xc (float) – Initial guess at the x coordinate of the centroid

  • yc (float) – Initial guess at the y coordinate of the centroid

  • radius (float, optional) – Pixel radius from the initial guess centroid that the calculated centroid is expected to reside on the image, default is 3.

  • max_iter (int, optional) – The max number of iterations of centroiding to perform (The actual number of iterations may be less). Default is 100.

  • max_pos_error (float, optional) – The maximimum positional error allowed before returning the calculated centroid, default is 0.01.

Returns

  • xc (float) – x centroid

  • yc (float) – y centroid

exowirc.photo_utils.clean_sources(sources, fwhm, bad_channel=False)

Cleans (i.e. removes) all sources close to the edge of the detector as well as sources that overlap with the apertures.

Parameters
  • sources (astropy.Table or dict) – Table of source locations with x and y centroids

  • fwhm (float) – Approximate FWHM of source PSFs. If sources are less than a FWHM from a detector edge, they’ll automatically be removed.

Returns

sources – Cleaned Table of source locations with bad sources removed.

Return type

astropy.Table or dict

exowirc.photo_utils.construct_bkg(background, scale_factors, multicomponent_frame)

Create a background frame specifically for the helium data.

Parameters
  • background (numpy.ndarray) – A stack of the background sky image data

  • scale_factors (numpy.ndarray) – An array of scale factors for each of the sky images that are part of the background dither sequence, relating the individual image median value bacto that of the first frame in the background sequence

  • multicomponent_frame (numpy.ndarray) – 2048 x 2048 numpy array representing radial distances from the filter center of the helium arc, used for correcting brightness variation due to the helium arc structure

Returns

An updated stack of sky background image data adjusted in brightness by the scale factors and with the multicomponent frame

Return type

numpy.ndarray

exowirc.photo_utils.find_my_source(sources, target_coords, tolerance=10)

Given a list of sources and an initial guess for the coordinates of the target, determines the index of the target source.

Parameters
  • sources (astropy.Table or dict) – Table of source locations with x and y centroids

  • target_coords (tuple, shape:(2)) – An (x, y) tuple describing approximately where the target is located

  • tolerance (float, optional) – The maximum distance away (in pixels) from the guess for a source to be considered correctly identified. If it’s small, your guess better be really good. If it’s big, be careful of additional nearby sources.

Returns

index – If the source is found, this is the index of the source in the sources dict. If not, None will be returned.

Return type

int or None

exowirc.photo_utils.find_sources(image, fwhm=20.0, sigma_threshold=20.0)

Using the photutils DAOStarFinder algorithm, automatically identify sources of a certain FWHM and a certain SNR.

Parameters
  • image (numpy.ndarray, shape(2048, 2048)) – The finding frame in which the sources will be located

  • fwhm (float, optional) – The approximate FWHM of all the sources to be detected

  • sigma_theshold (float, optional) – The number of sigmas that a source needs to be to be detected

Returns

sources – A Table of the detected sources with xcentroid, ycentroid, and some other auxilliary stats

Return type

astropy.Table

exowirc.photo_utils.fit_cut(arr, xval, yval)

Fit a gaussian profile to the star’s PSF and then cut the guassian profile to calculate the FWHM in function get_aperature_sum().

Parameters
  • arr (numpy.ndarray) – A localized 2D numpy image array of pixel brightness around the star. Supports the function make_image_arrs()

  • xval (int) – x-coordinate

  • yval (int) – y-coordinate

Returns

THE FWHM from the gaussian fit of the star’s PSF

Return type

flat

exowirc.photo_utils.gauss(x, *p)

Calculate a gaussian curve. Supports the scipy function curve_fit().

Parameters

x (float) – data point

Returns

y data point fitted to the gaussian curve described by parameters *p

Return type

float

exowirc.photo_utils.get_aperture_sum(sources, image, radii=[10.0], error=None, ann_rads=(25, 50), target_ind=0)

Given a list of sources, re-calculates image centroids via flux-weighted centroiding and performs aperture photometry on all the sources. All counts in the aperture are summed, and the local background is estimated using an annulus.

Parameters
  • sources (astropy.Table or dict) – Table of source locations with x and y centroids

  • image (numpy.ndarray, shape(2048, 2048)) – The finding frame in which the sources will be located

  • radius (numpy.ndarray, optional) – Radii of the apertures for the photometry

  • error (None or numpy.ndarray, shape(2048, 2048), optional) – If None, errors will not be calculated during photometry. If numpy.ndarray, the errors will be used to produce error estimates on the photometry

  • ann_rads (tuple, optional) – Tuple of form (float1, float2), where float1 specifies the inner radius and float2 specifies the outer radius of the annulus that will be used for local background subtraction

  • target_ind (int) – Index location of the target in the list of sources. Default to 0 because index loaction of the source coordinate is conventionally marked at the 0th index, and function find_my_source() moves the source with target coordinate to the top of the list

Returns

  • phot_table (astropy.Table) – Table with aperture sums for each radius and errors (if specified by input params)

  • xs (numpy.ndarrays) – Array of x centroids of all the sources

  • ys (numpy.ndarrays) – Array of y centroids of all the sources

  • widths (numpy.ndarrays) – Array of PSF widths for all the sources

exowirc.photo_utils.get_source_first(source_ind, xpos, ypos, widths, phot, errs)

Moves the source to be index 0 in each of the photometry and auxilliary arrays. Bubbling up target star to be index 0 in the list of stars.

Parameters
  • source_ind (int, optional) – Index of the target trace for all of the arrays.

  • xpos (array_like) – Array containing all the x coordinates for the centroids of every source

  • ypos (array_like) – Array containing all the y coordinates for the centroids of every source

  • widths (array_like) – Array containing the widths for every source PSF

  • phot (array_like) – Array containing the photometry for each of the sources

  • errs (array_like) – Array containing the raw errors for each of the sources

Returns

  • xpos (array_like) – Array containing all the x coordinates for the centroids of every source with the target as index 0

  • ypos (array_like) – Array containing all the y coordinates for the centroids of every source with the target as index 0

  • widths (array_like) – Array containing the widths for every source PSF with the target as index 0

  • phot (array_like) – Array containing the photometry for each of the sources with the target as index 0

  • errs (array_like) – Array containing the raw errors for each of the sources with the target as index 0

exowirc.photo_utils.init_data(n_sources, n_images, radii)

Initializes all the data storage arrays and dictionaries.

Parameters
  • n_sources (int) – Number of sources on which the photometry is being performed

  • n_images (int) – Number of images to perform photometry on

  • radii (numpy.ndarray) – The radii of the apertures for photometry

Returns

  • xpos_arr (numpy.ndarray, shape(n_sources, n_images)) – Storage array for x centroid positions

  • ypos_arr (numpy.ndarray, shape(n_sources, n_images)) – Storage array for y centroid positions

  • psf_widths (numpy.ndarray, shape(n_sources, n_images)) – Storage array for the widths of the source PSFs

  • phot_dict (dict of numpy.ndarray, shape(n_sources, n_images)) – Dictionary mapping aperture radius to aperture sum for each source and image number

  • err_dict (dict of numpy.ndarray, shape(n_sources, n_images)) – Dictionary mapping aperture radius to error on aperture sum for each source and image number

exowirc.photo_utils.make_img_arrs(sources, rad, img)

Given a list of sources and the image, make a list of smaller cutouts centered on each source. The cutouts go from (center - radius) to (center + rad) in both the x and the y directions.

Parameters
  • sources (astropy.Table or dict) – Table of source locations with x and y centroids

  • rad (int) – Half the size of one side of the cutout (or, if you prefer, the radius of the inscribed circle for the bounding box). Needs to be an int for indexing purposes.

  • image (array_like, shape(2048, 2048)) – The image from which the cutouts will be cut out

Returns

img_arrs – Array of cutouts for all the sources

Return type

list of arrays, shape (2 * radius, 2 * radius)

exowirc.photo_utils.perform_photometry(calib_dir, dump_dir, img_dir, science_ranges, target_coords, finding_fwhm=15.0, extraction_rads=[20.0], style='wirc', source_detection_sigma=50, max_num_compars=10, gain=1.2, bkg_fname=None, background_mode=None, ann_rads=(20, 50), target_and_compars=None, bad_channel=False)

Given a list of science images, perform aperture photometry. First, sources are automatically detected and cleaned. Then run the aperture photometry with local background subtraction using a sigma-clipped annulus. The aperture sums and errors for each radius, as well as diagnostics like x centroid, y centroid, and PSF width, are pickled and saved for fitting.

Parameters
  • calib_dir (string) – Path to the directory holding the calibrated science images.

  • dump_dir (string) – Path to the directory into which the pickled results will be saved.

  • img_dir (string) – Path to the directory holding all the diagnostic plots that will be automatically generated.

  • science_ranges (list of tuples) – List of (int1, int2) tuples, where each tuple defines a single linear sequence of science images

  • target_coords (tuple, shape:(2)) – An (x, y) tuple describing approximately where the target is located on the detector

  • finding_fwhm (float, optional) – The PSF FWHM used for automatic source detection

  • extraction_rads (array_like, optional) – A list of radii defining target aperture sizes to be used for the photometry

  • style (string, optional) – The prefix for the image number. usually ‘image’ or ‘wirc’ unless otherwise specified during observations

  • source_detection_sigma (float, optional) – The number of sigmas that a source needs to be above the background to be detected

  • max_num_compars (int, optional) – The maximum number of comparison stars to use.

  • gain (float, optional) – The gain for the WIRC detector. Made it a free parameter but it’s unlikely to change anytime soon, so probably leave this alone.

  • bkg_frame (int, optional) – The number of the background frame used for calibration, if necessary. If background frame subtraction was performed during calibration and you want accurate photometric errors, you definitely should set this parameter.

  • global_bkg_sub (boolean, optional) – If you chose to subtract a background frame or a sigma-clipped background from the science images during calibration, set this flag to True so that you can calculate accurate photometric errors.

  • ann_rads (tuple, optional) – Tuple of form (float1, float2), where float1 specifies the inner radius and float2 specifies the outer radius of the annulus that will be used for local background subtraction

  • target_and_compars (list of shape:(2) lists) – A list of [x, y] coordinates for manually selected target stars and comparison stars. Only select this if you don’t want automatic source detection. The target star is assumed to come first in the list.

Returns

clean_fnames – A list of the paths to the pickled and saved photometry and error arrays as well as to the auxilliary arrays for the centroids and widths

Return type

list of Strings

Using the residual sum of squares as a best-fit statistic, retains only a specified number of the best comparison stars. Removes bad comparison stars which do not vary in brightness in sync with the target star

Parameters
  • xpos (array_like) – Array containing all the x coordinates for the centroids of every source

  • ypos (array_like) – Array containing all the y coordinates for the centroids of every source

  • widths (array_like) – Array containing the widths for every source PSF

  • phot (array_like) – Array containing the photometry measurements for each of the sources

  • errs (array_like) – Array containing the raw errors for each of the sources

  • max_num_compars (int, optional) – The maximum number of comparison stars that you want to retain. Default is 10. Note that in sparse fields, there may be fewer comparison stars than this.

Returns

  • xpos (array_like) – Array containing all the x coordinates for the centroids ofevery source with only max_num_compars sources retained

  • ypos (array_like) – Array containing all the y coordinates for the centroids of every source with only max_num_compars sources retained

  • widths (array_like) – Array containing the widths for every source PSF with only max_num_compars sources retained

  • phot (array_like) – Array containing the photometry for each of the sources with only max_num_compars sources retained

  • errs (array_like) – Array containing the raw errors for each of the sources with only max_num_compars sources retained

exowirc.plot_utils module

exowirc.plot_utils.corner_plot(plot_dir, samples, varnames)
exowirc.plot_utils.doubleplot(plot_dir, dump_dir, x, ys, yerrs, compars, detrended_data, new_map, trace, texp, map_t0, map_p, phase='primary', bin_time=10, gp=False, plot_nominal=False, baseline=None, fit_tess=False)
exowirc.plot_utils.gen_photon_noise(lc, photon_noise, binsize, texp)
exowirc.plot_utils.gen_photon_noise_errors(lc, photon_noise, binsize)
exowirc.plot_utils.gen_rms(lc, binsize)
exowirc.plot_utils.plot_aperture_opt(plot_dir, apertures, rmses)
exowirc.plot_utils.plot_covariates(plot_dir, x, covariate_names, covs, tag='')
exowirc.plot_utils.plot_initial_map(plot_dir, x, ys, yerrs, compars, map_soln, gp=False, joint=False, joint_num='None')
exowirc.plot_utils.plot_outlier_rejection(plot_dir, x, quick_detrend, filtered, mask, tag='')
exowirc.plot_utils.plot_quickfit(plot_dir, x, ys, yerrs, tag='')
exowirc.plot_utils.plot_sources(img_dir, image, sources, fwhm, ann_rads)
exowirc.plot_utils.plot_tess(plot_dir, x, ys, yerrs, new_map, trace, texp, map_t0, map_p, bin_time=10)
exowirc.plot_utils.plot_white_light_curves(plot_dir, x, ys, tag='')
exowirc.plot_utils.represent_noise_stats(dump_dir, new_map, resid, yerrs)
exowirc.plot_utils.trace_plot(plot_dir, data, varnames)
exowirc.plot_utils.tripleplot(plot_dir, dump_dir, x, ys, yerrs, compars, detrended_data, new_map, trace, texp, map_t0, map_p, phase='primary', bin_time=10, gp=False, plot_nominal=False, baseline=None, fit_tess=False)
exowirc.plot_utils.tripleplot_joint(plot_dir, x_final, y_final, yerrs_final, resid_final, new_map, trace, texp_list, map_t0, map_p, full_x, full_y, full_yerr, full_resid, bin_time=5, plot_nominal=False)