-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_stars_lum_temp
196 lines (158 loc) · 5.94 KB
/
data_stars_lum_temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon May 27 14:31:51 2019
EART/ASTR 119
@author: Andrew Quartuccio
"""
# =============================================================================
# Module Imports
# =============================================================================
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import pandas as pd
# =============================================================================
# File/Directory Parmeters for Fig 1,2
# =============================================================================
file_in = './Data/hygdata_v3.csv'
file_out = './Data/star_location.gif'
dir_in = './Data'
pi = np.pi
# Load in data
hyg_data = np.genfromtxt( file_in, dtype = float, delimiter = ',', skip_header = 1, usecols = (16, 33)).T
hyg_ptdata = np.genfromtxt( file_in, dtype = float, delimiter = ',', skip_header = 1, usecols = (17,18,19,13)).T
hyg_vptdata= np.genfromtxt( file_in, dtype = float, delimiter = ',', skip_header = 1, usecols = (20,21,22)).T
# Position Vars
m_X = hyg_ptdata[0]
m_Y = hyg_ptdata[1]
m_Z = hyg_ptdata[2]
# Velocity Vars
m_vX = hyg_vptdata[0]
m_vY = hyg_vptdata[1]
m_vZ = hyg_vptdata[2]
# Stellar Variables
rho= ((m_X**2+m_Y**2+m_Z**2)**.5)
mag= hyg_ptdata[3]
ci= hyg_data[0]
Lum= hyg_data[1]
sigma= 5.670*1e-8
T= 4600*(1/((.92*ci)+1.7)+(1/((.92*ci)+.62)))
R= (np.sqrt(Lum/(4*pi*sigma*(T**4))))/1000
# PL_Fit Function
#=======================================================================================
def lin_LS( aX, aY):
"""
- linear least squares assuming normal distributed errors in Y, no errors in X
:param aX: - independent variable
:param aY: - measured dependent variable
:return: float(<slope>)
"""
meanX = aX.mean()
meanY = aY.mean()
# variance and co-variance - 1./N term omitted because it cancels in the following ratio
VarX = ( (aX - meanX)**2).sum()
#VarY = ( (aY - meanY)**2).sum()
CovXY = ( (aY-meanY)*(aX-meanX)).sum()
slope = CovXY/VarX
a = meanY - meanX*slope
return slope, a
#=======================================================================================
## Power Law fit
#tmin, tmax = 1, 1e5
#sel = np.logical_and( T[0::] >= tmin, T[0::] <= tmax, np.isnan(T[0::]) != True)
#slope, f_a = lin_LS( np.log10( T[sel]), np.log10( Lum[sel]))
#
#aX_fit = np.linspace( tmin*.5, tmax*5, 100)
#aPLfit = 10**(f_a)*aX_fit**slope
#
## Power Law Plot
#plt.figure(1)
#ax1 = plt.subplot(111)
#ax1.set_title( 'Power-Law Fit')
#ax1.loglog( T[sel], Lum[sel], 'ko', label = 'data')
#ax1.loglog( aX_fit, aPLfit, 'r--', label = 'L ~ T^(%.2f)'%( round( slope, 2)))
#ax1.legend( loc = 'lower left')
#ax1.set_xlim(ax1, 0, 100000)
#ax1.set_xlabel( 'Temperature [degree C]')
#ax1.set_ylabel( 'Luminosity [solar units]')
#plt.show()
## Distance vs Apparent Magnitude
#plt.figure(2)
#ax2 = plt.subplot(111)
#ax2.plot(rho, mag, 'r.')
#ax2.Axes.set_xlim(ax2, 0, 1100)
#ax2.Axes.set_ylim(ax2, 0, 15)
#plt.show()
# 3D Celestial Sphere
fig3 = plt.figure(3, figsize=(100,100))
ax = axes3d.Axes3D(fig3)
ax.scatter( m_X, m_Y, m_Z, c='r', marker='o')
plt.show()
# =============================================================================
# File/Directory Parmeters for Hertz-Sprung
# =============================================================================
df = pd.read_table(file_in, delimiter=',', header=0, index_col = 0, usecols = ( 0, 14, 9, 16, 15),
names = ['ID', 'dist', 'M_V', 'SpType', 'B-V'])
df_clean = df.applymap(lambda x: np.nan if isinstance(x, basestring)
and x.isspace() else x)
df_clean= df_clean.dropna()
#create new row with first two characters of spectral class
f = lambda s: (len(s) >= 2) and (s[0].isalpha()) and (s[1].isdigit())
i = df_clean['SpType'].apply(f)
df_clean = df_clean[i]
f = lambda s: s[0:2]
df_clean['SpType2'] = df_clean['SpType'].apply(f)
# Check spectral classes f = lambda s: s[0] #clases = df_clean['SpType'].map(f) #clases.value_counts()
#remove special classes C,N,R,S
f = lambda s: s[0] in 'OBAFGKM'
df_clean = df_clean[df_clean['SpType'].map(f)]
# order presicely
orden = {'O':'0', 'B':'1', 'A':'2', 'F':'3', 'G':'4', 'K':'5', 'M':'6'}
f = lambda s: orden[s[0]]+s[1]
df_clean['SpType2'] = df_clean['SpType2'].apply(f)
df_clean.head()
def plot_lum_class(b,c, label):
''' b: boolean Series to make the selection
c: Color
label: for the legend
'''
x = df_clean['B-V'][b]
y = df_clean['M_V'][b]
ax4.scatter(x, y, c = c, s=5, edgecolors='none', label = label)
fig4 = plt.figure(4,figsize=(8,10))
ax4 = fig4.add_subplot(111, facecolor='1.00')
ax4.set_xlim(-0.5, 2.75)
ax4.set_ylim(15, -15)
ax4.grid()
ax4.set_title('H-R Diagram /n HYD Star Database')
ax4.title.set_fontsize(15)
ax4.set_xlabel('Color index B-V')
ax4.xaxis.label.set_fontsize(15)
ax4.set_ylabel('Absolute magnitude')
ax4.yaxis.label.set_fontsize(15)
#code in luminosity class
f = lambda s: 'VII' in s
b = df_clean['SpType'].map(f)
plot_lum_class(b,'black', 'VII: white dwarfs')
f = lambda s: ('VI' in s) and ('VII' not in s)
b = df_clean['SpType'].map(f)
plot_lum_class(b,'darkblue', 'VI: subdwarfs')
f = lambda s: ('V' in s) and ('VI' not in s) and ('IV' not in s)
b = df_clean['SpType'].map(f)
plot_lum_class(b,'teal', 'V: main-sequence')
f = lambda s: 'IV' in s
b = df_clean['SpType'].map(f)
plot_lum_class(b,'hotpink', 'IV: subgiants')
f = lambda s: 'III' in s
b = df_clean['SpType'].map(f)
plot_lum_class(b,'green', 'III: giants')
f = lambda s: ('II' in s) and ('III' not in s) and ('VII' not in s)
b = df_clean['SpType'].map(f)
plot_lum_class(b,'orange', 'II: bright giants')
f = lambda s: ('I' in s) and ('II' not in s) and ('V' not in s)
b = df_clean['SpType'].map(f)
plot_lum_class(b,'yellow', 'I: supergiants')
ax4.tick_params(axis='both', labelsize=10)
ax4.legend(loc = 'best', scatterpoints=1,markerscale = 4, shadow=True)