Skip to content
Snippets Groups Projects
Commit 96b73616 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

Shorter name for essential visualization tool

call it plot_int because files to be plotted have extension int
parent 7b4a764d
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
'''
Plots intensity data difference stored in BornAgain "*.int" or "*.int.gz" format
Usage: python plot_intensity_data_diff.py reference.int.gz new.int.gz
Usage: python plot_diff_int.py reference.int.gz new.int.gz
'''
import numpy as np
import bornagain as ba
import plot_intensity_data as pid
import plot_int as pid
import sys
def plot_intensity_data_diff(filename1, filename2):
def plot_diff_int(filename1, filename2):
intensity_ref = ba.IntensityDataIOFactory.readIntensityData(filename1)
intensity_other = ba.IntensityDataIOFactory.readIntensityData(filename2)
data = 2 * np.abs(intensity_ref.array() - intensity_other.array()) \
......@@ -29,11 +29,11 @@ def plot_intensity_data_diff(filename1, filename2):
axis_values = np.asarray(intensity_ref.xAxis().binCenters())/ba.deg
pid.plot_raw_data_1d(axis_values, data, log_y=False)
else:
exit("Error in plot_intensity_data_diff: wrong data rank")
exit("Error in plot_diff_int: wrong data rank")
if __name__ == '__main__':
if len(sys.argv) != 3:
exit("Usage: plot_intensity_data_diff.py reference.int.gz other.int.gz")
exit("Usage: plot_diff_int.py reference.int.gz other.int.gz")
plot_intensity_data_diff(sys.argv[1], sys.argv[2])
plot_diff_int(sys.argv[1], sys.argv[2])
......@@ -2,7 +2,7 @@
'''
Plots data stored in BornAgain "*.int" or "*.int.gz" format
Can handle both 1D and 2D arrays
Usage: python plot_intensity_data.py intensity_file.int.gz [intensity_max]
Usage: python plot_int.py intensity_file.int.gz [intensity_max]
'''
import sys
......@@ -14,19 +14,19 @@ rc('font', **{'family': 'sans-serif', 'sans-serif': ['Helvetica']})
rc('text', usetex=True)
def plot_intensity_data(file_name, intensity_max=None):
def plot_int(file_name, intensity_max=None):
data = ba.IntensityDataIOFactory.readIntensityData(file_name)
if intensity_max is None:
intensity_max = data.getMaximum()
if data.rank() == 1:
plot_intensity_data_1d(data, intensity_max)
plot_int_1d(data, intensity_max)
elif data.rank() == 2:
plot_intensity_data_2d(data, intensity_max)
plot_int_2d(data, intensity_max)
else:
exit("Error in plot_intensity_data: wrong data rank")
exit("Error in plot_int: wrong data rank")
def plot_intensity_data_2d(histogram, intensity_max):
def plot_int_2d(histogram, intensity_max):
plot_raw_data_2d(histogram.array(), [
histogram.getXmin()/ba.deg,
histogram.getXmax()/ba.deg,
......@@ -47,7 +47,7 @@ def plot_raw_data_2d(values, extent_array, intensity_max):
plt.show()
def plot_intensity_data_1d(histogram, intensity_max):
def plot_int_1d(histogram, intensity_max):
axis_values = np.asarray(histogram.xAxis().binCenters())/ba.deg
array_values = histogram.array()*intensity_max/histogram.getMaximum()
plot_raw_data_1d(axis_values, array_values)
......@@ -65,9 +65,9 @@ def plot_raw_data_1d(axis, values, log_y=True):
if __name__ == '__main__':
if len(sys.argv) < 2 or len(sys.argv) > 3:
exit("Usage: plot_intensity_data.py intensity_file.int.gz [intensity_max]")
exit("Usage: plot_int.py intensity_file.int.gz [intensity_max]")
if len(sys.argv) == 2:
plot_intensity_data(sys.argv[1])
plot_int(sys.argv[1])
else:
plot_intensity_data(sys.argv[1], float(sys.argv[2]))
plot_int(sys.argv[1], float(sys.argv[2]))
......@@ -40,4 +40,4 @@ cd <build_dir>
-------------------------------------------------------------------------------
5) Inspect result
-------------------------------------------------------------------------------
<bornagain>/Examples/python/utils/plot_intensity_data.py result.int
\ No newline at end of file
<bornagain>/Examples/python/utils/plot_int.py result.int
\ No newline at end of file
......@@ -60,7 +60,7 @@ def get_simulation_BasicGISAS(sample=None):
return simulation
def plot_intensity_data(intensity):
def plot_int(intensity):
import matplotlib, pylab
data = intensity.getArray() + 1
# data = numpy.abs(intensity.getArray())
......
#### Reference data for functional tests
Core
: used by Tests/Functional/Core/CoreSpecial
`Core`
: used by `Tests/Functional/Core/CoreSpecial`
PyCore
: used by Tests/Functional/Tests/Functional/Python/PyCore
`PyCore`
: used by `Tests/Functional/Tests/Functional/Python/PyCore`
PyPersist
: used by Tests/Functional/Tests/Functional/Python/PyPersist
`PyPersist`
: used by `Tests/Functional/Tests/Functional/Python/PyPersist`
Std
`Std`
: used by Core, Python, and GUI standard tests
To visualize one data file, call
> python3 Examples/Python/utils/plot_intensity_data.py <reference.int.gz>
To visualize one data file, run
> `plot_int.py <reference.int.gz>`
This script is provided in `Examples/Python/utils`, and copied verbatim to `<build>/bin`.
......@@ -23,10 +23,10 @@ configure_file(${CONFIGURABLES_DIR}/BABuild.h.in ${BUILD_INC_DIR}/BABuild.h @ON
configure_file(${CONFIGURABLES_DIR}/BATesting.h.in ${BUILD_INC_DIR}/BATesting.h @ONLY)
string(APPEND CMAKE_CXX_FLAGS " -I${BUILD_INC_DIR}")
configure_file(${CMAKE_SOURCE_DIR}/Examples/Python/utils/plot_intensity_data.py
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plot_intensity_data.py COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/Examples/Python/utils/plot_intensity_data_diff.py
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plot_intensity_data_diff.py COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/Examples/Python/utils/plot_int.py
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plot_int.py COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/Examples/Python/utils/plot_diff_int.py
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/plot_diff_int.py COPYONLY)
# -----------------------------------------------------------------------------
# configure BornAgain launch scripts
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment