.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/io/export.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_io_export.py: ############## Exporting Data ############## If data is needed for external use, it may be helpful to export ATK data into a tabular format (i.e. a :class:`~pandas.DataFrame` or :class:`~astropy.table.Table`). This can be done via the **IO methods** :meth:`~ATK.base.DataFrameIOMixin.to_dataframe` and :meth:`~ATK.base.TableIOMixin.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. :class:`here ` if working with :class:`~ATK.Models.Spectrum` objects). | In this tutorial, the aforementioned **IO methods** will be demonstrated on a :class:`~ATK.Models.Spectrum`: .. GENERATED FROM PYTHON SOURCE LINES 19-26 .. code-block:: Python from ATK import query sdss_query = query("spectrum", targets=2802295461460467072, survey="sdss") sdss_query.show() .. rst-class:: sphx-glr-script-out .. code-block:: none .kind: Spectrum .targets: 2802295461460467072 | 12.352° 22.438° (icrs, 2016-01-01T00:00:00.000, 3.0″) .exception: False .data: 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() .. GENERATED FROM PYTHON SOURCE LINES 31-34 | To convert the stored :class:`~ATK.Models.Spectrum` into a :class:`~pandas.DataFrame`, simply extract it from the :class:`~ATK.Models.DataSet` and call :meth:`~ATK.base.DataFrameIOMixin.to_dataframe`: .. GENERATED FROM PYTHON SOURCE LINES 34-37 .. code-block:: Python df = sdss_query.data[0].to_dataframe() .. raw:: html
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



.. GENERATED FROM PYTHON SOURCE LINES 41-42 or to convert to a :class:`~astropy.table.Table`: .. GENERATED FROM PYTHON SOURCE LINES 42-45 .. code-block:: Python table = sdss_query.data[0].to_table() .. raw:: html
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


.. GENERATED FROM PYTHON SOURCE LINES 49-56 | .. note:: In either case, non-array-like attributes are not included in the output :class:`~pandas.DataFrame` or :class:`~astropy.table.Table`. If required, these should be extracted from the Spectrum alongside the use of :meth:`~ATK.base.DataFrameIOMixin.to_dataframe` or :meth:`~ATK.base.TableIOMixin.to_table`. Also note that :meth:`~ATK.base.TableIOMixin.to_table` offers a key advantage over :meth:`~ATK.base.DataFrameIOMixin.to_dataframe`, in that units are retained and stored in the output :class:`~astropy.table.Table`. .. GENERATED FROM PYTHON SOURCE LINES 58-63 | | | .. rubric:: Download this Tutorial .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.812 seconds) .. _sphx_glr_download_auto_tutorials_io_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: export.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: export.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: export.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_