Importing External Data#

Generating a Dataset#

ATK also supports the use of external data. The first step is to create an empty DataSet. This is done with from_target(), which requires any valid target for initialisation (see here). For example, using a Gaia Source ID:

from ATK.Models import DataSet

target = 4223502720986764672

dataset = DataSet.from_target(target)

Importing Data#

The next step is to generate a data container to add to the DataSet. For this tutorial, an externally-acquired spectrum will be imported into ATK. The easiest way to do this is to generate a Spectrum using one of its IO methods: from_table() and from_dataframe(). In this tutorial, from_dataframe() will be used.

The DataFrame (or Table if using from_table()) must contain a column with the same name as each array-like attribute of the required data container. To generate a Spectrum, the DataFrame must therefore have a wavelength column and a flux column.


Note

When generating data containers with from_dataframe(), all columns are assumed to be in specific units - details for which can be found in the container’s documentation (e.g. here for spectra). While units could be manually changed after initialisation, it may instead be preferable to work with a Table, as from_table() preserves all units of the input Table.


Since the format of external data can vary greatly, the process of generating a DataFrame will not be covered here, but this is what the DataFrame should look like:

df = ...
wavelength flux
0 5336.6 -812.069496
1 5336.8 119.795166
2 5337.0 104.242718
3 5337.2 -367.086382
4 5337.4 468.964615
... ... ...
24313 10199.2 11.602664
24314 10199.4 13.233428
24315 10199.6 10.652725
24316 10199.8 8.980172
24317 10200.0 10.517128

24318 rows × 2 columns



Any other required attributes must be passed as keyword arguments to from_dataframe() (or from_table()). A Spectrum only requires that we specify a survey.


Note

For information on the keyword arguments that are required by a data container, see its documentation for the IO method that is being used (for this tutorial, that would be from_dataframe()).


With everything ready, the following code generates a Spectrum from the external data:

from ATK.Models import Spectrum

spec = Spectrum.from_dataframe(target, data=df, survey="XSHOOTER")
spec.show()
<XSHOOTER Spectrum>

.survey:     XSHOOTER
.wavelength: [5336.6, 5336.8, ..., 10199.8, 10200.0] Å
.flux:       [-812.069, 119.795, ..., 8.98, 10.517] 1×10⁻¹⁷ erg Å⁻¹ s⁻¹ cm⁻²

Available Methods: .bin(), .crop(), .from_dataframe(), .from_table(), .show(), .to_dataframe(), .to_hdu(), .to_table(), .vspec()

Adding Data to a DataSet#

The final step is to add the Spectrum to the DataSet, which can be done with add():

dataset.add(spec)
dataset.show()
<Spectrum DataSet>

.kind:      Spectrum
.targets:   4223502720986764672 | 302.899° -2.228° (icrs, 2016-01-01T00:00:00.000)
.exception: False
.data:
      <XSHOOTER Spectrum>
            survey:     XSHOOTER
            wavelength: [5336.6, 5336.8, ..., 10199.8, 10200.0] Å
            flux:       [-812.069, 119.795, ..., 8.98, 10.517] 1×10⁻¹⁷ erg Å⁻¹ s⁻¹ cm⁻²


Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store()

Using the DataSet#

The newly constructed DataSet can then be used throughout ATK as if it were retrieved internally:

dataset.apply("crop", cmin=5700, inplace=True)
dataset.open(fit=True, prom=2, smooth=5)
Bokeh Figure



Another Example#

Below is a full example of the process for importing and utilising an externally-acquired light curve (excluding loading of the data):

df = ...
from ATK.Models import Lightcurve

target = 6050296829033196032

dataset = DataSet.from_target(target)
lc = Lightcurve.from_dataframe(target, data=df, survey="TNT", band="KG5")
dataset.add(lc)

folded = dataset.apply("fold", fmin=0, fmax=10, samples=10000, inplace=False)
folded.apply("bin", bins=200)
folded.open()
Bokeh Figure





Download this Tutorial

Total running time of the script: (0 minutes 7.641 seconds)

Gallery generated by Sphinx-Gallery