.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/multiple_targets/multi_target_query.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_multiple_targets_multi_target_query.py: #################### Multi-Target Queries #################### All tasks in ATK (including all of those showcased in previous tutorials) are designed to work modularly with multiple targets. **A target matching system is used to internally link each input target** (whether that be a Gaia source ID, a :class:`~ATK.Models.Target` or a :class:`~astropy.coordinates.SkyCoord`) **to the data that it returns.** | Performing a Multi-Target Query =============================== A multi-target query can be performed by passing multiple targets to :func:`~ATK.Tools.query`. An example of a multi-target `Vizier `_ query for two targets - **van Maanen's star** and **Hu Leo**, a cataclysmic variable - is shown below: .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python from ATK import query targets = [2552928187080872832, 587316166180416640] galex_query = query("vizier", targets=targets, survey="gaia") galex_query.show() .. rst-class:: sphx-glr-script-out .. code-block:: none .kind: Record .targets: 2552928187080872832 | 12.297° 5.377° (icrs, 2016-01-01T00:00:00.000, 3.0″), 587316166180416640 | 141.185° 8.031° (icrs, 2016-01-01T00:00:00.000, 3.0″) .exception: False .data: survey: gaia catalogue: I/355/gaiadr3 correction: full search_pos: 12.297° 5.377° (icrs, 2016-01-01T00:00:00.000) table: (astropy.Table) DR3Name: [Gaia DR3 2552928187080872832] RA_ICRS: [12.297] ° DE_ICRS: [5.377] ° SolID: [1636148068921376768] Source: [2552928187080872832] survey: gaia catalogue: I/355/gaiadr3 correction: full search_pos: 141.185° 8.031° (icrs, 2016-01-01T00:00:00.000) table: (astropy.Table) DR3Name: [Gaia DR3 587316166180416640] RA_ICRS: [141.185] ° DE_ICRS: [8.031] ° SolID: [1636148068921376768] Source: [587316166180416640] Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store() .. GENERATED FROM PYTHON SOURCE LINES 34-46 | .. note:: The returned :class:`~ATK.Models.Record` objects have been truncated here for clarity. | | Accessing Multi-Target Data =========================== The returned :class:`~ATK.Models.DataSet` contains two :class:`~ATK.Models.Record` objects. These could be extracted by pulling them out of the :attr:`~ATK.Models.DataSet.data` attribute: .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python van_maanen, hu_leo = galex_query.data .. GENERATED FROM PYTHON SOURCE LINES 50-59 **But this can easily produce unexpected results if no data is returned for one or more of the targets.** Instead, the :class:`~ATK.Models.DataSet`'s :meth:`~ATK.Models.DataSet.split` method should be used. :meth:`~ATK.Models.DataSet.split` takes one or more valid targets (with each target being a Gaia source ID, a :class:`~ATK.Models.Target`, or an astropy :class:`~astropy.coordinates.SkyCoord`) and returns a split of the :class:`~ATK.Models.DataSet` which only contains that target's data. | Splitting by ID --------------- Since Gaia source IDs were used in this example, these can be passed to :meth:`~ATK.Models.DataSet.split`: .. GENERATED FROM PYTHON SOURCE LINES 60-64 .. code-block:: Python van_maanen_2 = galex_query.split(2552928187080872832, inplace=False) van_maanen_2.show() .. rst-class:: sphx-glr-script-out .. code-block:: none .kind: Record .targets: 2552928187080872832 | 12.297° 5.377° (icrs, 2016-01-01T00:00:00.000, 3.0″) .exception: False .data: survey: gaia catalogue: I/355/gaiadr3 correction: full search_pos: 12.297° 5.377° (icrs, 2016-01-01T00:00:00.000) table: (astropy.Table) DR3Name: [Gaia DR3 2552928187080872832] RA_ICRS: [12.297] ° DE_ICRS: [5.377] ° SolID: [1636148068921376768] Source: [2552928187080872832] Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store() .. GENERATED FROM PYTHON SOURCE LINES 65-78 **The returned** :class:`~ATK.Models.DataSet` **contains only the requested target in its** :attr:`~ATK.Models.DataSet.targets` **attribute, and only the corresponding** :class:`~ATK.Models.Record` **in its** :attr:`~ATK.Models.DataSet.data` **attribute.** | .. note:: ``inplace = False`` tells :meth:`~ATK.Models.DataSet.split` to act on and return a copy of the :class:`~ATK.Models.DataSet` - leaving the original unchanged. | Splitting by Coordinates ------------------------ Equivalently, an astropy :class:`~astropy.coordinates.SkyCoord` can be passed to :meth:`~ATK.Models.DataSet.split`. This returns a split of the original :class:`~ATK.Models.DataSet` which only contains data corresponding to **input positions** (i.e. the uncorrected coordinates that were provided to :func:`~ATK.Tools.query` by the user) that fall within a given ``radius``: .. GENERATED FROM PYTHON SOURCE LINES 78-86 .. code-block:: Python import astropy.units as u from astropy.coordinates import SkyCoord coord = SkyCoord(141.185, 8.031, unit="deg", frame="icrs") hu_leo = galex_query.split(coord, inplace=False, radius = 5 * u.arcsec) hu_leo.show() .. rst-class:: sphx-glr-script-out .. code-block:: none .kind: Record .targets: 587316166180416640 | 141.185° 8.031° (icrs, 2016-01-01T00:00:00.000, 3.0″) .exception: False .data: survey: gaia catalogue: I/355/gaiadr3 correction: full search_pos: 141.185° 8.031° (icrs, 2016-01-01T00:00:00.000) table: (astropy.Table) DR3Name: [Gaia DR3 587316166180416640] RA_ICRS: [141.185] ° DE_ICRS: [8.031] ° SolID: [1636148068921376768] Source: [587316166180416640] Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store() .. GENERATED FROM PYTHON SOURCE LINES 87-98 | .. note:: In queries that target stars with their Gaia source IDs (like the one performed here), splitting via a :class:`~astropy.coordinates.SkyCoord` isn't particularly useful. However, it is worth noting that the **input positions** of the stars in this case would be those given by Gaia DR3. | Splitting by Target ------------------- Finally, a :class:`~ATK.Models.Target` can be passed to :meth:`~ATK.Models.DataSet.split`. **This enables exact matching without the need of a** ``radius``, **and is therefore preferable if a Gaia source ID isn't available:** .. GENERATED FROM PYTHON SOURCE LINES 98-110 .. code-block:: Python from ATK.Models import Target coord_1 = SkyCoord(12.2912, 5.3886, unit="deg", frame="icrs") # van Maanen's Star coord_2 = SkyCoord(141.1853, 8.0308, unit="deg", frame="icrs") # Hu Leo targets = [Target.from_coord(coord_1), Target.from_coord(coord_2)] gaia_query = query("vizier", targets=targets, survey="gaia") hu_leo = gaia_query.split(targets[1], inplace=False) hu_leo.show() .. rst-class:: sphx-glr-script-out .. code-block:: none .kind: Record .targets: 141.185° 8.031° (icrs, 2000-01-01T00:00:00.000, 3.0″) .exception: False .data: survey: gaia catalogue: I/355/gaiadr3 correction: none search_pos: 141.185° 8.031° (icrs, 2000-01-01T00:00:00.000) table: (astropy.Table) DR3Name: [Gaia DR3 587316166180416640] RA_ICRS: [141.185] ° DE_ICRS: [8.031] ° SolID: [1636148068921376768] Source: [587316166180416640] Available Methods: .add(), .apply(), .from_target(), .merge(), .open(), .plot(), .save(), .show(), .split(), .store() .. GENERATED FROM PYTHON SOURCE LINES 116-121 | | | .. rubric:: Download this Tutorial .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.662 seconds) .. _sphx_glr_download_auto_tutorials_multiple_targets_multi_target_query.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: multi_target_query.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: multi_target_query.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: multi_target_query.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_