Skip to content

Commit

Permalink
Add a test for the 'slinear' method of tinterpol(). method='slinear' …
Browse files Browse the repository at this point in the history
…seems less susceptible than 'linear' to producing inexact results when interpolating to output points that exactly match one of the input times.
  • Loading branch information
jameswilburlewis committed Sep 27, 2024
1 parent 331a8d5 commit b31f0c1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pyspedas/analysis/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,22 @@ def test_tinterpol_nonnegative2(self):
# unlikely to ever be fixed. See tests above for xarray.interp and scipy
# self.assertTrue((result.y >= 0.0).all())

def test_tinterpol_slinear(self):
# This test uses the 'slinear' interpolation method (order 1 spline) which
# seems not to be susceptible to the issue that method='linear' has with interpolating
# to points exactly matching the input times.
time_strings_input = np.array(['2018-07-01T13:02:16.892474880',
'2018-07-01T13:02:16.922475008',
'2018-07-01T13:02:16.952474880'])
values_input = np.array([0.028584518, 0., 0.013626526],dtype=np.float32)
time_strings_interp_to = np.array(['2018-07-01T13:02:16.922475008'])
input_times_npdt64 = np.array([np.datetime64(t) for t in time_strings_input])
interp_to_times_npdt64 = np.array([np.datetime64(t) for t in time_strings_interp_to])
store_data('interp_input', data={'x':input_times_npdt64, 'y':values_input})
store_data('interp_to', data={'x':interp_to_times_npdt64, 'y':[0.0]})
tinterpol('interp_input', 'interp_to', newname='interp_result', method='slinear')
result=get_data('interp_result')
self.assertTrue((result.y >= 0.0).all())

if __name__ == '__main__':
unittest.main()

0 comments on commit b31f0c1

Please sign in to comment.