From 208cb524bce78604d9f374a4e2cdd9b3b19bac52 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Sat, 9 Apr 2022 22:22:02 +0200
Subject: [PATCH] simplify: use NOSHOW, no need for kwarg plot

---
 Examples/scatter2d/HexagonalLatticesWithBasis.py |  2 ++
 Examples/specular/BeamAngularDivergence.py       |  2 +-
 Examples/varia/GratingMC.py                      |  5 ++---
 Tests/Examples/CMakeLists.txt                    |  2 +-
 Tests/Examples/RunPersistenceTest.py             |  2 +-
 Wrap/Python/ba_plot.py                           | 16 +++-------------
 6 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/Examples/scatter2d/HexagonalLatticesWithBasis.py b/Examples/scatter2d/HexagonalLatticesWithBasis.py
index a9578b6ff99..a4d6051190a 100755
--- a/Examples/scatter2d/HexagonalLatticesWithBasis.py
+++ b/Examples/scatter2d/HexagonalLatticesWithBasis.py
@@ -72,4 +72,6 @@ if __name__ == '__main__':
     sample = get_sample()
     simulation = get_simulation(sample, **simargs)
     result = simulation.simulate()
+    print("DEBUG HL1", flush=True)
     bp.plot_simulation_result(result, **plotargs)
+    print("DEBUG HL2", flush=True)
diff --git a/Examples/specular/BeamAngularDivergence.py b/Examples/specular/BeamAngularDivergence.py
index ca1f65b1779..77efdb8880f 100755
--- a/Examples/specular/BeamAngularDivergence.py
+++ b/Examples/specular/BeamAngularDivergence.py
@@ -69,7 +69,7 @@ if __name__ == '__main__':
     simulation = get_simulation(sample, **simargs)
     result = simulation.simulate()
     bp.plot_simulation_result(result, **plotargs)
-    if not plotargs.pop('plot', 'on') in ['on']:
+    if bp.NOSHOW:
         sys.exit(0)
     genx_axis, genx_values = reference_data(data_fname)
     plt.semilogy(genx_axis, genx_values, 'ko', markevery=300)
diff --git a/Examples/varia/GratingMC.py b/Examples/varia/GratingMC.py
index de21186e7e6..ddb93cd0de5 100755
--- a/Examples/varia/GratingMC.py
+++ b/Examples/varia/GratingMC.py
@@ -84,12 +84,11 @@ if __name__ == '__main__':
     xpeaks = [peak[0] for peak in peaks]
     ypeaks = [peak[1] for peak in peaks]
     print(peaks)
-    if not plotargs.pop('plot', 'on') in ['on']:
-        sys.exit(0)
     plt.plot(xpeaks,
              ypeaks,
              linestyle='None',
              marker='x',
              color='white',
              markersize=10)
-    plt.show()
+    if not bp.NOSHOW:
+        plt.show()
diff --git a/Tests/Examples/CMakeLists.txt b/Tests/Examples/CMakeLists.txt
index af478d6f92d..5bbe3d1f08a 100644
--- a/Tests/Examples/CMakeLists.txt
+++ b/Tests/Examples/CMakeLists.txt
@@ -48,7 +48,7 @@ function(test_equality example reference tolerance)
     add_test(NAME ${test_name}
         COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
         "BA_EXAMPLE_DATA_DIR=${EXAMPLES_DIR}/data"
-        "NOSHOW=ON"
+        "NOSHOW=NOSHOW"
         ${Python3_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/RunPersistenceTest.py
         ${script_path} ${reference}
         ${TEST_REFERENCE_DIR_EXAMPLES_MINI} ${TEST_OUTPUT_DIR_PY_PERSIST} 11 ${tolerance})
diff --git a/Tests/Examples/RunPersistenceTest.py b/Tests/Examples/RunPersistenceTest.py
index c1c97ad5524..b1fa5fd5dbd 100755
--- a/Tests/Examples/RunPersistenceTest.py
+++ b/Tests/Examples/RunPersistenceTest.py
@@ -64,7 +64,7 @@ def main(script, reference, refdir, outdir, sim_n, tolerance):
     newfile = os.path.join(outdir, reference+".int.gz")
     os.makedirs(os.path.dirname(newfile), exist_ok=True)
 
-    cmd = f'{script} sim_n={sim_n} plot=off datfile={newfile}'
+    cmd = f'{script} sim_n={sim_n} datfile={newfile}'
     print(cmd, flush=True)
     try:
         ret = subprocess.run(cmd.split(), check=True, timeout=3)
diff --git a/Wrap/Python/ba_plot.py b/Wrap/Python/ba_plot.py
index f8fbc240e55..24996662b21 100644
--- a/Wrap/Python/ba_plot.py
+++ b/Wrap/Python/ba_plot.py
@@ -258,33 +258,23 @@ def plot_simulation_result(result, **kwargs):
     :param intensity_max: Max value on amplitude's axis or color bar
     :param units: units for plot axes
     :param noshow: don't plot to interactive device
-    :param plot: create plot (default=True)
     :param datfile: save result to data file
     """
     noshow = kwargs.pop('noshow', NOSHOW)
     datfile = kwargs.pop('datfile', None)
-    tmp = kwargs.pop('plot', 'on')
-    doplot = True
-    if tmp in ['off']:
-        doplot = False
-    elif tmp not in ['on']:
-        raise Exception(f"plot_simulation_result: invalid parameter plot={plot}")
 
     if datfile:
         ba.IntensityDataIOFactory.writeSimulationResult(result, datfile)
 
-    if not doplot:
-        return 0
-
     if len(result.array().shape
            ) == 1:  # 1D data, specular simulation assumed
         plot_specular_simulation_result(result, **kwargs)
     else:
         plot_colormap(result, **kwargs)
     plt.tight_layout()
-    if not noshow:
-        plt.show()
-    else:
+    if NOSHOW:
         print("plot_simulation_result: noshow")
+    else:
+        plt.show()
 
     return 0
-- 
GitLab