{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import supporting package"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xarray as xr\n",
    "import numpy as np\n",
    "import copy\n",
    "\n",
    "from uncertainties import ufloat\n",
    "from uncertainties import unumpy as unp\n",
    "from uncertainties import umath\n",
    "import random\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.size'] = 12\n",
    "\n",
    "from DataContainer.ReadData import read_hdf5_file\n",
    "from Analyser.ImagingAnalyser import ImageAnalyser\n",
    "from Analyser.FitAnalyser import FitAnalyser\n",
    "from Analyser.FitAnalyser import NewFitModel, DensityProfileBEC2dModel\n",
    "from ToolFunction.ToolFunction import *\n",
    "\n",
    "from scipy.optimize import curve_fit\n",
    "\n",
    "from ToolFunction.HomeMadeXarrayFunction import errorbar, dataarray_plot_errorbar\n",
    "xr.plot.dataarray_plot.errorbar = errorbar\n",
    "xr.plot.accessor.DataArrayPlotAccessor.errorbar = dataarray_plot_errorbar\n",
    "\n",
    "imageAnalyser = ImageAnalyser()\n",
    "\n",
    "# %matplotlib notebook"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Start a client for parallel computing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\data\\AppData\\Roaming\\Python\\Python39\\site-packages\\distributed\\node.py:182: UserWarning: Port 8787 is already in use.\n",
      "Perhaps you already have a cluster running?\n",
      "Hosting the HTTP server on port 52367 instead\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "    <div style=\"width: 24px; height: 24px; background-color: #e1e1e1; border: 3px solid #9D9D9D; border-radius: 5px; position: absolute;\"> </div>\n",
       "    <div style=\"margin-left: 48px;\">\n",
       "        <h3 style=\"margin-bottom: 0px;\">Client</h3>\n",
       "        <p style=\"color: #9D9D9D; margin-bottom: 0px;\">Client-b21bc166-4363-11ee-942c-80e82ce2fa8e</p>\n",
       "        <table style=\"width: 100%; text-align: left;\">\n",
       "\n",
       "        <tr>\n",
       "        \n",
       "            <td style=\"text-align: left;\"><strong>Connection method:</strong> Cluster object</td>\n",
       "            <td style=\"text-align: left;\"><strong>Cluster type:</strong> distributed.LocalCluster</td>\n",
       "        \n",
       "        </tr>\n",
       "\n",
       "        \n",
       "            <tr>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52367/status\" target=\"_blank\">http://127.0.0.1:52367/status</a>\n",
       "                </td>\n",
       "                <td style=\"text-align: left;\"></td>\n",
       "            </tr>\n",
       "        \n",
       "\n",
       "        </table>\n",
       "\n",
       "        \n",
       "\n",
       "        \n",
       "            <details>\n",
       "            <summary style=\"margin-bottom: 20px;\"><h3 style=\"display: inline;\">Cluster Info</h3></summary>\n",
       "            <div class=\"jp-RenderedHTMLCommon jp-RenderedHTML jp-mod-trusted jp-OutputArea-output\">\n",
       "    <div style=\"width: 24px; height: 24px; background-color: #e1e1e1; border: 3px solid #9D9D9D; border-radius: 5px; position: absolute;\">\n",
       "    </div>\n",
       "    <div style=\"margin-left: 48px;\">\n",
       "        <h3 style=\"margin-bottom: 0px; margin-top: 0px;\">LocalCluster</h3>\n",
       "        <p style=\"color: #9D9D9D; margin-bottom: 0px;\">f17f13c5</p>\n",
       "        <table style=\"width: 100%; text-align: left;\">\n",
       "            <tr>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Dashboard:</strong> <a href=\"http://127.0.0.1:52367/status\" target=\"_blank\">http://127.0.0.1:52367/status</a>\n",
       "                </td>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Workers:</strong> 8\n",
       "                </td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Total threads:</strong> 128\n",
       "                </td>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Total memory:</strong> 149.01 GiB\n",
       "                </td>\n",
       "            </tr>\n",
       "            \n",
       "            <tr>\n",
       "    <td style=\"text-align: left;\"><strong>Status:</strong> running</td>\n",
       "    <td style=\"text-align: left;\"><strong>Using processes:</strong> True</td>\n",
       "</tr>\n",
       "\n",
       "            \n",
       "        </table>\n",
       "\n",
       "        <details>\n",
       "            <summary style=\"margin-bottom: 20px;\">\n",
       "                <h3 style=\"display: inline;\">Scheduler Info</h3>\n",
       "            </summary>\n",
       "\n",
       "            <div style=\"\">\n",
       "    <div>\n",
       "        <div style=\"width: 24px; height: 24px; background-color: #FFF7E5; border: 3px solid #FF6132; border-radius: 5px; position: absolute;\"> </div>\n",
       "        <div style=\"margin-left: 48px;\">\n",
       "            <h3 style=\"margin-bottom: 0px;\">Scheduler</h3>\n",
       "            <p style=\"color: #9D9D9D; margin-bottom: 0px;\">Scheduler-cfebc6e8-3543-4422-83e0-ad5571cb200d</p>\n",
       "            <table style=\"width: 100%; text-align: left;\">\n",
       "                <tr>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Comm:</strong> tcp://127.0.0.1:52370\n",
       "                    </td>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Workers:</strong> 8\n",
       "                    </td>\n",
       "                </tr>\n",
       "                <tr>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Dashboard:</strong> <a href=\"http://127.0.0.1:52367/status\" target=\"_blank\">http://127.0.0.1:52367/status</a>\n",
       "                    </td>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Total threads:</strong> 128\n",
       "                    </td>\n",
       "                </tr>\n",
       "                <tr>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Started:</strong> Just now\n",
       "                    </td>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Total memory:</strong> 149.01 GiB\n",
       "                    </td>\n",
       "                </tr>\n",
       "            </table>\n",
       "        </div>\n",
       "    </div>\n",
       "\n",
       "    <details style=\"margin-left: 48px;\">\n",
       "        <summary style=\"margin-bottom: 20px;\">\n",
       "            <h3 style=\"display: inline;\">Workers</h3>\n",
       "        </summary>\n",
       "\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 0</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52406\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52410/status\" target=\"_blank\">http://127.0.0.1:52410/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52373\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-1_z2lt_0\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 1</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52417\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52418/status\" target=\"_blank\">http://127.0.0.1:52418/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52374\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-iq7wc4yz\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 2</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52412\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52415/status\" target=\"_blank\">http://127.0.0.1:52415/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52375\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-4s052vw8\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 3</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52420\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52421/status\" target=\"_blank\">http://127.0.0.1:52421/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52376\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-u1n0zi10\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 4</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52423\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52424/status\" target=\"_blank\">http://127.0.0.1:52424/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52377\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-3vuc5miu\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 5</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52405\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52407/status\" target=\"_blank\">http://127.0.0.1:52407/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52378\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-suw918q8\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 6</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52409\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52413/status\" target=\"_blank\">http://127.0.0.1:52413/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52379\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-7dc78218\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "        <div style=\"margin-bottom: 20px;\">\n",
       "            <div style=\"width: 24px; height: 24px; background-color: #DBF5FF; border: 3px solid #4CC9FF; border-radius: 5px; position: absolute;\"> </div>\n",
       "            <div style=\"margin-left: 48px;\">\n",
       "            <details>\n",
       "                <summary>\n",
       "                    <h4 style=\"margin-bottom: 0px; display: inline;\">Worker: 7</h4>\n",
       "                </summary>\n",
       "                <table style=\"width: 100%; text-align: left;\">\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Comm: </strong> tcp://127.0.0.1:52435\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 16\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:52436/status\" target=\"_blank\">http://127.0.0.1:52436/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 18.63 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:52380\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\"></td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td colspan=\"2\" style=\"text-align: left;\">\n",
       "                            <strong>Local directory: </strong> C:\\Users\\data\\AppData\\Local\\Temp\\dask-worker-space\\worker-kdlokiw6\n",
       "                        </td>\n",
       "                    </tr>\n",
       "\n",
       "                    \n",
       "\n",
       "                    \n",
       "\n",
       "                </table>\n",
       "            </details>\n",
       "            </div>\n",
       "        </div>\n",
       "        \n",
       "\n",
       "    </details>\n",
       "</div>\n",
       "\n",
       "        </details>\n",
       "    </div>\n",
       "</div>\n",
       "            </details>\n",
       "        \n",
       "\n",
       "    </div>\n",
       "</div>"
      ],
      "text/plain": [
       "<Client: 'tcp://127.0.0.1:52370' processes=8 threads=128, memory=149.01 GiB>"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dask.distributed import Client\n",
    "client = Client(n_workers=8, threads_per_worker=16, processes=True, memory_limit='20GB')\n",
    "client"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Start a client for Mongo DB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pymongo\n",
    "import xarray_mongodb\n",
    "\n",
    "from DataContainer.MongoDB import MongoDB\n",
    "\n",
    "mongoClient = pymongo.MongoClient('mongodb://control:DyLab2021@127.0.0.1:27017/?authMechanism=DEFAULT')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set global path for experiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "groupList = [\n",
    "    \"images/MOT_3D_Camera/in_situ_absorption\",\n",
    "    \"images/ODT_1_Axis_Camera/in_situ_absorption\",\n",
    "    \"images/ODT_2_Axis_Camera/in_situ_absorption\",\n",
    "]\n",
    "\n",
    "dskey = {\n",
    "    \"images/MOT_3D_Camera/in_situ_absorption\": \"camera_0\",\n",
    "    \"images/ODT_1_Axis_Camera/in_situ_absorption\": \"camera_1\",\n",
    "    \"images/ODT_2_Axis_Camera/in_situ_absorption\": \"camera_2\",\n",
    "}\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaporative Cooling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "# img_dir = 'C:/Users/control/DyLab/Experiments/DyBEC/'\n",
    "img_dir = '//DyLabNAS/Data/'\n",
    "SequenceName = \"Evaporative_Cooling\"\n",
    "folderPath = img_dir + SequenceName + \"/\" + get_date()\n",
    "# folderPath = img_dir + SequenceName + \"/\" + '2023/06/30'# get_date()\n",
    "\n",
    "mongoDB = mongoClient[SequenceName]\n",
    "\n",
    "DB = MongoDB(mongoClient, mongoDB, date=get_date())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Could not find any dimension coordinates to use to order the datasets for concatenation",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mf:\\Jianshun\\analyseScript\\20230630_Data_Analysis.ipynb Cell 11\u001b[0m in \u001b[0;36m1\n\u001b[1;32m----> <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y504sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m xr\u001b[39m.\u001b[39;49mopen_mfdataset(filePath)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\backends\\api.py:1010\u001b[0m, in \u001b[0;36mopen_mfdataset\u001b[1;34m(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs)\u001b[0m\n\u001b[0;32m    997\u001b[0m     combined \u001b[39m=\u001b[39m _nested_combine(\n\u001b[0;32m    998\u001b[0m         datasets,\n\u001b[0;32m    999\u001b[0m         concat_dims\u001b[39m=\u001b[39mconcat_dim,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1005\u001b[0m         combine_attrs\u001b[39m=\u001b[39mcombine_attrs,\n\u001b[0;32m   1006\u001b[0m     )\n\u001b[0;32m   1007\u001b[0m \u001b[39melif\u001b[39;00m combine \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mby_coords\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m   1008\u001b[0m     \u001b[39m# Redo ordering from coordinates, ignoring how they were ordered\u001b[39;00m\n\u001b[0;32m   1009\u001b[0m     \u001b[39m# previously\u001b[39;00m\n\u001b[1;32m-> 1010\u001b[0m     combined \u001b[39m=\u001b[39m combine_by_coords(\n\u001b[0;32m   1011\u001b[0m         datasets,\n\u001b[0;32m   1012\u001b[0m         compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m   1013\u001b[0m         data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m   1014\u001b[0m         coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m   1015\u001b[0m         join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m   1016\u001b[0m         combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m   1017\u001b[0m     )\n\u001b[0;32m   1018\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m   1019\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m   1020\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m is an invalid option for the keyword argument\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m   1021\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39m ``combine``\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(combine)\n\u001b[0;32m   1022\u001b[0m     )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:975\u001b[0m, in \u001b[0;36mcombine_by_coords\u001b[1;34m(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)\u001b[0m\n\u001b[0;32m    973\u001b[0m     concatenated_grouped_by_data_vars \u001b[39m=\u001b[39m []\n\u001b[0;32m    974\u001b[0m     \u001b[39mfor\u001b[39;00m \u001b[39mvars\u001b[39m, datasets_with_same_vars \u001b[39min\u001b[39;00m grouped_by_vars:\n\u001b[1;32m--> 975\u001b[0m         concatenated \u001b[39m=\u001b[39m _combine_single_variable_hypercube(\n\u001b[0;32m    976\u001b[0m             \u001b[39mlist\u001b[39;49m(datasets_with_same_vars),\n\u001b[0;32m    977\u001b[0m             fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    978\u001b[0m             data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    979\u001b[0m             coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    980\u001b[0m             compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    981\u001b[0m             join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    982\u001b[0m             combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    983\u001b[0m         )\n\u001b[0;32m    984\u001b[0m         concatenated_grouped_by_data_vars\u001b[39m.\u001b[39mappend(concatenated)\n\u001b[0;32m    986\u001b[0m \u001b[39mreturn\u001b[39;00m merge(\n\u001b[0;32m    987\u001b[0m     concatenated_grouped_by_data_vars,\n\u001b[0;32m    988\u001b[0m     compat\u001b[39m=\u001b[39mcompat,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    991\u001b[0m     combine_attrs\u001b[39m=\u001b[39mcombine_attrs,\n\u001b[0;32m    992\u001b[0m )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:622\u001b[0m, in \u001b[0;36m_combine_single_variable_hypercube\u001b[1;34m(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)\u001b[0m\n\u001b[0;32m    616\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(datasets) \u001b[39m==\u001b[39m \u001b[39m0\u001b[39m:\n\u001b[0;32m    617\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m    618\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39mAt least one Dataset is required to resolve variable names \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    619\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39mfor combined hypercube.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    620\u001b[0m     )\n\u001b[1;32m--> 622\u001b[0m combined_ids, concat_dims \u001b[39m=\u001b[39m _infer_concat_order_from_coords(\u001b[39mlist\u001b[39;49m(datasets))\n\u001b[0;32m    624\u001b[0m \u001b[39mif\u001b[39;00m fill_value \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m    625\u001b[0m     \u001b[39m# check that datasets form complete hypercube\u001b[39;00m\n\u001b[0;32m    626\u001b[0m     _check_shape_tile_ids(combined_ids)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:145\u001b[0m, in \u001b[0;36m_infer_concat_order_from_coords\u001b[1;34m(datasets)\u001b[0m\n\u001b[0;32m    140\u001b[0m             tile_ids \u001b[39m=\u001b[39m [\n\u001b[0;32m    141\u001b[0m                 tile_id \u001b[39m+\u001b[39m (position,) \u001b[39mfor\u001b[39;00m tile_id, position \u001b[39min\u001b[39;00m \u001b[39mzip\u001b[39m(tile_ids, order)\n\u001b[0;32m    142\u001b[0m             ]\n\u001b[0;32m    144\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(datasets) \u001b[39m>\u001b[39m \u001b[39m1\u001b[39m \u001b[39mand\u001b[39;00m \u001b[39mnot\u001b[39;00m concat_dims:\n\u001b[1;32m--> 145\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m    146\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39mCould not find any dimension coordinates to use to \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    147\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39morder the datasets for concatenation\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    148\u001b[0m     )\n\u001b[0;32m    150\u001b[0m combined_ids \u001b[39m=\u001b[39m \u001b[39mdict\u001b[39m(\u001b[39mzip\u001b[39m(tile_ids, datasets))\n\u001b[0;32m    152\u001b[0m \u001b[39mreturn\u001b[39;00m combined_ids, concat_dims\n",
      "\u001b[1;31mValueError\u001b[0m: Could not find any dimension coordinates to use to order the datasets for concatenation"
     ]
    }
   ],
   "source": [
    "xr.open_mfdataset(filePath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "cannot reindex or align along dimension 'phony_dim_2' because of conflicting dimension sizes: {1088, 0}",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mf:\\Jianshun\\analyseScript\\20230630_Data_Analysis.ipynb Cell 11\u001b[0m in \u001b[0;36m4\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m shotNum \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m0071\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m filePath \u001b[39m=\u001b[39m folderPath \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m shotNum \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/*.h5\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m dataSetDict \u001b[39m=\u001b[39m {\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m     dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m     \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m [\u001b[39m1\u001b[39m]\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m }\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=8'>9</a>\u001b[0m dataSet \u001b[39m=\u001b[39m dataSetDict[\u001b[39m\"\u001b[39m\u001b[39mcamera_0\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m print_scanAxis(dataSet)\n",
      "\u001b[1;32mf:\\Jianshun\\analyseScript\\20230630_Data_Analysis.ipynb Cell 11\u001b[0m in \u001b[0;36m5\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m shotNum \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m0071\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m filePath \u001b[39m=\u001b[39m folderPath \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/\u001b[39m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m shotNum \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/*.h5\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m dataSetDict \u001b[39m=\u001b[39m {\n\u001b[1;32m----> <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m     dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m     \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m [\u001b[39m1\u001b[39m]\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m }\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=8'>9</a>\u001b[0m dataSet \u001b[39m=\u001b[39m dataSetDict[\u001b[39m\"\u001b[39m\u001b[39mcamera_0\u001b[39m\u001b[39m\"\u001b[39m]\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/20230630_Data_Analysis.ipynb#Y503sZmlsZQ%3D%3D?line=10'>11</a>\u001b[0m print_scanAxis(dataSet)\n",
      "File \u001b[1;32mf:\\Jianshun\\analyseScript\\DataContainer\\ReadData.py:226\u001b[0m, in \u001b[0;36mread_hdf5_file\u001b[1;34m(filePath, group, datesetOfGlobal, preprocess, join, parallel, engine, phony_dims, excludeAxis, maxFileNum, **kwargs)\u001b[0m\n\u001b[0;32m    223\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    224\u001b[0m     kwargs\u001b[39m.\u001b[39mupdate({\u001b[39m'\u001b[39m\u001b[39mpreprocess\u001b[39m\u001b[39m'\u001b[39m:preprocess})\n\u001b[1;32m--> 226\u001b[0m ds \u001b[39m=\u001b[39m xr\u001b[39m.\u001b[39mopen_mfdataset(fullFilePath, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m    228\u001b[0m newDimKey \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mappend([\u001b[39m'\u001b[39m\u001b[39mx\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39my\u001b[39m\u001b[39m'\u001b[39m, \u001b[39m'\u001b[39m\u001b[39mz\u001b[39m\u001b[39m'\u001b[39m], [ \u001b[39mchr\u001b[39m(i) \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m97\u001b[39m, \u001b[39m97\u001b[39m\u001b[39m+\u001b[39m\u001b[39m23\u001b[39m)])\n\u001b[0;32m    230\u001b[0m oldDimKey \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39msort(\n\u001b[0;32m    231\u001b[0m     [\n\u001b[0;32m    232\u001b[0m         key \n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    235\u001b[0m     ]\n\u001b[0;32m    236\u001b[0m )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\backends\\api.py:1010\u001b[0m, in \u001b[0;36mopen_mfdataset\u001b[1;34m(paths, chunks, concat_dim, compat, preprocess, engine, data_vars, coords, combine, parallel, join, attrs_file, combine_attrs, **kwargs)\u001b[0m\n\u001b[0;32m    997\u001b[0m     combined \u001b[39m=\u001b[39m _nested_combine(\n\u001b[0;32m    998\u001b[0m         datasets,\n\u001b[0;32m    999\u001b[0m         concat_dims\u001b[39m=\u001b[39mconcat_dim,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m   1005\u001b[0m         combine_attrs\u001b[39m=\u001b[39mcombine_attrs,\n\u001b[0;32m   1006\u001b[0m     )\n\u001b[0;32m   1007\u001b[0m \u001b[39melif\u001b[39;00m combine \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mby_coords\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m   1008\u001b[0m     \u001b[39m# Redo ordering from coordinates, ignoring how they were ordered\u001b[39;00m\n\u001b[0;32m   1009\u001b[0m     \u001b[39m# previously\u001b[39;00m\n\u001b[1;32m-> 1010\u001b[0m     combined \u001b[39m=\u001b[39m combine_by_coords(\n\u001b[0;32m   1011\u001b[0m         datasets,\n\u001b[0;32m   1012\u001b[0m         compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m   1013\u001b[0m         data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m   1014\u001b[0m         coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m   1015\u001b[0m         join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m   1016\u001b[0m         combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m   1017\u001b[0m     )\n\u001b[0;32m   1018\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m   1019\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m   1020\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39m{}\u001b[39;00m\u001b[39m is an invalid option for the keyword argument\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m   1021\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39m ``combine``\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m.\u001b[39mformat(combine)\n\u001b[0;32m   1022\u001b[0m     )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:975\u001b[0m, in \u001b[0;36mcombine_by_coords\u001b[1;34m(data_objects, compat, data_vars, coords, fill_value, join, combine_attrs, datasets)\u001b[0m\n\u001b[0;32m    973\u001b[0m     concatenated_grouped_by_data_vars \u001b[39m=\u001b[39m []\n\u001b[0;32m    974\u001b[0m     \u001b[39mfor\u001b[39;00m \u001b[39mvars\u001b[39m, datasets_with_same_vars \u001b[39min\u001b[39;00m grouped_by_vars:\n\u001b[1;32m--> 975\u001b[0m         concatenated \u001b[39m=\u001b[39m _combine_single_variable_hypercube(\n\u001b[0;32m    976\u001b[0m             \u001b[39mlist\u001b[39;49m(datasets_with_same_vars),\n\u001b[0;32m    977\u001b[0m             fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    978\u001b[0m             data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    979\u001b[0m             coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    980\u001b[0m             compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    981\u001b[0m             join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    982\u001b[0m             combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    983\u001b[0m         )\n\u001b[0;32m    984\u001b[0m         concatenated_grouped_by_data_vars\u001b[39m.\u001b[39mappend(concatenated)\n\u001b[0;32m    986\u001b[0m \u001b[39mreturn\u001b[39;00m merge(\n\u001b[0;32m    987\u001b[0m     concatenated_grouped_by_data_vars,\n\u001b[0;32m    988\u001b[0m     compat\u001b[39m=\u001b[39mcompat,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    991\u001b[0m     combine_attrs\u001b[39m=\u001b[39mcombine_attrs,\n\u001b[0;32m    992\u001b[0m )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:633\u001b[0m, in \u001b[0;36m_combine_single_variable_hypercube\u001b[1;34m(datasets, fill_value, data_vars, coords, compat, join, combine_attrs)\u001b[0m\n\u001b[0;32m    630\u001b[0m     _check_dimension_depth_tile_ids(combined_ids)\n\u001b[0;32m    632\u001b[0m \u001b[39m# Concatenate along all of concat_dims one by one to create single ds\u001b[39;00m\n\u001b[1;32m--> 633\u001b[0m concatenated \u001b[39m=\u001b[39m _combine_nd(\n\u001b[0;32m    634\u001b[0m     combined_ids,\n\u001b[0;32m    635\u001b[0m     concat_dims\u001b[39m=\u001b[39;49mconcat_dims,\n\u001b[0;32m    636\u001b[0m     data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    637\u001b[0m     coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    638\u001b[0m     compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    639\u001b[0m     fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    640\u001b[0m     join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    641\u001b[0m     combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    642\u001b[0m )\n\u001b[0;32m    644\u001b[0m \u001b[39m# Check the overall coordinates are monotonically increasing\u001b[39;00m\n\u001b[0;32m    645\u001b[0m \u001b[39mfor\u001b[39;00m dim \u001b[39min\u001b[39;00m concat_dims:\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:235\u001b[0m, in \u001b[0;36m_combine_nd\u001b[1;34m(combined_ids, concat_dims, data_vars, coords, compat, fill_value, join, combine_attrs)\u001b[0m\n\u001b[0;32m    231\u001b[0m \u001b[39m# Each iteration of this loop reduces the length of the tile_ids tuples\u001b[39;00m\n\u001b[0;32m    232\u001b[0m \u001b[39m# by one. It always combines along the first dimension, removing the first\u001b[39;00m\n\u001b[0;32m    233\u001b[0m \u001b[39m# element of the tuple\u001b[39;00m\n\u001b[0;32m    234\u001b[0m \u001b[39mfor\u001b[39;00m concat_dim \u001b[39min\u001b[39;00m concat_dims:\n\u001b[1;32m--> 235\u001b[0m     combined_ids \u001b[39m=\u001b[39m _combine_all_along_first_dim(\n\u001b[0;32m    236\u001b[0m         combined_ids,\n\u001b[0;32m    237\u001b[0m         dim\u001b[39m=\u001b[39;49mconcat_dim,\n\u001b[0;32m    238\u001b[0m         data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    239\u001b[0m         coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    240\u001b[0m         compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    241\u001b[0m         fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    242\u001b[0m         join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    243\u001b[0m         combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    244\u001b[0m     )\n\u001b[0;32m    245\u001b[0m (combined_ds,) \u001b[39m=\u001b[39m combined_ids\u001b[39m.\u001b[39mvalues()\n\u001b[0;32m    246\u001b[0m \u001b[39mreturn\u001b[39;00m combined_ds\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:270\u001b[0m, in \u001b[0;36m_combine_all_along_first_dim\u001b[1;34m(combined_ids, dim, data_vars, coords, compat, fill_value, join, combine_attrs)\u001b[0m\n\u001b[0;32m    268\u001b[0m     combined_ids \u001b[39m=\u001b[39m \u001b[39mdict\u001b[39m(\u001b[39msorted\u001b[39m(group))\n\u001b[0;32m    269\u001b[0m     datasets \u001b[39m=\u001b[39m combined_ids\u001b[39m.\u001b[39mvalues()\n\u001b[1;32m--> 270\u001b[0m     new_combined_ids[new_id] \u001b[39m=\u001b[39m _combine_1d(\n\u001b[0;32m    271\u001b[0m         datasets, dim, compat, data_vars, coords, fill_value, join, combine_attrs\n\u001b[0;32m    272\u001b[0m     )\n\u001b[0;32m    273\u001b[0m \u001b[39mreturn\u001b[39;00m new_combined_ids\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\combine.py:293\u001b[0m, in \u001b[0;36m_combine_1d\u001b[1;34m(datasets, concat_dim, compat, data_vars, coords, fill_value, join, combine_attrs)\u001b[0m\n\u001b[0;32m    291\u001b[0m \u001b[39mif\u001b[39;00m concat_dim \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[0;32m    292\u001b[0m     \u001b[39mtry\u001b[39;00m:\n\u001b[1;32m--> 293\u001b[0m         combined \u001b[39m=\u001b[39m concat(\n\u001b[0;32m    294\u001b[0m             datasets,\n\u001b[0;32m    295\u001b[0m             dim\u001b[39m=\u001b[39;49mconcat_dim,\n\u001b[0;32m    296\u001b[0m             data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    297\u001b[0m             coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    298\u001b[0m             compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    299\u001b[0m             fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    300\u001b[0m             join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    301\u001b[0m             combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    302\u001b[0m         )\n\u001b[0;32m    303\u001b[0m     \u001b[39mexcept\u001b[39;00m \u001b[39mValueError\u001b[39;00m \u001b[39mas\u001b[39;00m err:\n\u001b[0;32m    304\u001b[0m         \u001b[39mif\u001b[39;00m \u001b[39m\"\u001b[39m\u001b[39mencountered unexpected variable\u001b[39m\u001b[39m\"\u001b[39m \u001b[39min\u001b[39;00m \u001b[39mstr\u001b[39m(err):\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\concat.py:251\u001b[0m, in \u001b[0;36mconcat\u001b[1;34m(objs, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs)\u001b[0m\n\u001b[0;32m    239\u001b[0m     \u001b[39mreturn\u001b[39;00m _dataarray_concat(\n\u001b[0;32m    240\u001b[0m         objs,\n\u001b[0;32m    241\u001b[0m         dim\u001b[39m=\u001b[39mdim,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    248\u001b[0m         combine_attrs\u001b[39m=\u001b[39mcombine_attrs,\n\u001b[0;32m    249\u001b[0m     )\n\u001b[0;32m    250\u001b[0m \u001b[39melif\u001b[39;00m \u001b[39misinstance\u001b[39m(first_obj, Dataset):\n\u001b[1;32m--> 251\u001b[0m     \u001b[39mreturn\u001b[39;00m _dataset_concat(\n\u001b[0;32m    252\u001b[0m         objs,\n\u001b[0;32m    253\u001b[0m         dim\u001b[39m=\u001b[39;49mdim,\n\u001b[0;32m    254\u001b[0m         data_vars\u001b[39m=\u001b[39;49mdata_vars,\n\u001b[0;32m    255\u001b[0m         coords\u001b[39m=\u001b[39;49mcoords,\n\u001b[0;32m    256\u001b[0m         compat\u001b[39m=\u001b[39;49mcompat,\n\u001b[0;32m    257\u001b[0m         positions\u001b[39m=\u001b[39;49mpositions,\n\u001b[0;32m    258\u001b[0m         fill_value\u001b[39m=\u001b[39;49mfill_value,\n\u001b[0;32m    259\u001b[0m         join\u001b[39m=\u001b[39;49mjoin,\n\u001b[0;32m    260\u001b[0m         combine_attrs\u001b[39m=\u001b[39;49mcombine_attrs,\n\u001b[0;32m    261\u001b[0m     )\n\u001b[0;32m    262\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m    263\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\n\u001b[0;32m    264\u001b[0m         \u001b[39m\"\u001b[39m\u001b[39mcan only concatenate xarray Dataset and DataArray \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    265\u001b[0m         \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mobjects, got \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mtype\u001b[39m(first_obj)\u001b[39m}\u001b[39;00m\u001b[39m\"\u001b[39m\n\u001b[0;32m    266\u001b[0m     )\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\concat.py:483\u001b[0m, in \u001b[0;36m_dataset_concat\u001b[1;34m(datasets, dim, data_vars, coords, compat, positions, fill_value, join, combine_attrs)\u001b[0m\n\u001b[0;32m    480\u001b[0m \u001b[39m# Make sure we're working on a copy (we'll be loading variables)\u001b[39;00m\n\u001b[0;32m    481\u001b[0m datasets \u001b[39m=\u001b[39m [ds\u001b[39m.\u001b[39mcopy() \u001b[39mfor\u001b[39;00m ds \u001b[39min\u001b[39;00m datasets]\n\u001b[0;32m    482\u001b[0m datasets \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\n\u001b[1;32m--> 483\u001b[0m     align(\u001b[39m*\u001b[39;49mdatasets, join\u001b[39m=\u001b[39;49mjoin, copy\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m, exclude\u001b[39m=\u001b[39;49m[dim], fill_value\u001b[39m=\u001b[39;49mfill_value)\n\u001b[0;32m    484\u001b[0m )\n\u001b[0;32m    486\u001b[0m dim_coords, dims_sizes, coord_names, data_names, vars_order \u001b[39m=\u001b[39m _parse_datasets(\n\u001b[0;32m    487\u001b[0m     datasets\n\u001b[0;32m    488\u001b[0m )\n\u001b[0;32m    489\u001b[0m dim_names \u001b[39m=\u001b[39m \u001b[39mset\u001b[39m(dim_coords)\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\alignment.py:787\u001b[0m, in \u001b[0;36malign\u001b[1;34m(join, copy, indexes, exclude, fill_value, *objects)\u001b[0m\n\u001b[0;32m    591\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m    592\u001b[0m \u001b[39mGiven any number of Dataset and/or DataArray objects, returns new\u001b[39;00m\n\u001b[0;32m    593\u001b[0m \u001b[39mobjects with aligned indexes and dimension sizes.\u001b[39;00m\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    777\u001b[0m \n\u001b[0;32m    778\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[0;32m    779\u001b[0m aligner \u001b[39m=\u001b[39m Aligner(\n\u001b[0;32m    780\u001b[0m     objects,\n\u001b[0;32m    781\u001b[0m     join\u001b[39m=\u001b[39mjoin,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    785\u001b[0m     fill_value\u001b[39m=\u001b[39mfill_value,\n\u001b[0;32m    786\u001b[0m )\n\u001b[1;32m--> 787\u001b[0m aligner\u001b[39m.\u001b[39;49malign()\n\u001b[0;32m    788\u001b[0m \u001b[39mreturn\u001b[39;00m aligner\u001b[39m.\u001b[39mresults\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\alignment.py:573\u001b[0m, in \u001b[0;36mAligner.align\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    571\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39massert_no_index_conflict()\n\u001b[0;32m    572\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39malign_indexes()\n\u001b[1;32m--> 573\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49massert_unindexed_dim_sizes_equal()\n\u001b[0;32m    575\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mjoin \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39moverride\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m    576\u001b[0m     \u001b[39mself\u001b[39m\u001b[39m.\u001b[39moverride_indexes()\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\xarray\\core\\alignment.py:472\u001b[0m, in \u001b[0;36mAligner.assert_unindexed_dim_sizes_equal\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    470\u001b[0m     add_err_msg \u001b[39m=\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    471\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mlen\u001b[39m(sizes) \u001b[39m>\u001b[39m \u001b[39m1\u001b[39m:\n\u001b[1;32m--> 472\u001b[0m     \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\n\u001b[0;32m    473\u001b[0m         \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mcannot reindex or align along dimension \u001b[39m\u001b[39m{\u001b[39;00mdim\u001b[39m!r}\u001b[39;00m\u001b[39m \u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m    474\u001b[0m         \u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mbecause of conflicting dimension sizes: \u001b[39m\u001b[39m{\u001b[39;00msizes\u001b[39m!r}\u001b[39;00m\u001b[39m\"\u001b[39m \u001b[39m+\u001b[39m add_err_msg\n\u001b[0;32m    475\u001b[0m     )\n",
      "\u001b[1;31mValueError\u001b[0m: cannot reindex or align along dimension 'phony_dim_2' because of conflicting dimension sizes: {1088, 0}"
     ]
    }
   ],
   "source": [
    "shotNum = \"0071\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [1]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ALS"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0 - 0.025 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.    , 0.0009, 0.0018, 0.0027, 0.0036, 0.0045, 0.0054, 0.0063,\n",
      "       0.0072, 0.0081, 0.009 , 0.0099, 0.0108, 0.0117, 0.0126, 0.0135,\n",
      "       0.0144, 0.0153, 0.0162, 0.0171, 0.018 , 0.0189, 0.0198, 0.0207,\n",
      "       0.0216, 0.0225, 0.0234, 0.0243]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 26596 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0017\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = copy.copy(Ncount_mean)\n",
    "Ncount_std_total = copy.copy(Ncount_std)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.025 - 0.050 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.025 , 0.0259, 0.0268, 0.0277, 0.0286, 0.0295, 0.0304, 0.0313,\n",
      "       0.0322, 0.0331, 0.034 , 0.0349, 0.0358, 0.0367, 0.0376, 0.0385,\n",
      "       0.0394, 0.0403, 0.0412, 0.0421, 0.043 , 0.0439, 0.0448, 0.0457,\n",
      "       0.0466, 0.0475, 0.0484, 0.0493]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27664 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0018\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.050 - 0.075 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.05  , 0.0509, 0.0518, 0.0527, 0.0536, 0.0545, 0.0554, 0.0563,\n",
      "       0.0572, 0.0581, 0.059 , 0.0599, 0.0608, 0.0617, 0.0626, 0.0635,\n",
      "       0.0644, 0.0653, 0.0662, 0.0671, 0.068 , 0.0689, 0.0698, 0.0707,\n",
      "       0.0716, 0.0725, 0.0734, 0.0743, 0.0752, 0.0761]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27064 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0019\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33008 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean_total.plot.errorbar(ax=ax, yerr = Ncount_std_total, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.075 - 0.100 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.075 , 0.0759, 0.0768, 0.0777, 0.0786, 0.0795, 0.0804, 0.0813,\n",
      "       0.0822, 0.0831, 0.084 , 0.0849, 0.0858, 0.0867, 0.0876, 0.0885,\n",
      "       0.0894, 0.0903, 0.0912, 0.0921, 0.093 , 0.0939, 0.0948, 0.0957,\n",
      "       0.0966, 0.0975, 0.0984, 0.0993, 0.1002, 0.1011]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32792 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0020\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.100 - 0.125 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.1   , 0.1009, 0.1018, 0.1027, 0.1036, 0.1045, 0.1054, 0.1063,\n",
      "       0.1072, 0.1081, 0.109 , 0.1099, 0.1108, 0.1117, 0.1126, 0.1135,\n",
      "       0.1144, 0.1153, 0.1162, 0.1171, 0.118 , 0.1189, 0.1198, 0.1207,\n",
      "       0.1216, 0.1225, 0.1234, 0.1243, 0.1252, 0.1261]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 23720 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0021\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 5000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.125 - 0.150 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.125 , 0.1259, 0.1268, 0.1277, 0.1286, 0.1295, 0.1304, 0.1313,\n",
      "       0.1322, 0.1331, 0.134 , 0.1349, 0.1358, 0.1367, 0.1376, 0.1385,\n",
      "       0.1394, 0.1403, 0.1412, 0.1421, 0.143 , 0.1439, 0.1448, 0.1457,\n",
      "       0.1466, 0.1475, 0.1484, 0.1493, 0.1502, 0.1511]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 24364 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0022\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 5000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.150 - 0.175 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.15  , 0.1509, 0.1518, 0.1527, 0.1536, 0.1545, 0.1554, 0.1563,\n",
      "       0.1572, 0.1581, 0.159 , 0.1599, 0.1608, 0.1617, 0.1626, 0.1635,\n",
      "       0.1644, 0.1653, 0.1662, 0.1671, 0.168 , 0.1689, 0.1698, 0.1707,\n",
      "       0.1716, 0.1725, 0.1734, 0.1743, 0.1752, 0.1761]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 30232 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0023\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.175 - 0.200 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.175 , 0.1759, 0.1768, 0.1777, 0.1786, 0.1795, 0.1804, 0.1813,\n",
      "       0.1822, 0.1831, 0.184 , 0.1849, 0.1858, 0.1867, 0.1876, 0.1885,\n",
      "       0.1894, 0.1903, 0.1912, 0.1921, 0.193 , 0.1939, 0.1948, 0.1957,\n",
      "       0.1966, 0.1975, 0.1984, 0.1993, 0.2002, 0.2011, 0.202 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 31484 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0024\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.200 - 0.225 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.2   , 0.2009, 0.2018, 0.2027, 0.2036, 0.2045, 0.2054, 0.2063,\n",
      "       0.2072, 0.2081, 0.209 , 0.2099, 0.2108, 0.2117, 0.2126, 0.2135,\n",
      "       0.2144, 0.2153, 0.2162, 0.2171, 0.218 , 0.2189, 0.2198, 0.2207,\n",
      "       0.2216, 0.2225, 0.2234, 0.2243, 0.2252, 0.2261]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 32008 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0025\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.220 - 0.250 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.22  , 0.2209, 0.2218, 0.2227, 0.2236, 0.2245, 0.2254, 0.2263,\n",
      "       0.2272, 0.2281, 0.229 , 0.2299, 0.2308, 0.2317, 0.2326, 0.2335,\n",
      "       0.2344, 0.2353, 0.2362, 0.2371, 0.238 , 0.2389, 0.2398, 0.2407,\n",
      "       0.2416, 0.2425, 0.2434, 0.2443, 0.2452, 0.2461, 0.247 , 0.2479,\n",
      "       0.2488, 0.2497, 0.2506, 0.2515]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 29964 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0026\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.250 - 0.275 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.25  , 0.2509, 0.2518, 0.2527, 0.2536, 0.2545, 0.2554, 0.2563,\n",
      "       0.2572, 0.2581, 0.259 , 0.2599, 0.2608, 0.2617, 0.2626, 0.2635,\n",
      "       0.2644, 0.2653, 0.2662, 0.2671, 0.268 , 0.2689, 0.2698, 0.2707,\n",
      "       0.2716, 0.2725, 0.2734, 0.2743, 0.2752, 0.2761, 0.277 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28376 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0027\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.270 - 0.300 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.27  , 0.2709, 0.2718, 0.2727, 0.2736, 0.2745, 0.2754, 0.2763,\n",
      "       0.2772, 0.2781, 0.279 , 0.2799, 0.2808, 0.2817, 0.2826, 0.2835,\n",
      "       0.2844, 0.2853, 0.2862, 0.2871, 0.288 , 0.2889, 0.2898, 0.2907,\n",
      "       0.2916, 0.2925, 0.2934, 0.2943, 0.2952, 0.2961, 0.297 , 0.2979,\n",
      "       0.2988, 0.2997, 0.3006]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 28460 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0028\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.300 - 0.325 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.3   , 0.3009, 0.3018, 0.3027, 0.3036, 0.3045, 0.3054, 0.3063,\n",
      "       0.3072, 0.3081, 0.309 , 0.3099, 0.3108, 0.3117, 0.3126, 0.3135,\n",
      "       0.3144, 0.3153, 0.3162, 0.3171, 0.318 , 0.3189, 0.3198, 0.3207,\n",
      "       0.3216, 0.3225, 0.3234, 0.3243, 0.3252, 0.3261, 0.327 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27064 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0029\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.325 - 0.350 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.325 , 0.3259, 0.3268, 0.3277, 0.3286, 0.3295, 0.3304, 0.3313,\n",
      "       0.3322, 0.3331, 0.334 , 0.3349, 0.3358, 0.3367, 0.3376, 0.3385,\n",
      "       0.3394, 0.3403, 0.3412, 0.3421, 0.343 , 0.3439, 0.3448, 0.3457,\n",
      "       0.3466, 0.3475, 0.3484, 0.3493, 0.3502, 0.3511]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27804 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0030\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.350 - 0.375 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.35  , 0.3509, 0.3518, 0.3527, 0.3536, 0.3545, 0.3554, 0.3563,\n",
      "       0.3572, 0.3581, 0.359 , 0.3599, 0.3608, 0.3617, 0.3626, 0.3635,\n",
      "       0.3644, 0.3653, 0.3662, 0.3671, 0.368 , 0.3689, 0.3698, 0.3707,\n",
      "       0.3716, 0.3725, 0.3734, 0.3743, 0.3752, 0.3761, 0.377 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27144 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0031\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.375 - 0.400 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.375 , 0.3759, 0.3768, 0.3777, 0.3786, 0.3795, 0.3804, 0.3813,\n",
      "       0.3822, 0.3831, 0.384 , 0.3849, 0.3858, 0.3867, 0.3876, 0.3885,\n",
      "       0.3894, 0.3903, 0.3912, 0.3921, 0.393 , 0.3939, 0.3948, 0.3957,\n",
      "       0.3966, 0.3975, 0.3984, 0.3993, 0.4002, 0.4011, 0.402 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 27808 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0032\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.400 - 0.425 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.4   , 0.4009, 0.4018, 0.4027, 0.4036, 0.4045, 0.4054, 0.4063,\n",
      "       0.4072, 0.4081, 0.409 , 0.4099, 0.4108, 0.4117, 0.4126, 0.4135,\n",
      "       0.4144, 0.4153, 0.4162, 0.4171, 0.418 , 0.4189, 0.4198, 0.4207,\n",
      "       0.4216, 0.4225, 0.4234, 0.4243, 0.4252, 0.4261]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 26364 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0033\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.425 - 0.450 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.425 , 0.4259, 0.4268, 0.4277, 0.4286, 0.4295, 0.4304, 0.4313,\n",
      "       0.4322, 0.4331, 0.434 , 0.4349, 0.4358, 0.4367, 0.4376, 0.4385,\n",
      "       0.4394, 0.4403, 0.4412, 0.4421, 0.443 , 0.4439, 0.4448, 0.4457,\n",
      "       0.4466, 0.4475, 0.4484, 0.4493, 0.4502, 0.4511, 0.452 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 25956 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0034\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 2500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.450 - 0.475 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.45  , 0.4509, 0.4518, 0.4527, 0.4536, 0.4545, 0.4554, 0.4563,\n",
      "       0.4572, 0.4581, 0.459 , 0.4599, 0.4608, 0.4617, 0.4626, 0.4635,\n",
      "       0.4644, 0.4653, 0.4662, 0.4671, 0.468 , 0.4689, 0.4698, 0.4707,\n",
      "       0.4716, 0.4725, 0.4734, 0.4743, 0.4752, 0.4761]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 26976 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0035\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.475 - 0.500 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.475 , 0.4759, 0.4768, 0.4777, 0.4786, 0.4795, 0.4804, 0.4813,\n",
      "       0.4822, 0.4831, 0.484 , 0.4849, 0.4858, 0.4867, 0.4876, 0.4885,\n",
      "       0.4894, 0.4903, 0.4912, 0.4921, 0.493 , 0.4939, 0.4948, 0.4957,\n",
      "       0.4966, 0.4975, 0.4984, 0.4993, 0.5002, 0.5011, 0.502 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 26204 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0036\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.500 - 0.525 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.5   , 0.5009, 0.5018, 0.5027, 0.5036, 0.5045, 0.5054, 0.5063,\n",
      "       0.5072, 0.5081, 0.509 , 0.5099, 0.5108, 0.5117, 0.5126, 0.5135,\n",
      "       0.5144, 0.5153, 0.5162, 0.5171, 0.518 , 0.5189, 0.5198, 0.5207,\n",
      "       0.5216, 0.5225, 0.5234, 0.5243, 0.5252, 0.5261, 0.527 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 25228 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0037\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 0.525 - 0.550 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'als_final_current': array([0.525 , 0.5259, 0.5268, 0.5277, 0.5286, 0.5295, 0.5304, 0.5313,\n",
      "       0.5322, 0.5331, 0.534 , 0.5349, 0.5358, 0.5367, 0.5376, 0.5385,\n",
      "       0.5394, 0.5403, 0.5412, 0.5421, 0.543 , 0.5439, 0.5448, 0.5457,\n",
      "       0.5466, 0.5475, 0.5484, 0.5493, 0.5502, 0.5511, 0.552 ]), 'runs': array([0., 1.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 25568 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0038\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (535, 995)\n",
    "imageAnalyser.span = (350, 350)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.ylim([0, 3000])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = xr.concat((Ncount_mean_total, Ncount_mean), dim='als_final_current')\n",
    "Ncount_std_total = xr.concat((Ncount_std_total, Ncount_std), dim='als_final_current')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 100164 characters]",
      "text/plain": [
       "<Figure size 2400x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(24,6))\n",
    "ax = fig.gca()\n",
    "Ncount_mean_total.plot.errorbar(ax=ax, yerr = Ncount_std_total, fmt='ob')\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 51696 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.44224 ± 0.00038 A\n",
      "fwhm = 0.02101 ± 0.00111 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.4, 0.48)\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 46048 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.28128 ± 0.00016 A\n",
      "fwhm = 0.00680 ± 0.00039 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.26, 0.3)\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "params.add(name=\"A_amplitude\", value=  1, max=np.inf, min=-np.inf, vary=True)\n",
      "params.add(name=\"A_center\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
      "params.add(name=\"A_sigma\", value=  1, max=np.inf, min=  0, vary=True)\n",
      "params.add(name=\"B_amplitude\", value=  1, max=np.inf, min=-np.inf, vary=True)\n",
      "params.add(name=\"B_center\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
      "params.add(name=\"B_sigma\", value=  1, max=np.inf, min=  0, vary=True)\n",
      "params.add(name=\"B_offset\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
      "params.add(name=\"A_fwhm\", expr=\"2.3548200*A_sigma\")\n",
      "params.add(name=\"A_height\", expr=\"0.3989423*A_amplitude/max(1e-15, A_sigma)\")\n",
      "params.add(name=\"B_fwhm\", expr=\"2.3548200*B_sigma\")\n",
      "params.add(name=\"B_height\", expr=\"0.3989423*B_amplitude/max(1e-15, B_sigma)\")\n"
     ]
    }
   ],
   "source": [
    "from Analyser.FitAnalyser import GaussianModel, GaussianWithOffsetModel\n",
    "\n",
    "fitModel = GaussianModel(prefix='A_') + GaussianWithOffsetModel(prefix='B_')\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=1)\n",
    "fitAnalyser.print_params_set_template()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 48940 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.22367 ± 0.07911 A\n",
      "fwhm = 0.00031 ± 0.07203 A\n",
      "f = 0.22962 ± 0.00013 A\n",
      "fwhm = 0.00583 ± 0.00038 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.22, 0.240)\n",
    "\n",
    "from Analyser.FitAnalyser import GaussianModel, GaussianWithOffsetModel\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitModel = GaussianModel(prefix='A_') + GaussianWithOffsetModel(prefix='B_')\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=1)\n",
    "# params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"A_amplitude\", value= -0.65, max=np.inf, min=-0.7, vary=True)\n",
    "params.add(name=\"A_center\", value=  0.22321, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigma\", value=  0.00005, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"B_amplitude\", value=  -11, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_center\", value=  0.2280, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigma\", value=  0.0025, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"B_offset\", value=  2500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).A_center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).A_center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).A_sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).A_sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).B_center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).B_center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).B_sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).B_sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 44452 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.21004 ± 0.00012 A\n",
      "fwhm = 0.00118 ± 0.00025 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.208, 0.212)\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 38712 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.18586 ± 0.00021 A\n",
      "fwhm = 0.00085 ± 0.00025 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.183, 0.189)\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -1500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  0.1858, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.001, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  3700, max=np.inf, min=-np.inf, vary=True)\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 38904 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f = 0.17055 ± 0.00175 A\n",
      "fwhm = 0.00069 ± 0.00203 A\n"
     ]
    }
   ],
   "source": [
    "Brange=(0.167, 0.173)\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -10, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  0.1708, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.001, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  3700, max=np.inf, min=-np.inf, vary=True)\n",
    "fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "f_1 = fitAnalyser.get_fit_value(fitResult).center\n",
    "df_1 = fitAnalyser.get_fit_std(fitResult).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "s_1 = fitAnalyser.get_fit_value(fitResult).sigma\n",
    "ds_1 = fitAnalyser.get_fit_std(fitResult).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1\n",
    "dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 33048 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Brange=(0.07, 0.095)\n",
    "\n",
    "from Analyser.FitAnalyser import GaussianModel, GaussianWithOffsetModel\n",
    "\n",
    "data = Ncount_mean_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data = data.dropna(dim='als_final_current')\n",
    "data_std = Ncount_std_total.where(Brange[0]<Ncount_mean_total.als_final_current).where(Ncount_mean_total.als_final_current<Brange[1])\n",
    "data_std = data_std.dropna(dim='als_final_current')\n",
    "\n",
    "# fitModel = GaussianModel(prefix='A_') + GaussianWithOffsetModel(prefix='B_')\n",
    "# fitAnalyser = FitAnalyser(fitModel, fitDim=1)\n",
    "# # fitAnalyser = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# # params = fitAnalyser.guess(data, x='als_final_current', guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "# params = fitAnalyser.fitModel.make_params()\n",
    "# params.add(name=\"A_amplitude\", value= -1, max=np.inf, min=-0.7, vary=True)\n",
    "# params.add(name=\"A_center\", value=  0.09, max=np.inf, min=-np.inf, vary=True)\n",
    "# params.add(name=\"A_sigma\", value=  0.0005, max=np.inf, min=  0, vary=True)\n",
    "# params.add(name=\"B_amplitude\", value=  -11, max=np.inf, min=-np.inf, vary=True)\n",
    "# params.add(name=\"B_center\", value=  0.085, max=np.inf, min=-np.inf, vary=True)\n",
    "# params.add(name=\"B_sigma\", value=  0.01, max=np.inf, min=  0, vary=True)\n",
    "# params.add(name=\"B_offset\", value=  3500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "# fitResult = fitAnalyser.fit(data, params, x='als_final_current', dask=\"parallelized\").load()\n",
    "# fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(Brange[0], Brange[1], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, yerr = data_std, fmt='ob')\n",
    "# fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "# f_1 = fitAnalyser.get_fit_value(fitResult).A_center\n",
    "# df_1 = fitAnalyser.get_fit_std(fitResult).A_center\n",
    "\n",
    "# print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "# s_1 = fitAnalyser.get_fit_value(fitResult).A_sigma\n",
    "# ds_1 = fitAnalyser.get_fit_std(fitResult).A_sigma\n",
    "\n",
    "# fwhm_1 = 2.3548200*s_1\n",
    "# dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "# print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))\n",
    "\n",
    "# f_1 = fitAnalyser.get_fit_value(fitResult).B_center\n",
    "# df_1 = fitAnalyser.get_fit_std(fitResult).B_center\n",
    "\n",
    "# print('f = %.5f \\u00B1 %.5f A'% tuple([np.abs(f_1),df_1]))\n",
    "\n",
    "# s_1 = fitAnalyser.get_fit_value(fitResult).B_sigma\n",
    "# ds_1 = fitAnalyser.get_fit_std(fitResult).B_sigma\n",
    "\n",
    "# fwhm_1 = 2.3548200*s_1\n",
    "# dfwhm_1 = 2.3548200*ds_1\n",
    "\n",
    "# print('fwhm = %.5f \\u00B1 %.5f A'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
       "<defs>\n",
       "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
       "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
       "</symbol>\n",
       "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
       "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
       "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
       "</symbol>\n",
       "</defs>\n",
       "</svg>\n",
       "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
       " *\n",
       " */\n",
       "\n",
       ":root {\n",
       "  --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
       "  --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
       "  --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
       "  --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
       "  --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
       "  --xr-background-color: var(--jp-layout-color0, white);\n",
       "  --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
       "  --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
       "}\n",
       "\n",
       "html[theme=dark],\n",
       "body[data-theme=dark],\n",
       "body.vscode-dark {\n",
       "  --xr-font-color0: rgba(255, 255, 255, 1);\n",
       "  --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
       "  --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
       "  --xr-border-color: #1F1F1F;\n",
       "  --xr-disabled-color: #515151;\n",
       "  --xr-background-color: #111111;\n",
       "  --xr-background-color-row-even: #111111;\n",
       "  --xr-background-color-row-odd: #313131;\n",
       "}\n",
       "\n",
       ".xr-wrap {\n",
       "  display: block !important;\n",
       "  min-width: 300px;\n",
       "  max-width: 700px;\n",
       "}\n",
       "\n",
       ".xr-text-repr-fallback {\n",
       "  /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-header {\n",
       "  padding-top: 6px;\n",
       "  padding-bottom: 6px;\n",
       "  margin-bottom: 4px;\n",
       "  border-bottom: solid 1px var(--xr-border-color);\n",
       "}\n",
       "\n",
       ".xr-header > div,\n",
       ".xr-header > ul {\n",
       "  display: inline;\n",
       "  margin-top: 0;\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-obj-type,\n",
       ".xr-array-name {\n",
       "  margin-left: 2px;\n",
       "  margin-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-obj-type {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-sections {\n",
       "  padding-left: 0 !important;\n",
       "  display: grid;\n",
       "  grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
       "}\n",
       "\n",
       ".xr-section-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-section-item input {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-item input + label {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label {\n",
       "  cursor: pointer;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-item input:enabled + label:hover {\n",
       "  color: var(--xr-font-color0);\n",
       "}\n",
       "\n",
       ".xr-section-summary {\n",
       "  grid-column: 1;\n",
       "  color: var(--xr-font-color2);\n",
       "  font-weight: 500;\n",
       "}\n",
       "\n",
       ".xr-section-summary > span {\n",
       "  display: inline-block;\n",
       "  padding-left: 0.5em;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label {\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in + label:before {\n",
       "  display: inline-block;\n",
       "  content: '►';\n",
       "  font-size: 11px;\n",
       "  width: 15px;\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:disabled + label:before {\n",
       "  color: var(--xr-disabled-color);\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label:before {\n",
       "  content: '▼';\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked + label > span {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-section-summary,\n",
       ".xr-section-inline-details {\n",
       "  padding-top: 4px;\n",
       "  padding-bottom: 4px;\n",
       "}\n",
       "\n",
       ".xr-section-inline-details {\n",
       "  grid-column: 2 / -1;\n",
       "}\n",
       "\n",
       ".xr-section-details {\n",
       "  display: none;\n",
       "  grid-column: 1 / -1;\n",
       "  margin-bottom: 5px;\n",
       "}\n",
       "\n",
       ".xr-section-summary-in:checked ~ .xr-section-details {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-array-wrap {\n",
       "  grid-column: 1 / -1;\n",
       "  display: grid;\n",
       "  grid-template-columns: 20px auto;\n",
       "}\n",
       "\n",
       ".xr-array-wrap > label {\n",
       "  grid-column: 1;\n",
       "  vertical-align: top;\n",
       "}\n",
       "\n",
       ".xr-preview {\n",
       "  color: var(--xr-font-color3);\n",
       "}\n",
       "\n",
       ".xr-array-preview,\n",
       ".xr-array-data {\n",
       "  padding: 0 5px !important;\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-array-data,\n",
       ".xr-array-in:checked ~ .xr-array-preview {\n",
       "  display: none;\n",
       "}\n",
       "\n",
       ".xr-array-in:checked ~ .xr-array-data,\n",
       ".xr-array-preview {\n",
       "  display: inline-block;\n",
       "}\n",
       "\n",
       ".xr-dim-list {\n",
       "  display: inline-block !important;\n",
       "  list-style: none;\n",
       "  padding: 0 !important;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list li {\n",
       "  display: inline-block;\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "}\n",
       "\n",
       ".xr-dim-list:before {\n",
       "  content: '(';\n",
       "}\n",
       "\n",
       ".xr-dim-list:after {\n",
       "  content: ')';\n",
       "}\n",
       "\n",
       ".xr-dim-list li:not(:last-child):after {\n",
       "  content: ',';\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-has-index {\n",
       "  font-weight: bold;\n",
       "}\n",
       "\n",
       ".xr-var-list,\n",
       ".xr-var-item {\n",
       "  display: contents;\n",
       "}\n",
       "\n",
       ".xr-var-item > div,\n",
       ".xr-var-item label,\n",
       ".xr-var-item > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-even);\n",
       "  margin-bottom: 0;\n",
       "}\n",
       "\n",
       ".xr-var-item > .xr-var-name:hover span {\n",
       "  padding-right: 5px;\n",
       "}\n",
       "\n",
       ".xr-var-list > li:nth-child(odd) > div,\n",
       ".xr-var-list > li:nth-child(odd) > label,\n",
       ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
       "  background-color: var(--xr-background-color-row-odd);\n",
       "}\n",
       "\n",
       ".xr-var-name {\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-var-dims {\n",
       "  grid-column: 2;\n",
       "}\n",
       "\n",
       ".xr-var-dtype {\n",
       "  grid-column: 3;\n",
       "  text-align: right;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-preview {\n",
       "  grid-column: 4;\n",
       "}\n",
       "\n",
       ".xr-index-preview {\n",
       "  grid-column: 2 / 5;\n",
       "  color: var(--xr-font-color2);\n",
       "}\n",
       "\n",
       ".xr-var-name,\n",
       ".xr-var-dims,\n",
       ".xr-var-dtype,\n",
       ".xr-preview,\n",
       ".xr-attrs dt {\n",
       "  white-space: nowrap;\n",
       "  overflow: hidden;\n",
       "  text-overflow: ellipsis;\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-var-name:hover,\n",
       ".xr-var-dims:hover,\n",
       ".xr-var-dtype:hover,\n",
       ".xr-attrs dt:hover {\n",
       "  overflow: visible;\n",
       "  width: auto;\n",
       "  z-index: 1;\n",
       "}\n",
       "\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  display: none;\n",
       "  background-color: var(--xr-background-color) !important;\n",
       "  padding-bottom: 5px !important;\n",
       "}\n",
       "\n",
       ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
       ".xr-var-data-in:checked ~ .xr-var-data,\n",
       ".xr-index-data-in:checked ~ .xr-index-data {\n",
       "  display: block;\n",
       "}\n",
       "\n",
       ".xr-var-data > table {\n",
       "  float: right;\n",
       "}\n",
       "\n",
       ".xr-var-name span,\n",
       ".xr-var-data,\n",
       ".xr-index-name div,\n",
       ".xr-index-data,\n",
       ".xr-attrs {\n",
       "  padding-left: 25px !important;\n",
       "}\n",
       "\n",
       ".xr-attrs,\n",
       ".xr-var-attrs,\n",
       ".xr-var-data,\n",
       ".xr-index-data {\n",
       "  grid-column: 1 / -1;\n",
       "}\n",
       "\n",
       "dl.xr-attrs {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  display: grid;\n",
       "  grid-template-columns: 125px auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt,\n",
       ".xr-attrs dd {\n",
       "  padding: 0;\n",
       "  margin: 0;\n",
       "  float: left;\n",
       "  padding-right: 10px;\n",
       "  width: auto;\n",
       "}\n",
       "\n",
       ".xr-attrs dt {\n",
       "  font-weight: normal;\n",
       "  grid-column: 1;\n",
       "}\n",
       "\n",
       ".xr-attrs dt:hover span {\n",
       "  display: inline-block;\n",
       "  background: var(--xr-background-color);\n",
       "  padding-right: 10px;\n",
       "}\n",
       "\n",
       ".xr-attrs dd {\n",
       "  grid-column: 2;\n",
       "  white-space: pre-wrap;\n",
       "  word-break: break-all;\n",
       "}\n",
       "\n",
       ".xr-icon-database,\n",
       ".xr-icon-file-text2,\n",
       ".xr-no-icon {\n",
       "  display: inline-block;\n",
       "  vertical-align: middle;\n",
       "  width: 1em;\n",
       "  height: 1.5em !important;\n",
       "  stroke-width: 0;\n",
       "  stroke: currentColor;\n",
       "  fill: currentColor;\n",
       "}\n",
       "</style><pre class='xr-text-repr-fallback'>&lt;xarray.DataArray &#x27;OD&#x27; (als_final_current: 1)&gt;\n",
       "array([332.40889692])\n",
       "Coordinates:\n",
       "  * als_final_current  (als_final_current) float64 0.0903</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.DataArray</div><div class='xr-array-name'>'OD'</div><ul class='xr-dim-list'><li><span class='xr-has-index'>als_final_current</span>: 1</li></ul></div><ul class='xr-sections'><li class='xr-section-item'><div class='xr-array-wrap'><input id='section-003831ed-ef8c-4353-a89a-07d86978ba42' class='xr-array-in' type='checkbox' checked><label for='section-003831ed-ef8c-4353-a89a-07d86978ba42' title='Show/hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-array-preview xr-preview'><span>332.4</span></div><div class='xr-array-data'><pre>array([332.40889692])</pre></div></div></li><li class='xr-section-item'><input id='section-4cc78a1f-a9a6-41c2-925f-7a400b6a7c67' class='xr-section-summary-in' type='checkbox'  checked><label for='section-4cc78a1f-a9a6-41c2-925f-7a400b6a7c67' class='xr-section-summary' >Coordinates: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>als_final_current</span></div><div class='xr-var-dims'>(als_final_current)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0903</div><input id='attrs-77640650-a651-4b7f-9a87-bfb5fff7b00a' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-77640650-a651-4b7f-9a87-bfb5fff7b00a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-159832ff-7ba7-40e1-bdef-5e2129e28470' class='xr-var-data-in' type='checkbox'><label for='data-159832ff-7ba7-40e1-bdef-5e2129e28470' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'></dl></div><div class='xr-var-data'><pre>array([0.0903])</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-ab676435-7c40-4818-b13d-724fa314ba5f' class='xr-section-summary-in' type='checkbox'  ><label for='section-ab676435-7c40-4818-b13d-724fa314ba5f' class='xr-section-summary' >Indexes: <span>(1)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-index-name'><div>als_final_current</div></div><div class='xr-index-preview'>PandasIndex</div><div></div><input id='index-84aad126-830b-4d0d-b08c-642b0b846989' class='xr-index-data-in' type='checkbox'/><label for='index-84aad126-830b-4d0d-b08c-642b0b846989' title='Show/Hide index repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-index-data'><pre>PandasIndex(Float64Index([0.0903], dtype=&#x27;float64&#x27;, name=&#x27;als_final_current&#x27;))</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-733a1cca-031d-4106-9c7c-717e605f3e7c' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-733a1cca-031d-4106-9c7c-717e605f3e7c' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.DataArray 'OD' (als_final_current: 1)>\n",
       "array([332.40889692])\n",
       "Coordinates:\n",
       "  * als_final_current  (als_final_current) float64 0.0903"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.where(data==data.min(), drop='True')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total_origin = copy.deepcopy(Ncount_mean_total)\n",
    "Ncount_mean_std_origin = copy.deepcopy(Ncount_std_total)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<xarray.backends.zarr.ZarrStore at 0x29546678dd0>"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res = Ncount_mean_total_origin.to_dataset()\n",
    "res = res.assign(std = Ncount_mean_std_origin)\n",
    "res.to_zarr('./CompZ.zarr')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Ncount_mean_total = copy.deepcopy(Ncount_mean_total_origin)\n",
    "Ncount_mean_std = copy.deepcopy(Ncount_mean_std_origin)\n",
    "\n",
    "B = np.sqrt((Ncount_mean_total['als_final_current'] * 10.6021 + 0.3254)**2 + (0.4333**2 - 0.3254**2))\n",
    "Ncount_mean_total['als_final_current'] = B\n",
    "Ncount_std_total['als_final_current'] = B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.patches as patches\n",
    "\n",
    "B0 = [1.2950, 1.3060, 2.1740, 2.3360, 2.5910, 2.7400, 2.8030, 2.7800, 3.3570, 4.9490, 5.0830]# , 7.1720, 7.2040, 7.1340]\n",
    "B0_width = [0.0090, 0.0100, 0.0005, 0.0005, 0.0010, 0.0005, 0.0210, 0.0150, 0.0430, 0.0005, 0.1300]# , 0.0240, 0.0005, 0.0360]\n",
    "\n",
    "fig = plt.figure(figsize=(24,6))\n",
    "ax = fig.gca()\n",
    "Ncount_mean_total.plot.errorbar(ax=ax, yerr = Ncount_std_total, fmt='ob')\n",
    "\n",
    "for i in range(len(B0)):\n",
    "    rect = patches.Rectangle((B0[i] - B0_width[i], 000), B0_width[i]*2, 4000, linewidth=1, edgecolor='r', facecolor='r', alpha=0.4)\n",
    "    ax.add_patch(rect)\n",
    "\n",
    "plt.ylim([0, 4500])\n",
    "plt.ylabel('NCount')\n",
    "plt.xlabel('Magnetic Field (G)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = [0.44224, 0.28128, 0.22367, 0.22962, 0.21004, 0.18586, 0.17055, 0.0903] \n",
    "df = [0.00038, 0.00016, 0.01, 0.00013, 0.00012, 0.00021, 0.00175, 0]\n",
    "B = [(1.2950 + 1.3060)/2, 2.1740, 2.3360, 2.5910, 2.7400, (2.8030 + 2.7800)/2, 3.3570, 5.0830]# , 7.1720, 7.2040, 7.1340]\n",
    "\n",
    "# f = [0.44224, 0.28128, 0.21004, 0.18586, 0.17055, 0.0903] \n",
    "# df = [0.00038, 0.00016, 0.00012, 0.00021, 0.00175, 0]\n",
    "# B = [(1.2950 + 1.3060)/2, 2.1740, 2.3360, 2.5910, 3.3570, 5.0830]# , 7.1720, 7.2040, 7.1340]\n",
    "B = np.flip(B)\n",
    "\n",
    "data = xr.DataArray(\n",
    "    data=B,\n",
    "    dims='x',\n",
    "    coords=dict(x=f)\n",
    ")\n",
    "\n",
    "data_std = xr.DataArray(\n",
    "    data=df,\n",
    "    dims='x',\n",
    "    coords=dict(x=f)\n",
    ")\n",
    "\n",
    "fitAnalyser = FitAnalyser(\"Linear\", fitDim=1)\n",
    "params = fitAnalyser.guess(data, dask=\"parallelized\")\n",
    "# params = fitAnalyser.fitModel.make_params()\n",
    "fitResult = fitAnalyser.fit(data, params, dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=np.linspace(f[-1], f[0], 500), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "data.plot.errorbar(ax=ax, xerr = df, fmt='ob')\n",
    "fitCurve.plot.errorbar(ax=ax)\n",
    "\n",
    "# plt.ylim([0, 4500])\n",
    "plt.ylabel('Magnetic Field (G)')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "slope = fitAnalyser.get_fit_value(fitResult).slope\n",
    "dslope = fitAnalyser.get_fit_std(fitResult).slope\n",
    "\n",
    "print('slope = %.5f \\u00B1 %.5f A'% tuple([np.abs(slope),dslope]))\n",
    "\n",
    "intercept = fitAnalyser.get_fit_value(fitResult).intercept\n",
    "dintercept = fitAnalyser.get_fit_std(fitResult).intercept\n",
    "\n",
    "print('intercept = %.5f \\u00B1 %.5f A'% tuple([np.abs(intercept),dintercept]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def magnetic_field_func(x, b0=0, by0=0, alpha=1):\n",
    "    return np.sqrt( (b0**2 - by0**2) + (alpha * x + by0)**2 )\n",
    "\n",
    "data_quadratic = data\n",
    "\n",
    "fitModel_quadratic = NewFitModel(magnetic_field_func)\n",
    "fitAnalyser_quadratic = FitAnalyser(fitModel_quadratic, fitDim=1)\n",
    "params_quadratic = fitAnalyser_quadratic.fitModel.make_params()\n",
    "params_quadratic.add(name=\"b0\", value=  0.4333, max=np.inf, min=-np.inf, vary=True)\n",
    "params_quadratic.add(name=\"by0\", value=  0.33732, max=np.inf, min=-np.inf, vary=True)\n",
    "params_quadratic.add(name=\"alpha\", value=  10.6021, max=np.inf, min=-np.inf, vary=True)\n",
    "fitResult_quadratic = fitAnalyser_quadratic.fit(data_quadratic, params_quadratic).load()\n",
    "\n",
    "fitCurve_quadratic = fitAnalyser_quadratic.eval(fitResult_quadratic, x=np.linspace(0, 0.6, 100), dask=\"parallelized\").load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_linear = data[3:]\n",
    "\n",
    "fitAnalyser_linear = FitAnalyser('Linear', fitDim=1)\n",
    "params_linear = fitAnalyser_linear.guess(data_linear, dask=\"parallelized\")\n",
    "fitResult_linear = fitAnalyser_linear.fit(data_linear, params_linear).load()\n",
    "\n",
    "fitCurve_linear = fitAnalyser_linear.eval(fitResult_linear, x=np.linspace(0, 0.5, 100), dask=\"parallelized\").load()\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "data.plot.errorbar(ax=ax, fmt='ob', yerr=data_std)\n",
    "# fitCurve_linear.plot.errorbar(ax=ax)\n",
    "fitCurve_quadratic.plot.errorbar(ax=ax)\n",
    "\n",
    "plt.ylabel('Magnetic Field (G)')\n",
    "plt.xlabel('Z_offset current (A)')\n",
    "plt.xticks(fontsize=12)\n",
    "plt.yticks(fontsize=12)\n",
    "# plt.legend(fontsize=12)\n",
    "#plt.xlim(-0.01, 0.04)\n",
    "# plt.ylim(0, 10000)\n",
    "plt.grid(visible=1)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha = fitAnalyser.get_fit_value(fitResult_quadratic).alpha\n",
    "dalpha = fitAnalyser.get_fit_std(fitResult_quadratic).alpha\n",
    "\n",
    "print('alpha = %.5f \\u00B1 %.5f G/A'% tuple([np.abs(alpha),dalpha]))\n",
    "\n",
    "beta = fitAnalyser.get_fit_value(fitResult_quadratic).by0\n",
    "dbeta = fitAnalyser.get_fit_std(fitResult_quadratic).by0\n",
    "\n",
    "print('beta = %.5f \\u00B1 %.5f A'% tuple([beta,dbeta]))\n",
    "\n",
    "b0 = fitAnalyser.get_fit_value(fitResult_quadratic).b0\n",
    "db0 = fitAnalyser.get_fit_std(fitResult_quadratic).b0\n",
    "\n",
    "print('b0 = %.5f \\u00B1 %.5f A'% tuple([b0,db0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([0], [9.46], fmt='ob', label='Theory')\n",
    "ax.errorbar([1], [9.52], yerr=[0.05], fmt='or', label='RF')\n",
    "ax.errorbar([2], [9.523], yerr=[0.019], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [9.576], yerr=[0.032], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.ylabel('Alpha X (G/A)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [-0.164], yerr=[0.017], fmt='or', label='RF')\n",
    "ax.errorbar([2], [0.105], yerr=[0.006], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [ -0.138], yerr=[0.018], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.xlim([-0.1, 3.1])\n",
    "plt.ylabel('Beta X (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([0], [10.75], fmt='ob', label='Theory')\n",
    "ax.errorbar([1], [10.6021], yerr=[0.0022], fmt='or', label='RF')\n",
    "ax.errorbar([2], [10.73], yerr=[0.12], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [10.683], yerr=[0.028], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.ylabel('Alpha Z (G/A)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [0.3254], yerr=[0.0008], fmt='or', label='RF')\n",
    "ax.errorbar([2], [0.337], yerr=[0.031], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [0.365], yerr=[0.014], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.xlim([-0.1, 3.1])\n",
    "plt.ylabel('Beta Z (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([0], [10.18], fmt='ob', label='Theory')\n",
    "ax.errorbar([1], [10.30], yerr=[0.05], fmt='or', label='RF')\n",
    "ax.errorbar([2], [10.447], yerr=[0.023], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [10.516], yerr=[0.038], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.ylabel('Alpha Y (G/A)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [0.202], yerr=[0.015], fmt='or', label='RF')\n",
    "ax.errorbar([2], [0.0762 ], yerr=[0.0064], fmt='og', label='ALS Linear')\n",
    "ax.errorbar([3], [0.039 ], yerr=[0.019], fmt='ok', label='ALS Quadratic')\n",
    "\n",
    "plt.xlim([-0.1, 3.1])\n",
    "plt.ylabel('Beta Y (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [-0.164], yerr=[0.017], fmt='or', label='RF')\n",
    "ax.errorbar([3], [-0.138], yerr=[0.018], fmt='ok', label='ALS Quadratic')\n",
    "ax.errorbar([4], [0.417], yerr=[0.01], fmt='ob', label='RF average')\n",
    "\n",
    "plt.xlim([-0.1, 4.1])\n",
    "plt.ylabel('B0 X (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [0.440], yerr=[0.009], fmt='or', label='RF')\n",
    "ax.errorbar([3], [0.313], yerr=[0.071], fmt='ok', label='ALS Quadratic')\n",
    "ax.errorbar([4], [0.417], yerr=[0.01], fmt='ob', label='RF average')\n",
    "\n",
    "plt.xlim([-0.1, 4.1])\n",
    "plt.ylabel('B0 Y (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "ax.errorbar([1], [0.4333], yerr=[0.0007], fmt='or', label='RF')\n",
    "ax.errorbar([3], [0.243 ], yerr=[0.054], fmt='ok', label='ALS Quadratic')\n",
    "ax.errorbar([4], [0.417], yerr=[0.01], fmt='ob', label='RF average')\n",
    "\n",
    "plt.xlim([-0.1, 4.1])\n",
    "plt.ylabel('B0 Z (G)')\n",
    "\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0024\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i], excludeAxis = ['sweep_start_freq', 'sweep_stop_freq'])\n",
    "    for i in [0]\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_0\"]\n",
    "\n",
    "print_scanAxis(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "imageAnalyser.center = (135, 990)\n",
    "imageAnalyser.span = (250, 250)\n",
    "imageAnalyser.fraction = (0.1, 0.1)\n",
    "\n",
    "dataSet_cropOD = imageAnalyser.crop_image(dataSet.OD)\n",
    "dataSet_cropOD = imageAnalyser.substract_offset(dataSet_cropOD).load()\n",
    "\n",
    "Ncount = imageAnalyser.get_Ncount(dataSet_cropOD)\n",
    "Ncount_mean = calculate_mean(Ncount)\n",
    "Ncount_std = calculate_std(Ncount)\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "#plt.ylim([0, 3500])\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "l = list(np.arange(525e-3, 552e-3, 0.9e-3))\n",
    "# l = np.logspace(np.log10(250e-6), np.log10(500e-3), num=15)\n",
    "\n",
    "l = [round(item, 7) for item in l]\n",
    "#random.shuffle(l)\n",
    "\n",
    "print(l)\n",
    "print(len(l))\n",
    "np.mean(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pixel = 5.86e-6\n",
    "M     = 0.6827\n",
    "F = (1/(0.3725*8.4743e-14)) * (pixel / M)**2\n",
    "NCount = 85000\n",
    "AtomNumber = NCount * F / 1e8\n",
    "print(AtomNumber)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "muB = 9.274e-24\n",
    "hbar = 6.626e-34 / (2 * np.pi)\n",
    "gJ = 1.24\n",
    "Delta = 2 * np.pi * 100 * 1e3\n",
    "\n",
    "Bz = (Delta*hbar) / (muB*gJ)\n",
    "print(Bz * 1e4)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ODT 1 Calibration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_high = 2.7\n",
    "\"\"\"High Power\"\"\"\n",
    "P_arm1_high = 5.776 * v_high - 0.683\n",
    "\n",
    "v_mid = 0.2076\n",
    "\"\"\"Intermediate Power\"\"\"\n",
    "P_arm1_mid = 5.815 * v_mid - 0.03651\n",
    "\n",
    "v_low = 0.062\n",
    "\"\"\"Low Power\"\"\"\n",
    "P_arm1_low = 5271 * v_low - 27.5\n",
    "\n",
    "print(round(P_arm1_high, 3))\n",
    "print(round(P_arm1_mid, 3))\n",
    "print(round(P_arm1_low, 3))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ODT 2 Power Calibration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v = 0.842\n",
    "P_arm2 = 2.302 * v - 0.06452\n",
    "print(round(P_arm2, 3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.12"
  },
  "vscode": {
   "interpreter": {
    "hash": "c05913ad4f24fdc6b2418069394dc5835b1981849b107c9ba6df693aafd66650"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
