Skip to content

Commit a787d6e

Browse files
erusseilpre-commit-ci[bot]hombit
authored
Update temperature.py (#414)
* Update temperature.py Improved lower bounds and initial guess for t_color * Update bolometric.py Improved time scale parameters for linexp and doublexp * Update test_rainbow.py Fixed tests * Update temperature.py Homogenize t_color guess for DelayedSigmoid * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Konstantin Malanchev <hombit@gmail.com>
1 parent 6f127d9 commit a787d6e

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

light-curve/light_curve/light_curve_py/features/rainbow/bolometric.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,14 @@ def value(t, t0, amplitude, rise_time):
227227
def initial_guesses(t, m, sigma, band):
228228

229229
A = np.ptp(m)
230+
med_dt = median_dt(t, band)
230231

231232
# Compute points after or before maximum
232233
peak_time = t[np.argmax(m)]
233234
after = t[-1] - peak_time
234235
before = peak_time - t[0]
235236

236-
# Peak position as weighted centroid of everything above zero
237-
idx = m > np.median(m)
238-
# Weighted centroid sigma
239-
dt = np.sqrt(np.sum((t[idx] - peak_time) ** 2 * m[idx] / sigma[idx]) / np.sum(m[idx] / sigma[idx]))
240-
# Empirical conversion of sigma to rise/rise times
241-
rise_time = dt / 2
237+
rise_time = 100 * med_dt
242238
rise_time = rise_time if before >= after else -rise_time
243239

244240
initial = {}
@@ -297,39 +293,36 @@ def value(t, t0, amplitude, time1, time2, p):
297293
@staticmethod
298294
def initial_guesses(t, m, sigma, band):
299295
A = np.ptp(m)
296+
med_dt = median_dt(t, band)
300297

301298
# Naive peak position from the highest point
302299
t0 = t[np.argmax(m)]
303-
# Peak position as weighted centroid of everything above zero
304-
idx = m > np.median(m)
305-
# t0 = np.sum(t[idx] * m[idx] / sigma[idx]) / np.sum(m[idx] / sigma[idx])
306-
# Weighted centroid sigma
307-
dt = np.sqrt(np.sum((t[idx] - t0) ** 2 * m[idx] / sigma[idx]) / np.sum(m[idx] / sigma[idx]))
308300

309301
# Empirical conversion of sigma to rise/fall times
310-
time1 = 10 * dt
311-
time2 = 10 * dt
302+
time1 = 50 * med_dt
303+
time2 = 50 * med_dt
312304

313305
initial = {}
314306
initial["reference_time"] = t0
315307
initial["amplitude"] = A
316308
initial["time1"] = time1
317309
initial["time2"] = time2
318-
initial["p"] = 1
310+
initial["p"] = 0.1
319311

320312
return initial
321313

322314
@staticmethod
323315
def limits(t, m, sigma, band):
324316
t_amplitude = np.ptp(t)
325317
m_amplitude = np.ptp(m)
318+
med_dt = median_dt(t, band)
326319

327320
limits = {}
328321
limits["reference_time"] = (np.min(t) - 10 * t_amplitude, np.max(t) + 10 * t_amplitude)
329322
limits["amplitude"] = (0.0, 10 * m_amplitude)
330-
limits["time1"] = (1e-1, 2 * t_amplitude)
331-
limits["time2"] = (1e-1, 2 * t_amplitude)
332-
limits["p"] = (0, 100)
323+
limits["time1"] = (med_dt, 2 * t_amplitude)
324+
limits["time2"] = (med_dt, 2 * t_amplitude)
325+
limits["p"] = (1e-4, 10)
333326

334327
return limits
335328

@@ -338,6 +331,15 @@ def peak_time(t0, p):
338331
return t0 + np.real(-lambertw(p * np.exp(1)) + 1)
339332

340333

334+
def median_dt(t, band):
335+
# Compute the median distance between points in each band
336+
dt = []
337+
for b in np.unique(band):
338+
dt += list(t[band == b][1:] - t[band == b][:-1])
339+
med_dt = np.median(dt)
340+
return med_dt
341+
342+
341343
bolometric_terms = {
342344
"sigmoid": SigmoidBolometricTerm,
343345
"bazin": BazinBolometricTerm,

light-curve/light_curve/light_curve_py/features/rainbow/temperature.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,24 @@ def value(t, t0, temp_min, temp_max, t_color):
111111

112112
@staticmethod
113113
def initial_guesses(t, m, sigma, band):
114+
med_dt = median_dt(t, band)
115+
114116
initial = {}
115117
initial["Tmin"] = 7000.0
116118
initial["Tmax"] = 10000.0
117-
initial["t_color"] = 1.0
119+
initial["t_color"] = 10 * med_dt
118120

119121
return initial
120122

121123
@staticmethod
122124
def limits(t, m, sigma, band):
123125
t_amplitude = np.ptp(t)
126+
med_dt = median_dt(t, band)
124127

125128
limits = {}
126129
limits["Tmin"] = (1e3, 2e6) # K
127130
limits["Tmax"] = (1e3, 2e6) # K
128-
limits["t_color"] = (1e-4, 10 * t_amplitude)
131+
limits["t_color"] = (2 * med_dt, 10 * t_amplitude)
129132

130133
return limits
131134

@@ -160,27 +163,39 @@ def value(t, t0, Tmin, Tmax, t_color, t_delay):
160163

161164
@staticmethod
162165
def initial_guesses(t, m, sigma, band):
166+
med_dt = median_dt(t, band)
167+
163168
initial = {}
164169
initial["Tmin"] = 7000.0
165170
initial["Tmax"] = 10000.0
166-
initial["t_color"] = 1.0
171+
initial["t_color"] = 10 * med_dt
167172
initial["t_delay"] = 0.0
168173

169174
return initial
170175

171176
@staticmethod
172177
def limits(t, m, sigma, band):
173178
t_amplitude = np.ptp(t)
179+
med_dt = median_dt(t, band)
174180

175181
limits = {}
176182
limits["Tmin"] = (1e3, 2e6) # K
177183
limits["Tmax"] = (1e3, 2e6) # K
178-
limits["t_color"] = (1e-4, 10 * t_amplitude)
184+
limits["t_color"] = (2 * med_dt, 10 * t_amplitude)
179185
limits["t_delay"] = (-t_amplitude, t_amplitude)
180186

181187
return limits
182188

183189

190+
def median_dt(t, band):
191+
# Compute the median distance between points in each band
192+
dt = []
193+
for b in np.unique(band):
194+
dt += list(t[band == b][1:] - t[band == b][:-1])
195+
med_dt = np.median(dt)
196+
return med_dt
197+
198+
184199
temperature_terms = {
185200
"constant": ConstantTemperatureTerm,
186201
"sigmoid": SigmoidTemperatureTerm,

light-curve/tests/light_curve_py/features/test_rainbow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_noisy_all_functions_combination():
7272
bolometric_names = ["bazin", "sigmoid", "linexp", "doublexp"]
7373
bolometric_params = [bazin_parameters, sigmoid_parameters, linexp_parameters, doublexp_parameters]
7474

75-
Tsigmoid_parameters = [5e3, 15e3, 4.0] # Tmin # Tmax # t_color
75+
Tsigmoid_parameters = [5e3, 15e3, 10] # Tmin # Tmax # t_color
7676

7777
constant_parameters = [1e4] # T
7878

0 commit comments

Comments
 (0)