-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstellar_model.py
323 lines (240 loc) · 9.81 KB
/
stellar_model.py
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/usr/bin/env python3
#
# File: stellar_model.py
# Author: Timothy Van Reeth <[email protected]>
# License: GPL-3+
# Description: Module that builds a stellar model from a set of base parameters
import numpy as np
from astropy import units as u
class stellar_model(object):
def __init__(self, Mstar, Rstar, incl_deg, frot, ld_coeff=0.6):
"""
Reading in a stellar model from a GYRE input file (calculated with MESA),
and setting other (custom) parameter values, including the inclination
angle (in degrees) and the cyclic rotation frequency (in d^{-1}) of the
star.
Parameters:
Mstar: astropy quantity
the stellar mass
Rstar: astropy quantity
the stellar radius
incl_deg: float
the inclination angle of the star in degrees
frot: astropy quantity
the rotation frequency of the star
ld_coeff: float; optional
limb darkening coefficient (default = 0.6)
"""
# Initialsing the necessary quantities for the functions below
# (also serves as an overview of the class variables)
self._Mstar = Mstar
self._Rstar = Rstar
self._incl_deg = incl_deg
self._frot = frot
self._ld_coeff = ld_coeff
self._theta = 0.
self._phi = 0.
self._cell_weight = 0.
self._theta_incl = 0.
self._phi_incl = 0.
self._set_surfacegrid()
self._set_inclined_surface()
self._pulsating = False
return
@property
def Mstar(self):
return self._Mstar
@property
def Rstar(self):
return self._Rstar
@property
def ld_coeff(self):
return self._ld_coeff
@property
def incl_deg(self):
return self._incl_deg
@property
def incl(self):
return self._incl_deg * np.pi / 180.
@property
def frot(self):
return self._frot
@property
def theta(self):
return self._theta
@property
def phi(self):
return self._phi
@property
def cell_weight(self):
return self._cell_weight
@property
def theta_incl(self):
return self._theta_incl
@property
def phi_incl(self):
return self._phi_incl
@property
def pulsating(self):
return self._pulsating
@Mstar.setter
def Mstar(self, mass):
self._Mstar = mass
@Rstar.setter
def Rstar(self, radius):
self._Rstar = radius
@incl_deg.setter
def incl_deg(self, incl_degrees):
self._incl_deg = incl_degrees
self._set_inclined_surface(incl_degrees)
@frot.setter
def frot(self, rot_freq):
self._frot = rot_freq
@ld_coeff.setter
def ld_coeff(self, mu):
self._ld_coeff = mu
@pulsating.setter
def pulsating(self, puls):
self._pulsating = puls
def _set_surfacegrid(self, Ntheta=200, Nphi=400):
"""
Setting the 2D-surface grid in (theta,phi) in which we
want to evaluate the stellar properties and pulsations,
as well as the necessary cell_weights for when we need
to calculate selected quantities by integrating over the
surface.
Parameters:
self: stellar_model object
Ntheta: int; optional
the number of grid cells in the
latitudinal direction (default: 200)
Nphi: int; optional
the number of grid cells in the
azimuthal direction (default: 400)
Returns:
None
"""
theta = np.linspace(0, np.pi, Ntheta)
phi = np.linspace(0., 2.*np.pi, Nphi)
theta_weight = np.ones(len(theta))*np.pi/float(len(theta)-1)
phi_weight = np.ones(len(phi))*np.pi/float(len(phi)-1)
theta_weight[0] /= 2.
theta_weight[-1] /= 2.
phi_weight[0] /= 2.
phi_weight[-1] /= 2.
self._theta,self._phi = np.meshgrid(theta,phi)
theta_weight,phi_weight = np.meshgrid(theta_weight,phi_weight)
self._cell_weight = theta_weight*phi_weight*np.sin(self._theta) * 4.*np.pi / np.nansum(theta_weight*phi_weight*np.sin(self._theta))
return
def _set_inclined_surface(self):
"""
Rotate the stellar model coordinates (in a spherical coordinate frame)
over the inclination angle.
NOTE: the rotation is always done around the y-axis. In other words, the
angle "phi = 0" remains in the same (xz)-plane.
Parameters:
self: stellar_model object
Returns:
None
"""
x,y,z = self._spherical_to_cartesian()
x_rot, y_rot, z_rot = self._rotate_cart(x,y,z,self.incl)
self._theta_incl, self._phi_incl = self._cartesian_to_spher(x_rot,y_rot,z_rot)
return
def _spherical_to_cartesian(self):
"""
Convert spherical surface coordinates to cartesian coordinates.
Parameters:
self: stellar_model object
Returns:
x: numpy array
the Cartesian coordinates on the x-axis
y: numpy array
the Cartesian coordinates on the y-axis
z: numpy array
the Cartesian coordinates on the z-axis
"""
x = np.sin(self._theta) * np.cos(self._phi)
y = np.sin(self._theta) * np.sin(self._phi)
z = np.cos(self._theta)
return x,y,z
def _cartesian_to_spher(self,x,y,z):
"""
Convert cartesian coordinates to spherical coordinates.
Parameters:
self: stellar_model object
x: numpy array
the Cartesian coordinates on the x-axis
y: numpy array
the Cartesian coordinates on the y-axis
z: numpy array
the Cartesian coordinates on the z-axis
Returns:
theta: numpy array
colatitude (in rad)
phi: numpy array
azimuthal angle (in rad)
"""
theta = np.arctan2(np.sqrt(x**2. + y**2.),z)
phi = np.arctan2(y,x)
return theta,phi
def _rotate_cart(self,x,y,z,i_rot):
"""
Rotate the stellar model coordinates (in a cartesian frame) over the
angle i_rot.
NOTE: the rotation is always done around the y-axis. In other words, the
angle "phi = 0" remains in the same (xz)-plane.
Parameters:
self: stellar_model object
x: numpy array
the original coordinates on the x-axis
y: numpy array
the original coordinates on the y-axis
z: numpy array
the original coordinates on the z-axis
i_rot: float
the angle over which we rotate the model (in rad).
Returns:
x_rot: numpy array
the rotated coordinates on the x-axis
y_rot: numpy array
the rotated coordinates on the y-axis
z_rot: numpy array
the rotated coordinates on the z-axis
"""
x_rot = np.cos(i_rot)*x - np.sin(i_rot)*z
y_rot = y
z_rot = np.sin(i_rot)*x + np.cos(i_rot)*z
return x_rot, y_rot, z_rot
def limb_darkening(self):
"""
Basic linear limb darkening law, applied to the observed stellar surface.
Parameters:
self: stellar_model object
Returns:
ld: numpy array
relative intensity of the observed stellar disk
"""
ld = 1. - self._ld_coeff * (1. - np.cos(self.theta_incl))
return ld
def rotational_velocityfield(self):
"""
Calculate the velocity field of the star in the inertial reference
frame, caused by the stellar rotation
NOTE 1: the rotation is always done around the y-axis. In other words,
the angle "phi = 0" remains in the same (xz)-plane.
Returns:
radv: astropy Quantity array
the radial component of the rotational velocity field in the
inertial reference frame (in km/s)
thv: astropy Quantity array
the colatitudinal component of the rotational velocity field
in the inertial reference frame (in km/s)
phv: astropy Quantity array
the azimuthal component of the rotational velocity field in
the inertial reference frame (in km/s)
"""
radv = np.zeros(self._theta.shape) * u.km / u.s
thv = np.zeros(self._theta.shape) * u.km / u.s
phv = 2. * np.pi * self._Rstar.to(u.km) * np.sin(self._theta) * self.frot.to(u.Hz)
return radv, thv, phv