Using External Data

While support for further surveys is being gradually added, it is also possible to use data from external sources in ATK through the Models module. This module provides empty data structures for use throughout the package, which can be filled with any relevant data. Some attributes can be filled automatically if the model is provided with a pos or source.

As an example, we will use some photometry from the Thai National Telescope (TNT) for a system that we have already seen: the white dwarf pulsar, AR Sco. For reference, the data takes the form:

mjd            flux     error
2457517.209956 0.454216 0.0185251
2457517.210012 0.123707 0.0158678
2457517.210074 -0.0441742 0.015052
2457517.210136 0.160731 0.0161515
2457517.210198 0.398715 0.0172122
...            ...      ...

and is saved as AR_Sco_TNT.txt in this example. We must first read the data into Python, in this case we will use Pandas:

import pandas as pd

data = pd.read_csv("AR_Sco_TNT.txt", delimiter="\s+")

We then import and create a custom ATK Lightcurve Structure:

from AstroToolkit.Models import CustomLightcurveStruct

lightcurve = CustomLightcurveStruct().showdata()
.kind:       lightcurve
.survey:     None
.source:     None
.pos:        None
.identifier: None
.figure:     None
.dataname:   None
.plotname:   None
.data:       None
Available Methods: .bin(), .crop(), .exportplot(), .plot(), .savedata(), .saveplot(), .showdata(), .showplot(), .sigmaclip()

As we can see, we now have an empty LightcurveStruct which we can fill with data. Since we know the source (or position) of our data, we can get a head start by providing this to CustomLightcurveStruct:

lightcurve = CustomLightcurveStruct(source=6050296829033196032).showdata()
Running gaia data query
source = 6050296829033196032
pos = None
radius = 3.0


.kind:       lightcurve
.survey:     None
.source:     6050296829033196032
.pos:        [245.44701332769, -22.88621824697]
.identifier: J162147.28-225310.39
.figure:     None
.dataname:   J162147.28-225310.39_6050296829033196032_ATKlightcurve.fits
.plotname:   J162147.28-225310.39_6050296829033196032_ATKlightcurve.html
.data:       None
Available Methods: .bin(), .crop(), .exportplot(), .plot(), .savedata(), .saveplot(), .showdata(), .showplot(), .sigmaclip()

With a number of the structure’s fields being filled out for us, we simply fill those that remain with the name of the survey and our custom data (in the same format as a normal LightcurveStruct):

lightcurve.survey = "TNT"
lightcurve.data = [
    {
        "band": "g",
        "mjd": data["mjd"].tolist(),
        "flux": data["flux"].tolist(),
        "flux_err": data["error"].tolist(),
    }
]

And that is it! We can now use our external data throughout ATK as if it were officially supported:

lightcurve.plot(colours=["green"]).showplot()
lightcurve.plot(kind="powspec", start_freq=650, stop_freq=800).showplot()
lightcurve.plot(kind="phasefold", bins=300, foverlay=False, freq=6.74157303371).showplot()

Note: The code used in this tutorial can be executed using:

from AstroToolkit.Examples import external_data