Skip to content

Commit

Permalink
Return UserWarning for compositions outside of the epsilon calibratio…
Browse files Browse the repository at this point in the history
…n ranges, UserWarning for when data do not span the full wavenumber range
  • Loading branch information
sarahshi committed Jul 12, 2024
1 parent bed2fb4 commit 5ccb635
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
7 changes: 6 additions & 1 deletion docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ Change Log
==========


Version 0.6.3
=============
Return UserWarning for compositions outside of the calibration ranges for the epsilon absorption coefficients in function calculate_concentrations and calculate_epsilon, UserWarning for when data do not span the full wavenumber range of 1000-5500 cm^-1 whilst using class SampleDataLoader. Thanks to Dr. Shuo Ding and Emilia Pelegano-Titmuss for identifying common errors during test usage, which contributed to these improvements.


Version 0.6.2
=============
Return ValueError for mismatched samples in peak height and composition DataFrames, UserWarning for missing data columns in composition DataFrame.
Return ValueError for mismatched samples in peak height and composition DataFrames in function calculate_concentrations, UserWarning for missing data columns in composition DataFrame in class SampleDataLoader. Thanks to Dr. Shuo Ding for identifying common errors during test usage, which contributed to these improvements.


Version 0.6.1
Expand Down
2 changes: 1 addition & 1 deletion src/PyIRoGlass/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# 1) we don't load dependencies by storing it in __init__.py
# 2) we can import it in setup.py for the same reason
# 3) we can import it into your module
__version__ = "0.6.2"
__version__ = "0.6.3"
51 changes: 51 additions & 0 deletions src/PyIRoGlass/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def load_spectrum_directory(self, wn_high=5500, wn_low=1000):
df = df.iloc[::-1]
df.set_index("Wavenumber", inplace=True)
spectrum = df.loc[wn_low:wn_high]
if wn_low == 1000 and wn_high == 5500:
if not (spectrum.index.min() <= wn_low and
spectrum.index.max() >= wn_high):
warnings.warn(f"{file} data do not span the required "
f"wavenumbers of 1000-5500 cm^-1.",
UserWarning,
stacklevel=2)
dfs.append(spectrum)
files.append(file)

Expand Down Expand Up @@ -692,6 +699,7 @@ def calculate_baselines(dfs_dict, export_path):
indparams = [wavenumber, PCmatrix, H2Om1635_PCmatrix, Nvectors]

full_path = os.path.join(os.getcwd(), "FINALDATA")
file_name = "DF.csv" if export_path is None else f"{export_path}_DF.csv"

# Create DataFrames to store peak height data:
# P_ = peak_, _BP = best parameter, #_STD = _stdev
Expand Down Expand Up @@ -1354,6 +1362,15 @@ def calculate_epsilon(composition, T, P):
covz_error_SiAl = np.zeros((2, 2))
covz_error_NaCa = np.zeros((2, 2))

# Define calibration ranges
tau_ranges = {
"epsilon_H2Om_5200": (0.6, 0.8641748075261225),
"epsilon_OH_4500": (0.6, 0.8641748075261225),
"epsilon_H2Ot_3550": (0.5078379123837519, 0.9023427189457927),
"epsilon_H2Om_1635": (0.627337511542476, 0.86)
}
eta_range = (0.23157895182099122, 0.8406489374848108)

# Loop through and calculate for all MI or glass compositions.
for i in composition.index:
# Calculate extinction coefficients with best-fit parameters
Expand Down Expand Up @@ -1412,6 +1429,40 @@ def calculate_epsilon(composition, T, P):
}
)

# Check whether Tau and Eta are in calibration ranges, warn if not
# Same ranges for epsilon_H2Om_5200 and epsilon_OH_4500, simplify
if not (tau_ranges["epsilon_H2Om_5200"][0]
<= SiAl_tot[i] <= tau_ranges["epsilon_H2Om_5200"][1]):
warnings.warn(f"Tau ({round(SiAl_tot[i], 4)}) for {i} "
f"is outside the calibration range for "
f"epsilon_H2Om_5200 and epsilon_OH_4500. "
f"Use caution.",
UserWarning,
stacklevel=2)

if not (tau_ranges["epsilon_H2Ot_3550"][0]
<= SiAl_tot[i] <= tau_ranges["epsilon_H2Ot_3550"][1]):
warnings.warn(f"Tau ({round(SiAl_tot[i], 4)}) for {i} "
f"is outside the calibration range for "
f"epsilon_H2Ot_3550. Use caution.",
UserWarning,
stacklevel=2)

if not (tau_ranges["epsilon_H2Om_1635"][0]
<= SiAl_tot[i] <= tau_ranges["epsilon_H2Om_1635"][1]):
warnings.warn(f"Tau ({round(SiAl_tot[i], 4)}) for {i} "
f"is outside the calibration range for "
f"epsilon_H2Om_1635. Use caution.",
UserWarning,
stacklevel=2)

if not (eta_range[0] <= Na_NaCa[i] <= eta_range[1]):
warnings.warn(f"Eta ({round(Na_NaCa[i], 4)}) for {i} "
f"is outside the calibration range for "
f"epsilon_CO2. Use caution.",
UserWarning,
stacklevel=2)

return epsilon


Expand Down

0 comments on commit 5ccb635

Please sign in to comment.