Skip to content

Commit

Permalink
Return ValueError for mismatched samples, UserWarning for missing dat…
Browse files Browse the repository at this point in the history
…a columns
  • Loading branch information
sarahshi committed Jul 10, 2024
1 parent a99f99e commit 8700333
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Test and publish to PyPI

on:
push:
branches: [ main ]
branches:
- main
- development
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main ]
branches:
- main
- development
release:
types: [ created ]

Expand Down Expand Up @@ -66,7 +70,8 @@ jobs:
python -m pip install --upgrade pip;
python -m pip install build
pip install setuptools wheel twine
python setup.py sdist bdist_wheel
python -m build
# python setup.py sdist bdist_wheel
- uses: actions/upload-artifact@v2
with:
name: dist
Expand Down
6 changes: 6 additions & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
Change Log
==========


Version 0.6.2
=============
Return ValueError for mismatched samples in peak height and composition DataFrames, UserWarning for missing data columns in composition DataFrame.


Version 0.6.1
=============
Update composition-dependent epsilon inversions to add Shi et al., 2024 values for H2Ot, 3550 and carbonate, slight correction. Correct data export paths in calculate_baselines and calculate_concentrations. Update PC vector creation.
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.1"
__version__ = "0.6.2"
65 changes: 47 additions & 18 deletions src/PyIRoGlass/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,41 @@ def load_chemistry_thickness(self):
chem_thickness = pd.read_csv(self.chemistry_thickness_path)
chem_thickness.set_index("Sample", inplace=True)

oxides = [
"SiO2",
"TiO2",
"Al2O3",
"Fe2O3",
"FeO",
"MnO",
"MgO",
"CaO",
"Na2O",
"K2O",
"P2O5",
]

thicknesses = [
"Thickness",
"Sigma_Thickness"
]

missing_columns = [col for col in oxides+thicknesses if col
not in chem_thickness.columns]
if missing_columns:
warnings.warn(f"Missing required columns: {missing_columns}. "
f"Column created and filled with NaN. "
f"Please correct the values.",
UserWarning,
stacklevel=2)
for col in missing_columns:
chem_thickness[col] = np.nan

chemistry = chem_thickness.loc[
:,
[
"SiO2",
"TiO2",
"Al2O3",
"Fe2O3",
"FeO",
"MnO",
"MgO",
"CaO",
"Na2O",
"K2O",
"P2O5",
],
oxides,
].fillna(0)
thickness = chem_thickness.loc[:, ["Thickness", "Sigma_Thickness"]]
thickness = chem_thickness.loc[:, thicknesses]

self.chemistry = chemistry
self.thickness = thickness
Expand Down Expand Up @@ -1281,8 +1299,8 @@ def calculate_epsilon(composition, T, P):
or glass composition dataset.
Parameters:
composition (dictionary): Dictionary containing the weight percentages
of each oxide in the glass composition
composition (pd.DataFrame): Dataframe containing oxide weight
percentages for the glass composition.
T (int): temperature at which the density is calculated (in Celsius)
P (int): pressure at which the density is calculated (in bars)
Expand Down Expand Up @@ -1416,8 +1434,8 @@ def calculate_concentrations(Volatile_PH, composition, thickness,
of total H2O (3550 cm^-1), molecular H2O (1635 cm^-1), and
carbonate peaks (1515 and 1430 cm^-1). Each row represents a
different sample.
composition (dictionary): Dictionary with keys as oxide names and
values as their weight percentages in the glass composition.
composition (pd.DataFrame): Dataframe containing oxide weight
percentages for the glass composition.
thickness (pd.DataFrame): DataFrame with "Thickness" column
indicating wafer thickness in micrometers (µm) for each sample.
N (int): Number of Monte Carlo simulations to perform for uncertainty
Expand All @@ -1442,6 +1460,17 @@ def calculate_concentrations(Volatile_PH, composition, thickness,
the accuracy of the results.
"""

# Check if sample names match between Volatile_PH and composition
Volatile_PH_samples = set(Volatile_PH.index)
composition_samples = set(composition.index)
mismatched_samples = Volatile_PH_samples.symmetric_difference(composition_samples)

if mismatched_samples:
raise ValueError(
f"Sample names in Volatile_PH and composition do not match. "
f"Mismatched samples: {mismatched_samples}"
)

if export_path is not None:

warnings.filterwarnings("ignore", category=DeprecationWarning)
Expand Down

0 comments on commit 8700333

Please sign in to comment.