From a098505de56fee77e6179aa6c4e1714422bcc51e Mon Sep 17 00:00:00 2001 From: mlietzow Date: Mon, 26 Aug 2024 15:08:19 +0200 Subject: [PATCH] do not mix for single composition --- miex_app.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/miex_app.py b/miex_app.py index 935a19f..eb61169 100644 --- a/miex_app.py +++ b/miex_app.py @@ -312,11 +312,6 @@ def interp1d_log(xx, yy, kind="linear", fill_value=np.nan): log_interp = lambda zz: np.power(10.0, lin_interp(np.log10(zz))) return log_interp - - with placeholder.container(): - progress_text = "Mixing materials ..." - progress_bar = st.progress(0, text=progress_text) - eps_comp = np.zeros((ncomp, nlam), dtype=complex) # read lambda/n/k database for icomp in range(ncomp): @@ -344,18 +339,25 @@ def interp1d_log(xx, yy, kind="linear", fill_value=np.nan): ) eps_comp[icomp] = (real_interp(wavelength) + 1j * imag_interp(wavelength))**2 - from mpmath import findroot - eps_mean = np.zeros(nlam, dtype=complex) - counter = 0 - for ilam in range(nlam): - def bruggeman_mix(x): - return np.sum(abun * ((eps_comp[:,ilam] - x) / (eps_comp[:,ilam] + 2 * x))) + if ncomp > 1: + with placeholder.container(): + progress_text = "Mixing materials ..." + progress_bar = st.progress(0, text=progress_text) - counter += 1 - if int(counter % (nlam / 10)) == 0: - progress_bar.progress(int(counter / nlam * 100), text=progress_text) + from mpmath import findroot + eps_mean = np.zeros(nlam, dtype=complex) + counter = 0 + for ilam in range(nlam): + def bruggeman_mix(x): + return np.sum(abun * ((eps_comp[:,ilam] - x) / (eps_comp[:,ilam] + 2 * x))) + + counter += 1 + if int(counter % (nlam / 10)) == 0: + progress_bar.progress(int(counter / nlam * 100), text=progress_text) - eps_mean[ilam] = complex(findroot(bruggeman_mix, complex(1.0, 0.1))) + eps_mean[ilam] = complex(findroot(bruggeman_mix, complex(1.0, 0.1))) + else: + eps_mean = eps_comp[0] ri_real = np.real(np.sqrt(eps_mean)) ri_imag = np.imag(np.sqrt(eps_mean))