Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da7925b

Browse files
committed
Deal with empty input arrays in kepler_spline.choose_kepler_spline().
PiperOrigin-RevId: 201007094
1 parent 9546b04 commit da7925b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

research/astronet/third_party/kepler_spline/kepler_spline.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def choose_kepler_spline(all_time,
187187
# model and sigma is the constant standard deviation for all flux values.
188188
# Moreover, we assume that s[i] ~= s[i+1]. Therefore,
189189
# (f[i+1] - f[i]) / sqrt(2) ~ N(0, sigma^2).
190-
scaled_diffs = np.concatenate([np.diff(f) / np.sqrt(2) for f in all_flux])
190+
scaled_diffs = [np.diff(f) / np.sqrt(2) for f in all_flux]
191+
scaled_diffs = np.concatenate(scaled_diffs) if scaled_diffs else np.array([])
191192
if not scaled_diffs.size:
192193
best_spline = [np.array([np.nan] * len(f)) for f in all_flux]
193194
metadata.light_curve_mask = [

research/astronet/third_party/kepler_spline/kepler_spline_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ def testInsufficientPointsError(self):
7979

8080
class ChooseKeplerSplineTest(absltest.TestCase):
8181

82+
def testEmptyInput(self):
83+
# Logarithmically sample candidate break point spacings.
84+
bkspaces = np.logspace(np.log10(0.5), np.log10(5), num=20)
85+
86+
spline, metadata = kepler_spline.choose_kepler_spline(
87+
all_time=[],
88+
all_flux=[],
89+
bkspaces=bkspaces,
90+
penalty_coeff=1.0,
91+
verbose=False)
92+
np.testing.assert_array_equal(spline, [])
93+
np.testing.assert_array_equal(metadata.light_curve_mask, [])
94+
8295
def testNoPoints(self):
8396
all_time = [np.array([])]
8497
all_flux = [np.array([])]

0 commit comments

Comments
 (0)