{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import supporting package"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "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": 2,
   "metadata": {},
   "outputs": [
    {
     "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-f69f7e77-14be-11ee-a66c-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:8787/status\" target=\"_blank\">http://127.0.0.1:8787/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;\">cbd5084a</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:8787/status\" target=\"_blank\">http://127.0.0.1:8787/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-0b555d69-83fd-43e1-9215-9c67aeb6d78c</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:61752\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:8787/status\" target=\"_blank\">http://127.0.0.1:8787/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:61792\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:61794/status\" target=\"_blank\">http://127.0.0.1:61794/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:61755\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-vwm7x29k\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:61793\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:61798/status\" target=\"_blank\">http://127.0.0.1:61798/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:61756\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-dsm02jmm\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:61810\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:61811/status\" target=\"_blank\">http://127.0.0.1:61811/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:61757\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-kb6dkrm1\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:61775\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:61790/status\" target=\"_blank\">http://127.0.0.1:61790/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:61758\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-vtzwx9iy\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:61804\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:61806/status\" target=\"_blank\">http://127.0.0.1:61806/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:61759\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-a97vh11n\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:61796\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:61801/status\" target=\"_blank\">http://127.0.0.1:61801/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:61760\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-2jc_h5j9\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:61797\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:61800/status\" target=\"_blank\">http://127.0.0.1:61800/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:61761\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-mvwb15rr\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:61805\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:61808/status\" target=\"_blank\">http://127.0.0.1:61808/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:61762\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-co4d63m7\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:61752' processes=8 threads=128, memory=149.01 GiB>"
      ]
     },
     "execution_count": 2,
     "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": 3,
   "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": 4,
   "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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_dir = 'C:/Users/control/DyLab/Experiments/DyBEC/'\n",
    "SequenceName = \"Repetition_scan\"\n",
    "folderPath = img_dir + SequenceName + \"/\" + get_date()\n",
    "\n",
    "mongoDB = mongoClient[SequenceName]\n",
    "\n",
    "DB = MongoDB(mongoClient, mongoDB, date=get_date())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Repetition Scans"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scan MOT freq - Z Comp 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0001\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\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 = (310, 825)\n",
    "imageAnalyser.span = (550, 1200)\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 = Ncount.mean(dim='runs')\n",
    "Ncount_std = Ncount.std(dim='runs')\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "plt.xlabel('MOT AOM Freq (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "DB.create_global(shotNum, dataSet)\n",
    "DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scan Push freq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0002\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\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 = (310, 825)\n",
    "imageAnalyser.span = (525, 1255)\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.xlabel('Push AOM Freq (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "DB.create_global(shotNum, dataSet)\n",
    "DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scan Z comp current"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0005\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\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 = (305, 875)\n",
    "imageAnalyser.span = (400, 400)\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.xlabel('comp Z current (A)')\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "DB.create_global(shotNum, dataSet)\n",
    "DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## scan cMOT final Amp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "shotNum = \"0006\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\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 = (305, 875)\n",
    "imageAnalyser.span = (400, 400)\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.xlabel('cMOT final Amp (%)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 25000])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "DB.create_global(shotNum, dataSet)\n",
    "DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0011\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\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 = (305, 875)\n",
    "imageAnalyser.span = (400, 400)\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.xlabel('comp Z current (A)')\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "DB.create_global(shotNum, dataSet)\n",
    "DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Evaporative Cooling"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_dir = '//DyLabNAS/Data/'\n",
    "SequenceName = \"Evaporative_Cooling\"\n",
    "#folderPath = img_dir + SequenceName + \"/\" + get_date()\n",
    "folderPath = img_dir + SequenceName + \"/2023/06/20\"\n",
    "\n",
    "mongoDB = mongoClient[SequenceName]\n",
    "\n",
    "DB = MongoDB(mongoClient, mongoDB, date=get_date())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calibration of the magnetic fields"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.119 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0004\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -6000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  2.9576, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  6000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(2.9445, 2.9601, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 3500])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.189 A, 0.25 Vpp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0008\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i], maxFileNum = 100, 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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -6000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  4.25, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  6000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(4.2375, 4.266, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 3500])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.189 A, 0.5 Vpp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0009\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i], maxFileNum = 100, 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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -6000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  4.25, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  6000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(4.23, 4.275, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 3500])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.189 A, 1 Vpp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0010\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i], maxFileNum = 100, 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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -6000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  4.25, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  6000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(4.23, 4.275, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 3500])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.189 A, 3 Vpp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0011\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i], maxFileNum = 80, 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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -6000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  4.25, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  6000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(4.22, 4.275, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.ylim([0, 3500])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Scan Z offset field during evaporation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The detected scaning axes and values are: \n",
      "\n",
      "{'compZ_current_sg': array([0.18 , 0.182, 0.184, 0.186, 0.188, 0.19 , 0.192, 0.194, 0.196,\n",
      "       0.198, 0.2  , 0.202, 0.204, 0.206, 0.208, 0.21 , 0.212, 0.214,\n",
      "       0.216, 0.218, 0.22 ]), 'runs': array([0., 1., 2.])}\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 38592 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "shotNum = \"0015\"\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 = (890, 880)\n",
    "imageAnalyser.span = (150, 150)\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.xlabel('comp Z current (A)')\n",
    "plt.ylabel('NCount')\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()\n",
    "\n",
    "# DB.create_global(shotNum, dataSet)\n",
    "# DB.add_data(shotNum, dataSet_cropOD, engine='xarray')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 84328 characters]",
      "text/plain": [
       "<Figure size 640x480 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure()\n",
    "\n",
    "data = dataSet_cropOD.sel(compZ_current_sg = 0.198, runs=0)\n",
    "data = data.assign_coords(x=data.x * 2.352 * 5.86)\n",
    "data = data.assign_coords(y=data.y * 2.352 * 5.86)\n",
    "\n",
    "data.plot.pcolormesh(cmap='jet', vmin=0, vmax=2)\n",
    "\n",
    "plt.title('')\n",
    "plt.xlabel('x ($\\mu m$)')\n",
    "plt.ylabel('y ($\\mu m$)')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "f:\\Jianshun\\analyseScript\\Analyser\\FitAnalyser.py:86: RuntimeWarning: invalid value encountered in power\n",
      "  res = (1- ((x-centerx)/(sigmax))**2 - ((y-centery)/(sigmay))**2)**(3 / 2)\n"
     ]
    }
   ],
   "source": [
    "data = dataSet_cropOD.sel(compZ_current_sg = 0.198, runs=0)\n",
    "\n",
    "fitModel = DensityProfileBEC2dModel()\n",
    "fitAnalyser_1 = FitAnalyser(fitModel, fitDim=2)\n",
    "\n",
    "params = fitAnalyser_1.guess(data, dask=\"parallelized\")\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(data, params).load()\n",
    "\n",
    "# x = np.linspace(2.7725, 2.822, 500)\n",
    "# y = np.linspace(2.7725, 2.822, 500)\n",
    "# fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=x, y=y, dask=\"parallelized\").load()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\data\\AppData\\Roaming\\Python\\Python39\\site-packages\\numpy\\lib\\function_base.py:2246: RuntimeWarning: invalid value encountered in _get_fit_full_result_single (vectorized)\n",
      "  outputs = ufunc(*inputs)\n"
     ]
    },
    {
     "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.Dataset&gt;\n",
       "Dimensions:              ()\n",
       "Coordinates:\n",
       "    compZ_current_sg     float64 0.198\n",
       "    runs                 float64 0.0\n",
       "Data variables:\n",
       "    BEC_amplitude        object 792.7896024042066+/-nan\n",
       "    thermal_amplitude    object 0.0+/-nan\n",
       "    BEC_centerx          object 72.03322637975705+/-nan\n",
       "    BEC_centery          object 74.15709273093088+/-nan\n",
       "    thermal_centerx      object 73.1219837873983+/-nan\n",
       "    thermal_centery      object 75.0675362391377+/-nan\n",
       "    BEC_sigmax           object 25.92336716503899+/-nan\n",
       "    BEC_sigmay           object 10.643305951751195+/-nan\n",
       "    thermal_sigmax       object 17.18976684635309+/-nan\n",
       "    thermal_sigmay       object 14.449859669689275+/-nan\n",
       "    thermalAspectRatio   object 0.8406082408706373+/-nan\n",
       "    condensate_fraction  object 1.0+/-nan\n",
       "Attributes:\n",
       "    IMAGE_SUBCLASS:       IMAGE_GRAYSCALE\n",
       "    IMAGE_VERSION:        1.2\n",
       "    IMAGE_WHITE_IS_ZERO:  0\n",
       "    x_start:              815\n",
       "    x_end:                965\n",
       "    y_end:                955\n",
       "    y_start:              805\n",
       "    x_center:             890\n",
       "    y_center:             880\n",
       "    x_span:               150\n",
       "    y_span:               150</pre><div class='xr-wrap' style='display:none'><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-ee805def-8782-4ff7-aaa5-0307542091fe' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-ee805def-8782-4ff7-aaa5-0307542091fe' class='xr-section-summary'  title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-bbeb3fd8-9d26-42ce-a0f6-9e9fccaac797' class='xr-section-summary-in' type='checkbox'  checked><label for='section-bbeb3fd8-9d26-42ce-a0f6-9e9fccaac797' class='xr-section-summary' >Coordinates: <span>(2)</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>compZ_current_sg</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.198</div><input id='attrs-290bd221-ede4-4895-b984-6361188a7a61' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-290bd221-ede4-4895-b984-6361188a7a61' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0fc86fa5-f9e1-436b-96fd-ee93ac5da45c' class='xr-var-data-in' type='checkbox'><label for='data-0fc86fa5-f9e1-436b-96fd-ee93ac5da45c' 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.198)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>runs</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>0.0</div><input id='attrs-0c115949-5d9f-4808-a73d-8486b09d9ef7' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-0c115949-5d9f-4808-a73d-8486b09d9ef7' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-7240579c-8983-46b8-8df4-f5586e5c5c9d' class='xr-var-data-in' type='checkbox'><label for='data-7240579c-8983-46b8-8df4-f5586e5c5c9d' 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.)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-1b80cf78-e245-4bdf-b9d3-38af0d71eae7' class='xr-section-summary-in' type='checkbox'  checked><label for='section-1b80cf78-e245-4bdf-b9d3-38af0d71eae7' class='xr-section-summary' >Data variables: <span>(12)</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>BEC_amplitude</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>792.7896024042066+/-nan</div><input id='attrs-829f02b0-3ab6-4c29-a25b-a21789ce5b42' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-829f02b0-3ab6-4c29-a25b-a21789ce5b42' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1ef932b3-726d-43a3-a5de-0dcf8f5a42f6' class='xr-var-data-in' type='checkbox'><label for='data-1ef932b3-726d-43a3-a5de-0dcf8f5a42f6' 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(792.7896024042066+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermal_amplitude</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>0.0+/-nan</div><input id='attrs-325b3b78-a941-4d6a-b7d1-990d99338c66' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-325b3b78-a941-4d6a-b7d1-990d99338c66' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-a6a0ed95-0836-42a9-84a8-f21fafc8c87c' class='xr-var-data-in' type='checkbox'><label for='data-a6a0ed95-0836-42a9-84a8-f21fafc8c87c' 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.0+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>BEC_centerx</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>72.03322637975705+/-nan</div><input id='attrs-bba65f9c-d068-4d2a-997f-d59e73c00815' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-bba65f9c-d068-4d2a-997f-d59e73c00815' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-e47fe682-8729-48dd-84e3-8519bd55cdbd' class='xr-var-data-in' type='checkbox'><label for='data-e47fe682-8729-48dd-84e3-8519bd55cdbd' 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(72.03322637975705+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>BEC_centery</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>74.15709273093088+/-nan</div><input id='attrs-f9cfbeac-597e-435f-b815-f22b515ccc6b' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-f9cfbeac-597e-435f-b815-f22b515ccc6b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-dde4a815-c791-4da9-8a62-df7acf73d8eb' class='xr-var-data-in' type='checkbox'><label for='data-dde4a815-c791-4da9-8a62-df7acf73d8eb' 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(74.15709273093088+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermal_centerx</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>73.1219837873983+/-nan</div><input id='attrs-ecef8712-c5f6-4562-98c6-4f212d91bf5d' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ecef8712-c5f6-4562-98c6-4f212d91bf5d' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-72ff6427-fdba-4430-bca9-7fb4a2a5123c' class='xr-var-data-in' type='checkbox'><label for='data-72ff6427-fdba-4430-bca9-7fb4a2a5123c' 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(73.1219837873983+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermal_centery</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>75.0675362391377+/-nan</div><input id='attrs-b0873bad-e216-468d-a0ab-d3618fee8275' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-b0873bad-e216-468d-a0ab-d3618fee8275' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c4c9ca1a-1373-4dd1-88ad-b2406ba71c9e' class='xr-var-data-in' type='checkbox'><label for='data-c4c9ca1a-1373-4dd1-88ad-b2406ba71c9e' 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(75.0675362391377+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>BEC_sigmax</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>25.92336716503899+/-nan</div><input id='attrs-dc327619-c896-4a56-b50b-44666fe31227' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-dc327619-c896-4a56-b50b-44666fe31227' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-af3ece8f-8eb2-4e6a-9759-3e4df0202e65' class='xr-var-data-in' type='checkbox'><label for='data-af3ece8f-8eb2-4e6a-9759-3e4df0202e65' 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(25.92336716503899+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>BEC_sigmay</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>10.643305951751195+/-nan</div><input id='attrs-a8adae5d-d924-4146-9c94-b613464e2415' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-a8adae5d-d924-4146-9c94-b613464e2415' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-ca6acbbe-f9cb-4353-bbae-c96c6fe41958' class='xr-var-data-in' type='checkbox'><label for='data-ca6acbbe-f9cb-4353-bbae-c96c6fe41958' 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(10.643305951751195+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermal_sigmax</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>17.18976684635309+/-nan</div><input id='attrs-5e4e1667-afc4-48e4-a761-087c233df25c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-5e4e1667-afc4-48e4-a761-087c233df25c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-6b67ab31-cd74-4079-8283-c63cfefa77a7' class='xr-var-data-in' type='checkbox'><label for='data-6b67ab31-cd74-4079-8283-c63cfefa77a7' 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(17.18976684635309+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermal_sigmay</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>14.449859669689275+/-nan</div><input id='attrs-cef60924-f084-4637-b29d-43379935d91a' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-cef60924-f084-4637-b29d-43379935d91a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-efca491e-3c05-49ff-971a-b41bc9bc4e15' class='xr-var-data-in' type='checkbox'><label for='data-efca491e-3c05-49ff-971a-b41bc9bc4e15' 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(14.449859669689275+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>thermalAspectRatio</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>0.8406082408706373+/-nan</div><input id='attrs-4619e4bc-31c7-40d1-8a18-c8d99e8c9672' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4619e4bc-31c7-40d1-8a18-c8d99e8c9672' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1e9287cd-6395-43e4-87e3-e53faf91bc3c' class='xr-var-data-in' type='checkbox'><label for='data-1e9287cd-6395-43e4-87e3-e53faf91bc3c' 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.8406082408706373+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>condensate_fraction</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>1.0+/-nan</div><input id='attrs-4697bed4-a3ab-43b8-849a-27cb1c294259' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4697bed4-a3ab-43b8-849a-27cb1c294259' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-2667370e-34a2-4631-b03a-848a9dc9f74a' class='xr-var-data-in' type='checkbox'><label for='data-2667370e-34a2-4631-b03a-848a9dc9f74a' 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(1.0+/-nan, dtype=object)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-85181b44-d4a0-4862-997d-3cbb8f6f9835' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-85181b44-d4a0-4862-997d-3cbb8f6f9835' class='xr-section-summary'  title='Expand/collapse section'>Indexes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'></ul></div></li><li class='xr-section-item'><input id='section-5d1bf8af-9415-4f31-90bb-4416117d730d' class='xr-section-summary-in' type='checkbox'  ><label for='section-5d1bf8af-9415-4f31-90bb-4416117d730d' class='xr-section-summary' >Attributes: <span>(11)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>IMAGE_SUBCLASS :</span></dt><dd>IMAGE_GRAYSCALE</dd><dt><span>IMAGE_VERSION :</span></dt><dd>1.2</dd><dt><span>IMAGE_WHITE_IS_ZERO :</span></dt><dd>0</dd><dt><span>x_start :</span></dt><dd>815</dd><dt><span>x_end :</span></dt><dd>965</dd><dt><span>y_end :</span></dt><dd>955</dd><dt><span>y_start :</span></dt><dd>805</dd><dt><span>x_center :</span></dt><dd>890</dd><dt><span>y_center :</span></dt><dd>880</dd><dt><span>x_span :</span></dt><dd>150</dd><dt><span>y_span :</span></dt><dd>150</dd></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:              ()\n",
       "Coordinates:\n",
       "    compZ_current_sg     float64 0.198\n",
       "    runs                 float64 0.0\n",
       "Data variables:\n",
       "    BEC_amplitude        object 792.7896024042066+/-nan\n",
       "    thermal_amplitude    object 0.0+/-nan\n",
       "    BEC_centerx          object 72.03322637975705+/-nan\n",
       "    BEC_centery          object 74.15709273093088+/-nan\n",
       "    thermal_centerx      object 73.1219837873983+/-nan\n",
       "    thermal_centery      object 75.0675362391377+/-nan\n",
       "    BEC_sigmax           object 25.92336716503899+/-nan\n",
       "    BEC_sigmay           object 10.643305951751195+/-nan\n",
       "    thermal_sigmax       object 17.18976684635309+/-nan\n",
       "    thermal_sigmay       object 14.449859669689275+/-nan\n",
       "    thermalAspectRatio   object 0.8406082408706373+/-nan\n",
       "    condensate_fraction  object 1.0+/-nan\n",
       "Attributes:\n",
       "    IMAGE_SUBCLASS:       IMAGE_GRAYSCALE\n",
       "    IMAGE_VERSION:        1.2\n",
       "    IMAGE_WHITE_IS_ZERO:  0\n",
       "    x_start:              815\n",
       "    x_end:                965\n",
       "    y_end:                955\n",
       "    y_start:              805\n",
       "    x_center:             890\n",
       "    y_center:             880\n",
       "    x_span:               150\n",
       "    y_span:               150"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fitAnalyser_1.get_fit_full_result(fitResult_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.1654007155341837"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "792.7896024042066 * 147 /1e5"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calibration of the magnetic fields - after connecting the Z coils to the HiPPS"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.119 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0035\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -5000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  2.8, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  5000, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(2.7725, 2.822, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.140 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0044\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -2500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  3.177, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  2500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(3.158, 3.198, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.200 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0048\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -4500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  4.275, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  4500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(4.260, 4.289, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.259 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0056\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -4500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  5.3, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  4500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(5.34, 5.364, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.329 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0059\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -4500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  6.636, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  4500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(6.62, 6.655, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.419 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0063\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -1500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  8.286, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.1, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  1500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(8.27, 8.305, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_dir = 'C:/Users/control/DyLab/Experiments/DyBEC/'\n",
    "SequenceName = \"Evaporative_Cooling\"\n",
    "folderPath = img_dir + SequenceName + \"/\" + get_date()\n",
    "\n",
    "mongoDB = mongoClient[SequenceName]\n",
    "\n",
    "DB = MongoDB(mongoClient, mongoDB, date=get_date())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Z Offset field =  0.489 A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "shotNum = \"0002\"\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 = (160, 880)\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": {},
   "outputs": [],
   "source": [
    "Ncount_mean_1 = Ncount_mean\n",
    "Ncount_std_1 = Ncount_std\n",
    "\n",
    "fitAnalyser_1 = FitAnalyser(\"Gaussian With Offset\", fitDim=1)\n",
    "# params = fitAnalyser.guess(Ncount_mean_1, x=scanAxis[0], guess_kwargs=dict(negative=True), dask=\"parallelized\")\n",
    "params = fitAnalyser_1.fitModel.make_params()\n",
    "params.add(name=\"amplitude\", value=  -2500, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"center\", value=  9.575, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"sigma\", value=  0.2, max=np.inf, min=  0, vary=True)\n",
    "params.add(name=\"offset\", value=  2500, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "fitResult_1 = fitAnalyser_1.fit(Ncount_mean_1, params, x=scanAxis[0]).load()\n",
    "freqdata = np.linspace(9.555, 9.595, 500)\n",
    "fitCurve_1 = fitAnalyser_1.eval(fitResult_1, x=freqdata, dask=\"parallelized\").load()\n",
    "fitCurve_1 = fitCurve_1.assign_coords({'x':np.array(freqdata)})\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "\n",
    "Ncount_mean.plot.errorbar(ax=ax, yerr = Ncount_std, fmt='ob')\n",
    "fitCurve_1.plot.errorbar(ax=ax, fmt='--g')\n",
    "plt.xlabel('Center Frequency (MHz)')\n",
    "plt.ylabel('NCount')\n",
    "#plt.xlim([2.7828, 2.81625])\n",
    "plt.tight_layout()\n",
    "plt.grid(visible=1)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f_1 = fitAnalyser_1.get_fit_value(fitResult_1).center\n",
    "df_1 = fitAnalyser_1.get_fit_std(fitResult_1).center\n",
    "\n",
    "print('f = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(f_1)* 1e3,df_1* 1e3]))\n",
    "\n",
    "s_1 = fitAnalyser_1.get_fit_value(fitResult_1).sigma\n",
    "ds_1 = fitAnalyser_1.get_fit_std(fitResult_1).sigma\n",
    "\n",
    "fwhm_1 = 2.3548200*s_1 * 1e3\n",
    "dfwhm_1 = 2.3548200*ds_1 * 1e3\n",
    "\n",
    "print('fwhm = %.5f \\u00B1 %.5f kHz'% tuple([np.abs(fwhm_1),dfwhm_1]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = [2798.24971, 3178.49790, 4275.39905, 5352.17283, 6637.80418, 8288.35264, 9573.59333]\n",
    "df = [0.36873, 0.29413, 0.20667, 0.20818, 0.21978, 0.20285, 0.18495]\n",
    "z_offset_current = [0.119, 0.140, 0.2, 0.259, 0.329, 0.419, 0.489]\n",
    "\n",
    "f_fit = f\n",
    "df_fit = df\n",
    "z_offset_current_fit = z_offset_current\n",
    "\n",
    "\n",
    "x = np.array(z_offset_current_fit)\n",
    "y = np.array(f_fit)\n",
    "\n",
    "# Degree of the fitting polynomial\n",
    "deg = 1\n",
    "# Parameters from the fit of the polynomial\n",
    "p = np.polyfit(x, y, deg)\n",
    "m = p[0]  # Gradient\n",
    "c = p[1]  # y-intercept\n",
    "\n",
    "#print(f'The fitted straight line has equation y = {m:.1f}x {c:=+6.1f}')\n",
    "\n",
    "# Model the data using the parameters of the fitted straight line\n",
    "y_model = np.polyval(p, x)\n",
    "\n",
    "# Create the linear (1 degree polynomial) model\n",
    "model = np.poly1d(p)\n",
    "# Fit the model\n",
    "y_model = model(x)\n",
    "\n",
    "# Mean\n",
    "y_bar = np.mean(y)\n",
    "# Coefficient of determination, R²\n",
    "R2 = np.sum((y_model - y_bar)**2) / np.sum((y - y_bar)**2)\n",
    "\n",
    "#print(f'R² = {R2:.2f}')\n",
    "\n",
    "fitted_SlopeInkHz = m\n",
    "fitted_offsetInkHz = c\n",
    "muB = 9.274e-24\n",
    "hbar = 6.626e-34 / (2 * np.pi)\n",
    "gJ = 1.24\n",
    "Slope = (((2 * np.pi * fitted_SlopeInkHz * 1e3)*hbar) / (muB*gJ)) * 1e4\n",
    "Offset  = (((2 * np.pi * fitted_offsetInkHz * 1e3)*hbar) / (muB*gJ)) * 1e4\n",
    "\n",
    "def calib_fit(x, B):\n",
    "    alpha = ((2 * np.pi * fitted_SlopeInkHz * 1e3)*hbar) / (muB*gJ)\n",
    "    beta  = ((2 * np.pi * fitted_offsetInkHz * 1e3)*hbar) / (muB*gJ)\n",
    "    delta_nu = ((muB * gJ) / hbar) * np.sqrt((B**2-beta**2) + ((alpha * x) + beta)**2)\n",
    "    return delta_nu / (2 * np.pi * 1e3)\n",
    "\n",
    "\n",
    "popt, pcov = curve_fit(calib_fit, z_offset_current, f, np.array([0.1*1e-4]))\n",
    "Boffset = popt[0] * 1e4\n",
    "dBoffset = pcov[0][0]**0.5 * 1e4\n",
    "\n",
    "fig = plt.figure()\n",
    "ax = fig.gca()\n",
    "plt.clf\n",
    "#plt.scatter(z_offset_current, f, c='gray', marker='o', edgecolors='k', s=30)\n",
    "plt.errorbar(z_offset_current, f, yerr=df, fmt='o')\n",
    "xvals = np.linspace(0, 0.5, 500)\n",
    "plt.plot(np.array(xvals), p[1] + p[0] * np.array(xvals), label=f'Line Fit')\n",
    "plt.plot(xvals, calib_fit(xvals, *popt), label=f'Curve Fit')\n",
    "plt.text(0.25, 2200, f'Line Slope  = {Slope:.3f} G/A', fontsize=12)\n",
    "plt.text(0.25, 1500, f'Line Offset = {Offset:=.3f} G', fontsize=12)\n",
    "plt.text(0.25, 800, f'Bo= {Boffset:=.3f} +/- {dBoffset:=.3f} G', fontsize=12)\n",
    "plt.xlabel('Z Offset Coil Current (A)', fontsize=12)\n",
    "plt.ylabel('Resonance Frequency (kHz)', fontsize=12)\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, 2000)\n",
    "plt.grid(visible=1)\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "l = list(np.arange(9.555, 9.595, 0.002))\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 * 9573.59333  * 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.0587\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.7607\n",
    "P_arm2 = 2.302 * v - 0.06452\n",
    "print(round(P_arm2, 3))"
   ]
  }
 ],
 "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
}
