Utilities (corrections.utilities)

Collection of utility functions that can be used throughout the corrections package.

Code author: Rasmus Handberg <rasmush@phys.au.dk>

class corrections.utilities.ListHandler(*args, message_queue, **kwargs)[source]

Bases: logging.Handler

A logging.Handler that writes messages into a list object.

The standard logging.QueueHandler/logging.QueueListener can not be used for this because the QueueListener runs in a private thread, not the main thread.

Warning

This handler is not thread-safe. Do not use it in threaded environments.

__init__(*args, message_queue, **kwargs)[source]

Initialize by copying the queue and sending everything else to superclass.

emit(record)[source]

Add the formatted log message (sans newlines) to the queue.

corrections.utilities.fix_fits_table_headers(table, column_titles=None)[source]

Fix headers in FITS files, adding appropiate comments where they are missing.

Changes headers in-place.

Parameters
  • table (fits.BinTableHDU) – Table HDU to fix headers for.

  • column_titles (dict) – Descriptions of columns to add to header comments.

Code author: Rasmus Handberg <rasmush@phys.au.dk>

corrections.utilities.loadPickle(fname)[source]

Load an object from file using pickle.

Parameters
  • fname (string) – File name to save to. If the name ends in ‘.gz’ the file will be automatically unzipped.

  • obj (object) – Any pickalble object to be saved to file.

Returns

The unpickled object from the file.

Return type

object

corrections.utilities.ptp(lc)[source]

Compute robust Point-To-Point scatter.

Parameters

lc (lightkurve.TessLightCurve object) – Lightcurve to calculate PTP for.

Returns

Robust PTP.

Return type

float

Code author: Rasmus Handberg <rasmush@phys.au.dk>

corrections.utilities.rms_timescale(lc, timescale=0.041666666666666664)[source]

Compute robust RMS on specified timescale. Using MAD scaled to RMS.

Parameters
  • lc (lightkurve.TessLightCurve object) – Timeseries to calculate RMS for.

  • timescale (float, optional) – Timescale to bin timeseries before calculating RMS. Default=1 hour.

Returns

Robust RMS on specified timescale.

Return type

float

Code author: Rasmus Handberg <rasmush@phys.au.dk>

corrections.utilities.savePickle(fname, obj)[source]

Save an object to file using pickle.

Parameters
  • fname (string) – File name to save to. If the name ends in ‘.gz’ the file will be automatically gzipped.

  • obj (object) – Any pickalble object to be saved to file.

corrections.utilities.sphere_distance(ra1, dec1, ra2, dec2)[source]

Calculate the great circle distance between two points using the Vincenty formulae.

Parameters
  • ra1 (float or ndarray) – Longitude of first point in degrees.

  • dec1 (float or ndarray) – Lattitude of first point in degrees.

  • ra2 (float or ndarray) – Longitude of second point in degrees.

  • dec2 (float or ndarray) – Lattitude of second point in degrees.

Returns

Distance between points in degrees.

Return type

ndarray

corrections.utilities.PICKLE_DEFAULT_PROTOCOL = 4

Default protocol to use for saving pickle files.

corrections.utilities.mad_to_sigma = 1.482602218505602

Conversion constant from MAD to Sigma. Constant is 1/norm.ppf(3/4)