#!/usr/bin/env python # coding: utf-8 # # Color-magnitude diagram # The tutorial shows how to create a color-magnitude diagram which combines the photometry from field and young/low-gravity objects, synthetic photometry computed from isochrones and model spectra, and photometry from directly imaged objects. # ## Initiating *species* # In[1]: import species import wget import numpy as np # In[2]: species.SpeciesInit() database = species.Database() # ## Adding data to the database # All available photometric data of directly imaged planets and brown dwarfs is added with `add_companion` by setting `name=None`. These data are extracted from the [dictionary with apparent magnitudes](https://github.com/tomasstolker/species/blob/master/species/data/companions.py) in the `data.companions` module. # In[3]: database.add_companion(name=None) # The broadband photometry and parallaxes of the [Database of Ultracool Parallaxes](http://www.as.utexas.edu/~tdupuy/plx/Database_of_Ultracool_Parallaxes.html) is added. # In[4]: database.add_photometry(phot_library='vlm-plx') # The isochrones from the AMES-Cond and AMES-Dusty evolutionary models are downloaded with `wget`. # In[5]: wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Cond/ISOCHRONES/model.AMES-Cond-2000.M-0.0.NaCo.Vega', out='data/model.AMES-Cond-2000.M-0.0.NaCo.Vega') wget.download('https://phoenix.ens-lyon.fr/Grids/AMES-Dusty/ISOCHRONES/model.AMES-dusty.M-0.0.NaCo.Vega', out='data/model.AMES-dusty.M-0.0.NaCo.Vega') # And added to the HDF5 database. # In[6]: database.add_isochrones(filename='data/model.AMES-Cond-2000.M-0.0.NaCo.Vega', isochrone_tag='iso_cond', model='baraffe') database.add_isochrones(filename='data/model.AMES-dusty.M-0.0.NaCo.Vega', isochrone_tag='iso_dusty', model='baraffe') # Also the synthetic spectra from the AMES-Cond and AMES-Dusty atmospheric models are dowloaded and added to the database. # In[7]: database.add_model(model='ames-cond', wavel_range=(0.5, 10.), teff_range=(100., 4000.), spec_res=1000.) database.add_model(model='ames-dusty', wavel_range=(0.5, 10.), teff_range=(100., 4000.), spec_res=1000.) # ## Database content # Let's have a look at all the data that is stored in the database. # In[8]: database.list_content() # ## Synthetic photometry from isochrones # Magnitudes are available in the isochrone data which can be extracted with the `get_isochrone` function of `ReadIsochrone`. However, in this example, we consistently recompute the synthetic photometry by making use of both the isochrones and the model spectra. # The isochrones will be iterpolated for three different ages and the synthetic photometry is computed for 100 logarithmically spaced masses. # In[9]: ages = [20., 100., 1000.] # [Myr] masses = np.logspace(-1., 4., 100) # [Mjup] # Object of `ReadIsochones` are initiated for both the AMES-Cond and AMES-Dusty isochrones. # In[10]: read_iso_cond = species.ReadIsochrone(isochrone_tag='iso_cond') read_iso_dusty = species.ReadIsochrone(isochrone_tag='iso_dusty') # The colors and magnitudes are computed by chosing the corresponding model spectra that are stored in the database. The results of two models are stored in `ColorMagBox` objects for the three different ages. # In[11]: boxes = [] for item in ages: modelcolor1 = read_iso_cond.get_color_magnitude(age=item, masses=masses, model='ames-cond', filters_color=('MKO/NSFCam.H', 'MKO/NSFCam.Lp'), filter_mag='MKO/NSFCam.Lp') modelcolor2 = read_iso_dusty.get_color_magnitude(age=item, masses=masses, model='ames-dusty', filters_color=('MKO/NSFCam.H', 'MKO/NSFCam.Lp'), filter_mag='MKO/NSFCam.Lp') boxes.append(modelcolor1) boxes.append(modelcolor2) # ## Photometry of directly imaged objects # Before selecting the photometric data of the directly imaged planets and brown dwarfs, let's see which objects and magnitudes are stored in the database. # In[12]: database.list_companions() # A list with object names and filters for the colors and magnitudes is created. # In[13]: objects = [('HR 8799 b', 'Keck/NIRC2.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('HR 8799 c', 'Keck/NIRC2.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('HR 8799 d', 'Keck/NIRC2.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('HR 8799 e', 'Paranal/SPHERE.IRDIS_D_H23_2', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('kappa And b', 'Subaru/CIAO.H', 'Keck/NIRC2.Lp', 'Keck/NIRC2.Lp'), ('GSC 06214 B', 'MKO/NSFCam.H', 'MKO/NSFCam.Lp', 'MKO/NSFCam.Lp'), ('ROXs 42 Bb', 'Keck/NIRC2.H', 'Keck/NIRC2.Lp', 'Keck/NIRC2.Lp'), ('51 Eri b', 'MKO/NSFCam.H', 'Keck/NIRC2.Lp', 'Keck/NIRC2.Lp'), ('2M1207 b', 'Paranal/NACO.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('2M0103 ABb', 'Paranal/NACO.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('1RXS 1609 B', 'Gemini/NIRI.H-G0203w', 'Gemini/NIRI.Lprime-G0207w', 'Gemini/NIRI.Lprime-G0207w'), ('beta Pic b', 'Paranal/NACO.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('HIP 65426 b', 'Paranal/SPHERE.IRDIS_D_H23_2', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('PZ Tel B', 'Paranal/NACO.H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp'), ('HD 206893 B', 'Paranal/SPHERE.IRDIS_B_H', 'Paranal/NACO.Lp', 'Paranal/NACO.Lp')] # ## Reading color-magnitude data # The colors and magnitude of the Database of Ultracool Parallaxes are read from the HDF5 database by first creating an object of `ReadColorMagnitude`. # In[14]: colormag = species.ReadColorMagnitude(phot_library=['vlm-plx', ], filters_color=('MKO/NSFCam.H', 'MKO/NSFCam.Lp'), filter_mag='MKO/NSFCam.Lp') # And then extracting the `ColorMagBox` objects for field and young/low-gravity objects separately. # In[15]: color_field = colormag.get_color_magnitude(object_type='field') color_young = colormag.get_color_magnitude(object_type='young') # ## Plotting a color-magnitude diagram # The color-magnitude diagram is plotted with the `plot_color_magnitude` function. The boxes with photometric data are provided as list to the `colorbox` parameter. The boxes with synthetic photometry are provided to the `models` parameter. # In[16]: species.plot_color_magnitude(colorbox=[color_field, color_young], objects=objects, models=boxes, mass_labels=[1., 3., 5., 10., 20., 50., 100., 200.], companion_labels=False, field_range=('late M', 'late T'), label_x='H - L$^\prime$ [mag]', label_y='M$_\mathregular{L\prime}$ [mag]', xlim=(0.3, 4.), ylim=(15., 7.1), offset=(-0.08, -0.09), legend=(0.04, 0.04), output='color_mag.png') # In[17]: from IPython.display import Image Image('color_mag.png')