{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Extracting the SI prefix\n", "\n", "`ubermagutil` provides convenience methods for determining the prefix of a value, such as pico, micro, mega, etc. The prefixes are:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('y', 1e-24),\n", " ('z', 1e-21),\n", " ('a', 1e-18),\n", " ('f', 1e-15),\n", " ('p', 1e-12),\n", " ('n', 1e-09),\n", " ('u', 1e-06),\n", " ('m', 0.001),\n", " ('', 1),\n", " ('k', 1000.0),\n", " ('M', 1000000.0),\n", " ('G', 1000000000.0),\n", " ('T', 1000000000000.0),\n", " ('P', 1000000000000000.0),\n", " ('E', 1e+18),\n", " ('Z', 1e+21),\n", " ('Y', 1e+24)])" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import ubermagutil.units as uu\n", "\n", "uu.si_prefixes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "From a single value, prefix can be extracted using `si_multiplier`:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1e-12" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uu.si_multiplier(5e-12)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1000000.0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uu.si_multiplier(-3e6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, for a list of values, the largest prefix can be determined using `si_max_multiplier`:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.001" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "uu.si_max_multiplier([2e-3, 2e-6, 6e-9])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }