Skip to content

Commit

Permalink
Type checks added to ReadObject, check for duplicare filter names in …
Browse files Browse the repository at this point in the history
…plot_color_magnitude/color
  • Loading branch information
Tomas Stolker committed May 7, 2020
1 parent 9a4f9e5 commit 9309555
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 30 deletions.
12 changes: 6 additions & 6 deletions species/data/companions.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ def get_data() -> Dict[str, Dict[str, Union[Tuple[float, float],
'PDS 70 b': {'distance': (113.43, 0.52),
'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.78, 0.31), (16.72, 0.05)], # Stolker et al. in prep.
'Paranal/SPHERE.IRDIS_D_K12_2': [(16.23, 0.32), (16.38, 0.06)], # Stolker et al. in prep.
'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.
'Paranal/SPHERE.IRDIS_D_K12_1': [(16.96, 0.38), (16.71, 0.04)], # Stolker et al. in prep.
'Paranal/SPHERE.IRDIS_D_K12_2': [(16.43, 0.43), (16.39, 0.06)], # Stolker et al. in prep.
'Paranal/NACO.Lp': (14.73, 0.58), # Stolker et al. in prep.
'Paranal/NACO.NB405': (14.73, 0.40), # Stolker et al. in prep.
'Paranal/NACO.Mp': (13.64, 0.23), # Stolker et al. in prep.
'Keck/NIRC2.Lp': (14.64, 0.18)}}, # Wang et al. 2020

'PDS 70 c': {'distance': (113.43, 0.52),
'app_mag': {'Paranal/NACO.NB405': (15.05, 0.59), # Stolker et al. in prep.
'app_mag': {'Paranal/NACO.NB405': (14.91, 0.35), # Stolker et al. in prep.
'Keck/NIRC2.Lp': (15.5, 0.46)}}, # Wang et al. 2020

'2M1207 b': {'distance': (64.42, 0.65),
Expand Down
58 changes: 42 additions & 16 deletions species/plot/plot_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,23 @@ def plot_color_magnitude(boxes: list,
angle = np.degrees(np.arctan2(sp2[1]-sp1[1], sp2[0]-sp1[0]))
text.set_rotation(angle)

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

if objects is not None:
for i, item in enumerate(objects):
objdata = read_object.ReadObject(item[0])

objcolor1 = objdata.get_photometry(item[1])
objcolor2 = objdata.get_photometry(item[2])

if objcolor1.ndim == 2:
print(f'Found {objcolor1.shape[1]} values for filter {item[1]} of {item[0]}')
print(f'so using the first value: {objcolor1[0, 0]} +/- {objcolor1[1, 0]} mag')
objcolor1 = objcolor1[:, 0]

if objcolor2.ndim == 2:
print(f'Found {objcolor2.shape[1]} values for filter {item[1]} of {item[0]}')
print(f'so using the first value: {objcolor2[0, 0]} +/- {objcolor2[1, 0]} mag')
objcolor2 = objcolor2[:, 0]

abs_mag, abs_err = objdata.get_absmag(item[3])

colorerr = math.sqrt(objcolor1[1]**2+objcolor2[1]**2)
Expand Down Expand Up @@ -451,6 +460,8 @@ def plot_color_magnitude(boxes: list,
ax1.annotate(objdata.object_name, (x_color, abs_mag), zorder=3,
textcoords='offset points', **kwargs)

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

if legend is not None:
handles, labels = ax1.get_legend_handles_labels()

Expand Down Expand Up @@ -845,27 +856,40 @@ def plot_color_color(boxes: list,
angle = np.degrees(np.arctan2(sp2[1]-sp1[1], sp2[0]-sp1[0]))
text.set_rotation(angle)

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

if objects is not None:
for i, item in enumerate(objects):
objdata = read_object.ReadObject(item[0])

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]
objphot1 = objdata.get_photometry(item[1][0])
objphot2 = objdata.get_photometry(item[1][1])
objphot3 = objdata.get_photometry(item[2][0])
objphot4 = objdata.get_photometry(item[2][1])

if objphot1.ndim == 2:
print(f'Found {objphot1.shape[1]} values for filter {item[1][0]} of {item[0]}')
print(f'so using the first value: {objphot1[0, 0]} +/- {objphot1[1, 0]} mag')
objphot1 = objphot1[:, 0]

if objphot2.ndim == 2:
print(f'Found {objphot2.shape[1]} values for filter {item[1][0]} of {item[0]}')
print(f'so using the first value: {objphot2[0, 0]} +/- {objphot2[1, 0]} mag')
objphot2 = objphot2[:, 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]
if objphot3.ndim == 2:
print(f'Found {objphot3.shape[1]} values for filter {item[1][0]} of {item[0]}')
print(f'so using the first value: {objphot3[0, 0]} +/- {objphot3[1, 0]} mag')
objphot3 = objphot3[:, 0]

color1 = mag1 - mag2
color2 = mag3 - mag4
if objphot4.ndim == 2:
print(f'Found {objphot4.shape[1]} values for filter {item[1][0]} of {item[0]}')
print(f'so using the first value: {objphot4[0, 0]} +/- {objphot4[1, 0]} mag')
objphot4 = objphot4[:, 0]

error1 = math.sqrt(err1**2+err2**2)
error2 = math.sqrt(err3**2+err4**2)
color1 = objphot1[0] - objphot2[0]
color2 = objphot3[0] - objphot4[0]

error1 = math.sqrt(objphot1[1]**2+objphot2[1]**2)
error2 = math.sqrt(objphot3[1]**2+objphot4[1]**2)

if len(item) > 3 and item[3] is not None:
kwargs = item[3]
Expand Down Expand Up @@ -897,6 +921,8 @@ def plot_color_color(boxes: list,
ax1.annotate(objdata.object_name, (color1, color2), zorder=3,
textcoords='offset points', **kwargs)

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

handles, labels = ax1.get_legend_handles_labels()

if legend is not None:
Expand Down
29 changes: 22 additions & 7 deletions species/read/read_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import math
import configparser

from typing import Tuple

import h5py
import numpy as np

from typeguard import typechecked

from species.util import phot_util


Expand All @@ -17,8 +21,9 @@ class ReadObject:
Class for reading data from an individual object from the database.
"""

@typechecked
def __init__(self,
object_name):
object_name: str) -> None:
"""
Parameters
----------
Expand All @@ -45,8 +50,9 @@ def __init__(self,
raise ValueError(f'The object \'{self.object_name}\' is not present in the '
f'database.')

@typechecked
def get_photometry(self,
filter_name):
filter_name: str) -> np.ndarray:
"""
Function for reading the photometry of the object.
Expand All @@ -57,7 +63,7 @@ def get_photometry(self,
Returns
-------
numpy.ndarray
np.ndarray
Apparent magnitude (mag), magnitude error (error), flux (W m-2 um-1),
flux error (W m-2 um-1).
"""
Expand All @@ -72,7 +78,8 @@ def get_photometry(self,

return obj_phot

def get_spectrum(self):
@typechecked
def get_spectrum(self) -> dict:
"""
Function for reading the spectra and covariance matrices of the object.
Expand Down Expand Up @@ -106,7 +113,8 @@ def get_spectrum(self):

return spectrum

def get_distance(self):
@typechecked
def get_distance(self) -> Tuple[float, float]:
"""
Function for reading the distance to the object.
Expand All @@ -123,8 +131,9 @@ def get_distance(self):

return obj_distance[0], obj_distance[1]

@typechecked
def get_absmag(self,
filter_name):
filter_name: str) -> Tuple[float, float]:
"""
Function for calculating the absolute magnitudes of the object from the apparent
magnitudes and distance. The errors on the apparent magnitude and distance are propagated
Expand All @@ -151,4 +160,10 @@ def get_absmag(self,
raise ValueError(f'There is no photometric data of \'{self.object_name}\' '
f'available with the {filter_name}.')

return phot_util.apparent_to_absolute(obj_phot[0:2], obj_distance)
if obj_phot.ndim == 1:
abs_mag = phot_util.apparent_to_absolute(obj_phot[0:2], obj_distance)

elif obj_phot.ndim == 2:
abs_mag = phot_util.apparent_to_absolute(obj_phot[0:2, :], obj_distance)

return abs_mag
3 changes: 2 additions & 1 deletion species/read/read_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def get_magnitude(self,
app_tmp, abs_tmp = synphot.spectrum_to_magnitude(wavelength=specbox.wavelength[i],
flux=specbox.flux[i],
error=specbox.error[i],
distance=specbox.distance[i])
distance=(float(specbox.distance[i][0]),
float(specbox.distance[i][1])))

app_mag.append(app_tmp)
abs_mag.append(abs_tmp)
Expand Down

0 comments on commit 9309555

Please sign in to comment.