{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Import stuff"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xarray as xr\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import scipy.constants as const\n",
    "import scipy.integrate as integrate\n",
    "import mpmath as mp\n",
    "import copy\n",
    "import xarray\n",
    "\n",
    "# import xrft\n",
    "# import finufft\n",
    "\n",
    "from uncertainties import ufloat\n",
    "from uncertainties import unumpy as unp\n",
    "from uncertainties import umath\n",
    "\n",
    "from datetime import datetime\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.size'] = 18\n",
    "\n",
    "from DataContainer.ReadData import read_hdf5_file, read_hdf5_global, read_hdf5_run_time\n",
    "from Analyser.ImagingAnalyser import ImageAnalyser\n",
    "from Analyser.FitAnalyser import FitAnalyser\n",
    "from ToolFunction.ToolFunction import *\n",
    "from Analyser.FitAnalyser import Gaussian2dModel, DensityProfileBEC2dModel\n",
    "from lmfit.lineshapes import gaussian2d\n",
    "\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",
    "Li2_vec = np.vectorize(lambda x: np.array(mp.fp.polylog(2, x), dtype=np.complex128))"
   ]
  },
  {
   "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-32175c6f-1597-11ee-bde8-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;\">d2bb20ef</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> 6\n",
       "                </td>\n",
       "            </tr>\n",
       "            <tr>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Total threads:</strong> 24\n",
       "                </td>\n",
       "                <td style=\"text-align: left;\">\n",
       "                    <strong>Total memory:</strong> 44.70 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-5e76ff5a-863e-458c-94c5-8655e950d00c</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:61965\n",
       "                    </td>\n",
       "                    <td style=\"text-align: left;\">\n",
       "                        <strong>Workers:</strong> 6\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> 24\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> 44.70 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:61998\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:62001/status\" target=\"_blank\">http://127.0.0.1:62001/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61968\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-tq4qoxbr\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:62000\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:62004/status\" target=\"_blank\">http://127.0.0.1:62004/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61969\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-bhx86y4h\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:61995\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:61996/status\" target=\"_blank\">http://127.0.0.1:61996/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61970\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-b8rqi6f7\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:62007\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:62008/status\" target=\"_blank\">http://127.0.0.1:62008/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61971\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-y967j_78\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:61999\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:62003/status\" target=\"_blank\">http://127.0.0.1:62003/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61972\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-s6j4tmqp\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:61982\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Total threads: </strong> 4\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Dashboard: </strong> <a href=\"http://127.0.0.1:61993/status\" target=\"_blank\">http://127.0.0.1:61993/status</a>\n",
       "                        </td>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Memory: </strong> 7.45 GiB\n",
       "                        </td>\n",
       "                    </tr>\n",
       "                    <tr>\n",
       "                        <td style=\"text-align: left;\">\n",
       "                            <strong>Nanny: </strong> tcp://127.0.0.1:61973\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-dpv1awpr\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:61965' processes=6 threads=24, memory=44.70 GiB>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from dask.distributed import Client\n",
    "client = Client(n_workers=6, threads_per_worker=4, processes=True, memory_limit='8GB')\n",
    "client"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Different f/T\n",
    "The simulation was peformed for 11 different values for teh condensate fraction f from 0 to 10 and the input temperature was changed according to the formular $f = 1-(T/T_c)^3$ <br>\n",
    "N = 3.21e5<br>\n",
    "omgx = 2pi 200 Hz<br>\n",
    "omgy = 2pi 100 Hz<br>\n",
    "omgz = 2pi 200 Hz<br>\n",
    "a = 100 a0 <br>\n",
    "tof = 20 ms <br>\n",
    "The simulation was done for a flatfield lightsource and a manual light source."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Flatfield"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get the data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# load the simulated data\n",
    "sim_fT_flatfield_np = np.load(\"F:/Jianshun/analyseScript/testData/OD_fT_flatfield.npy\")\n",
    "sim_fT_flatfield_np = np.nan_to_num(sim_fT_flatfield_np)\n",
    "'''\n",
    "sim_fT_flatfield_x10_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_flatfield_x10.npy\")\n",
    "sim_fT_flatfield_x10_np = np.nan_to_num(sim_fT_flatfield_x10_np)\n",
    "sim_fT_flatfield_x100_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_flatfield_x100.npy\")\n",
    "sim_fT_flatfield_x100_np = np.nan_to_num(sim_fT_flatfield_x100_np)\n",
    "sim_fT_flatfield_x1000_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_flatfield_x1000.npy\")\n",
    "sim_fT_flatfield_x1000_np = np.nan_to_num(sim_fT_flatfield_x1000_np)\n",
    "sim_fT_manual_x1000_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual_x1000.npy\")\n",
    "sim_fT_manual_x1000_np = np.nan_to_num(sim_fT_manual_x1000_np)\n",
    "sim_fT_manual_x10000_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual_x10000.npy\")\n",
    "sim_fT_manual_x10000_np = np.nan_to_num(sim_fT_manual_x10000_np)\n",
    "'''\n",
    "\n",
    "\n",
    "# define axis\n",
    "x = np.linspace(0, 1201, 1200)\n",
    "y = np.linspace(0, 1921, 1920)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# crop the data around the center to get manly the area of the cloud\n",
    "sim_fT_flatfield_np = sim_fT_flatfield_np[0:12, 500:-500, 860:-860]\n",
    "'''\n",
    "sim_fT_flatfield_x10_np = sim_fT_flatfield_x10_np[0:12, 550:-550, 910:-910]\n",
    "sim_fT_flatfield_x100_np = sim_fT_flatfield_x100_np[0:12, 550:-550, 910:-910]\n",
    "sim_fT_flatfield_x1000_np = sim_fT_flatfield_x1000_np[0:12, 550:-550, 910:-910]\n",
    "sim_fT_manual_x10000_np = sim_fT_manual_x10000_np[0:12, 550:-550, 910:-910]\n",
    "'''\n",
    "\n",
    "f = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])\n",
    "x = x[500:-500]\n",
    "y = y[860:-860]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Perform the fit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n## perform the BEC fit\\n\\n# set the fit Model\\nfitModel = DensityProfileBEC2dModel()\\nfitAnalyser = FitAnalyser(fitModel, fitDim=2)\\n\\nfit_fT_flatfield_x1000_result = np.empty((11,12))\\nfit_fT_flatfield_x1000_std = np.empty((11,12))\\n\\n# tansfer the data into an xarray\\nfor i in range (11):\\n    print(i)\\n    sim_fT_flatfield_x1000 = xr.DataArray(\\n    data = sim_fT_flatfield_x1000_np[i], \\n    dims = [\"x\", \"y\"],\\n    coords = dict(\\n        x = (\"x\", x),\\n        y = (\"y\", y),\\n        )\\n    )\\n    # perform the fit for one simulation with flatfield\\n    params = fitAnalyser.guess(sim_fT_flatfield_x1000, dask=\"parallelized\")\\n    fitResult = fitAnalyser.fit(sim_fT_flatfield_x1000, params, dask=\"parallelized\").load()\\n    fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\\n    fitValue = fitAnalyser.get_fit_value(fitResult)\\n    fitStd = fitAnalyser.get_fit_std(fitResult)\\n    # store the results as numpy array\\n    fit_fT_flatfield_x1000 = fitCurve.to_numpy()\\n    fitValue_array = fitValue.to_array()\\n    fitStd_array = fitStd.to_array()\\n    fit_fT_flatfield_x1000_result[i] = fitValue_array.to_numpy()\\n    fit_fT_flatfield_x1000_std[i] = fitStd_array.to_numpy()\\n'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## perform the BEC fit\n",
    "\n",
    "# set the fit Model\n",
    "fitModel = DensityProfileBEC2dModel()\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=2)\n",
    "\n",
    "fit_fT_flatfield_x1000_result = np.empty((11,12))\n",
    "fit_fT_flatfield_x1000_std = np.empty((11,12))\n",
    "\n",
    "# tansfer the data into an xarray\n",
    "for i in range (11):\n",
    "    print(i)\n",
    "    sim_fT_flatfield_x1000 = xr.DataArray(\n",
    "    data = sim_fT_flatfield_x1000_np[i], \n",
    "    dims = [\"x\", \"y\"],\n",
    "    coords = dict(\n",
    "        x = (\"x\", x),\n",
    "        y = (\"y\", y),\n",
    "        )\n",
    "    )\n",
    "    # perform the fit for one simulation with flatfield\n",
    "    params = fitAnalyser.guess(sim_fT_flatfield_x1000, dask=\"parallelized\")\n",
    "    fitResult = fitAnalyser.fit(sim_fT_flatfield_x1000, params, dask=\"parallelized\").load()\n",
    "    fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\n",
    "    fitValue = fitAnalyser.get_fit_value(fitResult)\n",
    "    fitStd = fitAnalyser.get_fit_std(fitResult)\n",
    "    # store the results as numpy array\n",
    "    fit_fT_flatfield_x1000 = fitCurve.to_numpy()\n",
    "    fitValue_array = fitValue.to_array()\n",
    "    fitStd_array = fitStd.to_array()\n",
    "    fit_fT_flatfield_x1000_result[i] = fitValue_array.to_numpy()\n",
    "    fit_fT_flatfield_x1000_std[i] = fitStd_array.to_numpy()\n",
    "'''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "0.3092462503676215\n",
      "0.028120653587753792\n",
      "<Parameter 'BEC_amplitude', value=36.39788888382145, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=6.253359378774255, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=5.939879881569993, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=636.0835195600501, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=36.39788888382145, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=36.39788888382145, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 86172 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "0.5528817557540787\n",
      "0.28214712300392425\n",
      "<Parameter 'BEC_amplitude', value=98.41779453626728, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=3.3467229538363825, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=2.9910144173151707, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=571.8366157932207, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=98.41779453626728, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=98.41779453626728, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 84268 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "0.6676448877490091\n",
      "0.45280279486430974\n",
      "<Parameter 'BEC_amplitude', value=204.6134675755257, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=3.858167192178399, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=3.3611224858332776, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=498.1775441243017, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=204.6134675755257, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=204.6134675755257, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 85772 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "0.8209805520698302\n",
      "0.5698729694548221\n",
      "<Parameter 'BEC_amplitude', value=314.62838536232505, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.261130378826574, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=3.7182217550401617, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=367.6158038782502, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=314.62838536232505, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=314.62838536232505, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 81428 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "0.9524451336942912\n",
      "0.7133580209950589\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.531159303422342, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=3.9948050534083563, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=234.346332071024, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 83544 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "0.9679921062510455\n",
      "0.8353970604407345\n",
      "<Parameter 'BEC_amplitude', value=556.8529128920721, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.676859970607908, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.090095537635108, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=138.73314738692025, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=556.8529128920721, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=556.8529128920721, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 81200 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "111\n",
      "<Parameter 'thermal_amplitude', value=18.11559956556029, bounds=[0:inf]>\n",
      "111\n",
      "1.1007065302712244\n",
      "0.9474072638704876\n",
      "<Parameter 'BEC_amplitude', value=676.9280696811649, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.847622882969768, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.229774867478724, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=4.6111713076833265, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=676.9280696811649, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=676.9280696811649, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 81428 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "111\n",
      "<Parameter 'thermal_amplitude', value=1.5964361357756474e-05, bounds=[0:inf]>\n",
      "111\n",
      "1.1271856611121658\n",
      "1.0443499897922286\n",
      "<Parameter 'BEC_amplitude', value=715.9101065602428, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.712712244300954, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.174281856530882, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=2.4916588305431375, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=715.9101065602428, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=715.9101065602428, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 81052 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n",
      "111\n",
      "<Parameter 'thermal_amplitude', value=6.152406713200165e-06, bounds=[0:inf]>\n",
      "111\n",
      "1.24761097358594\n",
      "1.1007144514442881\n",
      "<Parameter 'BEC_amplitude', value=731.6475562621214, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.684134961245081, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.072284625627418, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=4.418579710142679, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=731.6475562621214, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=731.6475562621214, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 82024 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n",
      "111\n",
      "<Parameter 'thermal_amplitude', value=1.0471999798422615e-06, bounds=[0:inf]>\n",
      "111\n",
      "1.2696766909374297\n",
      "1.1316765124630221\n",
      "<Parameter 'BEC_amplitude', value=736.2192048064755, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.644189572770608, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.019899236706962, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=2.767321194144596, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=736.2192048064755, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=736.2192048064755, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 83092 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "111\n",
      "<Parameter 'thermal_amplitude', value=2.0170076719949748e-09, bounds=[0:inf]>\n",
      "111\n",
      "1.0770639524619068\n",
      "0.9921090880797887\n",
      "<Parameter 'BEC_amplitude', value=746.360298383822, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=5.030614372702362, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=4.291492331580912, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=2.379912245174944, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=746.360298383822, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=746.360298383822, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 79992 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "## perform the BEC fit\n",
    "\n",
    "# set the fit Model\n",
    "fitModel = DensityProfileBEC2dModel()\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=2)\n",
    "\n",
    "fit_fT_flatfield_result = np.empty((11,13))\n",
    "fit_fT_flatfield_std = np.empty((11,13))\n",
    "\n",
    "# params = fitAnalyser.guess(data_sim, dask=\"parallelized\")\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"A_amplitude\", value=  3000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmax\", value= 50e-6, max=  0, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmay\", value=  30e-6, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_amplitude\", value=  27000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmax\", value=  80e-6, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmay\", value=  80e-6, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "# for i in range (11):\n",
    "#     print(i)\n",
    "#     sim_fT_flatfield = xr.DataArray(\n",
    "#     data = sim_fT_flatfield_np[i], \n",
    "#     dims = [\"x\", \"y\"],\n",
    "#     coords = dict(\n",
    "#         x = (\"x\", x),\n",
    "#         y = (\"y\", y),\n",
    "#         )\n",
    "#     )\n",
    "#     # perform the fit for one simulation with flatfield\n",
    "#     params = fitAnalyser.guess(sim_fT_flatfield, dask=\"parallelized\", guess_kwargs=dict(pureBECThreshold=1.2))\n",
    "#     fitResult = fitAnalyser.fit(sim_fT_flatfield, params, dask=\"parallelized\").load()\n",
    "#     fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\n",
    "#     fitValue = fitAnalyser.get_fit_value(fitResult)\n",
    "#     fitStd = fitAnalyser.get_fit_std(fitResult)\n",
    "#     # store the results as numpy array\n",
    "#     fit_fT_flatfield = fitCurve.to_numpy()\n",
    "#     fitValue_array = fitValue.to_array()\n",
    "#     fitStd_array = fitStd.to_array()\n",
    "#     fit_fT_flatfield_result[i] = fitValue_array.to_numpy()\n",
    "#     fit_fT_flatfield_std[i] = fitStd_array.to_numpy()\n",
    "#     # plot fit\n",
    "#     plt.figure(figsize=(12,8))\n",
    "#     plt.errorbar(x, sim_fT_flatfield_np[i,100], fmt = '.', label = \"simulated data\")\n",
    "#     plt.plot(x, fit_fT_flatfield[100], label = \"BEC fit\")\n",
    "#     plt.xlabel(\"y axis [px]\")\n",
    "#     plt.ylabel(\"OD\")\n",
    "#     plt.title(\"OD distribution cross-section \\n f={}, flatfield lightsource\".format(str(f[i])))\n",
    "#     plt.legend()\n",
    "#     plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class DensityProfileBEC2dModel(Model):\n",
    "\n",
    "    fwhm_factor = 2*np.sqrt(2*np.log(2))\n",
    "    height_factor = 1./2*np.pi\n",
    "\n",
    "    def __init__(self, independent_vars=['x', 'y'], prefix='', nan_policy='raise',\n",
    "                 **kwargs):\n",
    "        kwargs.update({'prefix': prefix, 'nan_policy': nan_policy,\n",
    "                       'independent_vars': independent_vars})\n",
    "        super().__init__(density_profile_BEC_2d, **kwargs)\n",
    "        self._set_paramhints_prefix()\n",
    "\n",
    "    def _set_paramhints_prefix(self):\n",
    "        # self.set_param_hint('BEC_sigmax', min=0)\n",
    "        self.set_param_hint('deltax', min=0)\n",
    "        self.set_param_hint('BEC_sigmax', expr=f'3 * {self.prefix}thermal_sigmax - {self.prefix}deltax')\n",
    "        \n",
    "        self.set_param_hint('BEC_sigmay', min=0)\n",
    "        self.set_param_hint('thermal_sigmax', min=0)\n",
    "        # self.set_param_hint('thermal_sigmay', min=0)\n",
    "        self.set_param_hint('BEC_amplitude', min=0)\n",
    "        self.set_param_hint('thermal_amplitude', min=0)\n",
    "        \n",
    "        self.set_param_hint('thermalAspectRatio', min=0.8, max=1.2)\n",
    "        self.set_param_hint('thermal_sigmay', expr=f'{self.prefix}thermalAspectRatio * {self.prefix}thermal_sigmax')\n",
    "        \n",
    "        # self.set_param_hint('betax', value=0)\n",
    "        # self.set_param_hint('BEC_centerx', expr=f'{self.prefix}thermal_sigmax - {self.prefix}betax')\n",
    "        \n",
    "        self.set_param_hint('condensate_fraction', expr=f'{self.prefix}BEC_amplitude / ({self.prefix}BEC_amplitude + {self.prefix}thermal_amplitude)')\n",
    "\n",
    "    def guess(self, data, x, y, negative=False, pureBECThreshold=0.5, noBECThThreshold=0.0, **kwargs):\n",
    "        \"\"\"Estimate initial model parameter values from data.\"\"\"\n",
    "        fitModel = TwoGaussian2dModel()\n",
    "        pars = fitModel.guess(data, x=x, y=y, negative=negative)\n",
    "        pars['A_amplitude'].set(min=0)\n",
    "        pars['B_amplitude'].set(min=0)\n",
    "        pars['A_centerx'].set(min=pars['A_centerx'].value - 3 * pars['A_sigmax'], \n",
    "                              max=pars['A_centerx'].value + 3 * pars['A_sigmax'],)\n",
    "        pars['A_centery'].set(min=pars['A_centery'].value - 3 * pars['A_sigmay'], \n",
    "                              max=pars['A_centery'].value + 3 * pars['A_sigmay'],)\n",
    "        pars['B_centerx'].set(min=pars['B_centerx'].value - 3 * pars['B_sigmax'], \n",
    "                              max=pars['B_centerx'].value + 3 * pars['B_sigmax'],)\n",
    "        pars['B_centery'].set(min=pars['B_centery'].value - 3 * pars['B_sigmay'], \n",
    "                              max=pars['B_centery'].value + 3 * pars['B_sigmay'],)\n",
    "        \n",
    "        fitResult = fitModel.fit(data, x=x, y=y, params=pars, **kwargs)\n",
    "        pars_guess = fitResult.params\n",
    "        \n",
    "        BEC_amplitude = pars_guess['A_amplitude'].value\n",
    "        thermal_amplitude = pars_guess['B_amplitude'].value\n",
    "                \n",
    "        pars = self.make_params(BEC_amplitude=BEC_amplitude,\n",
    "                                thermal_amplitude=thermal_amplitude, \n",
    "                                BEC_centerx=pars_guess['A_centerx'].value, BEC_centery=pars_guess['A_centery'].value,\n",
    "                                # BEC_sigmax=(pars_guess['A_sigmax'].value / 2.355), \n",
    "                                deltax = 3 * (pars_guess['B_sigmax'].value * s2) - (pars_guess['A_sigmax'].value / 2.355),\n",
    "                                BEC_sigmay=(pars_guess['A_sigmay'].value / 2.355), \n",
    "                                thermal_centerx=pars_guess['B_centerx'].value, thermal_centery=pars_guess['B_centery'].value,\n",
    "                                thermal_sigmax=(pars_guess['B_sigmax'].value * s2), \n",
    "                                thermalAspectRatio=(pars_guess['B_sigmax'].value * s2) / (pars_guess['B_sigmay'].value * s2)\n",
    "                                # thermal_sigmay=(pars_guess['B_sigmay'].value * s2)\n",
    "                                )\n",
    "        \n",
    "        nBEC = pars[f'{self.prefix}BEC_amplitude'] / 2 / np.pi / 5.546 / pars[f'{self.prefix}BEC_sigmay'] / pars[f'{self.prefix}BEC_sigmax']\n",
    "        if (pars[f'{self.prefix}condensate_fraction']>0.95) and (np.max(data) > 1.05 * nBEC):\n",
    "            temp = ((np.max(data) - nBEC) * s2pi * pars[f'{self.prefix}thermal_sigmay'] / pars[f'{self.prefix}thermal_sigmax'])\n",
    "            if temp > pars[f'{self.prefix}BEC_amplitude']:\n",
    "                pars[f'{self.prefix}thermal_amplitude'].set(value=pars[f'{self.prefix}BEC_amplitude'] / 2)\n",
    "            else:\n",
    "                pars[f'{self.prefix}thermal_amplitude'].set(value=temp * 10)\n",
    "        \n",
    "        if BEC_amplitude / (thermal_amplitude + BEC_amplitude) > pureBECThreshold:\n",
    "            pars[f'{self.prefix}thermal_amplitude'].set(value=0)\n",
    "            pars[f'{self.prefix}BEC_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))\n",
    "        \n",
    "        if BEC_amplitude / (thermal_amplitude + BEC_amplitude) < noBECThThreshold:\n",
    "            pars[f'{self.prefix}BEC_amplitude'].set(value=0)\n",
    "            pars[f'{self.prefix}thermal_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))\n",
    "        \n",
    "        pars[f'{self.prefix}BEC_centerx'].set(\n",
    "            min=pars[f'{self.prefix}BEC_centerx'].value - 10 * pars[f'{self.prefix}BEC_sigmax'].value,\n",
    "            max=pars[f'{self.prefix}BEC_centerx'].value + 10 * pars[f'{self.prefix}BEC_sigmax'].value,  \n",
    "        )\n",
    "        \n",
    "        pars[f'{self.prefix}thermal_centerx'].set(\n",
    "            min=pars[f'{self.prefix}thermal_centerx'].value - 3 * pars[f'{self.prefix}thermal_sigmax'].value,\n",
    "            max=pars[f'{self.prefix}thermal_centerx'].value + 3 * pars[f'{self.prefix}thermal_sigmax'].value,  \n",
    "        )\n",
    "        \n",
    "        pars[f'{self.prefix}BEC_centery'].set(\n",
    "            min=pars[f'{self.prefix}BEC_centery'].value - 10 * pars[f'{self.prefix}BEC_sigmay'].value,\n",
    "            max=pars[f'{self.prefix}BEC_centery'].value + 10 * pars[f'{self.prefix}BEC_sigmay'].value,  \n",
    "        )\n",
    "        \n",
    "        pars[f'{self.prefix}thermal_centery'].set(\n",
    "            min=pars[f'{self.prefix}thermal_centery'].value - 3 * pars[f'{self.prefix}thermal_sigmay'].value,\n",
    "            max=pars[f'{self.prefix}thermal_centery'].value + 3 * pars[f'{self.prefix}thermal_sigmay'].value,  \n",
    "        )\n",
    "        \n",
    "        pars[f'{self.prefix}BEC_sigmay'].set(\n",
    "            max=5 * pars[f'{self.prefix}BEC_sigmay'].value,  \n",
    "        )\n",
    "        \n",
    "        pars[f'{self.prefix}thermal_sigmax'].set(\n",
    "            max=5 * pars[f'{self.prefix}thermal_sigmax'].value,   \n",
    "        )\n",
    "        \n",
    "        return update_param_vals(pars, self.prefix, **kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "0.9524451336942912\n",
      "0.7133580209950589\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmay', value=4.531159303422342, bounds=[0:inf]>\n",
      "<Parameter 'BEC_sigmax', value=3.9948050534083563, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>\n",
      "<Parameter 'thermal_amplitude', value=234.346332071024, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n",
      "<Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>\n"
     ]
    },
    {
     "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"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 83544 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Parameters([('BEC_amplitude', <Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>), ('thermal_amplitude', <Parameter 'thermal_amplitude', value=234.346332071024, bounds=[0:inf]>), ('BEC_centerx', <Parameter 'BEC_centerx', value=600.4901284357314, bounds=[560.5420779016479:640.438178969815]>), ('BEC_centery', <Parameter 'BEC_centery', value=960.6538995040197, bounds=[915.3423064697963:1005.9654925382431]>), ('thermal_centerx', <Parameter 'thermal_centerx', value=600.3018356023492, bounds=[499.70580257202505:700.8978686326734]>), ('thermal_centery', <Parameter 'thermal_centery', value=960.5575103290612, bounds=[858.7135761857239:1062.4014444723985]>), ('BEC_sigmax', <Parameter 'BEC_sigmax', value=3.9948050534083563, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>), ('BEC_sigmay', <Parameter 'BEC_sigmay', value=4.531159303422342, bounds=[0:22.65579651711171]>), ('thermal_sigmax', <Parameter 'thermal_sigmax', value=33.53201101010806, bounds=[0:167.66005505054028]>), ('thermal_sigmay', <Parameter 'thermal_sigmay', value=33.94797804777908, bounds=[-inf:inf], expr='thermalAspectRatio * thermal_sigmax'>), ('deltax', <Parameter 'deltax', value=96.60122797691582, bounds=[0:inf]>), ('thermalAspectRatio', <Parameter 'thermalAspectRatio', value=1.012405072798814, bounds=[0.8:1.2]>), ('condensate_fraction', <Parameter 'condensate_fraction', value=0.6575408911220945, bounds=[-inf:inf], expr='BEC_amplitude / (BEC_amplitude + thermal_amplitude)'>)])\n"
     ]
    }
   ],
   "source": [
    "i = 4\n",
    "print(i)\n",
    "sim_fT_flatfield = xr.DataArray(\n",
    "data = sim_fT_flatfield_np[i], \n",
    "dims = [\"x\", \"y\"],\n",
    "coords = dict(\n",
    "    x = (\"x\", x),\n",
    "    y = (\"y\", y),\n",
    "    )\n",
    ")\n",
    "# perform the fit for one simulation with flatfield\n",
    "params = fitAnalyser.guess(sim_fT_flatfield, dask=\"parallelized\", guess_kwargs=dict(pureBECThreshold=20))\n",
    "fitResult = fitAnalyser.fit(sim_fT_flatfield, params, dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\n",
    "fitValue = fitAnalyser.get_fit_value(fitResult)\n",
    "fitStd = fitAnalyser.get_fit_std(fitResult)\n",
    "# store the results as numpy array\n",
    "fit_fT_flatfield = fitCurve.to_numpy()\n",
    "fitValue_array = fitValue.to_array()\n",
    "fitStd_array = fitStd.to_array()\n",
    "fit_fT_flatfield_result[i] = fitValue_array.to_numpy()\n",
    "fit_fT_flatfield_std[i] = fitStd_array.to_numpy()\n",
    "# plot fit\n",
    "plt.figure(figsize=(12,8))\n",
    "plt.errorbar(x, sim_fT_flatfield_np[i,100], fmt = '.', label = \"simulated data\")\n",
    "plt.plot(x, fit_fT_flatfield[100], label = \"BEC fit\")\n",
    "plt.xlabel(\"y axis [px]\")\n",
    "plt.ylabel(\"OD\")\n",
    "plt.title(\"OD distribution cross-section \\n f={}, flatfield lightsource\".format(str(f[i])))\n",
    "plt.legend()\n",
    "plt.show()\n",
    "\n",
    "print(params.item())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 46352 characters]",
      "text/plain": [
       "<Figure size 1200x800 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(12,8))\n",
    "plt.errorbar(x, np.sum(sim_fT_flatfield_np[i], axis=0), fmt = '.', label = \"simulated data\")\n",
    "plt.plot(x, np.sum(fit_fT_flatfield, axis=0), label = \"BEC fit\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 60624 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import cm\n",
    "\n",
    "X, Y = np.meshgrid(x, y)\n",
    "\n",
    "fig, ax = plt.subplots(subplot_kw={\"projection\": \"3d\"})\n",
    "\n",
    "ax.plot_surface(X, Y, sim_fT_flatfield_np[i], cmap=cm.coolwarm,\n",
    "                       linewidth=0, antialiased=False)\n",
    "# plt.plot(x, fit_fT_flatfield[100], label = \"BEC fit\")\n",
    "# plt.xlabel(\"y axis [px]\")\n",
    "# plt.ylabel(\"OD\")\n",
    "# plt.title(\"OD distribution cross-section \\n f={}, flatfield lightsource\".format(str(f[i])))\n",
    "# plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table><tr><th> name </th><th> value </th><th> initial value </th><th> min </th><th> max </th><th> vary </th><th> expression </th></tr><tr><td> BEC_amplitude </td><td>  449.958235 </td><td> None </td><td>  0.00000000 </td><td>         inf </td><td> True </td><td>  </td></tr><tr><td> thermal_amplitude </td><td>  234.346332 </td><td> None </td><td>  0.00000000 </td><td>         inf </td><td> True </td><td>  </td></tr><tr><td> BEC_centerx </td><td>  600.490128 </td><td> None </td><td>  560.542078 </td><td>  640.438179 </td><td> True </td><td>  </td></tr><tr><td> BEC_centery </td><td>  960.653900 </td><td> None </td><td>  915.342306 </td><td>  1005.96549 </td><td> True </td><td>  </td></tr><tr><td> thermal_centerx </td><td>  600.301836 </td><td> None </td><td>  499.705803 </td><td>  700.897869 </td><td> True </td><td>  </td></tr><tr><td> thermal_centery </td><td>  960.557510 </td><td> None </td><td>  858.713576 </td><td>  1062.40144 </td><td> True </td><td>  </td></tr><tr><td> BEC_sigmax </td><td>  3.99480505 </td><td> None </td><td>        -inf </td><td>         inf </td><td> False </td><td> 3 * thermal_sigmax - deltax </td></tr><tr><td> BEC_sigmay </td><td>  4.53115930 </td><td> None </td><td>  0.00000000 </td><td>  22.6557965 </td><td> True </td><td>  </td></tr><tr><td> thermal_sigmax </td><td>  33.5320110 </td><td> None </td><td>  0.00000000 </td><td>  167.660055 </td><td> True </td><td>  </td></tr><tr><td> thermal_sigmay </td><td>  33.9479780 </td><td> None </td><td>        -inf </td><td>         inf </td><td> False </td><td> thermalAspectRatio * thermal_sigmax </td></tr><tr><td> deltax </td><td>  96.6012280 </td><td> None </td><td>  0.00000000 </td><td>         inf </td><td> True </td><td>  </td></tr><tr><td> thermalAspectRatio </td><td>  1.01240507 </td><td> None </td><td>  0.80000000 </td><td>  1.20000000 </td><td> True </td><td>  </td></tr><tr><td> condensate_fraction </td><td>  0.65754089 </td><td> None </td><td>        -inf </td><td>         inf </td><td> False </td><td> BEC_amplitude / (BEC_amplitude + thermal_amplitude) </td></tr></table>"
      ],
      "text/plain": [
       "Parameters([('BEC_amplitude', <Parameter 'BEC_amplitude', value=449.95823450592684, bounds=[0:inf]>), ('thermal_amplitude', <Parameter 'thermal_amplitude', value=234.346332071024, bounds=[0:inf]>), ('BEC_centerx', <Parameter 'BEC_centerx', value=600.4901284357314, bounds=[560.5420779016479:640.438178969815]>), ('BEC_centery', <Parameter 'BEC_centery', value=960.6538995040197, bounds=[915.3423064697963:1005.9654925382431]>), ('thermal_centerx', <Parameter 'thermal_centerx', value=600.3018356023492, bounds=[499.70580257202505:700.8978686326734]>), ('thermal_centery', <Parameter 'thermal_centery', value=960.5575103290612, bounds=[858.7135761857239:1062.4014444723985]>), ('BEC_sigmax', <Parameter 'BEC_sigmax', value=3.9948050534083563, bounds=[-inf:inf], expr='3 * thermal_sigmax - deltax'>), ('BEC_sigmay', <Parameter 'BEC_sigmay', value=4.531159303422342, bounds=[0:22.65579651711171]>), ('thermal_sigmax', <Parameter 'thermal_sigmax', value=33.53201101010806, bounds=[0:167.66005505054028]>), ('thermal_sigmay', <Parameter 'thermal_sigmay', value=33.94797804777908, bounds=[-inf:inf], expr='thermalAspectRatio * thermal_sigmax'>), ('deltax', <Parameter 'deltax', value=96.60122797691582, bounds=[0:inf]>), ('thermalAspectRatio', <Parameter 'thermalAspectRatio', value=1.012405072798814, bounds=[0.8:1.2]>), ('condensate_fraction', <Parameter 'condensate_fraction', value=0.6575408911220945, bounds=[-inf:inf], expr='BEC_amplitude / (BEC_amplitude + thermal_amplitude)'>)])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "params.item()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "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",
       "Data variables: (12/13)\n",
       "    BEC_amplitude        object 0.0005808768046449142+/-nan\n",
       "    thermal_amplitude    object 588.5963406894194+/-nan\n",
       "    BEC_centerx          object 600.511601780056+/-nan\n",
       "    BEC_centery          object 960.6113364263412+/-nan\n",
       "    thermal_centerx      object 600.4841611552301+/-nan\n",
       "    thermal_centery      object 960.6425220578551+/-nan\n",
       "    ...                   ...\n",
       "    BEC_sigmay           object 5.279015683706861+/-nan\n",
       "    thermal_sigmax       object 11.152763795479629+/-nan\n",
       "    thermal_sigmay       object 13.231941010349708+/-nan\n",
       "    deltax               object 19.549896361379112+/-nan\n",
       "    thermalAspectRatio   object 1.1864270823804945+/-nan\n",
       "    condensate_fraction  object (9.868838645965612+/-nan)e-07</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-63557ffa-e3b5-4773-810c-266fa087ce33' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-63557ffa-e3b5-4773-810c-266fa087ce33' 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-4dfa7f99-04f5-436a-84f5-b9397742ba7f' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-4dfa7f99-04f5-436a-84f5-b9397742ba7f' class='xr-section-summary'  title='Expand/collapse section'>Coordinates: <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-af0244dd-0669-4ce9-b80d-6f812388606d' class='xr-section-summary-in' type='checkbox'  checked><label for='section-af0244dd-0669-4ce9-b80d-6f812388606d' class='xr-section-summary' >Data variables: <span>(13)</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'>0.0005808768046449142+/-nan</div><input id='attrs-34bd94b7-52ac-4f36-a49d-b6f672e2b23e' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-34bd94b7-52ac-4f36-a49d-b6f672e2b23e' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-bed0e479-26cd-4fb5-b2cf-a23b86dba17e' class='xr-var-data-in' type='checkbox'><label for='data-bed0e479-26cd-4fb5-b2cf-a23b86dba17e' 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.0005808768046449142+/-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'>588.5963406894194+/-nan</div><input id='attrs-1b6fbad9-a3cf-4588-9f9b-4937e8762f61' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-1b6fbad9-a3cf-4588-9f9b-4937e8762f61' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-5271c939-2859-479e-94a7-a9d037ab6713' class='xr-var-data-in' type='checkbox'><label for='data-5271c939-2859-479e-94a7-a9d037ab6713' 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(588.5963406894194+/-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'>600.511601780056+/-nan</div><input id='attrs-4f90806c-441e-46d7-b982-0424724b696a' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4f90806c-441e-46d7-b982-0424724b696a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-5e965908-0549-42f2-80c0-6b208be35523' class='xr-var-data-in' type='checkbox'><label for='data-5e965908-0549-42f2-80c0-6b208be35523' 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(600.511601780056+/-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'>960.6113364263412+/-nan</div><input id='attrs-3e0c98a2-b443-4ddc-b479-09c35fca6ecc' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-3e0c98a2-b443-4ddc-b479-09c35fca6ecc' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4b1f02b8-a762-4c1b-9e90-ea31999aa076' class='xr-var-data-in' type='checkbox'><label for='data-4b1f02b8-a762-4c1b-9e90-ea31999aa076' 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(960.6113364263412+/-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'>600.4841611552301+/-nan</div><input id='attrs-12fb82a3-6fac-49be-acb8-f914a20e30b0' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-12fb82a3-6fac-49be-acb8-f914a20e30b0' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-755807ed-4375-4c2c-9b0a-3d66f0d59a6f' class='xr-var-data-in' type='checkbox'><label for='data-755807ed-4375-4c2c-9b0a-3d66f0d59a6f' 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(600.4841611552301+/-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'>960.6425220578551+/-nan</div><input id='attrs-82de31de-c679-451c-b0ea-ebe24c7d8d58' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-82de31de-c679-451c-b0ea-ebe24c7d8d58' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-87cc188e-3660-4dc5-9b5a-41ac73793ed8' class='xr-var-data-in' type='checkbox'><label for='data-87cc188e-3660-4dc5-9b5a-41ac73793ed8' 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(960.6425220578551+/-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'>13.908395025059775+/-nan</div><input id='attrs-4f6d3b6b-ec92-498c-adc9-8207a8a64447' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-4f6d3b6b-ec92-498c-adc9-8207a8a64447' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d3fa875f-84fa-426a-8f43-c21f739bc1cb' class='xr-var-data-in' type='checkbox'><label for='data-d3fa875f-84fa-426a-8f43-c21f739bc1cb' 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(13.908395025059775+/-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'>5.279015683706861+/-nan</div><input id='attrs-6919cdb4-e31d-4be0-a5ab-75658f5c3e00' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-6919cdb4-e31d-4be0-a5ab-75658f5c3e00' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4986f84c-2037-462b-b946-559d8c278c02' class='xr-var-data-in' type='checkbox'><label for='data-4986f84c-2037-462b-b946-559d8c278c02' 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(5.279015683706861+/-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'>11.152763795479629+/-nan</div><input id='attrs-8017aabe-03cc-4043-ab00-c3d800613e1c' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-8017aabe-03cc-4043-ab00-c3d800613e1c' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-7c9267a9-7784-42b8-827d-55472af5c625' class='xr-var-data-in' type='checkbox'><label for='data-7c9267a9-7784-42b8-827d-55472af5c625' 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(11.152763795479629+/-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'>13.231941010349708+/-nan</div><input id='attrs-d5b614cf-0a52-4239-bd74-f9271f465643' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-d5b614cf-0a52-4239-bd74-f9271f465643' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-f03aa7b6-90f5-428d-a8b2-0e599efbd807' class='xr-var-data-in' type='checkbox'><label for='data-f03aa7b6-90f5-428d-a8b2-0e599efbd807' 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(13.231941010349708+/-nan, dtype=object)</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>deltax</span></div><div class='xr-var-dims'>()</div><div class='xr-var-dtype'>object</div><div class='xr-var-preview xr-preview'>19.549896361379112+/-nan</div><input id='attrs-bb7198b2-b885-437b-9ac8-d298e6f4e563' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-bb7198b2-b885-437b-9ac8-d298e6f4e563' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-5073361e-d0e5-4f64-828e-c431f9269642' class='xr-var-data-in' type='checkbox'><label for='data-5073361e-d0e5-4f64-828e-c431f9269642' 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(19.549896361379112+/-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'>1.1864270823804945+/-nan</div><input id='attrs-ce0e2899-85e0-47b1-a407-37ac5f46e9de' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-ce0e2899-85e0-47b1-a407-37ac5f46e9de' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-bf60a434-746d-44ba-bce7-41cf629c6478' class='xr-var-data-in' type='checkbox'><label for='data-bf60a434-746d-44ba-bce7-41cf629c6478' 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.1864270823804945+/-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'>(9.868838645965612+/-nan)e-07</div><input id='attrs-b3995a3d-e637-4673-91e0-00aaaee65b32' class='xr-var-attrs-in' type='checkbox' disabled><label for='attrs-b3995a3d-e637-4673-91e0-00aaaee65b32' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-d8c1531b-d9ac-4275-ac0d-1bf2e555ecb6' class='xr-var-data-in' type='checkbox'><label for='data-d8c1531b-d9ac-4275-ac0d-1bf2e555ecb6' 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(9.868838645965612e-07+/-nan, dtype=object)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-28230dcd-6b0e-40cf-a653-948f9a433bd7' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-28230dcd-6b0e-40cf-a653-948f9a433bd7' 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-ab6a74ee-09b6-4bd9-8b1f-c3db0ccb75f2' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-ab6a74ee-09b6-4bd9-8b1f-c3db0ccb75f2' class='xr-section-summary'  title='Expand/collapse section'>Attributes: <span>(0)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'></dl></div></li></ul></div></div>"
      ],
      "text/plain": [
       "<xarray.Dataset>\n",
       "Dimensions:              ()\n",
       "Data variables: (12/13)\n",
       "    BEC_amplitude        object 0.0005808768046449142+/-nan\n",
       "    thermal_amplitude    object 588.5963406894194+/-nan\n",
       "    BEC_centerx          object 600.511601780056+/-nan\n",
       "    BEC_centery          object 960.6113364263412+/-nan\n",
       "    thermal_centerx      object 600.4841611552301+/-nan\n",
       "    thermal_centery      object 960.6425220578551+/-nan\n",
       "    ...                   ...\n",
       "    BEC_sigmay           object 5.279015683706861+/-nan\n",
       "    thermal_sigmax       object 11.152763795479629+/-nan\n",
       "    thermal_sigmay       object 13.231941010349708+/-nan\n",
       "    deltax               object 19.549896361379112+/-nan\n",
       "    thermalAspectRatio   object 1.1864270823804945+/-nan\n",
       "    condensate_fraction  object (9.868838645965612+/-nan)e-07"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fitAnalyser.get_fit_full_result(fitResult)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Calculate the parameter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nfit_fT_flatfield_x1000_result = fit_fT_flatfield_x1000_result.T\\nfit_fT_flatfield_x1000_std = fit_fT_flatfield_x1000_std.T\\n'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "fit_fT_flatfield_x1000_result = fit_fT_flatfield_x1000_result.T\n",
    "fit_fT_flatfield_x1000_std = fit_fT_flatfield_x1000_std.T\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n## calculate the peak densities and the radii\\nlam = 421e-9\\nsig0 = 3*lam**2/(2*np.pi)\\neff_px_size = 2.493e-6\\n\\n\\nRxc_fit = fit_fT_flatfield_x1000_result[6]*eff_px_size\\nRxc_err = Rxc_fit*fit_fT_flatfield_x1000_std[6]/fit_fT_flatfield_x1000_std[6]\\nRyc_fit = fit_fT_flatfield_x1000_result[7]*eff_px_size\\nRyc_err = Ryc_fit*fit_fT_flatfield_x1000_std[7]/fit_fT_flatfield_x1000_result[7]\\nRxth_fit = fit_fT_flatfield_x1000_result[8]*np.sqrt(2)*eff_px_size\\nRxth_err = Rxth_fit*fit_fT_flatfield_x1000_std[8]/Rxth_fit*fit_fT_flatfield_x1000_result[8]\\nRyth_fit = fit_fT_flatfield_x1000_result[9]*np.sqrt(2)*eff_px_size\\nRyth_err = Ryth_fit*fit_fT_flatfield_x1000_std[9]/fit_fT_flatfield_x1000_result[9]\\nNc_fit = fit_fT_flatfield_x1000_result[0]/sig0*eff_px_size*eff_px_size\\nNc_err = Nc_fit*fit_fT_flatfield_x1000_std[0]/fit_fT_flatfield_x1000_result[0]\\nNth_fit = fit_fT_flatfield_x1000_result[1]/sig0*eff_px_size*eff_px_size\\nNth_err = Nth_fit*fit_fT_flatfield_x1000_std[1]/fit_fT_flatfield_x1000_result[1]\\nN_fit = Nc_fit + Nth_fit\\nN_err = np.sqrt(Nth_err**2 + Nc_err**2)\\nn2D0c_fit = Nc_fit*5/(2*np.pi*Rxc_fit*Ryc_fit)\\nn2D0th_fit =Nth_fit/(2*np.pi*1.20206*Rxth_fit/np.sqrt(2)*Ryth_fit/np.sqrt(2))\\nf_fit = fit_fT_flatfield_x1000_result[11]\\nf_err = fit_fT_flatfield_x1000_std[11]\\n\\n## Assumed to be given\\ntof = 20e-3\\nomgx = 2*np.pi*200\\nomgy = 2*np.pi*100\\nomgz = 2*np.pi*200\\nomg = (omgx*omgy*omgz)**(1/3)\\nm = 164*const.u \\na0 = 4*np.pi*const.epsilon_0*const.hbar**2/(const.e**2*const.electron_mass)\\n\\n## Calculate T\\nT_x_fit = Rxth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\\nT_x_err = T_x_fit * 2*Rxth_err/Rxth_fit\\nT_y_fit = Ryth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\\nT_y_err = T_y_fit * 2*Ryth_err/Ryth_fit\\nT_fit = (T_x_fit + T_y_fit)/2\\nT_err = 1/2*np.sqrt(T_x_err**2+T_y_err**2)\\n\\n## Calculate scattering lenght a\\naho = np.sqrt(const.hbar/(m*omg))\\nahox = np.sqrt(const.hbar/(m*omgx))\\nahoy = np.sqrt(const.hbar/(m*omgy))\\nahoz = np.sqrt(const.hbar/(m*omgz))\\na_x = Ryc_fit**5*ahox/(15*Nc_fit)*(const.hbar*omgx/m*(1+omgx**2*tof**2)/omgx**2)**(-5/2)\\na_x_err = a_x*5*Ryc_err/Ryc_fit\\na_y = Rxc_fit**5*ahoy/(15*Nc_fit)*(const.hbar*omgy/m*(1+omgy**2*tof**2)/omgy**2)**(-5/2)\\na_y_err = a_y*5*Rxc_err/Rxc_fit\\na_fac_fit = (a_x+a_y)/2/a0\\na_fac_err =1/2/a0*np.sqrt(a_x_err**2+a_y_err**2)\\n'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "## calculate the peak densities and the radii\n",
    "lam = 421e-9\n",
    "sig0 = 3*lam**2/(2*np.pi)\n",
    "eff_px_size = 2.493e-6\n",
    "\n",
    "\n",
    "Rxc_fit = fit_fT_flatfield_x1000_result[6]*eff_px_size\n",
    "Rxc_err = Rxc_fit*fit_fT_flatfield_x1000_std[6]/fit_fT_flatfield_x1000_std[6]\n",
    "Ryc_fit = fit_fT_flatfield_x1000_result[7]*eff_px_size\n",
    "Ryc_err = Ryc_fit*fit_fT_flatfield_x1000_std[7]/fit_fT_flatfield_x1000_result[7]\n",
    "Rxth_fit = fit_fT_flatfield_x1000_result[8]*np.sqrt(2)*eff_px_size\n",
    "Rxth_err = Rxth_fit*fit_fT_flatfield_x1000_std[8]/Rxth_fit*fit_fT_flatfield_x1000_result[8]\n",
    "Ryth_fit = fit_fT_flatfield_x1000_result[9]*np.sqrt(2)*eff_px_size\n",
    "Ryth_err = Ryth_fit*fit_fT_flatfield_x1000_std[9]/fit_fT_flatfield_x1000_result[9]\n",
    "Nc_fit = fit_fT_flatfield_x1000_result[0]/sig0*eff_px_size*eff_px_size\n",
    "Nc_err = Nc_fit*fit_fT_flatfield_x1000_std[0]/fit_fT_flatfield_x1000_result[0]\n",
    "Nth_fit = fit_fT_flatfield_x1000_result[1]/sig0*eff_px_size*eff_px_size\n",
    "Nth_err = Nth_fit*fit_fT_flatfield_x1000_std[1]/fit_fT_flatfield_x1000_result[1]\n",
    "N_fit = Nc_fit + Nth_fit\n",
    "N_err = np.sqrt(Nth_err**2 + Nc_err**2)\n",
    "n2D0c_fit = Nc_fit*5/(2*np.pi*Rxc_fit*Ryc_fit)\n",
    "n2D0th_fit =Nth_fit/(2*np.pi*1.20206*Rxth_fit/np.sqrt(2)*Ryth_fit/np.sqrt(2))\n",
    "f_fit = fit_fT_flatfield_x1000_result[11]\n",
    "f_err = fit_fT_flatfield_x1000_std[11]\n",
    "\n",
    "## Assumed to be given\n",
    "tof = 20e-3\n",
    "omgx = 2*np.pi*200\n",
    "omgy = 2*np.pi*100\n",
    "omgz = 2*np.pi*200\n",
    "omg = (omgx*omgy*omgz)**(1/3)\n",
    "m = 164*const.u \n",
    "a0 = 4*np.pi*const.epsilon_0*const.hbar**2/(const.e**2*const.electron_mass)\n",
    "\n",
    "## Calculate T\n",
    "T_x_fit = Rxth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_x_err = T_x_fit * 2*Rxth_err/Rxth_fit\n",
    "T_y_fit = Ryth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_y_err = T_y_fit * 2*Ryth_err/Ryth_fit\n",
    "T_fit = (T_x_fit + T_y_fit)/2\n",
    "T_err = 1/2*np.sqrt(T_x_err**2+T_y_err**2)\n",
    "\n",
    "## Calculate scattering lenght a\n",
    "aho = np.sqrt(const.hbar/(m*omg))\n",
    "ahox = np.sqrt(const.hbar/(m*omgx))\n",
    "ahoy = np.sqrt(const.hbar/(m*omgy))\n",
    "ahoz = np.sqrt(const.hbar/(m*omgz))\n",
    "a_x = Ryc_fit**5*ahox/(15*Nc_fit)*(const.hbar*omgx/m*(1+omgx**2*tof**2)/omgx**2)**(-5/2)\n",
    "a_x_err = a_x*5*Ryc_err/Ryc_fit\n",
    "a_y = Rxc_fit**5*ahoy/(15*Nc_fit)*(const.hbar*omgy/m*(1+omgy**2*tof**2)/omgy**2)**(-5/2)\n",
    "a_y_err = a_y*5*Rxc_err/Rxc_fit\n",
    "a_fac_fit = (a_x+a_y)/2/a0\n",
    "a_fac_err =1/2/a0*np.sqrt(a_x_err**2+a_y_err**2)\n",
    "'''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "index 12 is out of bounds for axis 0 with size 11",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32mf:\\Jianshun\\analyseScript\\test_fit.ipynb Cell 21\u001b[0m in \u001b[0;36m2\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X36sZmlsZQ%3D%3D?line=23'>24</a>\u001b[0m n2D0c_fit \u001b[39m=\u001b[39m Nc_fit\u001b[39m*\u001b[39m\u001b[39m5\u001b[39m\u001b[39m/\u001b[39m(\u001b[39m2\u001b[39m\u001b[39m*\u001b[39mnp\u001b[39m.\u001b[39mpi\u001b[39m*\u001b[39mRxc_fit\u001b[39m*\u001b[39mRyc_fit)\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X36sZmlsZQ%3D%3D?line=24'>25</a>\u001b[0m n2D0th_fit \u001b[39m=\u001b[39mNth_fit\u001b[39m/\u001b[39m(\u001b[39m2\u001b[39m\u001b[39m*\u001b[39mnp\u001b[39m.\u001b[39mpi\u001b[39m*\u001b[39m\u001b[39m1.20206\u001b[39m\u001b[39m*\u001b[39mRxth_fit\u001b[39m/\u001b[39mnp\u001b[39m.\u001b[39msqrt(\u001b[39m2\u001b[39m)\u001b[39m*\u001b[39mRyth_fit\u001b[39m/\u001b[39mnp\u001b[39m.\u001b[39msqrt(\u001b[39m2\u001b[39m))\n\u001b[1;32m---> <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X36sZmlsZQ%3D%3D?line=25'>26</a>\u001b[0m f_fit \u001b[39m=\u001b[39m fit_fT_flatfield_result[\u001b[39m12\u001b[39;49m]\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X36sZmlsZQ%3D%3D?line=26'>27</a>\u001b[0m f_err \u001b[39m=\u001b[39m fit_fT_flatfield_std[\u001b[39m12\u001b[39m]\n\u001b[0;32m     <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X36sZmlsZQ%3D%3D?line=28'>29</a>\u001b[0m \u001b[39m## Assumed to be given\u001b[39;00m\n",
      "\u001b[1;31mIndexError\u001b[0m: index 12 is out of bounds for axis 0 with size 11"
     ]
    }
   ],
   "source": [
    "fit_fT_flatfield_result = fit_fT_flatfield_result.T\n",
    "fit_fT_flatfield_std = fit_fT_flatfield_std.T\n",
    "\n",
    "## calculate the peak densities and the radii\n",
    "lam = 421e-9\n",
    "sig0 = 3*lam**2/(2*np.pi)\n",
    "eff_px_size = 2.493e-6\n",
    "\n",
    "\n",
    "Rxc_fit = fit_fT_flatfield_result[6]*eff_px_size\n",
    "Rxc_err = Rxc_fit*fit_fT_flatfield_std[6]/fit_fT_flatfield_std[6]\n",
    "Ryc_fit = fit_fT_flatfield_result[7]*eff_px_size\n",
    "Ryc_err = Ryc_fit*fit_fT_flatfield_std[7]/fit_fT_flatfield_result[7]\n",
    "Rxth_fit = fit_fT_flatfield_result[8]*np.sqrt(2)*eff_px_size\n",
    "Rxth_err = Rxth_fit*fit_fT_flatfield_std[8]/Rxth_fit*fit_fT_flatfield_result[8]\n",
    "Ryth_fit = fit_fT_flatfield_result[9]*np.sqrt(2)*eff_px_size\n",
    "Ryth_err = Ryth_fit*fit_fT_flatfield_std[9]/fit_fT_flatfield_result[9]\n",
    "Nc_fit = fit_fT_flatfield_result[0]/sig0*eff_px_size*eff_px_size\n",
    "Nc_err = Nc_fit*fit_fT_flatfield_std[0]/fit_fT_flatfield_result[0]\n",
    "Nth_fit = fit_fT_flatfield_result[1]/sig0*eff_px_size*eff_px_size\n",
    "Nth_err = Nth_fit*fit_fT_flatfield_std[1]/fit_fT_flatfield_result[1]\n",
    "N_fit = Nc_fit + Nth_fit\n",
    "N_err = np.sqrt(Nth_err**2 + Nc_err**2)\n",
    "n2D0c_fit = Nc_fit*5/(2*np.pi*Rxc_fit*Ryc_fit)\n",
    "n2D0th_fit =Nth_fit/(2*np.pi*1.20206*Rxth_fit/np.sqrt(2)*Ryth_fit/np.sqrt(2))\n",
    "f_fit = fit_fT_flatfield_result[12]\n",
    "f_err = fit_fT_flatfield_std[12]\n",
    "\n",
    "## Assumed to be given\n",
    "tof = 20e-3\n",
    "omgx = 2*np.pi*200\n",
    "omgy = 2*np.pi*100\n",
    "omgz = 2*np.pi*200\n",
    "omg = (omgx*omgy*omgz)**(1/3)\n",
    "m = 164*const.u \n",
    "a0 = 4*np.pi*const.epsilon_0*const.hbar**2/(const.e**2*const.electron_mass)\n",
    "\n",
    "## Calculate T\n",
    "T_x_fit = Rxth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_x_err = T_x_fit * 2*Rxth_err/Rxth_fit\n",
    "T_y_fit = Ryth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_y_err = T_y_fit * 2*Ryth_err/Ryth_fit\n",
    "T_fit = (T_x_fit + T_y_fit)/2\n",
    "T_err = 1/2*np.sqrt(T_x_err**2+T_y_err**2)\n",
    "\n",
    "## Calculate scattering lenght a\n",
    "aho = np.sqrt(const.hbar/(m*omg))\n",
    "ahox = np.sqrt(const.hbar/(m*omgx))\n",
    "ahoy = np.sqrt(const.hbar/(m*omgy))\n",
    "ahoz = np.sqrt(const.hbar/(m*omgz))\n",
    "a_x = Ryc_fit**5*ahox/(15*Nc_fit)*(const.hbar*omgx/m*(1+omgx**2*tof**2)/omgx**2)**(-5/2)\n",
    "a_x_err = a_x*5*Ryc_err/Ryc_fit\n",
    "a_y = Rxc_fit**5*ahoy/(15*Nc_fit)*(const.hbar*omgy/m*(1+omgy**2*tof**2)/omgy**2)**(-5/2)\n",
    "a_y_err = a_y*5*Rxc_err/Rxc_fit\n",
    "a_fac_fit = (a_x+a_y)/2/a0\n",
    "a_fac_err =1/2/a0*np.sqrt(a_x_err**2+a_y_err**2)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot the results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 1.0, 'Peak density Thermal cloud n2D0th')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 407580 characters]",
      "text/plain": [
       "<Figure size 1600x2000 with 10 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, axs = plt.subplots(nrows = 5, ncols = 2, figsize = (16,20))\n",
    "fig.suptitle(\"Fit Results for Simulation with Flatfield light source\", fontsize = 28)\n",
    "fig.tight_layout(h_pad=4)\n",
    "plt.subplots_adjust(wspace = 0.25, hspace = 0.6, top=0.9)\n",
    "\n",
    "# Plot the results for f\n",
    "x_axis = np.linspace(0, 1, 10000)\n",
    "\n",
    "axs[0,0].errorbar(f, f_fit, fmt = '.', yerr = f_err)\n",
    "axs[0,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[0,0].set_ylabel(\"fitted condensate fraction $f_{fit}$\")\n",
    "axs[0,0].set_ylim(0, 1)\n",
    "axs[0,0].plot(x_axis, x_axis)\n",
    "axs[0,0].set_title(\"Condensate Fraction f\")\n",
    "\n",
    "# Plot the results for T\n",
    "Tc = 400e-9                             \n",
    "T_sim = (np.ones(len(x_axis))-x_axis**(1/3)) * Tc     \n",
    "\n",
    "axs[0,1].errorbar(f, T_fit/1e-9, fmt = '.', yerr = T_err)\n",
    "axs[0,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[0,1].set_ylabel(\"fitted Temperature $T_{fit}$ [nK]\")\n",
    "axs[0,1].set_ylim(0, 600)\n",
    "axs[0,1].plot(x_axis,  T_sim/1e-9)\n",
    "axs[0,1].set_title(\"Temperature T\")\n",
    "\n",
    "# Plot the results for a\n",
    "\n",
    "axs[1,0].errorbar(f, a_fac_fit, fmt = '.', yerr = a_fac_err)\n",
    "axs[1,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[1,0].set_ylim(-50, 500)\n",
    "axs[1,0].set_ylabel(\"fitted scattering length $a_{fit}$ [a0]\")\n",
    "axs[1,0].plot(x_axis, np.ones(len(x_axis))*300)\n",
    "axs[1,0].set_title(\"Scattering Length a\")\n",
    "\n",
    "# Plot the results for N\n",
    "\n",
    "axs[1,1].errorbar(f, N_fit/1000, fmt = '.', yerr = N_err/1000)\n",
    "axs[1,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[1,1].set_ylabel(\"fitted total atom number \\n $N_{fit}$ [$10^3$]\")\n",
    "axs[1,1].set_ylim(0.5e5/1000, 2e5/1000)\n",
    "axs[1,1].plot(x_axis, np.ones(len(x_axis))*1e5/1000)\n",
    "axs[1,1].set_title(\"Total Atom Number N\")\n",
    "\n",
    "# plot the results for N condensate\n",
    "\n",
    "axs[2,0].errorbar(f, Nc_fit/1000, fmt = '.', yerr = Nc_err/1000)\n",
    "axs[2,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[2,0].set_ylabel(\"fitted atom number \\n in the condensate $Nc_{fit}$ [$10^3$]\")\n",
    "axs[2,0].set_ylim(0, 1.2e5/1000)\n",
    "axs[2,0].plot(x_axis, x_axis*1e5/1000)\n",
    "axs[2,0].set_title(\"Atom Number in the Condensate Nc\")\n",
    "\n",
    "# Plot the results for N thermal\n",
    "\n",
    "axs[2,1].errorbar(f, Nth_fit/1000, fmt = '.', yerr = Nth_err/1000)\n",
    "axs[2,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[2,1].set_ylabel(\"fitted atom number \\n in the thermal gas $Nth_{fit}$ [$10^3$]\")\n",
    "axs[2,1].set_ylim(0, 1.2e5/1000)\n",
    "axs[2,1].plot(x_axis, 1e5*(np.ones(len(x_axis))-x_axis)/1000)\n",
    "axs[2,1].set_title(\"Atom Number in the Thermal Part Nth\")\n",
    "\n",
    "# plot the results for R condensate\n",
    "\n",
    "a = 300 * a0\n",
    "N = 1e5\n",
    "Rxc_sim = np.sqrt(const.hbar*omgy/m)*np.sqrt((1+omgy**2*tof**2)/omgy**2)*(15*N*x_axis*a/ahoy)**(1/5)\n",
    "Ryc_sim = np.sqrt(const.hbar*omgx/m)*np.sqrt((1+omgx**2*tof**2)/omgx**2)*(15*N*x_axis*a/ahox)**(1/5)\n",
    "axs[3,0].errorbar(f, Rxc_fit/1e-6, fmt = '.', yerr = Rxc_err/1e-6)\n",
    "axs[3,0].errorbar(f, Ryc_fit/1e-6, fmt = '.', yerr = Ryc_err/1e-6)\n",
    "axs[3,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[3,0].set_ylabel(\"Radius condensate \\n $Rc_{fit}$ [$\\mu$m]\")\n",
    "axs[3,0].plot(x_axis, Rxc_sim/1e-6)\n",
    "axs[3,0].plot(x_axis, Ryc_sim/1e-6)\n",
    "axs[3,0].set_title(\"Radius of the Condensate Rc\")\n",
    "\n",
    "# plot the results for R thermal\n",
    "\n",
    "Rth_sim = np.sqrt(const.k*T_sim/m*(1/omg**2+tof**2))\n",
    "axs[3,1].errorbar(f, Rxth_fit/1e-6, fmt = '.', yerr = Rxc_err/1e-6)\n",
    "axs[3,1].errorbar(f, Ryth_fit/1e-6, fmt = '.', yerr = Ryc_err/1e-6)\n",
    "axs[3,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[3,1].set_ylabel(\"Radius thermal cloud \\n $Rth_{fit}$ [$\\mu$m]\")\n",
    "axs[3,1].plot(x_axis, Rth_sim/1e-6)\n",
    "axs[3,1].set_title(\"Radius of the Thermal Cloud Rth\")\n",
    "\n",
    "# plot the results for n2D condensate\n",
    "\n",
    "mu = const.hbar*omg/2*(15*N*x_axis*a/aho)**(2/5)\n",
    "g = 4*const.pi*const.hbar**2*a/m\n",
    "Rzc = np.sqrt(const.hbar*omgz/m)*np.sqrt((1+omgz**2*tof**2)/omgz**2)*(15*N*x_axis*a/ahoz)**(1/5)\n",
    "n2D0c_sim = 4/3*Rzc*mu/g*1/(1+omg**2*tof**2)**(3/2)\n",
    "axs[4,0].errorbar(f, n2D0c_fit, fmt = '.', yerr = Rxc_err/1e-13)\n",
    "axs[4,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[4,0].set_ylabel(\"Peak density condensate\\n $n2Dc_{fit}$ [$10^{13}m^{-2}$]\")\n",
    "axs[4,0].plot(x_axis, n2D0c_sim)\n",
    "axs[4,0].set_title(\"Peak density Condensate n2D0c\")\n",
    "\n",
    "# plot the results for n2D thermal\n",
    "\n",
    "# n2D0th_sim = (1-x_axis)*N*integrate.nquad(lambda x,y: np.real(Li2_vec(np.exp(-(x/Rth_sim)**2-(y/Rth_sim)**2))), \n",
    "#                                             [[-6/np.sqrt(2)*Rth_sim, 6/np.sqrt(2)*Rth_sim], [-6/np.sqrt(2)*Rth_sim, 6/np.sqrt(2)*Rth_sim]])[0]**(-1) \n",
    "axs[4,1].errorbar(f, n2D0th_fit/1e-13, fmt = '.', yerr = Rxc_err/1e-13)\n",
    "axs[4,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[4,1].set_ylabel(\"Peak density thermal cloud\\n $n2Dth_{fit}$ [$10^{13} m^{-2}$]\")\n",
    "# axs[4,1].plot(x_axis, Rth_sim/1e-13)\n",
    "axs[4,1].set_title(\"Peak density Thermal cloud n2D0th\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Manual Light Source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual.npy'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32mf:\\Jianshun\\analyseScript\\test_fit.ipynb Cell 25\u001b[0m in \u001b[0;36m2\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X43sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39m# load the data\u001b[39;00m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X43sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m sim_fT_manual_np \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39;49mload(\u001b[39m\"\u001b[39;49m\u001b[39mC:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual.npy\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X43sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m sim_fT_manual_np \u001b[39m=\u001b[39m np\u001b[39m.\u001b[39mnan_to_num(sim_fT_manual_np)\n\u001b[0;32m      <a href='vscode-notebook-cell:/f%3A/Jianshun/analyseScript/test_fit.ipynb#X43sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m \u001b[39m# define axis\u001b[39;00m\n",
      "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\numpy\\lib\\npyio.py:417\u001b[0m, in \u001b[0;36mload\u001b[1;34m(file, mmap_mode, allow_pickle, fix_imports, encoding)\u001b[0m\n\u001b[0;32m    415\u001b[0m     own_fid \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[0;32m    416\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m--> 417\u001b[0m     fid \u001b[39m=\u001b[39m stack\u001b[39m.\u001b[39menter_context(\u001b[39mopen\u001b[39;49m(os_fspath(file), \u001b[39m\"\u001b[39;49m\u001b[39mrb\u001b[39;49m\u001b[39m\"\u001b[39;49m))\n\u001b[0;32m    418\u001b[0m     own_fid \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n\u001b[0;32m    420\u001b[0m \u001b[39m# Code to distinguish from NumPy binary files and pickles.\u001b[39;00m\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual.npy'"
     ]
    }
   ],
   "source": [
    "# load the data\n",
    "sim_fT_manual_np = np.load(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Simulations/OD_fT_manual.npy\")\n",
    "sim_fT_manual_np = np.nan_to_num(sim_fT_manual_np)\n",
    "\n",
    "# define axis\n",
    "x = np.linspace(0, 1201, 1200)\n",
    "y = np.linspace(0, 1921, 1920)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# crop the data around the center to get manly the area of the cloud\n",
    "sim_fT_manual_np = sim_fT_manual_np[0:12, 470:-470, 830:-830]\n",
    "\n",
    "f = np.array([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])\n",
    "x = x[470:-470]\n",
    "y = y[830:-830]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## perform the BEC fit\n",
    "\n",
    "# set the fit Model\n",
    "fitModel = DensityProfileBEC2dModel()\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=2)\n",
    "\n",
    "fit_fT_manual_result = np.empty((11,12))\n",
    "fit_fT_manual_std = np.empty((11,12))\n",
    "\n",
    "# params = fitAnalyser.guess(data_sim, dask=\"parallelized\")\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"A_amplitude\", value=  1000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmax\", value= 23, max=  0, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmay\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_amplitude\", value=  3300, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmax\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmay\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "\n",
    "for i in range (11):\n",
    "    print(i)\n",
    "    sim_fT_manual = xr.DataArray(\n",
    "    data = sim_fT_manual_np[i], \n",
    "    dims = [\"x\", \"y\"],\n",
    "    coords = dict(\n",
    "        x = (\"x\", x),\n",
    "        y = (\"y\", y),\n",
    "        )\n",
    "    )\n",
    "    # perform the fit for one simulation with flatfield\n",
    "    params = fitAnalyser.guess(sim_fT_manual, dask=\"parallelized\")\n",
    "    fitResult = fitAnalyser.fit(sim_fT_manual, params, dask=\"parallelized\").load()\n",
    "    fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\n",
    "    fitValue = fitAnalyser.get_fit_value(fitResult)\n",
    "    fitStd = fitAnalyser.get_fit_std(fitResult)\n",
    "    # store the results as numpy array\n",
    "    fit_fT_manual = fitCurve.to_numpy()\n",
    "    fitValue_array = fitValue.to_array()\n",
    "    fitStd_array = fitStd.to_array()\n",
    "    fit_fT_manual_result[i] = fitValue_array.to_numpy()\n",
    "    fit_fT_manual_std[i] = fitStd_array.to_numpy()\n",
    "    # plot fit\n",
    "    plt.figure(figsize=(12,8))\n",
    "    plt.errorbar(x, sim_fT_manual_np[i,130], fmt = '.', label = \"simulated data\")\n",
    "    plt.plot(x, fit_fT_manual[130], label = \"BEC fit\")\n",
    "    plt.xlabel(\"y axis [px]\")\n",
    "    plt.ylabel(\"OD\")\n",
    "    plt.title(\"OD distribution cross-section \\n f={}, mnanual light source\".format(str(f[i])))\n",
    "    plt.legend()\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fit_fT_manual_result = fit_fT_manual_result.T\n",
    "fit_fT_manual_std = fit_fT_manual_std.T\n",
    "\n",
    "## calculate the peak densities and the radii\n",
    "lam = 421e-9\n",
    "sig0 = 3*lam**2/(2*np.pi)\n",
    "eff_px_size = 2.493e-6\n",
    "\n",
    "\n",
    "Rxc_fit = fit_fT_manual_result[6]*eff_px_size\n",
    "Rxc_err = Rxc_fit*fit_fT_manual_std[6]/fit_fT_manual_std[6]\n",
    "Ryc_fit = fit_fT_manual_result[7]*eff_px_size\n",
    "Ryc_err = Ryc_fit*fit_fT_manual_std[7]/fit_fT_manual_result[7]\n",
    "Rxth_fit = fit_fT_manual_result[8]*np.sqrt(2)*eff_px_size\n",
    "Rxth_err = Rxth_fit*fit_fT_manual_std[8]/Rxth_fit*fit_fT_manual_result[8]\n",
    "Ryth_fit = fit_fT_manual_result[9]*np.sqrt(2)*eff_px_size\n",
    "Ryth_err = Ryth_fit*fit_fT_manual_std[9]/fit_fT_manual_result[9]\n",
    "Nc_fit = fit_fT_manual_result[0]/sig0*eff_px_size*eff_px_size\n",
    "Nc_err = Nc_fit*fit_fT_manual_std[0]/fit_fT_manual_result[0]\n",
    "Nth_fit = fit_fT_manual_result[1]/sig0*eff_px_size*eff_px_size\n",
    "Nth_err = Nth_fit*fit_fT_manual_std[1]/fit_fT_manual_result[1]\n",
    "N_fit = Nc_fit + Nth_fit\n",
    "N_err = np.sqrt(Nth_err**2 + Nc_err**2)\n",
    "n2D0c_fit = Nc_fit*5/(2*np.pi*Rxc_fit*Ryc_fit)\n",
    "n2D0th_fit =Nth_fit/(2*np.pi*1.20206*Rxth_fit/np.sqrt(2)*Ryth_fit/np.sqrt(2))\n",
    "f_fit = fit_fT_manual_result[11]\n",
    "f_err = fit_fT_manual_std[11]\n",
    "\n",
    "## Assumed to be given\n",
    "tof = 20e-3\n",
    "omgx = 2*np.pi*200\n",
    "omgy = 2*np.pi*100\n",
    "omgz = 2*np.pi*200\n",
    "omg = (omgx*omgy*omgz)**(1/3)\n",
    "m = 164*const.u \n",
    "a0 = 4*np.pi*const.epsilon_0*const.hbar**2/(const.e**2*const.electron_mass)\n",
    "\n",
    "## Calculate T\n",
    "T_x_fit = Rxth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_x_err = T_x_fit * 2*Rxth_err/Rxth_fit\n",
    "T_y_fit = Ryth_fit**2*m/(const.k)*(1/omg**2+tof**2)**(-1)\n",
    "T_y_err = T_y_fit * 2*Ryth_err/Ryth_fit\n",
    "T_fit = (T_x_fit + T_y_fit)/2\n",
    "T_err = 1/2*np.sqrt(T_x_err**2+T_y_err**2)\n",
    "\n",
    "## Calculate scattering lenght a\n",
    "aho = np.sqrt(const.hbar/(m*omg))\n",
    "ahox = np.sqrt(const.hbar/(m*omgx))\n",
    "ahoy = np.sqrt(const.hbar/(m*omgy))\n",
    "ahoz = np.sqrt(const.hbar/(m*omgz))\n",
    "a_x = Ryc_fit**5*ahox/(15*Nc_fit)*(const.hbar*omgx/m*(1+omgx**2*tof**2)/omgx**2)**(-5/2)\n",
    "a_x_err = a_x*5*Ryc_err/Ryc_fit\n",
    "a_y = Rxc_fit**5*ahoy/(15*Nc_fit)*(const.hbar*omgy/m*(1+omgy**2*tof**2)/omgy**2)**(-5/2)\n",
    "a_y_err = a_y*5*Rxc_err/Rxc_fit\n",
    "a_fac_fit = (a_x+a_y)/2/a0\n",
    "a_fac_err =1/2/a0*np.sqrt(a_x_err**2+a_y_err**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig, axs = plt.subplots(nrows = 5, ncols = 2, figsize = (16,20))\n",
    "fig.suptitle(\"Fit Results for Simulation with manual light source\", fontsize = 28)\n",
    "fig.tight_layout(h_pad=4)\n",
    "plt.subplots_adjust(wspace = 0.25, hspace = 0.6, top=0.9)\n",
    "\n",
    "# Plot the results for f\n",
    "x_axis = np.linspace(0, 1, 10000)\n",
    "\n",
    "axs[0,0].errorbar(f, f_fit, fmt = '.', yerr = f_err)\n",
    "axs[0,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[0,0].set_ylabel(\"fitted condensate fraction $f_{fit}$\")\n",
    "axs[0,0].set_ylim(0, 1)\n",
    "axs[0,0].plot(x_axis, x_axis)\n",
    "axs[0,0].set_title(\"Condensate Fraction f\")\n",
    "\n",
    "# Plot the results for T\n",
    "Tc = 400e-9                             \n",
    "T_sim = (np.ones(len(x_axis))-x_axis**(1/3)) * Tc     \n",
    "\n",
    "axs[0,1].errorbar(f, T_fit/1e-9, fmt = '.', yerr = T_err)\n",
    "axs[0,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[0,1].set_ylabel(\"fitted Temperature $T_{fit}$ [nK]\")\n",
    "axs[0,1].set_ylim(0, 600)\n",
    "axs[0,1].plot(x_axis,  T_sim/1e-9)\n",
    "axs[0,1].set_title(\"Temperature T\")\n",
    "\n",
    "# Plot the results for a\n",
    "\n",
    "axs[1,0].errorbar(f, a_fac_fit, fmt = '.', yerr = a_fac_err)\n",
    "axs[1,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[1,0].set_ylim(-50, 500)\n",
    "axs[1,0].set_ylabel(\"fitted scattering length $a_{fit}$ [a0]\")\n",
    "axs[1,0].plot(x_axis, np.ones(len(x_axis))*300)\n",
    "axs[1,0].set_title(\"Scattering Length a\")\n",
    "\n",
    "# Plot the results for N\n",
    "\n",
    "axs[1,1].errorbar(f, N_fit/1000, fmt = '.', yerr = N_err/1000)\n",
    "axs[1,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[1,1].set_ylabel(\"fitted total atom number \\n $N_{fit}$ [$10^3$]\")\n",
    "axs[1,1].set_ylim(0.5e5/1000, 2e5/1000)\n",
    "axs[1,1].plot(x_axis, np.ones(len(x_axis))*1e5/1000)\n",
    "axs[1,1].set_title(\"Total Atom Number N\")\n",
    "\n",
    "# plot the results for N condensate\n",
    "\n",
    "axs[2,0].errorbar(f, Nc_fit/1000, fmt = '.', yerr = Nc_err/1000)\n",
    "axs[2,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[2,0].set_ylabel(\"fitted atom number \\n in the condensate $Nc_{fit}$ [$10^3$]\")\n",
    "axs[2,0].set_ylim(0, 1.2e5/1000)\n",
    "axs[2,0].plot(x_axis, x_axis*1e5/1000)\n",
    "axs[2,0].set_title(\"Atom Number in the Condensate Nc\")\n",
    "\n",
    "# Plot the results for N thermal\n",
    "\n",
    "axs[2,1].errorbar(f, Nth_fit/1000, fmt = '.', yerr = Nth_err/1000)\n",
    "axs[2,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[2,1].set_ylabel(\"fitted atom number \\n in the thermal gas $Nth_{fit}$ [$10^3$]\")\n",
    "axs[2,1].set_ylim(0, 1.2e5/1000)\n",
    "axs[2,1].plot(x_axis, 1e5*(np.ones(len(x_axis))-x_axis)/1000)\n",
    "axs[2,1].set_title(\"Atom Number in the Thermal Part Nth\")\n",
    "\n",
    "# plot the results for R condensate\n",
    "\n",
    "a = 300 * a0\n",
    "N = 1e5\n",
    "Rxc_sim = np.sqrt(const.hbar*omgy/m)*np.sqrt((1+omgy**2*tof**2)/omgy**2)*(15*N*x_axis*a/ahoy)**(1/5)\n",
    "Ryc_sim = np.sqrt(const.hbar*omgx/m)*np.sqrt((1+omgx**2*tof**2)/omgx**2)*(15*N*x_axis*a/ahox)**(1/5)\n",
    "axs[3,0].errorbar(f, Rxc_fit/1e-6, fmt = '.', yerr = Rxc_err/1e-6)\n",
    "axs[3,0].errorbar(f, Ryc_fit/1e-6, fmt = '.', yerr = Ryc_err/1e-6)\n",
    "axs[3,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[3,0].set_ylabel(\"Radius condensate \\n $Rc_{fit}$ [$\\mu$m]\")\n",
    "axs[3,0].plot(x_axis, Rxc_sim/1e-6)\n",
    "axs[3,0].plot(x_axis, Ryc_sim/1e-6)\n",
    "axs[3,0].set_title(\"Radius of the Condensate Rc\")\n",
    "\n",
    "# plot the results for R thermal\n",
    "\n",
    "Rth_sim = np.sqrt(const.k*T_sim/m*(1/omg**2+tof**2))\n",
    "axs[3,1].errorbar(f, Rxth_fit/1e-6, fmt = '.', yerr = Rxc_err/1e-6)\n",
    "axs[3,1].errorbar(f, Ryth_fit/1e-6, fmt = '.', yerr = Ryc_err/1e-6)\n",
    "axs[3,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[3,1].set_ylabel(\"Radius thermal cloud \\n $Rth_{fit}$ [$\\mu$m]\")\n",
    "axs[3,1].plot(x_axis, Rth_sim/1e-6)\n",
    "axs[3,1].set_title(\"Radius of the Thermal Cloud Rth\")\n",
    "\n",
    "# plot the results for n2D condensate\n",
    "\n",
    "mu = const.hbar*omg/2*(15*N*x_axis*a/aho)**(2/5)\n",
    "g = 4*const.pi*const.hbar**2*a/m\n",
    "Rzc = np.sqrt(const.hbar*omgz/m)*np.sqrt((1+omgz**2*tof**2)/omgz**2)*(15*N*x_axis*a/ahoz)**(1/5)\n",
    "n2D0c_sim = 4/3*Rzc*mu/g*1/(1+omg**2*tof**2)**(3/2)\n",
    "axs[4,0].errorbar(f, n2D0c_fit, fmt = '.', yerr = Rxc_err/1e-13)\n",
    "axs[4,0].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[4,0].set_ylabel(\"Peak density condensate\\n $n2Dc_{fit}$ [$10^{13}m^{-2}$]\")\n",
    "axs[4,0].plot(x_axis, n2D0c_sim)\n",
    "axs[4,0].set_title(\"Peak density Condensate n2D0c\")\n",
    "\n",
    "# plot the results for n2D thermal\n",
    "\n",
    "# n2D0th_sim = (1-x_axis)*N*integrate.nquad(lambda x,y: np.real(Li2_vec(np.exp(-(x/Rth_sim)**2-(y/Rth_sim)**2))), \n",
    "#                                             [[-6/np.sqrt(2)*Rth_sim, 6/np.sqrt(2)*Rth_sim], [-6/np.sqrt(2)*Rth_sim, 6/np.sqrt(2)*Rth_sim]])[0]**(-1) \n",
    "axs[4,1].errorbar(f, n2D0th_fit/1e-13, fmt = '.', yerr = Rxc_err/1e-13)\n",
    "axs[4,1].set_xlabel(\"input condensate fraction $f_{sim}$\")\n",
    "axs[4,1].set_ylabel(\"Peak density thermal cloud\\n $n2Dth_{fit}$ [$10^{13} m^{-2}$]\")\n",
    "# axs[4,1].plot(x_axis, Rth_sim/1e-13)\n",
    "axs[4,1].set_title(\"Peak density Thermal cloud n2D0th\")\n",
    "\n",
    "# plt.savefig(\"C:/Users/QFBri/Code/analyseScript-Master III/Data/Fit_Results/FitResults_fT_flatfield_PureBECThreshold{}.jpg\".format(str(PureBECThreshold*10)), dpi = 300, bbox_inches='tight')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Real Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "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_1\",\n",
    "    \"images/ODT_1_Axis_Camera/in_situ_absorption\": \"camera_2\",\n",
    "    \"images/ODT_2_Axis_Camera/in_situ_absorption\": \"camera_3\",\n",
    "}\n",
    "\n",
    "img_dir = '//DyLabNAS/Data/'\n",
    "SequenceName = \"Evaporative_Cooling\" + \"/\"\n",
    "folderPath = img_dir + SequenceName + '2023/05/12'# get_date()\n",
    "\n",
    "shotNum = \"0065\"\n",
    "filePath = folderPath + \"/\" + shotNum + \"/*.h5\"\n",
    "\n",
    "dataSetDict = {\n",
    "    dskey[groupList[i]]: read_hdf5_file(filePath, groupList[i])\n",
    "    for i in [0] # range(len(groupList))\n",
    "}\n",
    "\n",
    "dataSet = dataSetDict[\"camera_1\"]\n",
    "dataSet = swap_xy(dataSet)\n",
    "\n",
    "scanAxis = get_scanAxis(dataSet)\n",
    "\n",
    "dataSet = auto_rechunk(dataSet)\n",
    "\n",
    "dataSet = imageAnalyser.get_absorption_images(dataSet)\n",
    "\n",
    "dataSet\n",
    "\n",
    "OD = dataSet[\"OD\"]\n",
    "\n",
    "OD_np = OD.to_numpy()\n",
    "\n",
    "dataSet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# crop image\n",
    "OD_np = OD_np[6, 151:451, 800:1100]\n",
    "y = np.linspace(800, 1100, 300)\n",
    "x = np.linspace(151, 451, 300)\n",
    "plt.imshow(OD_np)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## perform the BEC fit\n",
    "\n",
    "# set the fit Model\n",
    "fitModel = DensityProfileBEC2dModel()\n",
    "fitAnalyser = FitAnalyser(fitModel, fitDim=2)\n",
    "\n",
    "OD = xr.DataArray(\n",
    "    data = OD_np, \n",
    "    dims = [\"x\", \"y\"],\n",
    "    coords = dict(\n",
    "        x = (\"x\", x),\n",
    "        y = (\"y\", y),\n",
    "        )\n",
    "    )\n",
    "\n",
    "# perform the fit for one simulation with flatfield\n",
    "params = fitAnalyser.guess(OD, dask=\"parallelized\", guess_kwargs=dict(pureBECThreshold=0.6))\n",
    "'''\n",
    "params = fitAnalyser.fitModel.make_params()\n",
    "params.add(name=\"A_amplitude\", value=  1000, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmax\", value= 23, max=  0, min=-np.inf, vary=True)\n",
    "params.add(name=\"A_sigmay\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_amplitude\", value=  3300, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centerx\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_centery\", value=  0, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmax\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "params.add(name=\"B_sigmay\", value=  30, max=np.inf, min=-np.inf, vary=True)\n",
    "'''\n",
    "fitResult = fitAnalyser.fit(OD, params, dask=\"parallelized\").load()\n",
    "fitCurve = fitAnalyser.eval(fitResult, x=x, y=y).load()\n",
    "fitValue = fitAnalyser.get_fit_value(fitResult)\n",
    "fitStd = fitAnalyser.get_fit_std(fitResult)\n",
    "\n",
    "# store the results as numpy array\n",
    "fit = fitCurve.to_numpy()\n",
    "fitValue_array = fitValue.to_array()\n",
    "fitStd_array = fitStd.to_array()\n",
    "fit_result = fitValue_array.to_numpy()\n",
    "fit_std = fitStd_array.to_numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(np.shape(OD_np))\n",
    "plt.figure(figsize = (12, 8))\n",
    "plt.plot(x, OD_np[135], marker = \"o\", linewidth = 0)\n",
    "plt.plot(x, fit[135], label = \"BEC fit\")\n",
    "plt.xlabel(\"pixel\")\n",
    "plt.ylabel(\"OD\")\n",
    "plt.title(\"Simulated Data\")\n",
    "plt.xlabel(\"y axis [px]\")\n",
    "plt.ylabel(\"OD\")\n",
    "plt.title(\"OD distribution cross-section \\n real Data\")\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Analyser.FitAnalyser import ThomasFermi2dModel, Polylog22dModel\n",
    "\n",
    "# fitModel_draw = ThomasFermi2dModel(prefix='BEC_')\n",
    "fitModel_draw = Polylog22dModel(prefix='thermal_')\n",
    "\n",
    "fitAnalyser_draw = FitAnalyser(fitModel_draw, fitDim=2)\n",
    "\n",
    "fitCurve = fitAnalyser_draw.eval(fitResult, x=x, y=y).load()\n",
    "\n",
    "fit = fitCurve.to_numpy()\n",
    "\n",
    "# print(np.shape(OD_np))\n",
    "plt.figure(figsize = (12, 8))\n",
    "plt.plot(x, OD_np[135], marker = \"o\", linewidth = 0)\n",
    "plt.plot(x, fit[135], label = \"BEC fit\")\n",
    "plt.xlabel(\"pixel\")\n",
    "plt.ylabel(\"OD\")\n",
    "plt.title(\"Simulated Data\")\n",
    "plt.xlabel(\"y axis [px]\")\n",
    "plt.ylabel(\"OD\")\n",
    "plt.title(\"OD distribution cross-section \\n real Data\")\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fitAnalyser.get_fit_full_result(fitResult)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fitValue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(\"sigxc:\", fit_result[6])\n",
    "print(\"sigyc:\", fit_result[7])\n",
    "print(\"sigxth:\", fit_result[8])\n",
    "print(\"sigyth:\", fit_result[9])\n",
    "print(\"BEC amplitude\", fit_result[0])\n",
    "print(\"thermal amplitude:\", fit_result[1])\n",
    "print(\"condensate fraction:\", fit_result[11])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
