From 81fefaf59ee9e0d86546c461f15ff42c1587d8ec Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Tue, 26 Feb 2019 15:14:10 +0100 Subject: [PATCH] updated docs --- LICENSE | 2 +- README.rst | 17 ++- docs/about.rst | 4 +- docs/examples.rst | 2 +- docs/index.rst | 18 +-- docs/installation.rst | 6 +- docs/species.data.rst | 32 +++++ docs/species.plot.rst | 16 +-- species/__init__.py | 2 +- species/analysis/fit.py | 2 + species/core/box.py | 75 +++++++---- species/data/companions.py | 2 +- .../{plot_photometry.py => plot_color.py} | 117 +++++++++--------- species/plot/util.py | 47 +++++++ species/read/read_colormag.py | 17 ++- species/read/read_model.py | 50 ++++---- species/read/read_object.py | 37 ++++-- 17 files changed, 288 insertions(+), 158 deletions(-) rename species/plot/{plot_photometry.py => plot_color.py} (68%) diff --git a/LICENSE b/LICENSE index 8cabb026..5b9ca546 100644 --- a/LICENSE +++ b/LICENSE @@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: - SPECIES Copyright (C) 2018 Tomas Stolker + species Copyright (C) 2018 Tomas Stolker This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. diff --git a/README.rst b/README.rst index 34840495..0726baac 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ -SPECIES +species ======= -**Spectral and Photometric Examination Code for Investigating Exoplanet and Substellar atmospheres** +**spectral and photometric examination code for investigating exoplanet and substellar atmospheres** .. image:: https://badge.fury.io/py/species.svg :target: https://badge.fury.io/py/species @@ -24,7 +24,7 @@ SPECIES .. image:: https://img.shields.io/badge/License-GPLv3-blue.svg :target: https://github.com/tomasstolker/species/blob/master/LICENSE -SPECIES is a toolkit for analyzing spectral and photometric data of planetary and substellar objects. +*species* is a toolkit for analyzing spectral and photometric data of planetary and substellar objects. It provides a coherent framework to characterize the atmospheres of directly imaged companions by combining data from various resources. A central database is used to store various data sets such as spectral and photometric libraries, atmospheric models, photometry of individual targets, filter transmission curves, and analysis results. There are tools available for creating color-magnitude diagrams, fitting atmospheric models and retrieving the posterior distributions, creating synthetic photometry, plotting spectra, etc. The package has been released on `PyPI `_ but is still under active development. Documentation ------------- @@ -34,11 +34,16 @@ Documentation can be found at `http://species.readthedocs.io `_ on the Github page. License ------- -Copyright 2018 Tomas Stolker +Copyright 2019 Tomas Stolker -SPECIES is distributed under the GNU General Public License v3. See the LICENSE file for the terms and conditions. \ No newline at end of file +*species* is distributed under the GNU General Public License v3. See the LICENSE file for the terms and conditions. \ No newline at end of file diff --git a/docs/about.rst b/docs/about.rst index b0174ebe..775986f0 100644 --- a/docs/about.rst +++ b/docs/about.rst @@ -6,9 +6,9 @@ About Questions & feedback -------------------- -SPECIES is developed by Tomas Stolker (tomas.stolker@phys.ethz.ch). Feel free to send an email for questions, comments, or suggestions. +*species* is developed by Tomas Stolker (tomas.stolker@phys.ethz.ch). Feel free to send an email for questions, comments, or suggestions. Attribution ----------- -Please cite Stolker et al. in prep. whenever results from SPECIES are used in a publication. Please also make sure to give credit the relevant papers regarding the use of the publicly available data that SPECIES is using, such as the photometric and spectral libraries, atmospheric models, filter transmission curves, and photometry of individual objects. More details will follow. \ No newline at end of file +Please cite Stolker et al. in prep. whenever results from *species* are used in a publication. Please also make sure to give credit the relevant papers regarding the use of the publicly available data that *species* is using, such as the photometric and spectral libraries, atmospheric models, filter transmission curves, and photometry of individual objects. More details will follow. \ No newline at end of file diff --git a/docs/examples.rst b/docs/examples.rst index 0453eb4a..46e37eb8 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -47,7 +47,7 @@ Here photometric data of 51 Eri b (Rajan et al. 2017) is added to the database. import species - species.SpeciesInit("./", "./data") + species.SpeciesInit("./") magnitudes = {"MKO/NSFCam.J":19.04, "MKO/NSFCam.H":18.99, "MKO/NSFCam.K":18.67, "Keck/NIRC2.Lp":16.20, "Keck/NIRC2.Mp":16.1} diff --git a/docs/index.rst b/docs/index.rst index 0f93abda..2cfe1f47 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,22 +1,6 @@ -.. Welcome to SPECIES' documentation! -.. ================================= -.. -.. .. toctree:: -.. :maxdepth: 2 -.. :caption: Contents: -.. -.. -.. -.. Indices and tables -.. ================== -.. -.. * :ref:`genindex` -.. * :ref:`modindex` -.. * :ref:`search` - .. _index: -Documentation for SPECIES +Documentation for species ========================= .. toctree:: diff --git a/docs/installation.rst b/docs/installation.rst index 432ad99e..af846d72 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -3,7 +3,7 @@ Installation ============ -SPECIES can be installed from the |pypi| with the |pip|:: +*species* can be installed from the |pypi| with the |pip|:: $ pip install species @@ -11,11 +11,11 @@ Alternatively, the repository can be cloned from |github|:: $ git clone git@github.com:tomasstolker/species.git -In that case, the dependencies can be installed from the SPECIES folder:: +In that case, the dependencies can be installed from the *species* folder:: $ pip install -r requirements.txt -The installation can be tested by starting Python in interactive mode and printing the SPECIES version:: +The installation can be tested by starting Python in interactive mode and printing the *species* version:: >>> import species >>> print species.__version__ diff --git a/docs/species.data.rst b/docs/species.data.rst index f3627429..6e8750a5 100644 --- a/docs/species.data.rst +++ b/docs/species.data.rst @@ -4,6 +4,22 @@ species.data package Submodules ---------- +species.data.btnextgen module +----------------------------- + +.. automodule:: species.data.btnextgen + :members: + :undoc-members: + :show-inheritance: + +species.data.companions module +------------------------------ + +.. automodule:: species.data.companions + :members: + :undoc-members: + :show-inheritance: + species.data.database module ---------------------------- @@ -20,6 +36,14 @@ species.data.drift\_phoenix module :undoc-members: :show-inheritance: +species.data.filters module +--------------------------- + +.. automodule:: species.data.filters + :members: + :undoc-members: + :show-inheritance: + species.data.irtf module ------------------------ @@ -28,6 +52,14 @@ species.data.irtf module :undoc-members: :show-inheritance: +species.data.leggett module +--------------------------- + +.. automodule:: species.data.leggett + :members: + :undoc-members: + :show-inheritance: + species.data.queries module --------------------------- diff --git a/docs/species.plot.rst b/docs/species.plot.rst index 80a53a85..af4888cc 100644 --- a/docs/species.plot.rst +++ b/docs/species.plot.rst @@ -4,14 +4,6 @@ species.plot package Submodules ---------- -species.plot.plot\_chisquare module ------------------------------------ - -.. automodule:: species.plot.plot_chisquare - :members: - :undoc-members: - :show-inheritance: - species.plot.plot\_mcmc module ------------------------------ @@ -36,6 +28,14 @@ species.plot.plot\_spectrum module :undoc-members: :show-inheritance: +species.plot.util module +------------------------ + +.. automodule:: species.plot.util + :members: + :undoc-members: + :show-inheritance: + Module contents --------------- diff --git a/species/__init__.py b/species/__init__.py index bb95bfee..a18ebf77 100644 --- a/species/__init__.py +++ b/species/__init__.py @@ -28,7 +28,7 @@ from species.plot.plot_mcmc import plot_posterior, \ plot_walkers -from species.plot.plot_photometry import plot_color_magnitude +from species.plot.plot_color import plot_color_magnitude, plot_color_color from species.plot.plot_spectrum import plot_spectrum diff --git a/species/analysis/fit.py b/species/analysis/fit.py index 6d59fd16..467d382c 100644 --- a/species/analysis/fit.py +++ b/species/analysis/fit.py @@ -290,6 +290,8 @@ def store_samples(self, :type sampler: emcee.ensemble.EnsembleSampler :param model: Atmospheric model. :type model: str + :param tag: Database tag. + :type tag: str :param chisquare: Maximum likelihood solution. Tuple with the chi-square value and related parameter values. :type chisquare: tuple(float, float) diff --git a/species/core/box.py b/species/core/box.py index 14580bab..7a5ef32a 100644 --- a/species/core/box.py +++ b/species/core/box.py @@ -2,8 +2,6 @@ Box module. """ -import numpy as np - def open_box(box): """ @@ -19,19 +17,24 @@ def create_box(boxtype, **kwargs): :return: """ - if boxtype == 'model': + if boxtype == 'colormag': + box = ColorMagBox() + box.library = kwargs['library'] + box.object_type = kwargs['object_type'] + box.filters_color = kwargs['filters_color'] + box.filter_mag = kwargs['filter_mag'] + box.color = kwargs['color'] + box.magnitude = kwargs['magnitude'] + box.sptype = kwargs['sptype'] + + elif boxtype == 'model': box = ModelBox() box.model = kwargs['model'] + box.type = kwargs['type'] box.wavelength = kwargs['wavelength'] box.flux = kwargs['flux'] box.parameters = kwargs['parameters'] - elif boxtype == 'photometry': - box = PhotometryBox() - box.name = kwargs['name'] - box.wavelength = kwargs['wavelength'] - box.flux = kwargs['flux'] - elif boxtype == 'object': box = ObjectBox() box.name = kwargs['name'] @@ -40,6 +43,12 @@ def create_box(boxtype, **kwargs): box.flux = kwargs['flux'] box.distance = kwargs['distance'] + elif boxtype == 'photometry': + box = PhotometryBox() + box.name = kwargs['name'] + box.wavelength = kwargs['wavelength'] + box.flux = kwargs['flux'] + elif boxtype == 'samples': box = SamplesBox() box.model = kwargs['model'] @@ -49,9 +58,10 @@ def create_box(boxtype, **kwargs): elif boxtype == 'spectrum': box = SpectrumBox() + box.spectrum = kwargs['spectrum'] + box.wavelength = kwargs['wavelength'] + box.flux = kwargs['flux'] box.name = kwargs['name'] - box.wavelength = np.asarray([kwargs['wavelength']]) - box.flux = np.asarray([kwargs['flux']]) elif boxtype == 'synphot': box = SynphotBox() @@ -61,7 +71,7 @@ def create_box(boxtype, **kwargs): return box -class SpectrumBox: +class ColorMagBox: """ Text """ @@ -71,13 +81,13 @@ def __init__(self): :return: """ - self.spectrum = None - self.wavelength = None - self.flux = None - self.name = None - self.simbad = None + self.library = None + self.object_type = None + self.filters_color = None + self.filter_mag = None + self.color = None + self.magnitude = None self.sptype = None - self.distance = None class ModelBox: @@ -97,6 +107,23 @@ def __init__(self): self.parameters = None +class ObjectBox: + """ + Text + """ + + def __init__(self): + """ + :return: + """ + + self.name = None + self.filter = None + self.magnitude = None + self.flux = None + self.distance = None + + class PhotometryBox: """ Text @@ -127,7 +154,8 @@ def __init__(self): self.samples = None self.chisquare = None -class ObjectBox: + +class SpectrumBox: """ Text """ @@ -137,12 +165,15 @@ def __init__(self): :return: """ - self.name = None - self.filter = None - self.magnitude = None + self.spectrum = None + self.wavelength = None self.flux = None + self.name = None + self.simbad = None + self.sptype = None self.distance = None + class SynphotBox: """ Text diff --git a/species/data/companions.py b/species/data/companions.py index 892c2c9c..1d37657c 100644 --- a/species/data/companions.py +++ b/species/data/companions.py @@ -64,7 +64,7 @@ def get_data(): 'Paranal/SPHERE.IRDIS_D_H23_2':(18.41, 0.26), # Samland et al. 2017 'Paranal/SPHERE.IRDIS_D_K12_1':(17.55, 0.14), # Samland et al. 2017 'Keck/NIRC2.Lp':(16.20, 0.11), # Rajan et al. 2017 - 'Keck/NIRC2.Mp':(16.1, 0.5)}}, # Rajan et al. 2017 + 'Keck/NIRC2.Ms':(16.1, 0.5)}}, # Rajan et al. 2017 'GSC 06214 B':{'distance':108.84, 'app_mag':{'MKO/NSFCam.J':(16.24, 0.04), # Ireland et al. 2011 diff --git a/species/plot/plot_photometry.py b/species/plot/plot_color.py similarity index 68% rename from species/plot/plot_photometry.py rename to species/plot/plot_color.py index c019a040..2a5875a8 100644 --- a/species/plot/plot_photometry.py +++ b/species/plot/plot_color.py @@ -4,6 +4,8 @@ import os import sys +import math +import itertools import numpy as np import matplotlib as mpl @@ -11,6 +13,7 @@ from matplotlib.colorbar import Colorbar +from species.plot import util from species.read import read_object @@ -20,59 +23,33 @@ plt.rc('axes', edgecolor='black', linewidth=2) -def sptype_discrete(sptype, shape): - """ - :param sptype: - :type sptype: - - :return:: - :rtype: numpy.ndarray - """ - - spt_disc = np.zeros(shape) - - for i, item in enumerate(sptype): - sp = item[0:2] - - if sp in (np.string_('M0'), np.string_('M1'), np.string_('M2'), np.string_('M3'), np.string_('M4')): - spt_disc[i] = 0 - - elif sp in (np.string_('M5'), np.string_('M6'), np.string_('M7'), np.string_('M8'), np.string_('M9')): - spt_disc[i] = 1 - - elif sp in (np.string_('L0'), np.string_('L1'), np.string_('L2'), np.string_('L3'), np.string_('L4')): - spt_disc[i] = 2 - - elif sp in (np.string_('L5'), np.string_('L6'), np.string_('L7'), np.string_('L8'), np.string_('L9')): - spt_disc[i] = 3 - - elif sp in (np.string_('T0'), np.string_('T1'), np.string_('T2'), np.string_('T3'), np.string_('T4')): - spt_disc[i] = 4 - - elif sp in (np.string_('T5'), np.string_('T6'), np.string_('T7'), np.string_('T8'), np.string_('T9')): - spt_disc[i] = 5 - - elif np.string_('Y') in item: - spt_disc[i] = 6 - - else: - spt_disc[i] = np.nan - continue - - return spt_disc - -def plot_color_magnitude(color, - magnitude, - sptype, +def plot_color_magnitude(colorbox, objects, label_x, label_y, output, xlim=None, - ylim=None): + ylim=None, + legend='top left'): """ - :param color: - :type color: + :param colorbox: Box with the colors and magnitudes. + :type colorbox: tuple(species.core.box.ColorMagBox, ) + :param objects: Tuple with individual objects. The objects require a tuple with their database + tag, the two filter IDs for the color, and the filter ID for the absolute + magnitude. + :type objects: tuple(tuple(str, str, str, str), ) + :param label_x: Label for the x-axis. + :type label_x: str + :param label_y: Label for the y-axis. + :type label_y: str + :param output: Output filename. + :type output: str + :param xlim: Limits for the x-axis. + :type xlim: tuple(float, float) + :param ylim: Limits for the y-axis. + :type ylim: tuple(float, float) + :param legend: Legend position. + :type legend: str :return: None """ @@ -80,6 +57,8 @@ def plot_color_magnitude(color, sys.stdout.write('Plotting color-magnitude diagram: '+output+'... ') sys.stdout.flush() + marker = itertools.cycle(('o', 's', '*', 'p', '<', '>', 'P', 'v', '^')) + plt.figure(1, figsize=(4, 4.8)) gridsp = mpl.gridspec.GridSpec(3, 1, height_ratios=[0.2, 0.1, 4.5]) gridsp.update(wspace=0., hspace=0., left=0, right=1, bottom=0, top=1) @@ -111,20 +90,25 @@ def plot_color_magnitude(color, if ylim: ax1.set_ylim(ylim[0], ylim[1]) - indices = np.where(sptype != 'None')[0] - - sptype = sptype[indices] - color = color[indices] - magnitude = magnitude[indices] - - spt_disc = sptype_discrete(sptype, color.shape) - cmap = plt.cm.viridis bounds = np.arange(0, 8, 1) norm = mpl.colors.BoundaryNorm(bounds, cmap.N) - scat = ax1.scatter(color, magnitude, c=spt_disc, cmap=cmap, norm=norm, - zorder=3, s=25., alpha=0.6) + for item in colorbox: + sptype = item.sptype + color = item.color + magnitude = item.magnitude + + indices = np.where(sptype != 'None')[0] + + sptype = sptype[indices] + color = color[indices] + magnitude = magnitude[indices] + + spt_disc = util.sptype_discrete(sptype, color.shape) + + scat = ax1.scatter(color, magnitude, c=spt_disc, cmap=cmap, norm=norm, + zorder=1, s=25., alpha=0.6) cb = Colorbar(ax=ax2, mappable=scat, orientation='horizontal', ticklocation='top', format='%.2f') @@ -136,10 +120,21 @@ def plot_color_magnitude(color, if objects is not None: for item in objects: objdata = read_object.ReadObject(item[0]) - color = objdata.get_magnitude(item[1]) - objdata.get_magnitude(item[2]) - mag = objdata.get_magnitude(item[3]) + objcolor1 = objdata.get_photometry(item[1]) + objcolor2 = objdata.get_photometry(item[2]) + abs_mag = objdata.get_absmag(item[3]) - ax1.plot(color, mag, 's', ms=5, color='black') + colorerr = math.sqrt(objcolor1[1]**2+objcolor2[1]**2) + + ax1.errorbar(objcolor1[0]-objcolor2[0], abs_mag[0], yerr=abs_mag[1], xerr=colorerr, + marker=next(marker), ms=6, color='black', label=objdata.object_name, + markerfacecolor='white', markeredgecolor='black', zorder=2) + + handles, labels = ax1.get_legend_handles_labels() + + if handles: + handles = [h[0] for h in handles] + ax1.legend(handles, labels, loc=legend, prop={'size':9}, frameon=False, numpoints=1) plt.savefig(os.getcwd()+'/'+output, bbox_inches='tight') plt.close() @@ -195,7 +190,7 @@ def plot_color_color(colors, color = color[indices] magnitude = magnitude[indices] - spt_disc = sptype_discrete(sptype, color.shape) + spt_disc = util.sptype_discrete(sptype, color.shape) cmap = plt.cm.viridis bounds = np.arange(0, 8, 1) diff --git a/species/plot/util.py b/species/plot/util.py index 101cb2e9..6263ccde 100644 --- a/species/plot/util.py +++ b/species/plot/util.py @@ -2,6 +2,53 @@ Text. """ +import numpy as np + + +def sptype_discrete(sptype, + shape): + """ + :param sptype: + :type sptype: + :param shape: + :type shape: + + :return:: + :rtype: numpy.ndarray + """ + + spt_disc = np.zeros(shape) + + for i, item in enumerate(sptype): + sp = item[0:2] + + if sp in (np.string_('M0'), np.string_('M1'), np.string_('M2'), np.string_('M3'), np.string_('M4')): + spt_disc[i] = 0 + + elif sp in (np.string_('M5'), np.string_('M6'), np.string_('M7'), np.string_('M8'), np.string_('M9')): + spt_disc[i] = 1 + + elif sp in (np.string_('L0'), np.string_('L1'), np.string_('L2'), np.string_('L3'), np.string_('L4')): + spt_disc[i] = 2 + + elif sp in (np.string_('L5'), np.string_('L6'), np.string_('L7'), np.string_('L8'), np.string_('L9')): + spt_disc[i] = 3 + + elif sp in (np.string_('T0'), np.string_('T1'), np.string_('T2'), np.string_('T3'), np.string_('T4')): + spt_disc[i] = 4 + + elif sp in (np.string_('T5'), np.string_('T6'), np.string_('T7'), np.string_('T8'), np.string_('T9')): + spt_disc[i] = 5 + + elif np.string_('Y') in item: + spt_disc[i] = 6 + + else: + spt_disc[i] = np.nan + continue + + return spt_disc + def update_labels(param): """ diff --git a/species/read/read_colormag.py b/species/read/read_colormag.py index bddbe0e2..e77464dd 100644 --- a/species/read/read_colormag.py +++ b/species/read/read_colormag.py @@ -9,6 +9,7 @@ import numpy as np from species.analysis import photometry +from species.core import box from species.data import database @@ -43,14 +44,17 @@ def __init__(self, self.database = config['species']['database'] + if isinstance(self.library, str): + self.library = (self.library, ) + def get_color_magnitude(self, object_type): """ :param object_type: :type object_type: str - :return: - :rtype: numpy.ndarray, numpy.ndarray, numpy.ndarray + :return: Colors and magnitudes (mag). + :rtype: """ h5_file = h5py.File(self.database, 'r') @@ -109,4 +113,11 @@ def get_color_magnitude(self, h5_file.close() - return color[indices], mag[indices], sptype[indices] + return box.create_box(boxtype='colormag', + library=self.library, + object_type=object_type, + filters_color=self.filters_color, + filter_mag=self.filter_mag, + color=color[indices], + magnitude=mag[indices], + sptype=sptype[indices]) diff --git a/species/read/read_model.py b/species/read/read_model.py index 3a32c1c3..a08f65ac 100644 --- a/species/read/read_model.py +++ b/species/read/read_model.py @@ -133,29 +133,29 @@ def interpolate(self): flux = flux[:, :, :, wl_index] points = (teff, logg, feh, wavelength[wl_index]) - elif self.model == 'petitcode_warm_clear': - feh = np.asarray(h5_file['models/petitcode_warm_clear/feh']) - flux = flux[:, :, :, wl_index] - points = np.asarray((teff, logg, feh, wavelength[wl_index])) - - elif self.model == 'petitcode_warm_cloudy': - feh = np.asarray(h5_file['models/petitcode_warm_cloudy/feh']) - fsed = np.asarray(h5_file['models/petitcode_warm_cloudy/fsed']) - flux = flux[:, :, :, :, wl_index] - points = np.asarray((teff, logg, feh, fsed, wavelength[wl_index])) - - elif self.model == 'petitcode_hot_clear': - feh = np.asarray(h5_file['models/petitcode_hot_clear/feh']) - co_ratio = np.asarray(h5_file['models/petitcode_hot_clear/co']) - flux = flux[:, :, :, :, wl_index] - points = np.asarray((teff, logg, feh, co_ratio, wavelength[wl_index])) - - elif self.model == 'petitcode_hot_cloudy': - feh = np.asarray(h5_file['models/petitcode_hot_cloudy/feh']) - co_ratio = np.asarray(h5_file['models/petitcode_hot_cloudy/co']) - fsed = np.asarray(h5_file['models/petitcode_hot_cloudy/fsed']) - flux = flux[:, :, :, :, :, wl_index] - points = np.asarray((teff, logg, feh, co_ratio, fsed, wavelength[wl_index])) + # elif self.model == 'petitcode_warm_clear': + # feh = np.asarray(h5_file['models/petitcode_warm_clear/feh']) + # flux = flux[:, :, :, wl_index] + # points = np.asarray((teff, logg, feh, wavelength[wl_index])) + # + # elif self.model == 'petitcode_warm_cloudy': + # feh = np.asarray(h5_file['models/petitcode_warm_cloudy/feh']) + # fsed = np.asarray(h5_file['models/petitcode_warm_cloudy/fsed']) + # flux = flux[:, :, :, :, wl_index] + # points = np.asarray((teff, logg, feh, fsed, wavelength[wl_index])) + # + # elif self.model == 'petitcode_hot_clear': + # feh = np.asarray(h5_file['models/petitcode_hot_clear/feh']) + # co_ratio = np.asarray(h5_file['models/petitcode_hot_clear/co']) + # flux = flux[:, :, :, :, wl_index] + # points = np.asarray((teff, logg, feh, co_ratio, wavelength[wl_index])) + # + # elif self.model == 'petitcode_hot_cloudy': + # feh = np.asarray(h5_file['models/petitcode_hot_cloudy/feh']) + # co_ratio = np.asarray(h5_file['models/petitcode_hot_cloudy/co']) + # fsed = np.asarray(h5_file['models/petitcode_hot_cloudy/fsed']) + # flux = flux[:, :, :, :, :, wl_index] + # points = np.asarray((teff, logg, feh, co_ratio, fsed, wavelength[wl_index])) h5_file.close() @@ -340,8 +340,8 @@ def get_photometry(self, :param synphot: Synthetic photometry object. :type synphot: species.analysis.photometry.SyntheticPhotometry - :return: Apparent magnitude (mag), absolute magnitude (mag). - :rtype: float, float + :return: Average flux density (W m-2 micron-1). + :rtype: float """ if sampling is None: diff --git a/species/read/read_object.py b/species/read/read_object.py index 9aaadf94..afefa8ee 100644 --- a/species/read/read_object.py +++ b/species/read/read_object.py @@ -8,13 +8,16 @@ import h5py import numpy as np +from species.analysis import photometry + class ReadObject: """ Text """ - def __init__(self, object_name): + def __init__(self, + object_name): """ :param object_name: Object name. :type object_name: str @@ -31,21 +34,22 @@ def __init__(self, object_name): self.database = config['species']['database'] - def get_photometry(self, filter_name): + def get_photometry(self, + filter_name): """ :param filter_name: Filter name. :type filter_name: str - :return: Wavelength (micron), apparent magnitude (mag), magnitude error (error), + :return: Apparent magnitude (mag), magnitude error (error), apparent flux (W m-2 micron-1), flux error (W m-2 micron-1). :rtype: numpy.ndarray """ h5_file = h5py.File(self.database, 'r') - photometry = np.asarray(h5_file['objects/'+self.object_name+'/'+filter_name]) + obj_phot = np.asarray(h5_file['objects/'+self.object_name+'/'+filter_name]) h5_file.close() - return photometry + return obj_phot def get_distance(self): """ @@ -54,7 +58,26 @@ def get_distance(self): """ h5_file = h5py.File(self.database, 'r') - distance = np.asarray(h5_file['objects/'+self.object_name+'/distance']) + obj_distance = np.asarray(h5_file['objects/'+self.object_name+'/distance']) + h5_file.close() + + return float(obj_distance) + + def get_absmag(self, + filter_name): + """ + :param filter_name: Filter name. + :type filter_name: str + + :return: Absolute magnitude (mag), magnitude error (error). + :rtype: float, float + """ + + h5_file = h5py.File(self.database, 'r') + obj_distance = np.asarray(h5_file['objects/'+self.object_name+'/distance']) + obj_phot = np.asarray(h5_file['objects/'+self.object_name+'/'+filter_name]) h5_file.close() - return float(distance) + abs_mag = photometry.apparent_to_absolute(obj_phot[0], obj_distance) + + return abs_mag, obj_phot[1]