Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarJMue committed Aug 22, 2024
1 parent bd330c6 commit 2f525a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 0 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ sphinx-plotly-directive
sphinxcontrib-mermaid
matplotlib
h5py
importlib-resources
h5py
pyyaml
importlib-resources
rapidfuzz
Expand Down
11 changes: 5 additions & 6 deletions examples/gallery/plot_03_custom_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
# %%
# Data import
# -----------
# %%
data = elli.read_nexus_psi_delta("SiO2onSi.ellips.nxs").loc[
(slice(None), slice(210, 800)), :
]
Expand All @@ -31,7 +30,6 @@
# %%
# Setting up invariant materials and fitting parameters
# -----------------------------------------------------
# %%
rii_db = elli.db.RII()
Si = rii_db.get_mat("Si", "Aspnes")

Expand All @@ -49,7 +47,6 @@
# Model helper function
# ---------------------
# This model function is not strictly needed, but simplifies the fit function, as the model only needs to be defined once.
# %%
def model(lbda, angle, params):
SiO2 = elli.Cauchy(
params["SiO2_n0"],
Expand All @@ -74,7 +71,8 @@ def model(lbda, angle, params):
# -------------------------
# The fit function follows the protocol defined by the lmfit package and needs the parameters dictionary as first argument.
# It has to return a residual value, which will be minimized. Here psi and delta are used to calculate the residual, but could be changed to transmission or reflection data.
# %%


def fit_function(params, lbda, data):
residual = []

Expand All @@ -95,13 +93,14 @@ def fit_function(params, lbda, data):
# ---------------
# The fitting is performed by calling the minimize function with the fit_function and the needed arguments.
# It is possible to change the underlying algorithm by providing the method kwarg.
# %%

out = minimize(fit_function, params, args=(lbda, data), method="leastsq")
print(fit_report(out))

# %%
# Plotting the results
# ----------------------------------------------
# %%

fit_50 = model(lbda, 50, out.params)
fit_60 = model(lbda, 60, out.params)
fit_70 = model(lbda, 70, out.params)
Expand Down

0 comments on commit 2f525a6

Please sign in to comment.