from sunpy.timeseries import TimeSeries ############################################################################### # Let's first create a TimeSeries from sample data. goes_lc = TimeSeries(GOES_XRS_TIMESERIES).truncate('2011/06/07 06:10', '2011/06/07 07:00') ############################################################################### # Now we will extract data values from the TimeSeries and apply a BoxCar filter # to get smooth data. Boxcar smoothing is equivalent to taking our signal and # using it to make a new signal where each element is the average of w adjacent # elements. Here we will use astropy's convolve function with a "boxcar" kernel # of width w = 10. goes_lc = goes_lc.add_column( 'xrsa_smoothed', convolve(goes_lc.quantity('xrsa'), kernel=Box1DKernel(50))) ############################################################################### # Plotting original and smoothed timeseries. plt.figure() plt.xlabel('Time') plt.ylabel("Flux (Wm$^{-2}$") plt.title('Smoothing of Time Series') plt.plot(goes_lc.quantity('xrsa'), label='original') plt.plot(goes_lc.quantity('xrsa_smoothed'), label='smoothed') plt.legend() plt.show()
""" import matplotlib.pyplot as plt from astropy.convolution import convolve, Box1DKernel from sunpy.timeseries import TimeSeries from sunpy.data.sample import NOAAINDICES_TIMESERIES as noaa_ind ############################################################################### # Let's first create a TimeSeries from sample data ts_noaa_ind = TimeSeries(noaa_ind, source='NOAAIndices') ############################################################################### # Now we will extract data values from the TimeSeries and apply a BoxCar filter # to get smooth data. Boxcar smoothing is equivalent to taking our signal and # using it to make a new signal where each element is the average of w adjacent # elements. Here we will use AstroPy’s convolve function with a “boxcar” kernel # of width w = 10. ts_noaa_ind = ts_noaa_ind.add_column( 'sunspot SWO Smoothed', convolve(ts_noaa_ind.quantity('sunspot SWO'), kernel=Box1DKernel(10))) ############################################################################### # Plotting original and smoothed timeseries plt.ylabel('Sunspot Number') plt.xlabel('Time') plt.title('Smoothing of Time Series') plt.plot(ts_noaa_ind.quantity('sunspot SWO'), label='original data') plt.plot(ts_noaa_ind.quantity('sunspot SWO Smoothed'), label='smoothed') plt.legend() plt.show()