diff --git a/pyspedas_examples/examples/ex_avg.py b/pyspedas_examples/examples/ex_avg.py index 4e35420..2e8c431 100644 --- a/pyspedas_examples/examples/ex_avg.py +++ b/pyspedas_examples/examples/ex_avg.py @@ -40,7 +40,7 @@ def ex_avg(plot=True): return 1 -def ex_avg2(): +def ex_avg2(plot=True): """Load some random data and find the time average. The same example can be run on IDL to compare results. diff --git a/pyspedas_examples/examples/ex_colors.py b/pyspedas_examples/examples/ex_colors.py index b28d011..fa71ba5 100644 --- a/pyspedas_examples/examples/ex_colors.py +++ b/pyspedas_examples/examples/ex_colors.py @@ -5,7 +5,7 @@ from pyspedas.themis import state -def ex_colors(): +def ex_colors(plot=True): """Get state data for THEMIS Load position and velocity from THEMIS and plot with different colors. @@ -24,7 +24,8 @@ def ex_colors(): # choose line colors options('tha_pos', 'color', ['black', 'magenta', 'cyan']) - tplot(['tha_pos', 'tha_vel', ]) + if plot: + tplot(['tha_pos', 'tha_vel', ]) # Return 1 as indication that the example finished without problems. return 1 diff --git a/pyspedas_examples/examples/ex_cotrans.py b/pyspedas_examples/examples/ex_cotrans.py index 90fa237..fafdcf1 100644 --- a/pyspedas_examples/examples/ex_cotrans.py +++ b/pyspedas_examples/examples/ex_cotrans.py @@ -9,7 +9,7 @@ from pyspedas.themis import state -def ex_cotrans(): +def ex_cotrans(plot=True): """Transform state data for THEMIS from GEI to GSE. Load position and velocity from THEMIS. @@ -42,7 +42,8 @@ def ex_cotrans(): options(vel_in, 'legend_names', ["Vx, GEI", "Vy, GEI", "Vz, GEI"]) options(vel_out, 'ytitle', vel_out) options(vel_out, 'legend_names', ["Vx, GSE", "Vy, GSE", "Vz, GSE"]) - tplot([pos_in, vel_in, pos_out, vel_out]) + if plot: + tplot([pos_in, vel_in, pos_out, vel_out]) # Return 1 as indication that the example finished without problems. return 1 diff --git a/pyspedas_examples/examples/ex_mpause_2.py b/pyspedas_examples/examples/ex_mpause_2.py index a8d59a4..96057ca 100644 --- a/pyspedas_examples/examples/ex_mpause_2.py +++ b/pyspedas_examples/examples/ex_mpause_2.py @@ -9,7 +9,7 @@ from pyspedas import mpause_2 -def ex_mpause_2(): +def ex_mpause_2(plot=True): # Call the function without parameters to use default values xmp, ymp = mpause_2() @@ -36,7 +36,8 @@ def ex_mpause_2(): plt.title("Magnetopause Locations") # Display the plot - plt.show() + if plot: + plt.show() # Run the example code diff --git a/pyspedas_examples/examples/ex_mpause_t96.py b/pyspedas_examples/examples/ex_mpause_t96.py index d2f13f3..b65a4ce 100644 --- a/pyspedas_examples/examples/ex_mpause_t96.py +++ b/pyspedas_examples/examples/ex_mpause_t96.py @@ -12,7 +12,7 @@ from pyspedas import cotrans, mpause_t96 -def ex_mpause_t96(): +def ex_mpause_t96(plot=True): # Set the date and load one day of data date_start = '2019-01-05/00:00:00' @@ -47,7 +47,8 @@ def ex_mpause_t96(): plt.ylabel('Y (Re)') plt.title('Magnetopause Boundary') plt.grid(True) - plt.show() + if plot: + plt.show() # Run the example code diff --git a/tests/tests.py b/tests/tests.py index 1ec82e6..2b2014b 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2,37 +2,38 @@ import unittest +global_display=False class LoadTestCases(unittest.TestCase): """Run tests on examples.""" def test_version(self): - """Test ex_avg.""" + """Test version""" from pyspedas_examples.version import version self.assertFalse(version()) def test_ex_analysis(self): """Test ex_analysis.""" from pyspedas_examples.examples.ex_analysis import ex_analysis - ex = ex_analysis() + ex = ex_analysis(plot=global_display) self.assertEqual(ex, 1) def test_ex_avg(self): """Test ex_avg.""" from pyspedas_examples.examples.ex_avg import ex_avg - ex = ex_avg() + ex = ex_avg(plot=global_display) self.assertEqual(ex, 1) def test_ex_avg2(self): """Test ex_avg.""" from pyspedas_examples.examples.ex_avg import ex_avg2 - ex = ex_avg2() + ex = ex_avg2(plot=global_display) self.assertAlmostEqual(ex[0], 1044.22) def test_ex_basic(self): """Test ex_basic.""" from pyspedas_examples.examples.ex_basic import ex_basic - ex = ex_basic() + ex = ex_basic(plot=global_display) self.assertEqual(ex, 1) def test_ex_cdagui(self): @@ -47,58 +48,47 @@ def test_ex_cdasws(self): ex = ex_cdasws() self.assertEqual(ex, 1) - def test_ex_create(self): - """Test ex_basic.""" - from pyspedas_examples.examples.ex_create import ex_create - ex = ex_create() - self.assertEqual(ex, 1) - def test_ex_deriv(self): """Test ex_basic.""" from pyspedas_examples.examples.ex_deriv import ex_deriv - ex = ex_deriv() + ex = ex_deriv(plot=global_display) self.assertEqual(ex, 1) - def test_ex_deriv2(self): - """Test ex_basic.""" - from pyspedas_examples.examples.ex_deriv import ex_deriv2 - ex = ex_deriv2() - self.assertEqual(ex, 1) def test_ex_dsl2gse(self): """Test ex_dsl2gse.""" from pyspedas_examples.examples.ex_dsl2gse import ex_dsl2gse - ex = ex_dsl2gse() + ex = ex_dsl2gse(plot=global_display) self.assertEqual(ex, 1) def test_ex_gmag(self): """Test ex_dsl2gse.""" from pyspedas_examples.examples.ex_gmag import ex_gmag - ex = ex_gmag() + ex = ex_gmag(plot=global_display) self.assertEqual(ex, 1) def test_ex_smooth(self): """Test ex_dsl2gse.""" from pyspedas_examples.examples.ex_smooth import ex_smooth - ex = ex_smooth() + ex = ex_smooth(plot=global_display) self.assertEqual(ex, 1) def test_ex_spectra(self): """Test ex_spectra.""" from pyspedas_examples.examples.ex_spectra import ex_spectra - ex = ex_spectra() + ex = ex_spectra(plot=global_display) self.assertEqual(ex, 1) def test_ex_spikes(self): """Test ex_spectra.""" from pyspedas_examples.examples.ex_spikes import ex_spikes - ex = ex_spikes() + ex = ex_spikes(plot=global_display) self.assertEqual(ex, 1) def test_ex_wavelet(self): """Test ex_spectra.""" from pyspedas_examples.examples.ex_wavelet import ex_wavelet - ex = ex_wavelet() + ex = ex_wavelet(plot=global_display) self.assertEqual(ex, 1) def test_pseudovar_right_axis(self): @@ -110,7 +100,8 @@ def test_pseudovar_right_axis(self): store_data('spec', data=['mms1_des_energyspectr_omni_fast', 'mms1_edp_scpot_fast_l2']) options('spec', 'right_axis', True) tplot_options('xmargin', [0.1, 0.2]) - tplot('spec', xsize=12) + if global_display: + tplot('spec', xsize=12) if __name__ == '__main__': unittest.main()