Smooth function: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
Compare IDL code to python code. | Compare IDL code to python code for smoothing data. | ||
== IDL code: SPEDAS == | == IDL code: SPEDAS == |
Revision as of 03:15, 3 May 2020
Compare IDL code to python code for smoothing data.
IDL code: SPEDAS
pro test_smooth ; smooth data t = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.] y = [3., 5., 8., 15., 20., 1., 2., 3., 4., 5., 6., 4.] store_data, 'original', data={x:t, y:y} tsmooth2, 'original', 5, newname = 'smooth' ylim, 'original', 0, 20 ylim, 'smooth', 0, 20 tplot, ['original', 'smooth'] get_data, 'original', data=d0 print, 'Original data:', d0.y get_data, 'smooth', data=d print, 'Smooth data:', d.y ; Results: ;Original data: 3.00000 5.00000 8.00000 15.0000 20.0000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 4.00000 ;Smooth data: 3.00000 5.00000 10.2000 9.80000 9.20000 8.20000 6.00000 3.00000 4.00000 4.40000 6.00000 4.00000 end
Python code: pySPEDAS
import pytplot from pyspedas.analysis.tsmooth import tsmooth def ex_test_smooth(): t = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.] y = [3., 5., 8., 15., 20., 1., 2., 3., 4., 5., 6., 4.] pytplot.store_data('original', data={'x': t, 'y': y}) tsmooth('original', width=5, new_names='smooth', preserve_nans=1) pytplot.tplot(['original', 'smooth']) d0 = pytplot.get_data('original') print('Original data: ', d0[1]) d = pytplot.get_data('smooth') print('Smooth data: ', d[1]) """ Results: Original data:[ 3., 5., 8., 15., 20., 1., 2., 3., 4., 5., 6., 4.] Smooth data: [ 3., 5., 10.2, 9.8, 9.2, 8.2 6., 3., 4., 4.4, 6., 4.] """ # Run the example code ex_test_smooth()