def get_sec_spt(row):
"""
Get the secondary spectral type from the information we have. Meant to be
called as the `apply` method of a pandas DataFrame.
"""
if pd.notnull(row['Sp2']):
return row['Sp2']
elif pd.notnull(row['Sp1']) and pd.notnull(row['mag1']) and pd.notnull(row['mag2']):
# TODO: Do better than assuming V band!
band = 'V'
absmag_prim = MS.GetAbsoluteMagnitude(row['Sp1'], color=band)
dm = float(row['mag1']) - absmag_prim
absmag_sec = float(row['mag2']) - dm
return MS.GetSpectralType_FromAbsMag(absmag_sec, color=band)[0]
elif pd.notnull(row['Sp1']) and pd.notnull(row['K1']) and pd.notnull(row['K2']):
mass = MS.Interpolate('mass', row['Sp1'])
q = float(row['K1']) / float(row['K2'])
sec_mass = q * mass
return MS.GetSpectralType('mass', sec_mass)[0]
else:
print(row)
raise ValueError('Must give enough information to figure out the spectral type!')
评论列表
文章目录