From 261452c89748f5b3a3c5cebeb065a2606cac124f Mon Sep 17 00:00:00 2001 From: Marcin Kastek <37458996+MKastek@users.noreply.github.com> Date: Thu, 30 May 2024 16:33:19 +0200 Subject: [PATCH] improved tests --- README.md | 53 ++++++++++++++++++------------------- SimulatedLIBS/simulation.py | 2 -- tests/test_SimulatedLIBS.py | 6 +++++ 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index c53e7eb..169f55c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ pip install SimulatedLIBS ## Import ```python -from SimulatedLIBS import simulation +from SimulatedLIBS import SimulatedLIBS ``` ## Example Parameters: @@ -40,15 +40,15 @@ Parameters: ### Static websraping ```python -libs = simulation.SimulatedLIBS(Te=1.0, - Ne=10**17, - elements=['W','Fe','Mo'], - percentages=[50,25,25], - resolution=1000, - low_w=200, - upper_w=1000, - max_ion_charge=3, - webscraping='static') +libs = SimulatedLIBS(Te=1.0, + Ne=10**17, + elements=['W','Fe','Mo'], + percentages=[50,25,25], + resolution=1000, + low_w=200, + upper_w=1000, + max_ion_charge=3, + webscraping='static') ``` ### Plot @@ -75,15 +75,15 @@ libs.get_raw_spectrum() ``` ### Dynamic webscraping ```python -libs = simulation.SimulatedLIBS(Te=1.0, - Ne=10**17, - elements=['W','Fe','Mo'], - percentages=[50,25,25], - resolution=1000, - low_w=200, - upper_w=1000, - max_ion_charge=3, - webscraping='dynamic') +libs = SimulatedLIBS(Te=1.0, + Ne=10**17, + elements=['W','Fe','Mo'], + percentages=[50,25,25], + resolution=1000, + low_w=200, + upper_w=1000, + max_ion_charge=3, + webscraping='dynamic') ``` ### Plot @@ -102,7 +102,7 @@ libs.plot_ion_spectra() Based on .csv file with chemical composition of samples, one can generate dataset of simulated LIBS measurements with different Te and Ne values. -Example of input .csv file: +Example of input_composition_df pd.DataFrame: |W |H |He |name| |---|---|---|----| @@ -111,13 +111,12 @@ Example of input .csv file: |40 |40 |20 |C | ```python -simulation.SimulatedLIBS.create_dataset(input_csv_file="data.csv", - output_csv_file='output.csv', - size=100, - Te_min=1.0, - Te_max=2.0, - Ne_min=10**17, - Ne_max=10**18) +SimulatedLIBS.create_dataset(input_composition_df, + size=100, + Te_min=1.0, + Te_max=2.0, + Ne_min=10**17, + Ne_max=10**18) ``` Example of output .csv file: diff --git a/SimulatedLIBS/simulation.py b/SimulatedLIBS/simulation.py index 02fb1ed..e5cd200 100644 --- a/SimulatedLIBS/simulation.py +++ b/SimulatedLIBS/simulation.py @@ -295,7 +295,6 @@ def plot( plt.ylabel("Line Intensity [a.u.]") def plot_ion_spectra(self): - self.ion_spectra.drop(["Sum(calc)"], axis=1).plot( x="Wavelength (nm)", xlabel=r"$\lambda$ [nm]", @@ -413,7 +412,6 @@ def create_dataset( for spectra in spectra_pool: intensity = spectra.result()["spectrum"]["intensity"].values.tolist() - percentages = spectra.result()["composition"]["percentages"].values.tolist() intensity.extend(percentages) intensity.append(spectra.result()["name"]) diff --git a/tests/test_SimulatedLIBS.py b/tests/test_SimulatedLIBS.py index 1266c6a..d7304d7 100644 --- a/tests/test_SimulatedLIBS.py +++ b/tests/test_SimulatedLIBS.py @@ -35,6 +35,12 @@ def test_values(): def test_dataset(): input_df = pd.read_csv("data.csv") libs_df = SimulatedLIBS.create_dataset(input_df, size=1) + assert ( + input_df[ + input_df["name"] == libs_df.iloc[:, -6:-2]["name"].iloc[0] + ].values.tolist()[0] + == libs_df.iloc[:, -6:-2].iloc[0].values.tolist() + ) assert libs_df.iloc[:, :-6].max().max() > 0 if os.path.exists("out_put.csv"): os.remove("out_put.csv")