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