def testKeplerSplineError(self):
    # Big gap.
    time = np.concatenate([np.arange(0, 1, 0.1), [2]])
    flux = np.sin(time)

    with self.assertRaises(kepler_spline.SplineError):
      kepler_spline.kepler_spline(time, flux, bkspace=0.5)
  def testKeplerSplineSine(self):
    # Fit a sine wave.
    time = np.arange(0, 10, 0.1)
    flux = np.sin(time)

    # Expect very close fit with no outliers removed.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=0.5)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-4)
    self.assertTrue(np.all(mask))

    # Add some outliers.
    flux[35] = 10
    flux[77] = -3
    flux[95] = 2.9

    # Expect a close fit with outliers removed.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=0.5)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-4)
    self.assertEqual(np.sum(mask), 97)
    self.assertFalse(mask[35])
    self.assertFalse(mask[77])
    self.assertFalse(mask[95])

    # Increase breakpoint spacing. Fit is not quite as close.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=1)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 2e-3)
    self.assertEqual(np.sum(mask), 97)
    self.assertFalse(mask[35])
    self.assertFalse(mask[77])
    self.assertFalse(mask[95])
Пример #3
0
  def testFitSine(self):
    # Fit a sine wave.
    time = np.arange(0, 10, 0.1)
    flux = np.sin(time)

    # Expect very close fit with no outliers removed.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=0.5)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-4)
    self.assertTrue(np.all(mask))

    # Add some outliers.
    flux[35] = 10
    flux[77] = -3
    flux[95] = 2.9

    # Expect a close fit with outliers removed.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=0.5)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-4)
    self.assertEqual(np.sum(mask), 97)
    self.assertFalse(mask[35])
    self.assertFalse(mask[77])
    self.assertFalse(mask[95])

    # Increase breakpoint spacing. Fit is not quite as close.
    spline, mask = kepler_spline.kepler_spline(time, flux, bkspace=1)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 2e-3)
    self.assertEqual(np.sum(mask), 97)
    self.assertFalse(mask[35])
    self.assertFalse(mask[77])
    self.assertFalse(mask[95])
  def testKeplerSplineError(self):
    # Big gap.
    time = np.concatenate([np.arange(0, 1, 0.1), [2]])
    flux = np.sin(time)

    with self.assertRaises(kepler_spline.SplineError):
      kepler_spline.kepler_spline(time, flux, bkspace=0.5)
Пример #5
0
    def testInsufficientPointsError(self):
        # Empty light curve.
        time = np.array([])
        flux = np.array([])

        with self.assertRaises(kepler_spline.InsufficientPointsError):
            kepler_spline.kepler_spline(time, flux, bkspace=0.5)

        # Only 3 points.
        time = np.array([0.1, 0.2, 0.3])
        flux = np.sin(time)

        with self.assertRaises(kepler_spline.InsufficientPointsError):
            kepler_spline.kepler_spline(time, flux, bkspace=0.5)
Пример #6
0
  def testInsufficientPointsError(self):
    # Empty light curve.
    time = np.array([])
    flux = np.array([])

    with self.assertRaises(kepler_spline.InsufficientPointsError):
      kepler_spline.kepler_spline(time, flux, bkspace=0.5)

    # Only 3 points.
    time = np.array([0.1, 0.2, 0.3])
    flux = np.sin(time)

    with self.assertRaises(kepler_spline.InsufficientPointsError):
      kepler_spline.kepler_spline(time, flux, bkspace=0.5)
  def testKeplerSplineCubic(self):
    # Fit a cubic polynomial.
    time = np.arange(0, 10, 0.1)
    flux = (time - 5)**3 + 2 * (time - 5)**2 + 10

    # Expect very close fit with no outliers removed. We choose maxiter=1,
    # because a cubic spline will fit a cubic polynomial ~exactly, so the
    # standard deviation of residuals will be ~0, which will cause some closely
    # fit points to be rejected.
    spline, mask = kepler_spline.kepler_spline(
        time, flux, bkspace=0.5, maxiter=1)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-12)
    self.assertTrue(np.all(mask))
Пример #8
0
  def testFitCubic(self):
    # Fit a cubic polynomial.
    time = np.arange(0, 10, 0.1)
    flux = (time - 5)**3 + 2 * (time - 5)**2 + 10

    # Expect very close fit with no outliers removed. We choose maxiter=1,
    # because a cubic spline will fit a cubic polynomial ~exactly, so the
    # standard deviation of residuals will be ~0, which will cause some closely
    # fit points to be rejected.
    spline, mask = kepler_spline.kepler_spline(
        time, flux, bkspace=0.5, maxiter=1)
    rmse = np.sqrt(np.mean((flux[mask] - spline[mask])**2))
    self.assertLess(rmse, 1e-12)
    self.assertTrue(np.all(mask))