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

convert along_slices example

parent 67df5771
No related branches found
No related tags found
1 merge request!1967Base fit examples on Datafield (except last 2)
......@@ -28,7 +28,7 @@ def get_masked_simulation(P):
return simulation
def create_real_data():
def fake_data():
"""
Generating "real" data by adding noise to the simulated data.
"""
......@@ -57,7 +57,7 @@ class PlotObserver:
self.update(fit_objective)
@staticmethod
def plot_real_data(data):
def plot_data(data):
"""
Plot experimental data as heatmap with horizontal/vertical lines
representing slices on top.
......@@ -121,15 +121,15 @@ class PlotObserver:
"""
self.fig.clf()
real_data = fit_objective.experimentalData()
data = fit_objective.experimentalData()
simul_data = fit_objective.simulationResult()
# plot real data
plt.subplot(2, 2, 1)
self.plot_real_data(real_data)
self.plot_data(data)
# horizontal slices
slices = [("real", real_data.xProjection(alpha_slice_value)),
slices = [("real", data.xProjection(alpha_slice_value)),
("simul", simul_data.xProjection(alpha_slice_value))]
title = ("Horizontal slice at alpha =" +
'{:3.1f}'.format(alpha_slice_value))
......@@ -137,7 +137,7 @@ class PlotObserver:
self.plot_slices(slices, title)
# vertical slices
slices = [("real", real_data.yProjection(phi_slice_value)),
slices = [("real", data.yProjection(phi_slice_value)),
("simul", simul_data.yProjection(phi_slice_value))]
title = "Vertical slice at phi =" + '{:3.1f}'.format(
phi_slice_value)
......@@ -154,13 +154,13 @@ def run_fitting():
main function to run fitting
"""
real_data = create_real_data()
data = fake_data()
fit_objective = ba.FitObjective()
fit_objective.addSimulationAndData(get_masked_simulation, real_data, 1)
fit_objective.addSimulationAndData(get_masked_simulation, data, 1)
fit_objective.initPrint(10)
# creating custom observer which will draw fit progress
# creating custom observer which will draw fit progress
plotter = PlotObserver()
fit_objective.initPlot(10, plotter)
......
......@@ -28,7 +28,7 @@ def get_masked_simulation(P):
return simulation
def create_real_data():
def fake_data():
"""
Generating "real" data by adding noise to the simulated data.
"""
......@@ -57,7 +57,7 @@ class PlotObserver:
self.update(fit_objective)
@staticmethod
def plot_real_data(data):
def plot_data(data):
"""
Plot experimental data as heatmap with horizontal/vertical lines
representing slices on top.
......@@ -121,15 +121,15 @@ class PlotObserver:
"""
self.fig.clf()
real_data = fit_objective.experimentalData()
data = fit_objective.experimentalData()
simul_data = fit_objective.simulationResult()
# plot real data
plt.subplot(2, 2, 1)
self.plot_real_data(real_data)
self.plot_data(data)
# horizontal slices
slices = [("real", real_data.xProjection(alpha_slice_value)),
slices = [("real", data.xProjection(alpha_slice_value)),
("simul", simul_data.xProjection(alpha_slice_value))]
title = ("Horizontal slice at alpha =" +
'{:3.1f}'.format(alpha_slice_value))
......@@ -137,7 +137,7 @@ class PlotObserver:
self.plot_slices(slices, title)
# vertical slices
slices = [("real", real_data.yProjection(phi_slice_value)),
slices = [("real", data.yProjection(phi_slice_value)),
("simul", simul_data.yProjection(phi_slice_value))]
title = "Vertical slice at phi =" + '{:3.1f}'.format(
phi_slice_value)
......@@ -154,13 +154,13 @@ def run_fitting():
main function to run fitting
"""
real_data = create_real_data()
data = fake_data()
fit_objective = ba.FitObjective()
fit_objective.addSimulationAndData(get_masked_simulation, real_data, 1)
fit_objective.addSimulationAndData(get_masked_simulation, data, 1)
fit_objective.initPrint(10)
# creating custom observer which will draw fit progress
# creating custom observer which will draw fit progress
plotter = PlotObserver()
plt.close() # (hide plot) fit_objective.initPlot(10, plotter)
......
......@@ -28,7 +28,7 @@ def get_masked_simulation(P):
return simulation
def create_real_data():
def fake_data():
"""
Generating "real" data by adding noise to the simulated data.
"""
......@@ -57,7 +57,7 @@ class PlotObserver:
self.update(fit_objective)
@staticmethod
def plot_real_data(data):
def plot_data(data):
"""
Plot experimental data as heatmap with horizontal/vertical lines
representing slices on top.
......@@ -121,15 +121,15 @@ class PlotObserver:
"""
self.fig.clf()
real_data = fit_objective.experimentalData()
data = fit_objective.experimentalData()
simul_data = fit_objective.simulationResult()
# plot real data
plt.subplot(2, 2, 1)
self.plot_real_data(real_data)
self.plot_data(data)
# horizontal slices
slices = [("real", real_data.xProjection(alpha_slice_value)),
slices = [("real", data.xProjection(alpha_slice_value)),
("simul", simul_data.xProjection(alpha_slice_value))]
title = ("Horizontal slice at alpha =" +
'{:3.1f}'.format(alpha_slice_value))
......@@ -137,7 +137,7 @@ class PlotObserver:
self.plot_slices(slices, title)
# vertical slices
slices = [("real", real_data.yProjection(phi_slice_value)),
slices = [("real", data.yProjection(phi_slice_value)),
("simul", simul_data.yProjection(phi_slice_value))]
title = "Vertical slice at phi =" + '{:3.1f}'.format(
phi_slice_value)
......@@ -154,13 +154,13 @@ def run_fitting():
main function to run fitting
"""
real_data = create_real_data()
data = fake_data()
fit_objective = ba.FitObjective()
fit_objective.addSimulationAndData(get_masked_simulation, real_data, 1)
fit_objective.addSimulationAndData(get_masked_simulation, data, 1)
fit_objective.initPrint(10)
# creating custom observer which will draw fit progress
# creating custom observer which will draw fit progress
plotter = PlotObserver()
<%= sm ? "plt.close() # (hide plot) " :"" %>fit_objective.initPlot(10, plotter)
......
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