Skip to content

Commit

Permalink
Update docs and create new unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahshi committed Feb 27, 2024
1 parent 72d8df1 commit 98bfdfb
Show file tree
Hide file tree
Showing 37 changed files with 2,476 additions and 1,261 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,24 @@ Baseline_Comparison/nd70_statistics.csv
Baseline_Comparison/ND70Spec.zip
Baseline_Comparison/Comparison_Standards.csv
Baseline_Comparison/CComparison_Standards.csv
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL49_021920_30x30_H2O_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL53_101220_256s_30x30_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/STD_D1010_012821_256s_100x100_a.log
docs/examples/transmission_ftir/NPZTXTFILES/RESULTS/AC4_OL49_021920_30x30_H2O_a_statistics.txt
docs/examples/transmission_ftir/NPZTXTFILES/RESULTS/AC4_OL53_101220_256s_30x30_a_statistics.txt
docs/examples/transmission_ftir/NPZTXTFILES/RESULTS/STD_D1010_012821_256s_100x100_a_statistics.txt
docs/examples/transmission_ftir/PKLFILES/RESULTS/AC4_OL49_021920_30x30_H2O_a.pkl
docs/examples/transmission_ftir/PKLFILES/RESULTS/STD_D1010_012821_256s_100x100_a.pkl
docs/examples/transmission_ftir/PLOTFILES/RESULTS/HISTOGRAM/AC4_OL53_101220_256s_30x30_a_histogram.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/HISTOGRAM/STD_D1010_012821_256s_100x100_a_histogram.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/MODELFIT/AC4_OL53_101220_256s_30x30_a_modelfit.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/MODELFIT/STD_D1010_012821_256s_100x100_a_modelfit.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/PAIRWISE/AC4_OL53_101220_256s_30x30_a_pairwise.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/PAIRWISE/STD_D1010_012821_256s_100x100_a_pairwise.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/TRACE/AC4_OL53_101220_256s_30x30_a_trace.pdf
docs/examples/transmission_ftir/PLOTFILES/RESULTS/TRACE/STD_D1010_012821_256s_100x100_a_trace.pdf
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL49_021920_30x30_H2O_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL53_101220_256s_30x30_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL49_021920_30x30_H2O_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/AC4_OL53_101220_256s_30x30_a.log
docs/examples/transmission_ftir/LOGFILES/RESULTS/STD_D1010_012821_256s_100x100_a.log
1,191 changes: 635 additions & 556 deletions LICENSE.txt

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions UnitTests/test_density_epsilon.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ def setUp(self):

def test_density_calculation(self):

mol, density = pig.calculate_density(self.MI_Composition, self.T_room, self.P_room)
result = float(density.values)
expected = 2702.703558
_, density_ls = pig.calculate_density(self.MI_Composition, self.T_room, self.P_room, model='LS')
result_ls = float(density_ls.values)
expected_ls = 2702.703558
self.assertAlmostEqual(
result,
expected,
result_ls,
expected_ls,
self.decimalPlace,
msg="Density test and expected values from the "
"calculate_density function do not agree")
"calculate_density function with LS do not agree")

_, density_it = pig.calculate_density(self.MI_Composition, self.T_room, self.P_room, model='IT')
result_it = float(density_it.values)
expected_it = 2750.959065
self.assertAlmostEqual(
result_it,
expected_it,
self.decimalPlace,
msg="Density test and expected values from the "
"calculate_density function with IT do not agree")

def test_epsilon_calculation(self):

Expand Down
59 changes: 56 additions & 3 deletions UnitTests/test_fittingfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def test_NIR(self):
msg="H2Om5200 peak height test and expected values from the "
"NearIR_Process function do not agree")

def test_NIR_invalid_peak_type(self):

valid_data = next(iter(self.dfs_dict.values()))
invalid_peak_type = "InvalidPeakType" # Intentionally invalid peak type

with self.assertRaises(ValueError) as context:
pig.NIR_process(valid_data, 4875, 5400, invalid_peak_type)

self.assertTrue(f"Invalid peak type: {invalid_peak_type}"
in str(context.exception))

def test_MIR(self):

for _, data in self.dfs_dict.items():
Expand Down Expand Up @@ -112,21 +123,63 @@ def test_MCMC(self):
expected_H2Om_5200,
self.decimalPlace,
msg="H2Om_5200 peak height test and expected values from the "
"Run_All_Spectra function do not agree")
"calculate_baselines function do not agree")

self.assertAlmostEqual(
result_H2Ot_3550,
expected_H2Ot_3550,
self.decimalPlace,
msg="H2Ot_3550 peak height test and expected values from the "
"calculate_baselines function do not agree")

self.assertAlmostEqual(
result_CO2_1515,
expected_CO2_1515,
self.decimalPlace - 3,
msg="CO2_1515 peak height test and expected values from the "
"calculate_baselines function do not agree")

def test_MCMC_interp(self):

first_index = self.df.index > 1000
if any(first_index):
first_index_position = np.argmax(first_index)
drop_indices = self.df.index[first_index_position + 1:first_index_position + 11]
self.df_interp = self.df.drop(drop_indices)

self.dfs_dict_interp = {self.file: self.df_interp}

Volatiles_DF, _ = pig.calculate_baselines(self.dfs_dict_interp, None)

result_H2Om_5200 = float(Volatiles_DF['PH_5200_M'].iloc[0])
expected_H2Om_5200 = 0.00895907201720743

result_H2Ot_3550 = float(Volatiles_DF['PH_3550_M'].iloc[0])
expected_H2Ot_3550 = 1.52334293070956

result_CO2_1515 = float(Volatiles_DF['PH_1515_BP'].iloc[0])
expected_CO2_1515 = 0.057289618537916066

self.assertAlmostEqual(
result_H2Om_5200,
expected_H2Om_5200,
self.decimalPlace,
msg="H2Om_5200 peak height test and expected values from the "
"calculate_baselines function do not agree")

self.assertAlmostEqual(
result_H2Ot_3550,
expected_H2Ot_3550,
self.decimalPlace,
msg="H2Ot_3550 peak height test and expected values from the "
"Run_All_Spectra function do not agree")
"calculate_baselines function do not agree")

self.assertAlmostEqual(
result_CO2_1515,
expected_CO2_1515,
self.decimalPlace - 3,
msg="CO2_1515 peak height test and expected values from the "
"Run_All_Spectra function do not agree")
"calculate_baselines function do not agree")

def test_MCMC_exportpath(self):

Expand Down
19 changes: 19 additions & 0 deletions UnitTests/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ def test_load_dir_chemthick(self):
self.assertEqual(chemistry.shape, (9, 11))
self.assertEqual(thickness.shape, (9, 2))

def test_spectrum_path_none(self):
with self.assertRaises(ValueError):
loader = pig.SampleDataLoader(spectrum_path=None)
loader.load_spectrum_directory()

def test_chemistry_thickness_path_none(self):
with self.assertRaises(ValueError):
loader = pig.SampleDataLoader(chemistry_thickness_path=None)
loader.load_chemistry_thickness()

def test_invalid_csv_format(self):
# Assuming you have an invalid CSV file for this test
invalid_csv_path = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'path/to/your/invalid_csv_file.csv'
)
with self.assertRaises(ValueError):
loader = pig.SampleDataLoader(spectrum_path=invalid_csv_path)
loader.load_spectrum_directory()

if __name__ == '__main__':
unittest.main()
44 changes: 39 additions & 5 deletions UnitTests/test_plotting.py

Large diffs are not rendered by default.

99 changes: 66 additions & 33 deletions UnitTests/test_thickness.py

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions docs/examples/transmission_ftir/DF.csv

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/examples/transmission_ftir/FINALDATA/DF.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
,PH_3550_M,PH_3550_STD,H2Ot_3550_MAX,BL_H2Ot_3550_MAX,H2Ot_3550_SAT,PH_1635_BP,PH_1635_STD,PH_1515_BP,PH_1515_STD,P_1515_BP,P_1515_STD,STD_1515_BP,STD_1515_STD,PH_1430_BP,PH_1430_STD,P_1430_BP,P_1430_STD,STD_1430_BP,STD_1430_STD,PH_5200_M,PH_5200_STD,PH_4500_M,PH_4500_STD,STN_P5200,ERR_5200,STN_P4500,ERR_4500,AVG_BL_BP,AVG_BL_STD,PC1_BP,PC1_STD,PC2_BP,PC2_STD,PC3_BP,PC3_STD,PC4_BP,PC4_STD,m_BP,m_STD,b_BP,b_STD,PH_1635_PC1_BP,PH_1635_PC1_STD,PH_1635_PC2_BP,PH_1635_PC2_STD
AC4_OL49_021920_30x30_H2O_a,2.1722500209939493,0.0022116149510955836,2.649837,0.4598586208562721,*,0.6583491880184121,0.0030749126402198697,0.10686432559386666,0.003617684246677255,1517.474274372431,1.5182396123926605,35.611038435771576,1.9426494612507434,0.10942913704159829,0.003998298365950207,1427.9922206706017,1.4193664333281357,28.85332005352919,1.2055094429028048,0.024909186694699683,0.0008013162213433842,0.014570093124893511,6.460708464050103e-05,12.195762674599015,-,8.157689580452923,-,1.1040470270583682,0.037503998964593735,-1.0504933455802845,0.3994585233071356,0.9376266092174402,0.019781423344117303,-0.09340636256800676,0.06045770843644922,0.29999999999999993,0.023016725028572844,-0.0003100922174198882,6.76489938725298e-05,1.2338252968133392,0.021301724598351394,0.11213209405817827,0.016193177122467085,0.044745957015674034,0.020451733221300252
AC4_OL53_101220_256s_30x30_a,1.5233426827103218,0.0033092236185633846,1.631044,0.13554145039853702,-,0.29967506964819424,0.003062210614512881,0.05305994287064932,0.0036758392931568545,1519.2334635768602,2.8066057091459924,32.414304746275114,2.784238916959108,0.05024321853406153,0.004285715724583188,1427.2586532478908,3.1130943263832966,34.35120889642723,2.8233542411080745,0.008958906735709577,0.0004449140364037349,0.012517606386667756,0.00032036233298576015,6.90402676330999,-,5.527669572279575,-,0.511735256281459,0.043875233805488495,-2.963278565535986,0.4487172333197129,0.27570771325870513,0.020432535023846985,-0.5066370203992294,0.06132111604875771,0.22624896917334789,0.04227109362475997,-0.00044487318729776154,7.645869090603355e-05,0.7212552944882438,0.02301693318373148,-0.052546462541862994,0.01639656977793004,0.046798062360385494,0.017608365106921108
STD_D1010_012821_256s_100x100_a,2.7108938068234614,0.0015870027387259998,2.915508,0.20664130261763228,*,0.17348651543140622,0.003056241542456818,0.07555997483046767,0.0033492756922561748,1522.9753584005089,2.39819240541948,35.370538256455376,2.4311378337852196,0.06757826142692784,0.004063170725884987,1431.4522834178945,2.293519583887849,31.066664742008154,2.4400999678819013,0.008596527707852878,0.00012849123724541835,0.018646773532606183,0.0003276983762892409,12.116667428210414,-,13.264652936348938,-,3.9999999999999996,0.006223452071132112,0.761701691291354,0.10161089931202222,-0.44300286478842543,0.019334750691436323,-0.37899896502503055,0.02716550018552502,0.17861839731787293,0.023738484937729454,-0.00023214668050949028,1.4671822466810936e-05,2.4623525441636516,0.006594444676255823,0.07665825504300086,0.01647606902504966,-0.027976898391759562,0.021748326300020524
4 changes: 4 additions & 0 deletions docs/examples/transmission_ftir/FINALDATA/H2OCO2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
,H2Ot_MEAN,H2Ot_STD,H2Ot_3550_M,H2Ot_3550_STD,H2Ot_3550_SAT,H2Om_1635_BP,H2Om_1635_STD,CO2_MEAN,CO2_STD,CO2_1515_BP,CO2_1515_STD,CO2_1430_BP,CO2_1430_STD,H2Om_5200_M,H2Om_5200_STD,OH_4500_M,OH_4500_STD,PH_5200_STN,ERR_5200,PH_4500_STN,ERR_4500,Density,Density_Sat,Tau,Eta,epsilon_H2Ot_3550,sigma_epsilon_H2Ot_3550,epsilon_H2Om_1635,sigma_epsilon_H2Om_1635,epsilon_CO2,sigma_epsilon_CO2,epsilon_H2Om_5200,sigma_epsilon_H2Om_5200,epsilon_OH_4500,sigma_epsilon_OH_4500
AC4_OL49_021920_30x30_H2O_a,2.5439299152226322,0.16074153519987022,2.421720703313204,0.1898497089387326,*,1.3001072020452495,0.18973770039057375,748.7150728480483,36.86296041163745,740.746431155663,50.96691096280393,758.5248143152104,53.304705321880185,1.8186979013958553,0.3503436272858915,1.2469504909955509,0.25981952600301483,12.195762674599015,-,8.157689580452923,-,2681.9628385342203,2678.669397675602,0.7059903032671602,,66.11116080287024,7.524312502968801,37.32210817976659,8.645058408560972,259.75418947786505,19.25788234453022,1.0094574306540989,0.3008237891400822,0.8611962780779154,0.2795414046836688
AC4_OL53_101220_256s_30x30_a,4.038926750147803,0.4329778857990654,4.038926750147803,0.4329778857990654,-,1.4866476286944408,0.25712304172380684,727.6581699782867,61.169513420349816,747.4989226544318,84.94476407660733,707.8174173021414,88.04103897784796,1.698555731286261,0.3927119226483464,2.744234853836663,0.6701353551484185,6.90402676330999,-,5.527669572279575,-,2702.703564503572,2702.703564503572,0.6828948534384355,,64.46286878053799,7.401239521051048,34.452486205577344,8.504267139737374,296.3770385011226,17.091250588327085,0.9014740083073014,0.295851133072247,0.7796110934580489,0.2748942822302944
STD_D1010_012821_256s_100x100_a,0.9042708707728374,0.09700172482486706,1.2019858961960292,0.08831258244944437,*,0.15354829136765832,0.025439049432648915,154.4793817143202,7.22022065767248,162.57157814343182,9.763315053653848,145.39846834272782,10.569338351866723,0.3036153792808971,0.07283603511320189,0.7478287694979827,0.19139654049405352,12.116667428210414,-,13.264652936348938,-,2795.316980458168,2804.2911559980203,0.6585005613973197,,62.72188008969184,7.272084174154002,31.421482392916758,8.35434699872907,315.7646211973788,15.879741615329216,0.7874178128288873,0.29053392101418585,0.6934377201483826,0.2699749007943789
4 changes: 0 additions & 4 deletions docs/examples/transmission_ftir/H2OCO2.csv

This file was deleted.

Loading

0 comments on commit 98bfdfb

Please sign in to comment.