Skip to content

Commit

Permalink
More UnitTesting
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahshi committed Feb 27, 2024
1 parent 29e6855 commit 046d344
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 10 additions & 2 deletions UnitTests/test_thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,20 @@ def test_process_thickness(self):
remove_baseline=False,
plotting=False,
phaseol=True)

thickness_results_gl = pig.calculate_mean_thickness(
self.dfs_dict,
1.546,
self.wn_high_gl,
self.wn_low_gl,
remove_baseline=False,
plotting=False,
phaseol=True)
phaseol=False)

result_ol = float(thickness_results_ol['Thickness_M'].iloc[0])
expected_ol = 79.81
result_gl = float(thickness_results_gl['Thickness_M'].iloc[0])
expected_gl = 88.34
expected_gl = 8.83
self.assertAlmostEqual(
result_ol,
expected_ol,
Expand All @@ -103,6 +105,7 @@ def test_process_thickness(self):
2,
msg="Glass thickness test and expected values from "
"calculate_mean_thickness function disagree")

if thickness_results_ol.isnull().any().any():
self.assertTrue(thickness_results_ol.isnull().any().any(),
"Expected NaN values in the result due to processing failures.")
Expand All @@ -120,5 +123,10 @@ def test_process_thickness(self):
except Exception as e:
self.fail(f"Unexpected exception occurred: {e}")

def test_invalid_wavenumber_range(self):

with self.assertRaises(ValueError):
pig.calculate_mean_thickness(self.dfs_dict, 1.546, self.wn_high_gl, self.wn_low_gl)

if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"sys.path.append('../../../src/')\n",
"import PyIRoGlass as pig\n",
"\n",
"from IPython.display import Image\n",
Expand Down
2 changes: 1 addition & 1 deletion src/PyIRoGlass/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def NIR_process(data, wn_low, wn_high, peak):
PH_krige_index = int(
data_output["Peak_Subtract"][
data_output["Peak_Subtract"] == PH_max
].index.to_numpy()
].index.to_numpy()[0]
)
PH_std = (
data_output["Peak_Subtract"]
Expand Down
12 changes: 6 additions & 6 deletions src/PyIRoGlass/thickness.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ def calculate_mean_thickness(dfs_dict, n, wn_high, wn_low,

ThickDF = pd.DataFrame(
columns=[
'Thickness_M',
'Thickness_STD',
'Peak_Thicknesses',
'Peak_Thickness_M',
'Peak_Thickness_STD',
'Trough_Thicknesses',
'Trough_Thickness_M',
'Trough_Thickness_STD',
'Thickness_M',
'Thickness_STD'
'Trough_Thickness_STD'
]
)

Expand Down Expand Up @@ -363,6 +363,8 @@ def calculate_mean_thickness(dfs_dict, n, wn_high, wn_low,
).round(2)

ThickDF.loc[f"{filename}"] = pd.Series({
'Thickness_M': mean_t,
'Thickness_STD': std_t,
'Peak_Thicknesses': t_peaks_filt,
'Peak_Thickness_M': mean_t_peaks_filt,
'Peak_Thickness_STD': std_t_peaks_filt,
Expand All @@ -372,9 +374,7 @@ def calculate_mean_thickness(dfs_dict, n, wn_high, wn_low,
'Trough_Thickness_M': mean_t_troughs_filt,
'Trough_Thickness_STD': std_t_troughs_filt,
'Trough_Loc': troughs_loc_filt,
'Trough_Diff': troughs_diff_filt,
'Thickness_M': mean_t,
'Thickness_STD': std_t
'Trough_Diff': troughs_diff_filt
})

except Exception as e:
Expand Down

0 comments on commit 046d344

Please sign in to comment.