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()
wavelength flux
0 3600.808838 12.829317
1 3601.637207 0.585399
2 3602.467773 9.223813
3 3603.296387 6.716644
4 3604.125488 1.041800
... ... ...
4597 10377.670898 5.930060
4598 10380.064453 -22.424702
4599 10382.458008 9.461142
4600 10384.840820 46.597488
4601 10387.235352 44.008152

4602 rows × 2 columns



or to convert to a Table:

table = sdss_query.data[0].to_table()
Table length=4602
wavelengthflux
Angstrom1e-17 erg / (Angstrom s cm2)
float32float32
3600.808812.829317
3601.63720.58539885
3602.46789.223813
3603.29646.716644
3604.12551.0417998
3604.95655.692421
3605.78611.1126375
3606.617212.113641
3607.4479.009418
......
10368.11630.32188
10370.50735.617973
10372.89862.638107
10375.27934.284332
10377.6715.93006
10380.064-22.424702
10382.4589.461142
10384.84146.59749
10387.23544.008152



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)

Gallery generated by Sphinx-Gallery