{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Useful FTIR Functions for Density and Molar Absorptivity\n", "\n", "- This Jupyter notebook demonstrates the use of useful Python functions for calculating density and molar absorptivity. \n", "\n", "- The Jupyter notebook and data can be accessed here: https://github.com/SarahShi/PyIRoGlass/blob/main/docs/examples/ftir_functions/. \n", "\n", "- You need to have the PyIRoGlass PyPi package on your machine once. If you have not done this, please uncomment (remove the #) symbol and run the cell below. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#!pip install PyIRoGlass" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Load Python Packages and Data" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load Python Packages" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Import packages\n", "\n", "import PyIRoGlass as pig\n", "\n", "%matplotlib inline\n", "%config InlineBackend.figure_format = 'retina'\n", "\n", "pig.__version__" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Set paths to data\n", "\n", "Update the path to the chemistry and thickness data." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "chemistry_thickness_path = 'ChemThick.csv'\n", "print(chemistry_thickness_path)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load chemistry and thickness data\n", "\n", "We will use the class `pig.SampleDataLoader` to load all FTIR spectra and chemistry and thickness data. The class takes the arguments: \n", "\n", "- `spectrum_path`: String or list path to the directory with spectral data\n", "- `chemistry_thickness_path`: String path to CSV file with glass chemistry and thickness data\n", "\n", "and contains the methods: \n", "\n", "- `load_spectrum_directory`: Loads spectral data\n", "- `load_chemistry_thickness`: Loads chemistry and thickness data\n", "- `load_all_data`: Loads spectral and chemistry and thickness data\n", "\n", "Here, we use `load_chemistry_thickness`. This returns the outputs of: \n", "\n", "- `chemistry`: DataFrame of chemical data\n", "- `thickness`: DataFrame of thickness data\n", "\n", "The file names from the spectra (what comes before the .CSV) are important when we load in melt compositions and thicknesses. Unique identifiers identify the same samples. Make sure that this `ChemThick.CSV` file has the same sample names as the loaded spectra." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "loader = pig.SampleDataLoader(chemistry_thickness_path=chemistry_thickness_path)\n", "chemistry, thickness = loader.load_chemistry_thickness()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display `chemistry`, the DataFrame of glass compositions." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "chemistry" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We're ready to use the `pig.calculate_density` function now. We input the arguments: \n", "\n", "- `chemistry`: DataFrame of chemical data\n", "- `T`: Room temperature at time of FTIR analysis, given the sensitivity of density to temperature\n", "- `P`: Room pressure at time of FTIR analysis, given the sensitivity of density to pressure\n", "- `model`: Density model; default is `\"LS\"` for Lesher and Spera (2015), alternative is `\"IT\"` for Iacovino and Till (2019)\n", "\n", "and output: \n", "\n", "- `mol`: DataFrame containing oxide mole fraction for glass composition\n", "- `density`: DataFrame of glass density at the given room temperature and pressure during FTIR analysis" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "T = 25 # C\n", "P = 1 # Bar\n", "mol, density = pig.calculate_density(chemistry, T, P, model=\"LS\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display `mol`, the DataFrame of oxide mole fractions for the given glass composition." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mol" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display `density`, the DataFrame of glass density at given room temperature and pressure during FTIR analysis." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "density" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're ready to use the `pig.calculate_epsilon` function now. We input the arguments: \n", "\n", "- `chemistry`: DataFrame of chemical data\n", "- `T`: Room temperature at time of FTIR analysis, given the sensitivity of density to temperature. \n", "- `P`: Room pressure at time of FTIR analysis, given the sensitivity of density to pressure. \n", "\n", "and output: \n", "\n", "- `epsilon`: DataFrame of molar absorptivities with their uncertainties.\n", "\n", "Note that a `UserWarning` is returned if your compositions lie outside the calibration ranges for `Tau` or `Eta` and `Epsilon`. Use these molar absorptivities with caution. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "T = 25 # C\n", "P = 1 # Bar\n", "epsilon = pig.calculate_epsilon(chemistry, T, P)\n", "epsilon" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "There are a few things to note. `Tau` references the $\\mathrm{(Si^{4+}+Al^{3+})/Total \\, Cations}$ value and `Eta` references the $\\mathrm{(Na^{+}/(Na^{+}+Ca^{2+}))}$ value. Each column with the prefix `Epsilon` represents the mean molar absorptivity, `Sigma_Epsilon` represents the uncertainty on the molar absorptivity. " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" } }, "nbformat": 4, "nbformat_minor": 4 }