def ex_gmag(plot=True): """Demonstrate how to use gmag functions.""" # Delete any existing pytplot variables pytplot.del_data() # Define a time rage as a list trange = ['2015-12-31', '2015-12-31'] # Get a list of EPO gmag stations sites = pyspedas.themis.ground.gmag.gmag_list('epo') # Download gmag files and load data into pytplot variables pyspedas.themis.gmag(sites=sites, trange=trange) # Get a list of loaded sites sites_loaded = pyspedas.tnames() # Subtract mean values pyspedas.subtract_average(sites_loaded, '') # Download AE index data # pyspedas.load_data('gmag', time_list, ['idx'], '', '') pyspedas.themis.gmag(sites='idx', trange=trange) # Plot sites_loaded = pytplot.tplot_names() pytplot.tplot_options('title', 'EPO GMAG 2015-12-31') if plot: pytplot.tplot(sites_loaded) # Return 1 as indication that the example finished without problems. return 1
def ex_avg(plot=True): """Load GMAG data and average over 5 min intervals.""" # Delete any existing pytplot variables. pytplot.del_data() # Define a time rage as a list trange = ['2007-03-23', '2007-03-23'] # Download gmag files and load data into pytplot variables. sites = ['ccnv'] var = 'thg_mag_ccnv' pyspedas.themis.gmag(sites=sites, trange=trange, varnames=[var]) pytplot.tplot_options('title', 'GMAG data, thg_mag_ccnv 2007-03-23') pyspedas.subtract_average(var, median=1) var += '-m' # Five minute average using time dt. avg_data(var, dt=5 * 60.) # Five minute average using width (number of measurements). # Each measurement is 0.5 sec. avg_data(var, width=5 * 60. * 2., new_names=var + '-avg2') # Plot. if plot: pytplot.tplot([var, var + '-avg', var + '-avg2']) # Return 1 as indication that the example finished without problems. return 1
def ex_deriv(plot=True): """Find the derivative of a GMAG variable.""" # Derivative of data pytplot.del_data() # Define a time rage as a list trange = ['2007-03-23', '2007-03-23'] # Download gmag files and load data into pytplot variables sites = ['ccnv'] var = 'thg_mag_ccnv' pyspedas.themis.gmag(sites=sites, trange=trange, varnames=[var]) # pytplot.tplot_options('title', 'GMAG data, thg_mag_ccnv 2007-03-23') pyspedas.subtract_average(var, median=1) var += '-m' # Five minute average deriv_data(var) # pytplot.options(var, 'ytitle', var) # pytplot.options(var + '-der', 'ytitle', var + '-der') if plot: pytplot.tplot([var, var + '-der']) # Return 1 as indication that the example finished without problems. return 1
def ex_analysis(): # Print the installed version of pyspedas pyspedas.version() # Delete any existing pytplot variables pytplot.del_data() # Download THEMIS state data for 2015-12-31 pyspedas.load_data('themis', '2015-12-31', ['tha'], 'state', 'l1') # Use some analysis functions on tplot variables pyspedas.subtract_average('tha_pos') pyspedas.subtract_median('tha_pos') # Plot pytplot.tplot(["tha_pos", "tha_pos-d", "tha_pos-m"])
def test_subtract_median(self): """Test subtract_median.""" subtract_median('aaabbbccc') # Test non-existent name subtract_median('test') d = get_data('test-m') self.assertTrue(d[1].tolist() == [-3.5, -1.5, 1.5, 8.5, 13.5, -5.5]) dn = [[3., 5., 8.], [15., 20., 1.], [3., 5., 8.], [15., 20., 1.], [23., 15., 28.], [15., 20., float('nan')]] store_data('test1', data={'x': [1., 2., 3., 4., 5., 6.], 'y': dn}) subtract_median('aaabbbcc') subtract_median('test1', new_names='aabb') d = get_data('aabb') subtract_median(['test', 'aabb'], new_names='aaabbb') subtract_median('test1', overwrite=1) subtract_average('test', new_names="testtest") subtract_average(['test-m', 'test'], new_names="testtest2") self.assertTrue(len(d[1]) == 6)
def ex_analysis(): # Delete any existing pytplot variables pytplot.del_data() # Download THEMIS state data for 2015-12-31 time_range = ['2015-12-31 00:00:00', '2015-12-31 23:59:59'] pyspedas.themis.state(probe='a', trange=time_range) # Use some analysis functions on tplot variables pyspedas.subtract_average('tha_pos') pyspedas.subtract_median('tha_pos') # Plot pytplot.tplot(["tha_pos", "tha_pos-d", "tha_pos-m"]) # Return 1 as indication that the example finished without problems. return 1
def ex_gmag(): # Delete any existing pytplot variables pytplot.del_data() # Define list of dates time_list = ['2015-12-31'] # Get a list of EPO gmag stations sites = pyspedas.gmag_list(group='epo') # Download gmag files and load data into pytplot variables pyspedas.load_data('gmag', time_list, sites, '', '') # Get a list of loaded sites sites_loaded = pyspedas.tplot_names() # Subtact mean values pyspedas.subtract_average(sites_loaded, '') # Download AE index data pyspedas.load_data('gmag', time_list, ['idx'], '', '') # Plot sites_loaded = pyspedas.tplot_names() pytplot.tplot_options('title', 'EPO GMAG 2015-12-31') pytplot.tplot(sites_loaded)
def ex_avg(plot=False): """Load GMAG data and average over 5 min intervals.""" # Delete any existing pytplot variables pytplot.del_data() # Define a time rage as a list trange = ['2007-03-23', '2007-03-23'] # Download gmag files and load data into pytplot variables sites = ['ccnv'] var = 'thg_mag_ccnv' pyspedas.themis.gmag(sites=sites, trange=trange, varnames=[var]) pytplot.tplot_options('title', 'GMAG data, thg_mag_ccnv 2007-03-23') pyspedas.subtract_average(var, median=1) var += '-m' # Five minute average avg_data(var, width=5 * 60) if plot: pytplot.tplot([var, var + '-avg']) # Return 1 as indication that the example finished without problems. return 1
# set the y-axis to log scale options('mms4_des_numberdensity_brst', 'ylog', True) options('mms4_hpca_hplus_number_density', 'ylog', True) tplot(['mms4_des_numberdensity_brst', 'mms4_hpca_hplus_number_density']) ''' ========================================================================== Analysis Tools ========================================================================== ''' # subtract_average from pyspedas import subtract_average subtract_average('mms4_fgm_b_gsm_brst_l2') tplot(['mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d']) # subtract_median from pyspedas import subtract_median subtract_median('mms4_fgm_b_gsm_brst_l2') tplot([ 'mms4_fgm_b_gsm_brst_l2', 'mms4_fgm_b_gsm_brst_l2-d', 'mms4_fgm_b_gsm_brst_l2-m' ]) # time clip from pyspedas import time_clip
#################################################################################### # Download cdf files for all EPO GMAG stations and load data into pytplot variables. # # Some GMAG stations may not have any data files for the specified time interval. # In that case, we will get an error message that the remote file does not exist # for that GMAG station. load_data('gmag', time_range, sites, '', '') #################################################################################### # Print the names of the loaded GMAG sites. sites_loaded = tplot_names() #################################################################################### # Subtract the average values for these sites. subtract_average(sites_loaded, '') #################################################################################### # Download AE index data. load_data('gmag', time_range, ['idx'], '', '') #################################################################################### # Get a list of all the loaded GMAG sites plus the AE index data. sites_loaded = tplot_names() #################################################################################### # Plot GMAG and AE index data. # Use the bokeh library - the plots will appear in the web browser. tplot_options('title', 'EPO GMAG 2015-12-31') tplot(sites_loaded, bokeh=True)
def test_subtract_average(self): subtract_average('test') d = get_data('test-d') self.assertTrue( (np.round(d[1].tolist()) == [-6., -4., -1., 6., 11., -8.]).all())
def test_subtract_average(self): """Test subtract_average.""" subtract_average('aaabbbccc') # Test non-existent name subtract_average('test') d = get_data('test-d') self.assertTrue( (np.round(d[1].tolist()) == [-6., -4., -1., 6., 11., -8.]).all()) dn = [[3., 5., 8.], [15., 20., 1.], [3., 5., 8.], [15., 20., 1.], [23., 15., 28.], [15., 20., float('nan')]] store_data('test1', data={'x': [1., 2., 3., 4., 5., 6.], 'y': dn}) subtract_average('aaabbbcc') subtract_average('test1', new_names='aabb') d = get_data('aabb') subtract_average(['test', 'aabb'], new_names='aaabbb') subtract_average('test1', overwrite=1) subtract_average('test1', new_names="testtest") subtract_average(['test1', 'test'], new_names="testtest2") self.assertTrue(len(d[1]) == 6)