Note
Go to the end to download the full example code.
Manipulating Data#
Lightcurve objects offer the first examples of data methods - these are methods that manipulate the containers themselves.
Data Methods#
The set of available methods depends on the kind of data that is being stored in the DataSet, but all methods can be utilised via the DataSet’s apply() method.
To showcase this, some data will first be fetched from ZTF for Al Com - a WZ Sge cataclysmic variable:
from ATK import query
asassn_query = query("lightcurve", targets=3932951035266314496 , survey="ztf", path="example_lightcurve_4.fits.gz")
asassn_query.show(show_all=True)
asassn_query.open(time_format="original")
<Lightcurve DataSet>
.kind: Lightcurve
.targets: 3932951035266314496 | 188.107° 14.345° (icrs, 2016-01-01T00:00:00.000, 3.0″)
.exception: False
.data:
<ztf g-band Lightcurve>
survey: ztf
band: g
correction: full
search_pos: 188.107° 14.345° (icrs, 2019-01-01T00:00:00.000)
separation: 0.088″
mjd: [58202.312, 58216.264, ..., 60846.259, 60853.206] d
mag: [19.888, 20.018, ..., 19.771, 19.994] mag
mag_err: [0.129, 0.141, ..., 0.118, 0.138] mag
ra: [188.107, 188.107, ..., 188.107, 188.107] °
dec: [14.345, 14.345, ..., 14.345, 14.345] °
<ztf r-band Lightcurve>
survey: ztf
band: r
correction: full
search_pos: 188.107° 14.345° (icrs, 2019-01-01T00:00:00.000)
separation: 0.043″
mjd: [58217.279, 58217.28, ..., 59269.348, 59269.348] d
mag: [20.089, 19.978, ..., 19.804, 20.122] mag
mag_err: [0.154, 0.145, ..., 0.103, 0.126] mag
ra: [188.107, 188.107, ..., 188.107, 188.107] °
dec: [14.345, 14.345, ..., 14.345, 14.345] °
<ztf i-band Lightcurve>
survey: ztf
band: i
correction: full
search_pos: 188.107° 14.345° (icrs, 2019-01-01T00:00:00.000)
separation: 0.077″
mjd: [58232.295, 58257.206, ..., 60416.388, 60450.212] d
mag: [20.057, 19.959, ..., 19.185, 19.328] mag
mag_err: [0.179, 0.171, ..., 0.107, 0.118] mag
ra: [188.107, 188.107, ..., 188.107, 188.107] °
dec: [14.345, 14.345, ..., 14.345, 14.345] °
Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store()
Cropping a Light Curve#
The returned Lightcurve can be cropped by applying its crop() data method. This truncates all array-like attributes of the Lightcurve to match a chosen MJD range, in this case focusing on the large outburst:
cropped_data = asassn_query.apply("crop", cmin=58550, cmax=58660, inplace=False)
cropped_data.open(time_format="original")
Note
By default, apply() modifies the stored data containers in-place. To instead operate on a copy of the DataSet - thereby leaving the original unmodified - pass inplace=False to apply() (as above).
Binning a Light Curve#
The Lightcurve can also be binned, combining all array-like attributes into a requested number of bins or a given bin size:
binned_data = asassn_query.apply("bin", bins=200, inplace=False)
binned_data.open(time_format="original")
import astropy.units as u
binned_data = asassn_query.apply("bin", size=10*u.day, inplace=False)
binned_data.open(time_format="original")
Sigma-Clipping a Light Curve#
The Lightcurve can be sigma clipped by applying clip(), which clips all array-like attributes to eliminate data points where the light curve’s brightness is outside a given number of standard deviation from the median:
clipped_data = binned_data.apply("clip", sigma=2, inplace=False)
clipped_data.open(time_format="original")
Download this Tutorial
Total running time of the script: (0 minutes 2.364 seconds)