Smooth function: Difference between revisions

From SPEDAS Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== Smooth function ==
== IDL code: SPEDAS ==
 
Compare IDL SPEDAS to pyspedas code.
 
* IDL code:


<pre>
<pre>
Line 33: Line 29:




* Python code:
== Python code: pySPEDAS ==


<pre>
<pre>

Revision as of 23:25, 24 April 2020

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()