Skip to content

Commit

Permalink
read and plot color-color
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Stolker committed Mar 6, 2019
1 parent 100617b commit ac860da
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 44 deletions.
4 changes: 2 additions & 2 deletions species/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from species.read.read_spectrum import ReadSpectrum, \
get_planck

from species.read.read_colormag import ReadColorMagnitude, \
ReadColorColor
from species.read.read_color import ReadColorMagnitude, \
ReadColorColor

from species.read.read_object import ReadObject

Expand Down
46 changes: 28 additions & 18 deletions species/data/companions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# 'HR 8799 c':{'distance':41.29,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -53,7 +53,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# 'HR 8799 d':{'distance':41.29,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -62,7 +62,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# 'HR 8799 e':{'distance':41.29,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -71,7 +71,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# 'HD 95086 b':{'distance':86.44,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -80,7 +80,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# '2M1207 B':{'distance':64.42,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -99,7 +99,7 @@ def get_data():
'app_mag':{'Paranal/SPHERE.IRDIS_B_H':(16.79, 0.06), # Milli et al. 2016
'Paranal/SPHERE.IRDIS_D_K12_1':(15.2, 0.10), # Chauvin et al. 2017
'Paranal/SPHERE.IRDIS_D_K12_2':(14.88, 0.09), # Chauvin et al. 2017
'Paranal/NACO.Lp':(13.43, 0.16)}}, # Milli et al. 2016, TODO update error to +0.17, -0.15?
'Paranal/NACO.Lp':(13.43, 0.16)}}, # Milli et al. 2016, error is +0.17, -0.15?
# 'Paranal/NACO.Mp':(), # Stolker et al. in prep.

# 'GQ Lup B':{'distance':151.82,
Expand All @@ -112,7 +112,7 @@ def get_data():
# '':()}},

'PZ Tel B':{'distance':47.13,
'app_mag':{'Paranal/SPHERE.ZIMPOL_R_PRIM':(17.84, 0.3), # Maire et al. 2015, TODO update error to +0.22, −0.31?
'app_mag':{'Paranal/SPHERE.ZIMPOL_R_PRIM':(17.84, 0.3), # Maire et al. 2015, error is +0.22, −0.31?
'Paranal/SPHERE.ZIMPOL_I_PRIM':(15.16, 0.12), # Maire et al. 2015
'Paranal/SPHERE.IRDIS_D_H23_2':(11.78, 0.19), # Maire et al. 2015
'Paranal/SPHERE.IRDIS_D_H23_3':(11.65, 0.19), # Maire et al. 2015
Expand All @@ -135,16 +135,26 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#
# 'GJ 504 B':{'distance':17.54,
# 'app_mag':{'':(),
# '':(),
# '':(),
# '':(),
# '':(),
# '':(),
# '':()}},
#

'GJ 504 b':{'distance':17.54,
'app_mag':{'Paranal/SPHERE.IRDIS_D_Y23_2':(20.98, 0.20),
'Paranal/SPHERE.IRDIS_D_Y23_3':(20.14, 0.09),
# 'Paranal/SPHERE.IRDIS_D_J23_2':(>21.28, ),
'Paranal/SPHERE.IRDIS_D_J23_3':(19.01, 0.17),
'Paranal/SPHERE.IRDIS_D_H23_2':(18.95, 0.30),
'Paranal/SPHERE.IRDIS_D_H23_3':(21.81, 0.35),
'Paranal/SPHERE.IRDIS_D_K12_1':(18.77, 0.20),
# 'Paranal/SPHERE.IRDIS_D_K12_2':(>19.96, ),
'Subaru/CIAO.J':(19.78, 0.10),
'Subaru/CIAO.H':(20.01, 0.14),
'Subaru/CIAO.Ks':(19.38, 0.11),
'Subaru/CIAO.CH4s':(19.58, 0.13),
# 'Subaru/CIAO.CH4l':(>20.63, ),
# 'LBTI/LMIRcam.L_NB6':(17.59, 0.17),
# 'LBTI/LMIRcam.L_NB7':(16.47, 0.19),
# 'LBTI/LMIRcam.L_NB8':(15.85, 0.17),
'Subaru/IRCS.Lp':(16.70, 0.17)}},

# 'GU Psc B':{'distance':47.61,
# 'app_mag':{'':(),
# '':(),
Expand All @@ -153,7 +163,7 @@ def get_data():
# '':(),
# '':(),
# '':()}},
#

# '1RXS 1609 B':{'distance':139.67,
# 'app_mag':{'':(),
# '':(),
Expand Down
120 changes: 100 additions & 20 deletions species/plot/plot_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def plot_color_magnitude(colorbox,
output,
xlim=None,
ylim=None,
offset=None,
legend='top left'):
"""
:param colorbox: Box with the colors and magnitudes.
Expand Down Expand Up @@ -81,8 +82,12 @@ def plot_color_magnitude(colorbox,

ax1.invert_yaxis()

ax1.get_xaxis().set_label_coords(0.5, -0.08)
ax1.get_yaxis().set_label_coords(-0.12, 0.5)
if offset:
ax1.get_xaxis().set_label_coords(0.5, offset[0])
ax1.get_yaxis().set_label_coords(offset[1], 0.5)
else:
ax1.get_xaxis().set_label_coords(0.5, -0.08)
ax1.get_yaxis().set_label_coords(-0.12, 0.5)

if xlim:
ax1.set_xlim(xlim[0], xlim[1])
Expand All @@ -106,6 +111,13 @@ def plot_color_magnitude(colorbox,

spt_disc = util.sptype_discrete(sptype, color.shape)

_, unique = np.unique(color, return_index=True)

sptype = sptype[unique]
color = color[unique]
magnitude = magnitude[unique]
spt_disc = spt_disc[unique]

scat = ax1.scatter(color, magnitude, c=spt_disc, cmap=cmap, norm=norm,
zorder=1, s=25., alpha=0.6)

Expand All @@ -119,6 +131,7 @@ def plot_color_magnitude(colorbox,
if objects is not None:
for item in objects:
objdata = read_object.ReadObject(item[0])

objcolor1 = objdata.get_photometry(item[1])
objcolor2 = objdata.get_photometry(item[2])
abs_mag = objdata.get_absmag(item[3])
Expand Down Expand Up @@ -146,19 +159,43 @@ def plot_color_color(colorbox,
objects,
label_x,
label_y,
output):
output,
xlim=None,
ylim=None,
offset=None,
legend='top left'):
"""
:param colors:
:type colors: tuple(tuple(str, str), tuple(str, str))
:param colorbox: Box with the colors and magnitudes.
:type colorbox: 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 offset: Offset of the x- and y-axis label.
:type offset: tuple(float, float)
:param legend: Legend position.
:type legend: str
:return: None
"""

sys.stdout.write('Plotting color-color diagram: '+output+'... ')
sys.stdout.flush()

plt.figure(1, figsize=(4, 4.8))
gridsp = mpl.gridspec.GridSpec(3, 1, height_ratios=[0.2, 0.1, 4.5])
marker = itertools.cycle(('o', 's', 'p', '<', '>', 'P', 'v', '^', '*'))

plt.figure(1, figsize=(4, 4.3))
gridsp = mpl.gridspec.GridSpec(3, 1, height_ratios=[0.2, 0.1, 4.])
gridsp.update(wspace=0., hspace=0., left=0, right=1, bottom=0, top=1)

ax1 = plt.subplot(gridsp[2, 0])
Expand All @@ -179,23 +216,44 @@ def plot_color_color(colorbox,

ax1.invert_yaxis()

ax1.get_xaxis().set_label_coords(0.5, -0.08)
ax1.get_yaxis().set_label_coords(-0.12, 0.5)
if offset:
ax1.get_xaxis().set_label_coords(0.5, offset[0])
ax1.get_yaxis().set_label_coords(offset[1], 0.5)
else:
ax1.get_xaxis().set_label_coords(0.5, -0.08)
ax1.get_yaxis().set_label_coords(-0.12, 0.5)

indices = np.where(sptype != 'None')[0]

sptype = sptype[indices]
color = color[indices]
magnitude = magnitude[indices]
if xlim:
ax1.set_xlim(xlim[0], xlim[1])

spt_disc = util.sptype_discrete(sptype, color.shape)
if ylim:
ax1.set_ylim(ylim[0], ylim[1])

cmap = plt.cm.viridis
bounds = np.arange(0, 8, 1)
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

scat = ax1.scatter(colors[0], colors[1], c=spt_disc, cmap=cmap, norm=norm,
zorder=3, s=25., alpha=0.6)
sptype = colorbox.sptype
color1 = colorbox.color1
color2 = colorbox.color2

indices = np.where(sptype != 'None')[0]

sptype = sptype[indices]
color1 = color1[indices]
color2 = color2[indices]

spt_disc = util.sptype_discrete(sptype, color1.shape)

_, unique = np.unique(color1, return_index=True)

sptype = sptype[unique]
color1 = color1[unique]
color2 = color2[unique]
spt_disc = spt_disc[unique]

scat = ax1.scatter(color1, color2, 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')
Expand All @@ -207,10 +265,32 @@ def plot_color_color(colorbox,
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])

ax1.plot(color, mag, 's', ms=5, color='black')
mag1 = objdata.get_photometry(item[1][0])[0]
mag2 = objdata.get_photometry(item[1][1])[0]
mag3 = objdata.get_photometry(item[2][0])[0]
mag4 = objdata.get_photometry(item[2][1])[0]

err1 = objdata.get_photometry(item[1][0])[1]
err2 = objdata.get_photometry(item[1][1])[1]
err3 = objdata.get_photometry(item[2][0])[1]
err4 = objdata.get_photometry(item[2][1])[1]

color1 = mag1 - mag2
color2 = mag3 - mag4

error1 = math.sqrt(err1**2+err2**2)
error2 = math.sqrt(err3**2+err4**2)

ax1.errorbar(color1, color2, xerr=error1, yerr=error2,
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()
Expand Down
9 changes: 5 additions & 4 deletions species/read/read_colormag.py → species/read/read_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_color_magnitude(self,
sptype = np.concatenate((sptype, sptype_tmp), axis=0)

flag = np.concatenate((flag, flag_tmp), axis=0)
indices = np.concatenate((indices, indices_tmp), axis=0)
indices = np.concatenate((indices, indices.shape+indices_tmp), axis=0)

mag1_tmp = np.asarray(h5_file['photometry/'+item+'/'+self.filters_color[0]])
mag2_tmp = np.asarray(h5_file['photometry/'+item+'/'+self.filters_color[1]])
Expand Down Expand Up @@ -134,7 +134,7 @@ def __init__(self,
"""
:param library: Photometric libraries.
:type library: tuple(str, )
:param filters:
:param filters: Filter IDs for the two colors.
:type filters: tuple(tuple(str, str), tuple(str, str))
:return: None
Expand All @@ -156,7 +156,8 @@ def __init__(self,
def get_color_color(self,
object_type):
"""
:param object_type:
:param object_type: Object type (currently only 'field' possible). All objects are
selected if set to None.
:type object_type: str
:return: Box with the colors.
Expand Down Expand Up @@ -203,7 +204,7 @@ def get_color_color(self,
sptype = np.concatenate((sptype, sptype_tmp), axis=0)

flag = np.concatenate((flag, flag_tmp), axis=0)
indices = np.concatenate((indices, indices_tmp), axis=0)
indices = np.concatenate((indices, indices.shape+indices_tmp), axis=0)

mag1_tmp = np.asarray(h5_file['photometry/'+item+'/'+self.filters[0][0]])
mag2_tmp = np.asarray(h5_file['photometry/'+item+'/'+self.filters[0][1]])
Expand Down

0 comments on commit ac860da

Please sign in to comment.