Note
Go to the end to download the full example code.
Exporting Data#
If data is needed for external use, it may be helpful to export ATK data into a tabular format (i.e. a DataFrame or Table).
This can be done via the IO methods to_dataframe() and to_table().
Note
The availability of IO methods depends on the kind of data that is being used. See the documentation of the specific data container for information (e.g. here if working with Spectrum objects).
In this tutorial, the aforementioned IO methods will be demonstrated on a Spectrum:
from ATK import query
sdss_query = query("spectrum", targets=2802295461460467072, survey="sdss")
sdss_query.show()
<Spectrum DataSet>
.kind: Spectrum
.targets: 2802295461460467072 | 12.352° 22.438° (icrs, 2016-01-01T00:00:00.000, 3.0″)
.exception: False
.data:
<sdss Spectrum>
survey: sdss
correction: full
search_pos: 12.352° 22.438° (icrs, 2017-01-01T00:00:00.000)
separation: 0.084″
exposure: 3603.38 s
wavelength: [3600.80908203125, 3601.636962890625, ..., 10384.8408203125, 10387.2353515625] Å
flux: [12.829000473022461, 0.5849999785423279, ..., 46.59700012207031, 44.007999420166016] 1×10⁻¹⁷ erg Å⁻¹ s⁻¹ cm⁻²
Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store()
To convert the stored Spectrum into a DataFrame, simply extract it from the DataSet and call to_dataframe():
df = sdss_query.data[0].to_dataframe()
or to convert to a Table:
table = sdss_query.data[0].to_table()
Note
In either case, non-array-like attributes are not included in the output DataFrame or Table. If required, these should be extracted from the Spectrum alongside the use of to_dataframe() or to_table().
Also note that to_table() offers a key advantage over to_dataframe(), in that units are retained and stored in the output Table.
Download this Tutorial
Total running time of the script: (0 minutes 2.812 seconds)