Skip to content

Commit

Permalink
raise exception if wavelength distribution of multiple dust data file…
Browse files Browse the repository at this point in the history
…s do not match
  • Loading branch information
mlietzow committed Aug 15, 2024
1 parent d60a60e commit 6a31a74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
10 changes: 7 additions & 3 deletions miex_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import streamlit as st


# Converter for lambda/n/k database files
def conv(line):
return line.replace("D", "e")
# Converter for lambda/n/k database files
return line.replace(b"D", b"e")


st.set_page_config(page_title="MIEX", page_icon=None)
Expand Down Expand Up @@ -79,7 +79,7 @@ def conv(line):
abun = np.array([1.0])
else:
st.info(
"all data files have to contain the refractive index and the same wavelength distribution"
"All data files have to contain the refractive index and the same wavelength distribution. See https://github.com/mlietzow/MIEX-Python/tree/main/ri-data for exemplary files."
)
with col1:
ncomp = st.number_input(
Expand Down Expand Up @@ -252,6 +252,10 @@ def conv(line):
st.stop()
else:
if nlam <= len(w):
if icomp > 0 and not np.array_equal(wavelength, w[:nlam]):
st.error("Wavelength distribution in dust data files do not match.")
st.stop()

wavelength = w[:nlam]
ri_real[icomp] = n[:nlam]
ri_imag[icomp] = k[:nlam]
Expand Down
9 changes: 5 additions & 4 deletions miex_notebook_2.ipynb

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions run_miex.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

def conv(line):
# Converter for lambda/n/k database files
return line.replace("D", "e")
return line.replace(b"D", b"e")


def main(input_filename):
Expand Down Expand Up @@ -166,12 +166,17 @@ def main(input_filename):
# read lambda/n/k database
for icomp in range(ncomp):
w, n, k = np.loadtxt(
"ri-data/" + fnames[icomp], comments="#", unpack=True, converters=conv
"ri-data/" + fnames[icomp],
comments="#",
unpack=True,
converters=conv,
)
if icomp > 0 and not np.array_equal(wavelength, w[:nlam]):
raise Exception("Wavelength distribution in dust data files do not match.")

wavelength = w[:nlam]
n_real[icomp] = n[:nlam]
k_imag[icomp] = k[:nlam]
# first two lines of file give information about the content of the file; no need to save in a variable

# define radial step width
radminlog = np.log10(radmin)
Expand Down

0 comments on commit 6a31a74

Please sign in to comment.