Skip to content
Snippets Groups Projects
Commit 3adbed88 authored by Wuttke, Joachim's avatar Wuttke, Joachim Committed by Wuttke, Joachim
Browse files

sample, sim as args; new fct run_and_plot

parent cbb09945
No related branches found
No related tags found
No related merge requests found
......@@ -385,7 +385,7 @@ std::string defineGISASSimulation(const GISASSimulation* simulation) {
std::ostringstream result;
result << defineGISASBeam(*simulation);
result << defineDetector(simulation);
result << indent() << "simulation = ba.GISASSimulation(beam, get_sample(), detector)\n";
result << indent() << "simulation = ba.GISASSimulation(beam, sample, detector)\n";
result << defineDetectorResolutionFunction(simulation);
result << defineDetectorPolarizationAnalysis(simulation);
result << defineParameterDistributions(simulation);
......@@ -424,7 +424,7 @@ std::string defineSpecularSimulation(const SpecularSimulation* simulation) {
std::string defineSimulate(const ISimulation* simulation) {
std::ostringstream result;
result << "def get_simulation(sample=get_sample()):\n";
result << "def get_simulation(sample):\n";
if (auto gisas = dynamic_cast<const GISASSimulation*>(simulation))
result << defineGISASSimulation(gisas);
else if (auto offspec = dynamic_cast<const OffSpecularSimulation*>(simulation))
......@@ -435,21 +435,12 @@ std::string defineSimulate(const ISimulation* simulation) {
ASSERT(0);
result << " return simulation\n\n\n";
result << "def run_simulation():\n"
" simulation = get_simulation()\n"
" simulation.runSimulation()\n"
" return simulation.result()\n\n\n";
return result.str();
}
const std::string defineMain =
"if __name__ == '__main__':\n"
" result = run_simulation()\n"
" if len(sys.argv)>=2:\n"
" ba.IntensityDataIOFactory.writeSimulationResult(result, sys.argv[1])\n"
" else:\n"
" ba.plot_simulation_result(result)\n";
" ba.run_and_plot(get_simulation(get_sample()))\n";
} // namespace
......
......@@ -212,3 +212,7 @@ def plot_simulation_result(result, **kwargs):
plt.tight_layout()
if not (postpone_show):
plt.show()
def run_and_plot(simulation):
simulation.runSimulation()
ba.plot_simulation_result(simulation.result())
......@@ -43,8 +43,7 @@ def retrieve_simulation(ti, fname):
ns = {}
exec(c, ns)
globals().update(ns)
s = get_simulation()
s.setSample(get_sample())
s = get_simulation(get_sample())
return s
......
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