Comparisons

From SPEDAS Wiki
Revision as of 02:16, 6 March 2020 by Nikos (Talk | contribs)

Jump to: navigation, search

Comparisons of pySPEDAS to IDL SPEDAS

Some examples that show how to achieve the same results using either IDL SPEDAS or python pySPEDAS.


Smooth function

  • IDL code:
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:

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()
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox