{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Table merge\n", "\n", "Multiple OOMMF runs create multiple `.odt` files. Sometimes, it is necessary to analyse all runs as a single piece of data. Merging tables is achieved using `<<` binary operator.\n", "\n", "By merging tables the data from the second operand is appended to the data of the first one. Because independent variable (e.g. time) is always unique for each row, independent variable of the second operand is increased by the maximum value of the first one. If tables have non-matching columns, `Nan` will be added to missing data.\n", "\n", "As an example, let us merge two tables:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import ubermagtable as ut\n", "\n", "# Sample .odt file\n", "dirname = os.path.join(\"..\", \"ubermagtable\", \"tests\", \"test_sample\")\n", "odtfile1 = os.path.join(dirname, \"oommf-old-file1.odt\")\n", "odtfile2 = os.path.join(dirname, \"oommf-old-file2.odt\")\n", "\n", "table1 = ut.Table.fromfile(odtfile1, x=\"t\")\n", "table2 = ut.Table.fromfile(odtfile2, x=\"t\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Time time interval of `table1` is:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.4999999999999994e-11" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table1.xmax" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and of `table2` is" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.5e-11" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "table2.xmax" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Accordingly we expect that the length of the time interval would be the sum of those two. Let us now merge two tables:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "merged_table = table1 << table2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The time interval length of the resulting table is:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.999999999999999e-11" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "merged_table.xmax" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "as we expected. The final thing we want to check is the the time column in the merged table is monotonically increasing:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0 1.000000e-12\n", "1 2.000000e-12\n", "2 3.000000e-12\n", "3 4.000000e-12\n", "4 5.000000e-12\n", "5 6.000000e-12\n", "6 7.000000e-12\n", "7 8.000000e-12\n", "8 9.000000e-12\n", "9 1.000000e-11\n", "10 1.100000e-11\n", "11 1.200000e-11\n", "12 1.300000e-11\n", "13 1.400000e-11\n", "14 1.500000e-11\n", "15 1.600000e-11\n", "16 1.700000e-11\n", "17 1.800000e-11\n", "18 1.900000e-11\n", "19 2.000000e-11\n", "20 2.100000e-11\n", "21 2.200000e-11\n", "22 2.300000e-11\n", "23 2.400000e-11\n", "24 2.500000e-11\n", "25 2.600000e-11\n", "26 2.700000e-11\n", "27 2.800000e-11\n", "28 2.900000e-11\n", "29 3.000000e-11\n", "30 3.100000e-11\n", "31 3.200000e-11\n", "32 3.300000e-11\n", "33 3.400000e-11\n", "34 3.500000e-11\n", "35 3.600000e-11\n", "36 3.700000e-11\n", "37 3.800000e-11\n", "38 3.900000e-11\n", "39 4.000000e-11\n", "Name: t, dtype: float64" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "merged_table.data[\"t\"]" ] } ], "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.8.10" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }