diff --git a/docs/source/notebooks/custom-conversions.ipynb b/docs/source/notebooks/custom-conversions.ipynb deleted file mode 100644 index cda098d..0000000 --- a/docs/source/notebooks/custom-conversions.ipynb +++ /dev/null @@ -1,188 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "446173ed", - "metadata": {}, - "source": [ - "# Custom conversions\n", - "\n", - "Here we show how custom conversions can be passed to OpenSCM-Units' `ScmUnitRegistry`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "cd0c599a", - "metadata": {}, - "outputs": [], - "source": [ - "# NBVAL_IGNORE_OUTPUT\n", - "import traceback\n", - "\n", - "import pandas as pd\n", - "\n", - "from openscm_units import ScmUnitRegistry" - ] - }, - { - "cell_type": "markdown", - "id": "711f59c0", - "metadata": {}, - "source": [ - "## Custom conversions DataFrame\n", - "\n", - "On initialisation, a `pd.DataFrame` can be provided which contains the custom conversions. This `pd.DataFrame` should be formatted as shown below, with an index that contains the different species and columns which contain the conversion for different metrics." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "a6ed71c3", - "metadata": {}, - "outputs": [ - { - "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", - " \n", - " \n", - "
Custom1Custom2
Species
CH42025
N2O341300
\n", - "
" - ], - "text/plain": [ - " Custom1 Custom2\n", - "Species \n", - "CH4 20 25\n", - "N2O 341 300" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "metric_conversions_custom = pd.DataFrame([\n", - " {\n", - " \"Species\": \"CH4\",\n", - " \"Custom1\": 20,\n", - " \"Custom2\": 25,\n", - " },\n", - " {\n", - " \"Species\": \"N2O\",\n", - " \"Custom1\": 341,\n", - " \"Custom2\": 300,\n", - " },\n", - "]).set_index(\"Species\")\n", - "metric_conversions_custom" - ] - }, - { - "cell_type": "markdown", - "id": "b26b3ec2", - "metadata": {}, - "source": [ - "With such a `pd.DataFrame`, we can use custom conversions in our unit registry as shown." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "9f298b21", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'N2O: 1 N2O'" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "'N2O in CO2-equivalent: 341.0 CO2'" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# initialise the unit registry with custom conversions\n", - "unit_registry = ScmUnitRegistry(metric_conversions=metric_conversions_custom)\n", - "# add standard conversions before moving on\n", - "unit_registry.add_standards()\n", - "\n", - "# start with e.g. N2O\n", - "nitrous_oxide = unit_registry(\"N2O\")\n", - "display(f\"N2O: {nitrous_oxide}\")\n", - "\n", - "# our unit registry allows us to make conversions using the \n", - "# conversion factors we previously defined\n", - "with unit_registry.context(\"Custom1\"):\n", - " display(f\"N2O in CO2-equivalent: {nitrous_oxide.to('CO2')}\")" - ] - } - ], - "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.11.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}