{ "cells": [ { "cell_type": "markdown", "id": "c631de69", "metadata": {}, "source": [ "# Photometric data of directly imaged planets" ] }, { "cell_type": "markdown", "id": "c5c1437c", "metadata": {}, "source": [ "In this tutorial, we will add photometric data, parallaxes, and spectra of directly imaged planets and brown dwarfs to the database and use the reading functionalities to easily access those data." ] }, { "cell_type": "markdown", "id": "65a9843d", "metadata": {}, "source": [ "## Getting started" ] }, { "cell_type": "markdown", "id": "0adb2206", "metadata": {}, "source": [ "We start by importing the required Python packages." ] }, { "cell_type": "code", "execution_count": 1, "id": "b0c26068", "metadata": {}, "outputs": [], "source": [ "import species" ] }, { "cell_type": "markdown", "id": "28fd5bd3", "metadata": {}, "source": [ "The [species](https://species.readthedocs.io/en/latest/species.html) HDF5 database is initiated by creating an instance of the [SpeciesInit](https://species.readthedocs.io/en/latest/species.core.html#species.core.init.SpeciesInit) class." ] }, { "cell_type": "code", "execution_count": 2, "id": "67ceab5d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initiating species v0.5.1... [DONE]\n", "Creating species_config.ini... [DONE]\n", "Database: /Users/tomasstolker/applications/species/docs/tutorials/species_database.hdf5\n", "Data folder: /Users/tomasstolker/applications/species/docs/tutorials/data\n", "Working folder: /Users/tomasstolker/applications/species/docs/tutorials\n", "Creating species_database.hdf5... [DONE]\n", "Creating data folder... [DONE]\n" ] }, { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "species.SpeciesInit()" ] }, { "cell_type": "markdown", "id": "7dac1bee", "metadata": {}, "source": [ "## Adding companion data to the database" ] }, { "cell_type": "markdown", "id": "f5a0bd48", "metadata": {}, "source": [ "To add data to the database, we first create an instance of [Database](https://species.readthedocs.io/en/latest/species.data.html#species.data.database.Database)." ] }, { "cell_type": "code", "execution_count": 3, "id": "e73a89ba", "metadata": {}, "outputs": [], "source": [ "database = species.Database()" ] }, { "cell_type": "markdown", "id": "76b5c57a", "metadata": {}, "source": [ "Next, we use the [add_companion](https://species.readthedocs.io/en/latest/species.data.html#species.data.database.Database.add_companion) method of `Database` to add all companion data that is [available in the species toolkit](https://github.com/tomasstolker/species/blob/main/species/data/companions.py). This includes filter names, magnitudes, and parallaxes of most directly imaged planets and brown dwarfs, as well as spectra for some objects. We set the argument of `name` to `None` such that all data are added instead of selecting a single companion.\n", "\n", "Running this method will also download the relevant filter profiles from the [SVO Filter Profile Service](http://svo2.cab.inta-csic.es/svo/theory/fps/) and a flux-calibrated spectrum of Vega. The magnitudes that are available in the toolkit are converted into fluxes and both stored in the database. We set `verbose` to `False` to not print a overview of all the filter and companion data that are being added." ] }, { "cell_type": "code", "execution_count": 4, "id": "39f50cac", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading Vega spectrum (270 kB)... [DONE]\n", "Adding Vega spectrum... [DONE]\n", "Adding object: beta Pic b [DONE]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/tomasstolker/applications/species/species/data/database.py:1058: UserWarning: Found 33 fluxes with NaN in the data of GPI_YJHK. Removing the spectral fluxes that contain a NaN.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding object: beta Pic c [DONE]\n", "Adding object: HIP 65426 b [DONE]\n", "Adding object: 51 Eri b [DONE]\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/tomasstolker/applications/species/species/data/filters.py:214: UserWarning: The minimum transmission value of Subaru/CIAO.z is smaller than zero (-1.80e-03). Wavelengths with negative transmission values will be removed.\n", " warnings.warn(\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Adding object: HR 8799 b [DONE]\n", "Adding object: HR 8799 c [DONE]\n", "Adding object: HR 8799 d [DONE]\n", "Adding object: HR 8799 e [DONE]\n", "Adding object: HD 95086 b [DONE]\n", "Adding object: PDS 70 b [DONE]\n", "Adding object: PDS 70 c [DONE]\n", "Adding object: 2M 1207 B [DONE]\n", "Adding object: AB Pic B [DONE]\n", "Adding object: HD 206893 B [DONE]\n", "Adding object: RZ Psc B [DONE]\n", "Adding object: GQ Lup B [DONE]\n", "Adding object: PZ Tel B [DONE]\n", "Adding object: kappa And b [DONE]\n", "Adding object: HD 1160 B [DONE]\n", "Adding object: ROXs 12 B [DONE]\n", "Adding object: ROXs 42 Bb [DONE]\n", "Adding object: GJ 504 b [DONE]\n", "Adding object: GU Psc b [DONE]\n", "Adding object: 2M0103 ABb [DONE]\n", "Adding object: 1RXS 1609 B [DONE]\n", "Adding object: GSC 06214 B [DONE]\n", "Adding object: HD 72946 B [DONE]\n", "Adding object: HIP 64892 B [DONE]\n", "Adding object: HD 13724 B [DONE]\n", "Adding object: TYC 8988 b [DONE]\n", "Adding object: TYC 8988 c [DONE]\n", "Adding object: HD 142527 B [DONE]\n", "Adding object: CS Cha B [DONE]\n", "Adding object: CT Cha B [DONE]\n", "Adding object: SR 12 C [DONE]\n", "Adding object: DH Tau B [DONE]\n", "Adding object: HD 4747 B [DONE]\n", "Adding object: HR 3549 B [DONE]\n", "Adding object: CHXR 73 B [DONE]\n", "Adding object: HD 19467 B [DONE]\n", "Adding object: b Cen (AB)b [DONE]\n" ] } ], "source": [ "database.add_companion(name=None, verbose=False)" ] }, { "cell_type": "markdown", "id": "f97a7f84", "metadata": {}, "source": [ "To get an overview of the companion data that are stored in the database, one can use the [list_companions](https://species.readthedocs.io/en/latest/species.data.html#species.data.database.Database.list_companions) method of `Database`. This will also return a list with the companion names, which could for example be iterated when using the reading functionalities below." ] }, { "cell_type": "markdown", "id": "eab44319", "metadata": {}, "source": [ "## Reading companion data" ] }, { "cell_type": "markdown", "id": "655f9152", "metadata": {}, "source": [ "For reading data of individual companions/objects, we can use the reading functionalities of the toolkit. We start by creating an instance of [ReadObject](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.ReadObject) with the object name as stored in the database given as argument." ] }, { "cell_type": "code", "execution_count": 5, "id": "307717a4", "metadata": {}, "outputs": [], "source": [ "read_obj = species.ReadObject('beta Pic b')" ] }, { "cell_type": "markdown", "id": "1d943971", "metadata": {}, "source": [ "We can check for which filters there is photometric data available with the [list_filters](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.ReadObject.list_filters) method of `ReadObject`." ] }, { "cell_type": "code", "execution_count": 6, "id": "61c79078", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Available photometric data for beta Pic b:\n", " - Gemini/NICI.ED286\n", " - Magellan/VisAO.Ys\n", " - Paranal/NACO.H\n", " - Paranal/NACO.J\n", " - Paranal/NACO.Ks\n", " - Paranal/NACO.Lp\n", " - Paranal/NACO.Mp\n", " - Paranal/NACO.NB374\n", " - Paranal/NACO.NB405\n" ] } ], "source": [ "filter_list = read_obj.list_filters()" ] }, { "cell_type": "code", "execution_count": 7, "id": "510eb5fb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Gemini/NICI.ED286', 'Magellan/VisAO.Ys', 'Paranal/NACO.H', 'Paranal/NACO.J', 'Paranal/NACO.Ks', 'Paranal/NACO.Lp', 'Paranal/NACO.Mp', 'Paranal/NACO.NB374', 'Paranal/NACO.NB405']\n" ] } ], "source": [ "print(filter_list)" ] }, { "cell_type": "markdown", "id": "cf05f8d7", "metadata": {}, "source": [ "Let's now extract the photometric data of the NACO $M'$ filter. The [get_photometry](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.ReadObject.get_photometry) method returns an array with the apparent magnitude, magnitude error, flux density (W m$^{-2}$ $\\mu$m$^{-1}$), and flux density error." ] }, { "cell_type": "code", "execution_count": 8, "id": "997db7c6", "metadata": {}, "outputs": [], "source": [ "mp_phot = read_obj.get_photometry('Paranal/NACO.Mp')" ] }, { "cell_type": "markdown", "id": "5bf13903", "metadata": {}, "source": [ "Similarly, we can use the [get_spectrum](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.get_spectrum) method to return a dictionary with available spectra. In this case a GPI spectrum in the $YJHK$ bands from [Chilcote et al. 2017](https://ui.adsabs.harvard.edu/abs/2017AJ....153..182C/abstract) and a GRAVITY spectrum in the $K$ band from [Gravity Collaboration et al. 2020](https://ui.adsabs.harvard.edu/abs/2020A%26A...633A.110G/abstract)." ] }, { "cell_type": "code", "execution_count": 9, "id": "293fa593", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['GPI_YJHK', 'GRAVITY'])\n" ] } ], "source": [ "spec_dict = read_obj.get_spectrum()\n", "print(spec_dict.keys())" ] }, { "cell_type": "markdown", "id": "863ad6b7", "metadata": {}, "source": [ "Other methods for `ReadObject` are [get_distance](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.ReadObject.get_distance) for returning the distance and [get_absmag](https://species.readthedocs.io/en/latest/species.read.html#species.read.read_object.ReadObject.get_absmag) for calculating the absolute magnitude and uncertainty." ] }, { "cell_type": "code", "execution_count": 10, "id": "3cecacbc", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Distance (pc) = 19.44 +/- 0.05\n" ] } ], "source": [ "distance = read_obj.get_distance()\n", "print(f'Distance (pc) = {distance[0]:.2f} +/- {distance[1]:.2f}')" ] }, { "cell_type": "code", "execution_count": 11, "id": "692e5628", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apparent magnitude = 11.10 +/- 0.12\n", "Absolute magnitude = 9.66 +/- 0.12\n" ] } ], "source": [ "abs_mag = read_obj.get_absmag('Paranal/NACO.Mp')\n", "print(f'Apparent magnitude = {mp_phot[0]:.2f} +/- {mp_phot[1]:.2f}')\n", "print(f'Absolute magnitude = {abs_mag[0]:.2f} +/- {abs_mag[1]:.2f}')" ] }, { "cell_type": "markdown", "id": "9ed3c9d9", "metadata": {}, "source": [ "## Extracting an ObjectBox with data" ] }, { "cell_type": "markdown", "id": "5cb9b3f8", "metadata": {}, "source": [ "Instead of using the `ReadObject` functionalities, we can also use the [get_object](https://species.readthedocs.io/en/latest/species.data.html#species.data.database.Database.get_object) method of `Database` to extract an [ObjectBox](https://species.readthedocs.io/en/latest/species.core.html#species.core.box.ObjectBox) with the companion data from the database. The `inc_phot` and `inc_spec` parameters are either a boolean or a list of filter names / spectra. In this example, we will include all photometric data." ] }, { "cell_type": "code", "execution_count": 12, "id": "62efa7ec", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Getting object: beta Pic b... [DONE]\n" ] } ], "source": [ "object_box = database.get_object('beta Pic b', inc_phot=True, inc_spec=False)" ] }, { "cell_type": "markdown", "id": "86a84872", "metadata": {}, "source": [ "We can inspect the content of the `ObjectBox` with the [open_box](https://species.readthedocs.io/en/latest/species.core.html#species.core.box.Box.open_box) method. Let's have a look!" ] }, { "cell_type": "code", "execution_count": 13, "id": "7a3f95f5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Opening ObjectBox...\n", "name = beta Pic b\n", "filters = ['Gemini/NICI.ED286', 'Magellan/VisAO.Ys', 'Paranal/NACO.H', 'Paranal/NACO.J', 'Paranal/NACO.Ks', 'Paranal/NACO.Lp', 'Paranal/NACO.Mp', 'Paranal/NACO.NB374', 'Paranal/NACO.NB405']\n", "mean_wavel = {'Gemini/NICI.ED286': 1.5841803431418238, 'Magellan/VisAO.Ys': 0.9826820974261752, 'Paranal/NACO.H': 1.6588090664617747, 'Paranal/NACO.J': 1.265099894847529, 'Paranal/NACO.Ks': 2.144954491491888, 'Paranal/NACO.Lp': 3.8050282724280526, 'Paranal/NACO.Mp': 4.780970919324577, 'Paranal/NACO.NB374': 3.744805012092439, 'Paranal/NACO.NB405': 4.055862923806052}\n", "magnitude = {'Gemini/NICI.ED286': array([13.18, 0.15]), 'Magellan/VisAO.Ys': array([15.53, 0.34]), 'Paranal/NACO.H': array([13.32, 0.14]), 'Paranal/NACO.J': array([14.11, 0.21]), 'Paranal/NACO.Ks': array([12.64, 0.11]), 'Paranal/NACO.Lp': array([11.3 , 0.06]), 'Paranal/NACO.Mp': array([11.1 , 0.12]), 'Paranal/NACO.NB374': array([11.25, 0.23]), 'Paranal/NACO.NB405': array([10.98, 0.05])}\n", "flux = {'Gemini/NICI.ED286': array([6.98948256e-15, 9.68707446e-16]), 'Magellan/VisAO.Ys': array([4.24517648e-15, 1.35121790e-15]), 'Paranal/NACO.H': array([5.47258456e-15, 7.07618234e-16]), 'Paranal/NACO.J': array([6.86840606e-15, 1.33676606e-15]), 'Paranal/NACO.Ks': array([4.04416794e-15, 4.10431099e-16]), 'Paranal/NACO.Lp': array([1.58988159e-15, 8.79048294e-17]), 'Paranal/NACO.Mp': array([7.85616937e-16, 8.70064796e-17]), 'Paranal/NACO.NB374': array([1.69319021e-15, 3.61370420e-16]), 'Paranal/NACO.NB405': array([1.61004056e-15, 7.41713178e-17])}\n", "spectrum = None\n", "parallax = [51.44 0.12]\n", "distance = None\n" ] } ], "source": [ "object_box.open_box()" ] }, { "cell_type": "markdown", "id": "57af9768", "metadata": {}, "source": [ "Each [Box](https://species.readthedocs.io/en/latest/species.core.html#species.core.box.Box) is a Python object and the items in a box can be extracted as attributes. For example, to get the list of filter names:" ] }, { "cell_type": "code", "execution_count": 14, "id": "b076804c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['Gemini/NICI.ED286', 'Magellan/VisAO.Ys', 'Paranal/NACO.H', 'Paranal/NACO.J', 'Paranal/NACO.Ks', 'Paranal/NACO.Lp', 'Paranal/NACO.Mp', 'Paranal/NACO.NB374', 'Paranal/NACO.NB405']\n" ] } ], "source": [ "print(object_box.filters)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.0" } }, "nbformat": 4, "nbformat_minor": 5 }