ellc 1.8.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ellc/__init__.py ADDED
@@ -0,0 +1,39 @@
1
+ """
2
+ ellc
3
+ ----
4
+
5
+ Generate light curves or radial velocity curves for a binary star system
6
+ with the ellc light curve model [1].
7
+
8
+ Routines in this module:
9
+
10
+ lc(t_obs, radius_1, radius_2, sbratio, incl, ... )
11
+
12
+ rv(t_obs, radius_1, radius_2, sbratio, incl, t_zero, period, a, q, ...)
13
+
14
+ fluxes(t_obs, radius_1, radius_2, sbratio, incl, ... )
15
+
16
+ tmin(t_obs, radius_1, radius_2, sbratio, incl, ... )
17
+
18
+ Sub-packages in this module
19
+
20
+ ldy
21
+ - ldy.list_bands()
22
+ - ldy.LimbGravityDarkeningCoeffs(band)
23
+
24
+
25
+ Please cite Maxted (2016) if you published results based on this software.
26
+
27
+ References
28
+ ----------
29
+ .. [1] Maxted, P.F.L. 2016. A fast, flexible light curve model for detached
30
+ eclipsing binary stars and transiting exoplanets. A&A VOLUME, ARTICLE.
31
+
32
+ """
33
+
34
+ from .version import __version__
35
+ from .lc import lc
36
+ from .rv import rv
37
+ # from .tmin import tmin
38
+ from .fluxes import fluxes
39
+ from . import ldy
ellc/fluxes.py ADDED
@@ -0,0 +1,659 @@
1
+ # This file is part of the ellc binary star model
2
+ # Copyright (C) 2016 Pierre Maxted
3
+ #
4
+ # Modified by: ZhiXiang Zhang
5
+ # Affiliation: Xiamen University, Department of Astronomy
6
+ # Date: 2024-11-13
7
+ # Description of modifications:
8
+ # - Updated code for compatibility with Python 3.12
9
+ #
10
+ # This program is free software: you can redistribute it and/or modify
11
+ # it under the terms of the GNU General Public License as published by
12
+ # the Free Software Foundation, either version 3 of the License, or
13
+ # (at your option) any later version.
14
+ #
15
+ # This program is distributed in the hope that it will be useful,
16
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ # GNU General Public License for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License
21
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
22
+
23
+ from __future__ import (absolute_import, division, print_function,
24
+ unicode_literals)
25
+ import numpy as np
26
+ import os
27
+ import ctypes
28
+ absdir = os.path.dirname(os.path.abspath(__file__))
29
+ libname = os.path.join(absdir, 'libellc.so')
30
+ lib = ctypes.cdll.LoadLibrary(libname)
31
+
32
+
33
+ def fluxes(t_obs, radius_1, radius_2, sbratio, incl,
34
+ t_zero = 0, period = 1,
35
+ a = None,
36
+ q = 1,
37
+ f_c = None, f_s = None,
38
+ ldc_1 = None, ldc_2 = None,
39
+ gdc_1 = None, gdc_2 = None,
40
+ didt = None,
41
+ domdt = None,
42
+ rotfac_1 = 1, rotfac_2 = 1,
43
+ hf_1 = 1.5, hf_2 = 1.5,
44
+ bfac_1 = None, bfac_2 = None,
45
+ heat_1 = None, heat_2 = None,
46
+ lambda_1 = None, lambda_2 = None,
47
+ vsini_1 = None, vsini_2 = None,
48
+ t_exp=None, n_int=None,
49
+ grid_1='default', grid_2='default',
50
+ ld_1=None, ld_2=None,
51
+ shape_1='sphere', shape_2='sphere',
52
+ spots_1=None, spots_2=None,
53
+ exact_grav=False, verbose=1):
54
+ """
55
+ Calculate the fluxed emitted from each star in an eclipsing binary star
56
+
57
+ This function calculates the fluxes using the ellc binary star model [1].
58
+
59
+ Parameters
60
+ ----------
61
+ t_obs : array_like
62
+ Times or phases of observation. The units and time system used must be
63
+ consistent with t_zero and period.
64
+
65
+ radius_1 : float
66
+ Radius of star 1 in units of the semi-major axis of the binary.
67
+ The radius is defined to be the same as a sphere with the same volume as
68
+ the ellipsoid used to approximate the shape of the star.
69
+ Set radius_1=1 to fix radius at limiting radius in the Roche potential.
70
+
71
+ radius_2 : float
72
+ Radius of star 2 in units of the semi-major axis of the binary.
73
+ The radius is defined to be the same as a sphere with the same volume as
74
+ the ellipsoid used to approximate the shape of the star.
75
+ Set radius_2=1 to fix radius at limiting radius in the Roche potential.
76
+
77
+ sbratio : float
78
+ Surface brightness ratio, S_2/S_1
79
+
80
+ incl : float
81
+ Inclination in degrees.
82
+
83
+ t_zero : float, optional
84
+ Time (or phase) of mid-eclipse for star 1 by star 2.
85
+ The units and time system must be consistent with the values in t_obs.
86
+ Default is 0.
87
+
88
+ period : float, optional
89
+ Orbital period of the binary or (for phased data) 1.
90
+ For binary systes with apsidal motion, this is the anomalistic period.
91
+ If light-time effect or Doppler boosting is to be calculated correctly
92
+ then the units of period must be days, otherwise arbitrary units can be
93
+ used provided that these are consistent with t_zero and t_obs.
94
+ Default is 1.
95
+
96
+ a : {None, float}, optional
97
+ Semi-major axis in solar radii for calculation of light travel time
98
+ and Doppler boosting.
99
+
100
+ q : float, optional
101
+ Mass ratio m_2/m_1.
102
+ Default is 1.
103
+
104
+ f_c : {None, float}, optional
105
+ For eccentric orbits with eccentricity e and longitude of periastron w,
106
+ f_c = sqrt(e).cos(w)
107
+ If not None, then f_s must also be specified.
108
+ Default is None.
109
+
110
+ f_s : {None, float}, optional
111
+ For eccentric orbits with eccentricity e and longitude of periastron w,
112
+ f_s = sqrt(e).sin(w)
113
+ If not None, then f_c must also be specified.
114
+ Default is None.
115
+
116
+ ldc_1 : {None, float, 2-, 3- or 4-tuple of floats}, optional
117
+ Limb darkening coefficients for star 1.
118
+ Number of elements must match the selected limb-darkening law.
119
+ Default is None
120
+
121
+ ldc_2 : {None, float, 2-, 3- or 4-tuple of floats}, optional
122
+ Limb darkening coefficients for star 2.
123
+ Number of elements must match the selected limb-darkening law.
124
+ Default is None
125
+
126
+ gdc_1 : {None, float}, optional
127
+ Gravity darkening exponent for star 1.
128
+
129
+ gdc_2 : {None, float}, optional
130
+ Gravity darkening exponent for star 2.
131
+
132
+ didt : {None, float}, optional
133
+ Rate of change of inclination [degrees/anomalistic period]
134
+ Default is None.
135
+
136
+ domdt : {None, float}, optional
137
+ Apsidal motion rate [degrees/sidereal period].
138
+ Default is None.
139
+
140
+ rotfac_1 : float, optional
141
+ Asynchronous rotation factor for star 1, F_1
142
+ Default is 1.
143
+
144
+ rotfac_2 : float, optional
145
+ Asynchronous rotation factor for star 2, F_2
146
+ Default is 1.
147
+
148
+ hf_1 : float, optional
149
+ h_f, fluid second Love number for radial displacement, for star 1.
150
+ Only used if shape_1 = 'love'
151
+ Default is 1.5.
152
+
153
+ hf_2 : float, optional
154
+ h_f, fluid second Love number for radial displacement, for star 2.
155
+ Only used if shape_2 = 'love'
156
+ Default is 1.5.
157
+
158
+ bfac_1 : {None, float}, optional
159
+ Doppler boosting factor, star 1
160
+ N.B. Doppler boosting is not calculated is parameter a is None
161
+ Default is None.
162
+
163
+ bfac_2 : {None, float}, optional
164
+ Doppler boosting factor, star 2
165
+ N.B. Doppler boosting is not calculated is parameter a is None
166
+ Default is None.
167
+
168
+ heat_1 : {None, scalar, 3-tuple of floats}, optional
169
+ If scalar, coefficient of simplified reflection model - see Notes.
170
+ If 3-tuple, parameters of heating+reflection model [H_0, H_1, u_H]
171
+ H_0 is the coefficient, H_1 is the exponent and u_H is the linear
172
+ limb-darkening coefficient.
173
+ Default is None.
174
+
175
+ heat_2 : {None, scalar, 3-tuple of floats}, optional
176
+ If scalar, coefficient of simplified reflection model - see Notes.
177
+ If 3-tuple, parameters of heating+reflection model [H_0, H_1, u_H]
178
+ H_0 is the coefficient, H_1 is the exponent and u_H is the linear
179
+ limb-darkening coefficient.
180
+ Default is None.
181
+
182
+
183
+ lambda_1 : {None, float}, optional
184
+ Sky-projected angle between orbital and rotation axes, star 1 [degrees]
185
+ N.B. lambda_1 is only used if shape_1='sphere'
186
+ Default is None.
187
+
188
+ lambda_2 : {None, float}, optional
189
+ Sky-projected angle between orbital and rotation axes, star 2 [degrees]
190
+ N.B. lambda_2 is only used if shape_2='sphere'
191
+ Default is None.
192
+
193
+ vsini_1 : {None, float}, optional
194
+ V_rot.sini for calculation of R-M effect for star 1 [km/s]
195
+ Not used for this routine, but kept for consistency with lc.py and rv.py
196
+ Default is None.
197
+
198
+ vsini_2 : {None, float}, optional
199
+ V_rot.sini for calculation of R-M effect for star 2 [km/s]
200
+ Not used for this routine, but kept for consistency with lc.py and rv.py
201
+ Default is None.
202
+
203
+ t_exp : {None, float, array_like}, optional
204
+ Exposure time in the same units as t_obs and, if array_like, with the
205
+ same number of elements.
206
+ Default is None.
207
+
208
+ n_int : {None, int, array_like}
209
+ Number of integration points used to account for finite exposure time.
210
+ Set n_int or elements of n_int to 1 to make no correction for finite
211
+ integration time.
212
+ If array_like then set elements to 0 to use linear interpolation of the
213
+ other values in the light curve to estimate the light curve at the
214
+ corresponding values of t_obs.
215
+ Default is None.
216
+
217
+ grid_1 : {"very_sparse", "sparse", "default", "fine", "very_fine"}, optional
218
+ Grid size used to calculate the flux from star 1.
219
+ Default is "default"
220
+
221
+ grid_2 : {"very_sparse", "sparse", "default", "fine", "very_fine"}, optional
222
+ Grid size used to calculate the flux from star 2.
223
+ Default is "default"
224
+
225
+ ld_1 : {None, "lin", "quad", "sing", "claret", "log", "sqrt", "exp",
226
+ "power-2", "mugrid"}
227
+ Limb darkening law for star 1
228
+ The "power-2" limb darkening law is taken from Morello et al.,
229
+ 2017AJ....154..111M:
230
+ I_lambda(mu)/I_lambda(1) = 1 - ldc_1[0] * (1 - mu**ldc_1[1])
231
+ For the option "mugrid", ldc_1 must be an array of specific intensity
232
+ values as a function of mu=cos(theta), where theta is the angle between the
233
+ line of sight and the normal to a given point of the stellar surface. The
234
+ value of mu corresponding to element i of ldc_1 is i/(len(ldc_1)-1), where
235
+ i=0,1, ... len(ldc_1)-1.
236
+ Default is None
237
+
238
+ ld_2 : {None, "lin", "quad", "sing", "claret", "log", "sqrt", "exp",
239
+ "power-2", "mugrid"}
240
+ Limb darkening law for star 2.
241
+ See ld_1 for description of the power-2 and mugrid options.
242
+ Default is None
243
+
244
+ shape_1 : {"roche_v", "roche", "sphere", "poly1p5", "poly3p0", "love"}
245
+ Model used to calculate the shape of star 1 - see Notes.
246
+ Default is "sphere".
247
+
248
+ shape_2 : {"roche_v", "roche", "sphere", "poly1p5", "poly3p0", "love"}
249
+ Model used to calculate the shape of star 2 - see Notes.
250
+ Default is "sphere".
251
+
252
+ spots_1 : (4, n_spots_1) array_like
253
+ Parameters of the spots on star 1. For each spot the parameters, in order,
254
+ are latitude, longitude, size and brightness factor. All three angles are
255
+ in degrees.
256
+
257
+ spots_2 : (4, n_spots_2) array_like
258
+ Parameters of the spots on star 2. For each spot the parameters, in order,
259
+ are latitude, longitude, size and brightness factor. All three angles are
260
+ in degrees.
261
+
262
+ exact_grav : {True|False}
263
+ Use point-by-point calculation of local surface gravity for calculation of
264
+ gravity darkening is True, otherwise use (much faster) approximation based
265
+ on functional form fit to local gravity at 4 points on the star.
266
+
267
+ Returns
268
+ -------
269
+ flux1, flux2, : ndarray, ndarray
270
+ Fluxes from star 1 and star 2, respectively, in arbitrary units.
271
+
272
+ Notes
273
+ -----
274
+
275
+ The asynchronous rotation factors rotfac_1 and rotfac_2 are used to
276
+ calculate the shapes of the stars (unless spherical stars are specified).
277
+ These rotation factors are relative to the actual synchronous rotation rate
278
+ (rotation period = orbital period) not pseudo-synchronous rotation rate.
279
+
280
+ The effect of the spot on the light curve is calculated using the
281
+ algorithm by Eker [2] for circular spots on a spherical star with
282
+ quadratic limb darkening. If the limb-darkening law used for the main
283
+ calculation is not linear or quadratic then the coefficients of the
284
+ limb-darkening law used for the calculation of the effects of the spots
285
+ are set so that the intensity distribution matches at mu = 0, 0.5 and 1.
286
+
287
+ N.B. The effect of each spot on the light curve is additive so overlapping
288
+ spots can result in non-physical negative fluxes for some regions of the
289
+ star.
290
+
291
+ For the calculation of the star shape, the rotation and orbital angular
292
+ momentum vectors are assumed parallel. The shape of each star is
293
+ approximated by a triaxial ellipsoid with semi-major axes (A,B,C) and
294
+ offset towards companion, D, from the centre-of-mass of the star towards
295
+ the companion star. For the option "roche" the definition of the Roche
296
+ potential from Wilson [3] is used and the values of A, B, C, D are set to
297
+ that intersection points of the triaxial ellipsoid with x-, y- and z-axes
298
+ lie on an equipotential surface. For the options "poly1p5" and "poly3p0"
299
+ the star is assumed to behave as a polytrope with index n=1.5 or n=3,
300
+ respectively. The tidal and rotational distortion of the polytrope are
301
+ assumed to be independent. The tidal distortion for polytropes is from
302
+ Chandrasekhar [4] and the rotational distortion is calculated by
303
+ interpolation in Table 1 of James [5].
304
+
305
+ In eccentric orbits, the volume of the star is assumed to be constant. In
306
+ general, the volume is calculated from the volume of the approximating
307
+ ellipsoid. In the case of synchronous rotation, the volume of the star can
308
+ be calculated using equation (2.18) from Kopal "Dynamics of Close Binary
309
+ Systems" (Springer, 1978) by selecting the star shape model "roche_v".
310
+
311
+ The simplified reflection model is approximately equivalent to Lambert
312
+ law scattering with the coefficients heat_1 and heat_2 being equal to
313
+ A_g/2, where A_g is the geometric albedo.
314
+
315
+
316
+ Example
317
+ -------
318
+ >>> import ellc
319
+ >>> import numpy as np
320
+ >>> import matplotlib.pyplot as plt
321
+ >>> t = np.arange(-0.25,0.75, 0.001)
322
+ >>> spots_1 = [[30,180],[45,-45],[25,35],[0.2,0.8]]
323
+ >>> flux1,flux2 = ellc.fluxes(t,radius_1=0.1,radius_2=0.05,sbratio=0.2,
324
+ ... incl=89.95,q=0.5,ld_1='quad',ldc_1=[0.65,0.2],ld_2='lin',ldc_2=0.45,
325
+ ... shape_1='poly3p0',shape_2='poly1p5',spots_1=spots_1)
326
+ >>> plt.plot(t,flux1)
327
+ >>> plt.plot(t,flux2)
328
+ >>> plt.plot(t,flux1+flux2)
329
+ >>> plt.show()
330
+
331
+ References
332
+ ----------
333
+ .. [1] Maxted, P.F.L. 2016. A fast, flexible light curve model for detached
334
+ eclipsing binary stars and transiting exoplanets. A&A 591, A111, 2016.
335
+ .. [2] Eker, 1994, ApJ, 420, 373.
336
+ .. [3] Wilson, 1979, ApJ, 234, 1054.
337
+ .. [4] Chandrasekhar, 1933, MNRAS, 93, 449.
338
+ .. [5] James, 1964, ApJ, 140, 552.
339
+ .. [6] Correia, 2014, A&A 570, L5.
340
+
341
+ """
342
+
343
+
344
+ # Copy control parameters into an np.array
345
+
346
+ gridname_to_gridsize = {
347
+ "very_sparse" : 4,
348
+ "sparse" : 8,
349
+ "default" : 16,
350
+ "fine" : 24,
351
+ "very_fine" : 32,
352
+ }
353
+ n1 = gridname_to_gridsize.get(grid_1,None)
354
+ if n1 is None:
355
+ raise Exception("Invalid grid size name")
356
+ n2 = gridname_to_gridsize.get(grid_2,None)
357
+ if n2 is None:
358
+ raise Exception("Invalid grid size name")
359
+
360
+ ldstr_to_ldcode = {
361
+ "none" : 0,
362
+ "lin" : 1,
363
+ "quad" : 2,
364
+ "sing" : 3,
365
+ "claret" : 4,
366
+ "log" : 5,
367
+ "sqrt" : 6,
368
+ "exp" : 7,
369
+ "power-2": 8,
370
+ "mugrid" : -1
371
+ }
372
+ if ld_1 is None:
373
+ ldstr_1 = 'none'
374
+ else:
375
+ ldstr_1 = ld_1
376
+
377
+ if ld_2 is None:
378
+ ldstr_2 = 'none'
379
+ else:
380
+ ldstr_2 = ld_2
381
+
382
+ l1 = ldstr_to_ldcode.get(ldstr_1,None)
383
+ if l1 is None:
384
+ raise Exception("Invalid limb darkening law name")
385
+
386
+ l2 = ldstr_to_ldcode.get(ldstr_2,None)
387
+ if l2 is None:
388
+ raise Exception("Invalid limb darkening law name")
389
+
390
+ shapename_to_shapecode = {
391
+ "roche_v" : -2,
392
+ "roche" : -1,
393
+ "sphere" : 0,
394
+ "poly1p5" : 1,
395
+ "poly3p0" : 2,
396
+ "love" : 3
397
+ }
398
+ s1 = shapename_to_shapecode.get(shape_1,None)
399
+ if s1 is None:
400
+ raise Exception("Invalid star shape name")
401
+ s2 = shapename_to_shapecode.get(shape_2,None)
402
+ if s2 is None:
403
+ raise Exception("Invalid star shape name")
404
+
405
+ if spots_1 is None:
406
+ spar_1 = np.zeros([1,1])
407
+ n_spots_1 = 0
408
+ else:
409
+ spar_1 = np.array(spots_1, order='F')
410
+ if (spar_1.ndim != 2) or (spar_1.shape[0] != 4 ):
411
+ raise Exception("spots_1 is not (4, n_spots_1) array_like")
412
+ n_spots_1 = spar_1.shape[1]
413
+
414
+ if spots_2 is None:
415
+ spar_2 = np.zeros([1,1])
416
+ n_spots_2 = 0
417
+ else:
418
+ spar_2 = np.array(spots_2, order='F')
419
+ if (spar_2.ndim != 2) or (spar_2.shape[0] != 4 ):
420
+ raise Exception("spots_2 is not (4, n_spots_2) array_like")
421
+ n_spots_2 = spar_2.shape[1]
422
+
423
+ ipar = np.array([n1,n2,n_spots_1,n_spots_2,l1,l2,s1,s2,1,0],
424
+ dtype=np.int32)
425
+
426
+ if ld_1 == 'mugrid':
427
+ try:
428
+ mugrid_1 = np.array(ldc_1)
429
+ n_mugrid_1 = len(mugrid_1)
430
+ except:
431
+ raise Exception("failed to obtain limb darkening data from ldc_1")
432
+ if (n_mugrid_1 < 2):
433
+ raise Exception("ldc_1 must have at least 2 elements")
434
+ else:
435
+ mugrid_1 = np.array([0.])
436
+ n_mugrid_1 = 0
437
+
438
+ if ld_2 == 'mugrid':
439
+ try:
440
+ mugrid_2 = np.array(ldc_2)
441
+ n_mugrid_2 = len(mugrid_2)
442
+ except:
443
+ raise Exception("failed to obtain limb darkening data from ldc_2")
444
+ if (n_mugrid_2 < 2):
445
+ raise Exception("ldc_2 must have at least 2 elements")
446
+ else:
447
+ mugrid_2 = np.array([0.])
448
+ n_mugrid_2 = 0
449
+
450
+
451
+ # Copy binary parameters into an np.array
452
+
453
+ if (radius_1 < 0) or (radius_1 > 1):
454
+ raise ValueError("radius_1 argument out of range")
455
+ if (radius_1 == 1) and (shape_1 != "roche"):
456
+ raise ValueError("radius_1=1 only allowed for Roche potential")
457
+
458
+ if (radius_2 < 0) or (radius_2 > 1):
459
+ raise ValueError("radius_2 argument out of range")
460
+ if (radius_2 == 1) and (shape_2 != "roche"):
461
+ raise ValueError("radius_2=1 only allowed for Roche potential")
462
+
463
+ par = np.zeros(39)
464
+ par[0] = t_zero
465
+ par[1] = period
466
+ par[2] = sbratio
467
+ par[3] = radius_1
468
+ par[4] = radius_2
469
+ par[5] = incl
470
+
471
+ if a is not None : par[7] = a
472
+
473
+ if (f_c is None) and (f_s is None):
474
+ pass
475
+ elif (f_c is not None) and (f_s is not None):
476
+ par[8] = f_c
477
+ par[9] = f_s
478
+ else:
479
+ raise Exception("Must specify both f_c and f_s or neither.")
480
+
481
+ if q <= 0 :
482
+ raise ValueError("Mass ratio q must be positive.")
483
+ par[10] = q
484
+
485
+ ld_to_n = {
486
+ "none" : 0,
487
+ "lin" : 1,
488
+ "quad" : 2,
489
+ "sing" : 3,
490
+ "claret" : 4,
491
+ "log" : 2,
492
+ "sqrt" : 2,
493
+ "exp" : 2,
494
+ "power-2": 2,
495
+ "mugrid" : 0
496
+ }
497
+ ld_n_1 = ld_to_n.get(ldstr_1,None)
498
+ try:
499
+ if (ld_n_1 > 0):
500
+ par[11:11+ld_n_1] = ldc_1
501
+ except:
502
+ raise Exception("ldc_1 and ld_1 are inconsistent")
503
+ ld_n_2 = ld_to_n.get(ldstr_2,None)
504
+ try:
505
+ if (ld_n_2 > 0):
506
+ par[15:15+ld_n_2] = ldc_2
507
+ except:
508
+ raise Exception("ldc_2 and ld_2 are inconsistent")
509
+
510
+
511
+ if gdc_1 is not None : par[19] = gdc_1
512
+
513
+ if gdc_2 is not None : par[20] = gdc_2
514
+
515
+ if didt is not None : par[21] = didt
516
+
517
+ if domdt is not None : par[22] = domdt
518
+
519
+ par[23] = rotfac_1
520
+
521
+ par[24] = rotfac_2
522
+
523
+ if bfac_1 is not None : par[25] = bfac_1
524
+
525
+ if bfac_2 is not None : par[26] = bfac_2
526
+
527
+ if heat_1 is not None :
528
+ t = np.array(heat_1)
529
+ if t.size == 1:
530
+ par[27] = t
531
+ elif t.size == 3:
532
+ par[27:30] = t
533
+ else:
534
+ raise Exception('Invalid size for array heat_1')
535
+
536
+ if heat_2 is not None :
537
+ t = np.array(heat_2)
538
+ if t.size == 1:
539
+ par[30] = t
540
+ elif t.size == 3:
541
+ par[30:33] = t
542
+ else:
543
+ raise Exception('Invalid size for array heat_2')
544
+
545
+ if lambda_1 is not None : par[33] = lambda_1
546
+
547
+ if lambda_2 is not None : par[34] = lambda_2
548
+
549
+ if vsini_1 is not None : par[35] = vsini_1
550
+
551
+ if vsini_2 is not None : par[36] = vsini_2
552
+
553
+ if shape_1 == "love":
554
+ if rotfac_1 != 1:
555
+ raise Exception(
556
+ 'Non-synchronous rotation not implemented for shape_1="love"')
557
+ if (hf_1 <= 2/3.) or (hf_1 > 5):
558
+ raise Exception('Invalid value for hf_1')
559
+ par[37] = hf_1
560
+
561
+ if shape_2 == "love":
562
+ if rotfac_2 != 1:
563
+ raise Exception(
564
+ 'Non-synchronous rotation not implemented for shape_2="love"')
565
+ if (hf_2 <= 2/3.) or (hf_2 > 5):
566
+ raise Exception('Invalid value for hf_2')
567
+ par[38] = hf_2
568
+
569
+ t_obs_array = np.array(t_obs)
570
+ n_obs = len(t_obs_array)
571
+ if t_exp is None:
572
+ t_exp_array = np.zeros(n_obs)
573
+ else:
574
+ t_exp_array = np.ones(n_obs)*t_exp
575
+
576
+ if n_int is not None :
577
+ if np.amax(n_int) < 1 : raise Exception("No n_int values > 1.")
578
+ if np.amin(n_int) < 0 : raise Exception("Invalid negative n_int value(s).")
579
+ n_int_array = np.array(np.ones(n_obs)*n_int, dtype=int)
580
+ else:
581
+ n_int_array = np.ones(n_obs, dtype=int)
582
+
583
+ # Create list of times for calculation, weights for integration and
584
+ # indices to relate these both back to the original t_obs array
585
+ i_obs = np.arange(0,n_obs)
586
+ t_calc = t_obs_array[n_int_array == 1]
587
+ w_calc = np.ones_like(t_calc)
588
+ i_calc = i_obs[n_int_array == 1]
589
+ n_int_max = np.amax(n_int_array)
590
+ for i_int in np.unique(n_int_array[n_int_array > 1]) :
591
+ t_obs_i = t_obs_array[n_int_array == i_int]
592
+ t_exp_i = t_exp_array[n_int_array == i_int]
593
+ i_obs_i = i_obs[n_int_array == i_int]
594
+ for j_int in range(0,i_int):
595
+ t_calc = np.append(t_calc, t_obs_i+(j_int/(i_int-1.)-0.5)*t_exp_i)
596
+ i_calc = np.append(i_calc,i_obs_i)
597
+ if (j_int == 0) or (j_int == i_int-1):
598
+ w_calc = np.append(w_calc, 0.5*np.ones_like(t_obs_i)/(i_int-1.))
599
+ else:
600
+ w_calc = np.append(w_calc, np.ones_like(t_obs_i)/(i_int-1.))
601
+
602
+ c_n_obs = ctypes.c_int(n_obs)
603
+ c_n_mugrid_1 = ctypes.c_int(n_mugrid_1)
604
+ c_n_mugrid_2 = ctypes.c_int(n_mugrid_2)
605
+ c_verbose = ctypes.c_int(verbose)
606
+ lc_rv_flags = np.zeros((6, n_obs), dtype=np.float64)
607
+
608
+ lib.lc(
609
+ ctypes.byref(c_n_obs),
610
+ t_calc.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
611
+ par.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
612
+ ipar.ctypes.data_as(ctypes.POINTER(ctypes.c_int)),
613
+ spar_1.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
614
+ spar_2.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
615
+ ctypes.byref(c_n_mugrid_1),
616
+ mugrid_1.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
617
+ ctypes.byref(c_n_mugrid_2),
618
+ mugrid_2.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
619
+ ctypes.byref(c_verbose),
620
+ lc_rv_flags.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
621
+ )
622
+
623
+ if (np.sum(np.isnan(lc_rv_flags)) > 0 ) & (verbose > 0):
624
+ c_verbose9 = ctypes.c_int(9)
625
+ lc_dummy = np.zeros((6, n_obs), dtype=np.float64)
626
+ lib.lc(
627
+ ctypes.byref(c_n_obs),
628
+ t_calc.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
629
+ par.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
630
+ ipar.ctypes.data_as(ctypes.POINTER(ctypes.c_int)),
631
+ spar_1.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
632
+ spar_2.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
633
+ ctypes.byref(c_n_mugrid_1),
634
+ mugrid_1.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
635
+ ctypes.byref(c_n_mugrid_2),
636
+ mugrid_2.ctypes.data_as(ctypes.POINTER(ctypes.c_double)),
637
+ ctypes.byref(c_verbose9),
638
+ lc_dummy.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
639
+ )
640
+
641
+ flux1 = np.zeros(n_obs)
642
+ flux2 = np.zeros(n_obs)
643
+ for j in range(0,len(t_calc)):
644
+ flux1[i_calc[j]] += lc_rv_flags[1,i_calc[j]]*w_calc[j]
645
+ flux2[i_calc[j]] += lc_rv_flags[2,i_calc[j]]*w_calc[j]
646
+
647
+ t_obs_0 = t_obs_array[n_int_array == 0 ] # Points to be interpolated
648
+ n_obs_0 = len(t_obs_0)
649
+ if n_obs_0 > 0 :
650
+ i_sort = np.argsort(t_calc)
651
+ t_int = t_calc[i_sort]
652
+ f_int = lc_rv_flags[1,i_sort]
653
+ flux1[n_int_array == 0 ] = np.interp(t_obs_0,t_int,f_int)
654
+ f_int = lc_rv_flags[2,i_sort]
655
+ flux2[n_int_array == 0 ] = np.interp(t_obs_0,t_int,f_int)
656
+
657
+ return flux1,flux2
658
+
659
+