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: 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.

class corrections.utilities.LoggerWriter(logger, level=20)[source]

Bases: object

File-like object which passes input into a logger.

Can be used together with contextlib.redirect_stdout() or contextlib.redirect_stderr() to redirect streams to the given logger. Can be useful for wrapping codes which uses normal print() functions for logging.

1logger = logging.getLogger(__name__)
2with contextlib.redirect_stdout(LoggerWriter(logger, logging.INFO)):
3        print("This goes into the logger instead of STDOUT")

Warning

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

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

__init__(logger, level=20)[source]
write(message)[source]
corrections.utilities.CadenceType(x)[source]

Type-checker function to be used with argparse for “cadence” inputs.

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

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)