{ "cells": [ { "cell_type": "markdown", "id": "673fe77c-ddf2-4ed7-acf5-5ace55bc2408", "metadata": {}, "source": [ "# Map SPECIATE species to CRACMM\n", "\n", "---\n", " author: Nash Skipper\n", " date: 2024-08-09\n", "\n", " updated: Michael Pye\n", " date: 2025-02-27\n", "---\n", "\n", "## Notebook Description\n", "This notebook identifies the CRACMM species for each SPECIATE species using the mapper. The cracmm_mapper function depends on [rdkit](https://www.rdkit.org/).\n", "\n", "## Download Notebook\n", "Click [here](https://github.com/USEPA/CRACMM/blob/main/utilities/SPECIATE_map2cracmm.ipynb) to access the Jupyter Notebook file directly in GitHub where it can be downloaded. " ] }, { "cell_type": "markdown", "id": "7c57651a-9587-441e-b71e-967dfc77fd48", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "execution_count": null, "id": "a65b1911-c6f4-4000-8ce9-b3ee223045de", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import warnings\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "id": "a49350b5-da68-446a-af87-07ca7f166464", "metadata": {}, "outputs": [], "source": [ "## Install rdkit if not already installed\n", "\n", "# !python -m pip install --user rdkit\n", "\n", "# to install in the current kernel:\n", "# %pip install rdkit" ] }, { "cell_type": "code", "execution_count": null, "id": "cfa001a4-8cef-4235-8c04-6729e0856b06", "metadata": {}, "outputs": [], "source": [ "# set location of mapper downloaded from https://github.com/USEPA/CRACMM/\n", "# import sys\n", "# utildir = '/path/to/cracmm/utilities/directory' \n", "# sys.path.append(utildir)\n", "\n", "# Import the python utilities\n", "import cracmm1_mapper as cracmm1 # includes: get_cracmm_roc(smiles,koh,log10cstar) (Version 1)\n", "import cracmm2_mapper as cracmm2 # includes: get_cracmm_roc(smiles,koh,log10cstar) (Version 2)" ] }, { "cell_type": "code", "execution_count": null, "id": "df86d78d-fb71-4b0a-af22-6bc0666e3d90", "metadata": {}, "outputs": [], "source": [ "datadir = '../emissions/SPECIATEInputs/' # data files of mappings\n", "\n", "outputdir = os.path.join(os.getcwd(), 'output/')" ] }, { "cell_type": "code", "execution_count": 5, "id": "45da1ab2-b614-4370-a961-d06d7c2ec4e3", "metadata": {}, "outputs": [], "source": [ "pd.set_option('display.max_rows', None)\n", "pd.options.mode.copy_on_write = True\n", "warnings.simplefilter('ignore') # ignore warnings (comment out to see warnings for species that could not be mapped)\n", "csvout_kw = dict(sep=',', na_rep='', float_format=None, columns=None, header=True, index=False)" ] }, { "cell_type": "markdown", "id": "fbd43488-a11a-4550-8070-ea244ebe82b5", "metadata": {}, "source": [ "## SPECIATE Mapping\n", "\n", "[Input SPECIATE file](https://github.com/USEPA/CRACMM/tree/main/emissions/SPECIATEInputs)" ] }, { "cell_type": "code", "execution_count": null, "id": "701463bf-9f0e-4455-8586-ef6e13072fd2", "metadata": {}, "outputs": [], "source": [ "filename = datadir + 'SPECIATEv5.2x_fromCRACMM.csv' \n", "df = pd.read_csv(filename)\n", "# for checking if any species mapping changed\n", "orig_map_colname = 'CRACMM1' # select mechanism version to compare new mapping to" ] }, { "cell_type": "markdown", "id": "cfe8152c-21f0-4a08-87d1-68f9e24a27fe", "metadata": {}, "source": [ "### Calculate C* from Vapor Pressure\n", "\n", "$$ C^* \\text{must have units of } {\\mu g \\over m^3} $$\n", "$$ C^* = {p * M * 10^6 \\over R * T} $$\n", "$$ \\text{p and M are from the input csv file} $$\n", "$$ p = \\text{vapor pressure} \\left( Pa \\right) $$\n", "$$ M = \\text{molecular weight} \\left( g \\over mol\\right ) $$\n", "$$ R = 8.314 \\text{ } {m^3 * Pa \\over mol * K} $$\n", "$$ T = 298 \\text{ } K $$" ] }, { "cell_type": "code", "execution_count": 7, "id": "215f1617-12f5-4b38-82b0-ed5bd59e48a2", "metadata": {}, "outputs": [], "source": [ "vp_k = 'VP_Pascal_OPERA'\n", "mw_k = 'SPEC_MW'\n", "R = 8.314\n", "T = 298\n", "df['log10Cstar_ugm3'] = np.log10(df[vp_k] * df[mw_k]*10**6 / (R * T))" ] }, { "cell_type": "markdown", "id": "12df431b-3eaa-4cf8-abc2-2305c54f54f0", "metadata": {}, "source": [ "### Run CRACMM2 Mapper and see mapping changes from CRACMM1 to CRACMM2" ] }, { "cell_type": "code", "execution_count": null, "id": "6658a911-385c-44cd-b207-444874af434f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "the species mappings below changed from CRACMM2alpha\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
SPECIES_NAMECRACMM2alphaCRACMM2
856Carbon monoxideSLOWROCUNKCRACMM
857Carbon dioxideSLOWROCUNKCRACMM
\n", "
" ], "text/plain": [ " SPECIES_NAME CRACMM2alpha CRACMM2\n", "856 Carbon monoxide SLOWROC UNKCRACMM\n", "857 Carbon dioxide SLOWROC UNKCRACMM" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "smiles_k = 'Smiles Notation'\n", "koh_k = 'ATMOSPHERIC_HYDROXYLATION_RATE_(AOH)_CM3/MOLECULE*SEC_OPERA'\n", "cstar_k = 'log10Cstar_ugm3'\n", "df['CRACMMnew'] = df.apply(lambda x: cracmm2.get_cracmm_roc(x[smiles_k], x[koh_k], x[cstar_k]), axis=1)\n", "\n", "# check if any species mappings changed\n", "df_checkmatch = df.eval(f'match = {orig_map_colname}==CRACMMnew')\n", "display_changes = True\n", "show_cols = ['SPECIES_NAME','CRACMM1','CRACMMnew']\n", "if len(df_checkmatch[df_checkmatch.match==False])>0:\n", " print(f'there are {len(df_checkmatch[df_checkmatch.match==False])} changes')\n", " print(f'out of {len(df_checkmatch)} total species')\n", " print('the species mappings below changed from CRACMM1')\n", " display(df_checkmatch[show_cols][df_checkmatch.match==False])\n", "else:\n", " print('all species matched CRACMM1 mapping')\n", "\n", "# save output\n", "df = df.drop(columns=[orig_map_colname, cstar_k])\n", "df.to_csv(outputdir+'SPECIATEv5.2x_fromCRACMM.csv', **csvout_kw)" ] } ], "metadata": { "kernelspec": { "display_name": "xarray_env_kernel", "language": "python", "name": "xarray_env_kernel" }, "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.15" } }, "nbformat": 4, "nbformat_minor": 5 }