Skip to content

Commit

Permalink
Legend **kwargs in plot_spectrum
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Stolker committed Mar 13, 2020
1 parent ab63e03 commit bc49711
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
14 changes: 7 additions & 7 deletions species/analysis/fit_planck.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def lnlike(param,
distance,
spectrum):
"""
Internal function for the likelihood probability.
Internal function for the likelihood function.
Parameters
----------
Expand Down Expand Up @@ -177,7 +177,7 @@ def lnprob(param,

class FitPlanck:
"""
Class for fitting Planck spectra to spectral and photometric data.
Class for fitting Planck spectra to photometric and/or spectroscopic data.
"""

def __init__(self,
Expand All @@ -192,16 +192,16 @@ def __init__(self,
object_name : str
Object name in the database.
filters : tuple(str, )
Filter names for which the photometry is selected. All available photometry of the
object are used if set to None.
Filter names for which the photometry is selected. All available photometric data of
the object are used if set to None.
bounds : dict
Parameter boundaries for 'teff' and 'radius'. The values should be provided either as
float or as list of floats such that multiple Planck functions can be combined,
e.g. ``{'teff': [(1000., 2000.), (500., 1500.)], 'radius': [(0.5, 1.5), (1.5, 2.0)]}``.
inc_phot : bool
Include photometry data with the fit.
Include photometric data with the fit.
inc_spec : bool
Include spectral data with the fit.
Include spectroscopic data with the fit.
Returns
-------
Expand All @@ -210,7 +210,7 @@ def __init__(self,
"""

if not inc_phot and not inc_spec:
raise ValueError('No photometric or spectral data has been selected.')
raise ValueError('No photometric or spectroscopic data has been selected.')

if 'teff' not in bounds or 'radius' not in bounds:
raise ValueError('The \'bounds\' dictionary should contain \'teff\' and \'radius\'.')
Expand Down
5 changes: 4 additions & 1 deletion species/data/companions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def get_data():
'app_mag': {'Paranal/SPHERE.IRDIS_D_H23_2': (17.94, 0.24), # Keppler et al. 2018
'Paranal/SPHERE.IRDIS_D_H23_3': (17.95, 0.17), # Keppler et al. 2018
'Paranal/SPHERE.IRDIS_D_K12_1': (16.65, 0.06), # Müller et al. 2018
'Paranal/SPHERE.IRDIS_D_K12_2': (16.44, 0.05)}}, # Müller et al. 2018
'Paranal/SPHERE.IRDIS_D_K12_2': (16.44, 0.05), # Müller et al. 2018
'Paranal/NACO.Lp': (14.08, 0.33), # Stolker et al. in prep.
'Paranal/NACO.NB405': (13.91, 0.34), # Stolker et al. in prep.
'Paranal/NACO.Mp': (13.64, 0.22)}}, # Stolker et al. in prep.

'PDS 70 c': {'distance': (113.43, 0.52),
'app_mag': {'Paranal/NACO.NB405': (15.05, 0.59)}}, # Stolker et al. in prep.
Expand Down
8 changes: 4 additions & 4 deletions species/plot/plot_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def plot_color_magnitude(boxes,
"""

print(f'Plotting color-magnitude diagram: {output}... ', end='', flush=True)
print(f'Plotting color-magnitude diagram: {output}...', end='', flush=True)

model_color = ('#234398', '#f6a432', 'black')
model_linestyle = ('-', '--', ':', '-.')
Expand Down Expand Up @@ -389,7 +389,7 @@ def plot_color_magnitude(boxes,
plt.clf()
plt.close()

print('[DONE]')
print(' [DONE]')


def plot_color_color(boxes,
Expand Down Expand Up @@ -454,7 +454,7 @@ def plot_color_color(boxes,
None
"""

print(f'Plotting color-color diagram: {output}... ', end='', flush=True)
print(f'Plotting color-color diagram: {output}...', end='', flush=True)

model_color = ('#234398', '#f6a432')
model_linestyle = ('-', '--', ':', '-.')
Expand Down Expand Up @@ -687,4 +687,4 @@ def plot_color_color(boxes,
plt.clf()
plt.close()

print('[DONE]')
print(' [DONE]')
14 changes: 9 additions & 5 deletions species/plot/plot_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def plot_spectrum(boxes,
scale=('linear', 'linear'),
title=None,
offset=None,
legend='upper left',
legend=None,
figsize=(7., 5.),
object_type='planet',
quantity='flux',
Expand Down Expand Up @@ -63,8 +63,9 @@ def plot_spectrum(boxes,
Title.
offset : tuple(float, float)
Offset for the label of the x- and y-axis.
legend : str, None
Location of the legend.
legend : str, tuple, dict, None
Location of the legend (str, tuple) or a dictionary with the ``**kwargs`` of
``matplotlib.pyplot.legend``, e.g. ``{'loc': 'upper left', 'fontsize: 12.}``.
figsize : tuple(float, float)
Figure size.
object_type : str
Expand Down Expand Up @@ -465,8 +466,11 @@ def plot_spectrum(boxes,

handles, _ = ax1.get_legend_handles_labels()

if handles and legend:
ax1.legend(loc=legend, fontsize=10, frameon=False)
if handles and legend is not None:
if isinstance(legend, (str, tuple)):
ax1.legend(loc=legend, fontsize=8, frameon=False)
else:
ax1.legend(**legend)

plt.savefig(os.getcwd()+'/'+output, bbox_inches='tight')
plt.clf()
Expand Down
5 changes: 5 additions & 0 deletions species/util/phot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ def get_residuals(datatype,

if spectrum == 'planck':
readmodel = read_planck.ReadPlanck(wavel_range=wavel_range)

model = readmodel.get_spectrum(model_param=parameters, spec_res=1000.)

flux_new = spectres.spectres(new_spec_wavs=wl_new,
old_spec_wavs=model.wavelength,
spec_fluxes=model.flux)

else:
if spectrum == 'petitradtrans':
# TODO change back
Expand Down
8 changes: 0 additions & 8 deletions species/util/plot_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ def update_labels(param):
index = param.index('radius')
param[index] = r'$R$ ($\mathregular{R_{Jup}}$)'

if 'scaling' in param:
index = param.index('scaling')
param[index] = 'Scaling'

if 'offset' in param:
index = param.index('offset')
param[index] = 'Offset'

if 'teff' in param:
index = param.index('teff')
param[index] = r'$T_\mathregular{eff}$ (K)'
Expand Down

0 comments on commit bc49711

Please sign in to comment.