KASOC Filter (corrections.KASOCFilterCorrector)

Lightcurve correction using the KASOC Filter (Handberg et al. 2015).

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

class corrections.KASOCFilterCorrector(*args, **kwargs)[source]

Bases: corrections.BaseCorrector.BaseCorrector

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

Initialize the corrector.

  • input_folder (string) –
  • plot (boolean, optional) –
  • IOError – If (target ID) could not be found (TODO: other values as well?)
  • ValueError – (TODO: on a lot of places)

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


Close correction object.

correct(task, output_folder=None)

Run correction.

  • task (dict) – Dictionary defining a task/lightcurve to process.
  • output_folder (string, optional) – Path to directory where lightcurve should be saved.

Result dictionary containing information about the processing.

Return type:


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


Apply corrections to target lightcurve.

Parameters:lightcurve (lightkurve.TessLightCurve object) – Lightcurve of the target star to be corrected.
Returns:The status of the corrections and the corrected lightcurve object.

Load lightcurve from task ID or full task dictionary.

Parameters:task (integer or dict) –
Returns:Lightcurve for the star in question.
Return type:lightkurve.TessLightCurve
Raises:ValueError – On invalid file format.

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


Return folder path where plots for a given lightcurve should be saved.

Parameters:lc (lightkurve.TessLightCurve) – Lightcurve to return plot path for.
Returns:Path to directory where plots should be saved.
Return type:string

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

save_lightcurve(lc, output_folder=None)

Save generated lightcurve to file.

Parameters:output_folder (string, optional) – Path to directory where to save lightcurve. If None the directory specified in the attribute output_folder is used.
Returns:Path to the generated file.
Return type:string

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

Code author: Mikkel N. Lund <mikkelnl@phys.au.dk>

search_database(select=None, search=None, order_by=None, limit=None, distinct=False)

Search list of lightcurves and return a list of tasks/stars matching the given criteria.

  • search (list of strings or None) – Conditions to apply to the selection of stars from the database
  • order_by (list, string or None) – Column to order the database output by.
  • limit (int or None) – Maximum number of rows to retrieve from the database. If limit is None, all the rows are retrieved.
  • distinct (boolean) – Boolean indicating if the query should return unique elements only.

Returns all stars retrieved by the call to the database as dicts/tasks that can be consumed directly by load_lightcurve

Return type:

list of dicts

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

KASOC Filter

KASOC Filter for Asteroseismic Data Preparation

Corrects Kepler/K2 data for instrumental effects and planetary signals to create new datasets optimized for asteroseismic analysis.

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

Code author: Mikkel N. Lund

exception corrections.kasoc_filter.kasoc_filter.InvalidSigmasWarning[source]

Bases: UserWarning

corrections.kasoc_filter.kasoc_filter.extract_star_movement_1d(time, flux, position, dt=None, rapid_movement_sigma_clip=5.0, pixel_off_clip=15.0)[source]

Extract information about star movement on CCD to be used later.

  • time – Vector of timestamps.
  • flux – Vector of flux values.
  • position – Nx2 matrix of (x,y) positions of star on CCD.
  • dt – Mean distance between points in the time vector.

Flags indicating bad data points. star_movement: Object containing info to be passed to @filter_position_1d.

Return type:


corrections.kasoc_filter.kasoc_filter.filter(t, x, quality=None, position=None, P=None, jumps=None, timescale_long=3.0, timescale_short=0.041666666666666664, sigma_clip=4.5, scale_clip=5.0, scale_width=1.0, phase_smooth_factor=1000, transit_model=None, it=3)[source]

Main filter function.

  • t (ndarray) – Time vector (days).
  • x (ndarray) – Flux vector.
  • quality (ndarray, None) – Quality vector (bit-flags) from Kepler data; default=None.
  • position (ndarray, None) – Centroid positions of star on CCD as two column list; default=None.
  • P (ndarray) – Known planetary period (days); default=None.
  • jumps (list) – List of known jumps in the flux (timestamp in days); default=None.
  • timescale_long (float) – Timescale of long filter in days; default=3.
  • timescale_short (float) – Timescale of short filter in days; default=1/24.
  • sigma_clip (float) – Sigma-clip threshold; default=4.5.
  • scale_clip (float) – Scale at which to switch between long and short filters; default=5.
  • scale_width (float) – Width of transition region between filters; default=1.
  • phase_smooth_factor (float) – Fraction of period to smooth phase curce with; default=1000.
  • transit_model (ndarray) – Full transit model to be used instead of smoothed phase curve; default=None.
  • it (integer) – Number of iterations between different filters. Default=3.

tnew - New time vector with the same length as the input vectors. xnew - New flux vector with the same length as the input vectors. sigma - Vector of estmated errors on measurements. flags - Vector of KASOC flags. filt - Vector with the final filter applied (after jump removal). turnover - Turnover function with weights to long and short filter.

corrections.kasoc_filter.kasoc_filter.filter_flags(t, x, quality, quality_remove=239, return_flags=False)[source]

Filter out flagged data from Kepler quality column.

Returns new flux vector with bad datapoints removed (set to NaN) and a vector with flagged jump time postions. This vector can later be passed into filter_jumps().

  • t (ndarray) – Time vector (days).
  • x (ndarray) – Flux vector.
  • quality (ndarray) – Quality flags (integers).
  • quality_remove (integer, optional) – Flags that corresponds to bad data points.
  • return_flags (boolean) – Also return flags of removed points.

Flux vector filterd for bad data points. list: jumps ndarray: flag_removed

Return type:


Quality flags

Bit Value Default Action Meaning
1 1 Correct+Remove Attitude Tweak.
2 2 Ignore Spacecraft in Safe Mode.
3 4 Ignore Spacecraft in Coarse Point.
4 8 Ignore Spacecraft in Earth Point.
5 16 Ignore Reaction wheel zero crossing.
6 32 Remove Reaction wheel Desaturation Event.
7 64 Ignore Argabrightening detected across multiple channels.
8 128 Ignore Cosmic Ray in Optimal Aperture pixel.
9 256 Remove Manual Exclude. The cadence was excluded because of an anomaly.
10 512 Ignore Reserved.
11 1024 Correct Discontinuity corrected between this cadence and the following one.
12 2048 Ignore Impulsive outlier removed after cotrending.
13 4096 Remove Argabrightening event on specified CCD mod/out detected.
14 8192 Ignore Cosmic Ray detected on collateral pixel row or column in optimal aperture.
15 16385 Ignore Detector Anomaly.
16 32768 Ignore Spacecraft is not in Fine Point.
17 65536 Remove No Data Reported.
18 131072 Ignore Possible Thruster Firing.
19 262144 Remove Definite Thruster Firing.
corrections.kasoc_filter.kasoc_filter.filter_phase(t, x, Plist, smooth_factor=1000)[source]

Filter out specific periods by smoothing the phase-curve.

  • t (ndarray) – Time vector (days).
  • x (ndarray) – Flux vector.
  • P (list) – List of periods to remove.
  • smooth_factor (float, optional) – Factor of phase to use as smooth width.

Filter flux vector that can be removed from timeseries.


Does not require time to be sorted. Can handle NaN in flux vector.

corrections.kasoc_filter.kasoc_filter.filter_position_1d(time, flux, star_movement, timescale_position_smooth=None, dt=None)[source]

Filter the lightcurve for correlations in the stars position on the CCD.

corrections.kasoc_filter.kasoc_filter.pixelversion(pixelmask=1, custom_version=None)[source]
corrections.kasoc_filter.kasoc_filter.remove_jumps(t, x, jumps, width=3, return_flags=False)[source]

Remove jumps from timeseries.

  • t (ndarray) – Time vector (days). Must be sorted in time.
  • x (ndarray) – Flux vector. Can contain invalid points (NaN).
  • jumps (list) – Vector of timestamps where jumps are to be corrected.
  • width (float) – Width of the region on each side of jumps to compare (default=3 days).
  • return_flags (boolean) – Return two additional arrays with location of corrected jumps.
corrections.kasoc_filter.kasoc_filter.scale_timescales(numax, min_value_long=30.0)[source]

Scale the filter timescales with estimated nu_max of the star in question to avoid disturbing oscillation signals for low-numax stars.

  • numax (float) – nu_max in microHz.
  • min_value_long (float, optional) – The shortest filter width to return in days. Default=30.

New timescale which will avoid the specified nu_max region.

Return type:


corrections.kasoc_filter.kasoc_filter.set_output(folder=None, prefix='', fmt='png', native=False)[source]

Change the output settings for the plots generated by the filter.

corrections.kasoc_filter.kasoc_filter.spline_set_knots(x, num_knots, min_points_per_knot=3)[source]