Skip to content

Commit

Permalink
improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MKastek committed May 30, 2024
1 parent 5181855 commit 261452c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pip install SimulatedLIBS
## Import

```python
from SimulatedLIBS import simulation
from SimulatedLIBS import SimulatedLIBS
```
## Example
Parameters:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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|
|---|---|---|----|
Expand All @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions SimulatedLIBS/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down Expand Up @@ -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"])
Expand Down
6 changes: 6 additions & 0 deletions tests/test_SimulatedLIBS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 261452c

Please sign in to comment.