{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import lmfit\n",
    "import xarray as xr\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import copy\n",
    "\n",
    "import glob\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",
    "\n",
    "#test\n",
    "plt.rcParams['font.size'] = 18\n",
    "\n",
    "from scipy.ndimage import gaussian_filter, rotate\n",
    "import matplotlib as mpl\n",
    "from scipy.interpolate import CubicSpline\n",
    "from scipy.optimize import curve_fit\n",
    "mpl.rc('xtick', labelsize=8)\n",
    "mpl.rc('ytick', labelsize=8)\n",
    "\n",
    "import sys\n",
    "sys.path.append(\"C:/Users/Jianshun Gao/VisualCodeProjects/analysescript\")\n",
    "sys.path.append(\"C:/Users/Jianshun Gao/PycharmProjects/Foglight4/Data\")\n",
    "\n",
    "from DataContainer.ReadData import read_hdf5_file, read_hdf5_global, read_hdf5_run_time, read_csv_file\n",
    "from Analyser.ImagingAnalyser import ImageAnalyser\n",
    "from Analyser.FitAnalyser import FitAnalyser\n",
    "from Analyser.FitAnalyser import ThomasFermi2dModel, DensityProfileBEC2dModel, Polylog22dModel\n",
    "from Analyser.FFTAnalyser import fft, ifft, fft_nutou\n",
    "from ToolFunction.ToolFunction import *\n",
    "\n",
    "import time\n",
    "import logging as log\n",
    "import scipy.constants as const\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",
    "\n",
    "import Analyser.FitAnalyser as dp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:/Users/Jianshun Gao/PycharmProjects/Foglight4/Data/josch/high_cond_1.nc\n"
     ]
    }
   ],
   "source": [
    "path = \"C:/Users/Jianshun Gao/PycharmProjects/Foglight4/Data\"\n",
    "file = 'high_cond_1'\n",
    "file_path = f'{path}/josch/{file}.nc'\n",
    "print(file_path)\n",
    "with xr.open_dataarray(file_path) as data_x:\n",
    "    data_x\n",
    "\n",
    "data = data_x.to_numpy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "is_debug = True\n",
    "fitm = DensityProfileBEC2dModel(is_debug=is_debug, atom_n_conv=144/2)\n",
    "\n",
    "def calc_cen_bulk(thresh):\n",
    "    \"\"\"\n",
    "    returns array in shape of input, containing array with [Y_center,X_center] for each image\n",
    "    \"\"\"\n",
    "    shape = np.shape(thresh)\n",
    "    cen = np.zeros((shape[0], 2))\n",
    "    for i in range(0, shape[0]):\n",
    "        cen[i] = fitm.calc_cen_pix(thresh[i])\n",
    "    return cen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "shape = np.shape(data)\n",
    "data_rot = np.empty(shape)\n",
    "\n",
    "for i in range(0,shape[0]):\n",
    "    data_rot[i] = rotate(data[i], 36, reshape=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[599.42377261 959.62015504]\n",
      " [599.46599496 959.50629723]\n",
      " [599.47858942 959.49118388]\n",
      " [599.47505938 959.41330166]\n",
      " [599.68149883 959.26697892]\n",
      " [599.4627907  959.58372093]\n",
      " [599.46412556 959.46188341]]\n"
     ]
    }
   ],
   "source": [
    "# cropping\n",
    "pr_data = data_rot\n",
    "\n",
    "cut_width_x = 200\n",
    "cut_width_y = 150\n",
    "thresh = fitm.calc_thresh(pr_data)\n",
    "\n",
    "center = calc_cen_bulk(thresh)\n",
    "\n",
    "print(center)\n",
    "\n",
    "\n",
    "if len(shape) == 3:\n",
    "    cropOD = np.zeros((shape[0], cut_width_y, cut_width_x))\n",
    "    for i in range(0,shape[0]):\n",
    "        for j in range(0, shape[1]):\n",
    "            cropOD[i] = pr_data[i, round(center[i,0]-cut_width_y/2):round(center[i,0]+cut_width_y/2), round(center[i,1]-cut_width_x/2):round(center[i,1]+cut_width_x/2)]\n",
    "\n",
    "shape = np.shape(cropOD)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 244720 characters]",
      "text/plain": [
       "<Figure size 1750x250 with 7 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(1, shape[0], figsize=(2.5 *shape[0],2.5))\n",
    "for i in range(0, shape[0]):\n",
    "    ax[i].pcolormesh(cropOD[i], cmap='jet')\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 0\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45128 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [99.49748744 75.5033557 ]\n",
      "BEC widths: [24 13]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.805        0    4.694     None     True     None     None\n",
      "amp_th        1.805        0    4.694     None     True     None     None\n",
      "deltax           39        0      200     None     True     None     None\n",
      "sigma_bec     10.66        0       26     None     True     None     None\n",
      "sigma_th      26.94        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec         75.5     65.5     85.5     None     True     None     None\n",
      "x0_th          75.5     65.5     85.5     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 75.823, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 75.762, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "amp_bec: 2.929, (init = 1.805), bounds = [0.00 : 4.69] \n",
      "amp_th: 0.722, (init = 1.805), bounds = [0.00 : 4.69] \n",
      "sigma_bec: 10.851, (init = 10.656), bounds = [0.00 : 26.00] \n",
      "sigma_th: 9.869, (init = 26.936), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 47188 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.515        0    6.495     None     True     None     None\n",
      "amp_th                  0.866        0    6.495     None     True     None     None\n",
      "atom_number_bec         942.7     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          387.7     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7086     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                9.869        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec              10.85        0       26     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.515        0    6.495     None     True     None     None\n",
      "amp_th                  0.866        0    6.495     None     True     None     None\n",
      "atom_number_bec         942.7     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          387.7     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7086     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                9.869        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec              10.85        0       26     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.361, (init = 3.515), bounds = [0.00 : 6.50] \n",
      "amp_th: 1.033, (init = 0.866), bounds = [0.00 : 6.50] \n",
      "x0_bec: 100.041, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 76.006, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 99.794, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.935, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 23.817, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.257, (init = 10.851), bounds = [0.00 : 26.00] \n",
      "sigma_th: 9.384, (init = 9.869), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.361, (init = 3.515), bounds = [0.00 : 6.50] \n",
      "amp_th: 1.033, (init = 0.866), bounds = [0.00 : 6.50] \n",
      "x0_bec: 100.041, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 76.006, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 99.794, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.935, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 23.817, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.257, (init = 10.851), bounds = [0.00 : 26.00] \n",
      "sigma_th: 9.384, (init = 9.869), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 80596\n",
      "   N_th: 29742\n",
      "   N_ges: 110338\n",
      "   Cond. frac: 73.04 %\n",
      "\n",
      "Temperature: 31.40 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 1\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45360 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [99.49748744 75.5033557 ]\n",
      "BEC widths: [26 14]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.733        0    4.505     None     True     None     None\n",
      "amp_th        1.733        0    4.505     None     True     None     None\n",
      "deltax           42        0      200     None     True     None     None\n",
      "sigma_bec     11.48        0       28     None     True     None     None\n",
      "sigma_th      29.01        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec         75.5     65.5     85.5     None     True     None     None\n",
      "x0_th          75.5     65.5     85.5     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 75.810, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 75.715, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "amp_bec: 2.951, (init = 1.733), bounds = [0.00 : 4.51] \n",
      "amp_th: 0.574, (init = 1.733), bounds = [0.00 : 4.51] \n",
      "sigma_bec: 11.042, (init = 11.475), bounds = [0.00 : 28.00] \n",
      "sigma_th: 9.725, (init = 29.008), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 47688 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.554        0    6.284     None     True     None     None\n",
      "amp_th                 0.6913        0    6.284     None     True     None     None\n",
      "atom_number_bec          1051     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          300.6     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7776     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                9.725        0      200     None     True     None     None\n",
      "sigmax_bec              21.31        0       52     None     True     None     None\n",
      "sigmay_bec              11.04        0       28     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.554        0    6.284     None     True     None     None\n",
      "amp_th                 0.6913        0    6.284     None     True     None     None\n",
      "atom_number_bec          1051     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          300.6     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7776     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                9.725        0      200     None     True     None     None\n",
      "sigmax_bec              21.31        0       52     None     True     None     None\n",
      "sigmay_bec              11.04        0       28     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.445, (init = 3.554), bounds = [0.00 : 6.28] \n",
      "amp_th: 0.879, (init = 0.691), bounds = [0.00 : 6.28] \n",
      "x0_bec: 100.009, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 75.995, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 99.838, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.953, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 24.234, (init = 21.311), bounds = [0.00 : 52.00] \n",
      "sigmay_bec: 11.466, (init = 11.042), bounds = [0.00 : 28.00] \n",
      "sigma_th: 9.279, (init = 9.725), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.445, (init = 3.554), bounds = [0.00 : 6.28] \n",
      "amp_th: 0.879, (init = 0.691), bounds = [0.00 : 6.28] \n",
      "x0_bec: 100.009, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 75.995, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 99.838, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.953, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 24.234, (init = 21.311), bounds = [0.00 : 52.00] \n",
      "sigmay_bec: 11.466, (init = 11.042), bounds = [0.00 : 28.00] \n",
      "sigma_th: 9.279, (init = 9.725), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 85613\n",
      "   N_th: 24772\n",
      "   N_ges: 110385\n",
      "   Cond. frac: 77.56 %\n",
      "\n",
      "Temperature: 30.71 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 2\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45044 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [100.50251256  76.51006711]\n",
      "BEC widths: [24 12]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.886        0    4.903     None     True     None     None\n",
      "amp_th        1.886        0    4.903     None     True     None     None\n",
      "deltax           36        0      200     None     True     None     None\n",
      "sigma_bec     9.836        0       24     None     True     None     None\n",
      "sigma_th      24.86        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec        76.51    66.51    86.51     None     True     None     None\n",
      "x0_th         76.51    66.51    86.51     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 76.429, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 76.225, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "amp_bec: 3.016, (init = 1.886), bounds = [0.00 : 4.90] \n",
      "amp_th: 0.716, (init = 1.886), bounds = [0.00 : 4.90] \n",
      "sigma_bec: 11.100, (init = 9.836), bounds = [0.00 : 24.00] \n",
      "sigma_th: 8.387, (init = 24.864), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 47176 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.665        0    7.277     None     True     None     None\n",
      "amp_th                 0.8706        0    7.277     None     True     None     None\n",
      "atom_number_bec          1006     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          281.5     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7813     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.387        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec               11.1        0       24     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.665        0    7.277     None     True     None     None\n",
      "amp_th                 0.8706        0    7.277     None     True     None     None\n",
      "atom_number_bec          1006     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          281.5     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.7813     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.387        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec               11.1        0       24     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.557, (init = 3.665), bounds = [0.00 : 7.28] \n",
      "amp_th: 0.865, (init = 0.871), bounds = [0.00 : 7.28] \n",
      "x0_bec: 101.119, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.951, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 100.508, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 76.096, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 24.616, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.485, (init = 11.100), bounds = [0.00 : 24.00] \n",
      "sigma_th: 8.771, (init = 8.387), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.557, (init = 3.665), bounds = [0.00 : 7.28] \n",
      "amp_th: 0.865, (init = 0.871), bounds = [0.00 : 7.28] \n",
      "x0_bec: 101.119, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.951, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 100.508, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 76.096, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 24.616, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.485, (init = 11.100), bounds = [0.00 : 24.00] \n",
      "sigma_th: 8.771, (init = 8.387), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 89930\n",
      "   N_th: 21771\n",
      "   N_ges: 111702\n",
      "   Cond. frac: 80.51 %\n",
      "\n",
      "Temperature: 27.44 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 3\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45152 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [100.50251256  76.51006711]\n",
      "BEC widths: [24 13]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.868        0    4.856     None     True     None     None\n",
      "amp_th        1.868        0    4.856     None     True     None     None\n",
      "deltax           39        0      200     None     True     None     None\n",
      "sigma_bec     10.66        0       26     None     True     None     None\n",
      "sigma_th      26.94        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec        76.51    66.51    86.51     None     True     None     None\n",
      "x0_th         76.51    66.51    86.51     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 76.418, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 76.448, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "amp_bec: 3.137, (init = 1.868), bounds = [0.00 : 4.86] \n",
      "amp_th: 0.548, (init = 1.868), bounds = [0.00 : 4.86] \n",
      "sigma_bec: 11.291, (init = 10.656), bounds = [0.00 : 26.00] \n",
      "sigma_th: 8.453, (init = 26.936), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 47256 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.835        0    6.902     None     True     None     None\n",
      "amp_th                   0.67        0    6.902     None     True     None     None\n",
      "atom_number_bec          1070     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th            220     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.8295     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.453        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec              11.29        0       26     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.835        0    6.902     None     True     None     None\n",
      "amp_th                   0.67        0    6.902     None     True     None     None\n",
      "atom_number_bec          1070     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th            220     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.8295     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.453        0      200     None     True     None     None\n",
      "sigmax_bec              19.67        0       48     None     True     None     None\n",
      "sigmay_bec              11.29        0       26     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.645, (init = 3.835), bounds = [0.00 : 6.90] \n",
      "amp_th: 0.676, (init = 0.670), bounds = [0.00 : 6.90] \n",
      "x0_bec: 100.932, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 76.084, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 101.313, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 75.559, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 25.038, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.686, (init = 11.291), bounds = [0.00 : 26.00] \n",
      "sigma_th: 8.691, (init = 8.453), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.645, (init = 3.835), bounds = [0.00 : 6.90] \n",
      "amp_th: 0.676, (init = 0.670), bounds = [0.00 : 6.90] \n",
      "x0_bec: 100.932, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 76.084, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 101.313, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 75.559, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 25.038, (init = 19.672), bounds = [0.00 : 48.00] \n",
      "sigmay_bec: 11.686, (init = 11.291), bounds = [0.00 : 26.00] \n",
      "sigma_th: 8.691, (init = 8.453), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 95382\n",
      "   N_th: 16704\n",
      "   N_ges: 112086\n",
      "   Cond. frac: 85.10 %\n",
      "\n",
      "Temperature: 26.94 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 4\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 44912 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [100.50251256  75.5033557 ]\n",
      "BEC widths: [27 14]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.802        0    4.685     None     True     None     None\n",
      "amp_th        1.802        0    4.685     None     True     None     None\n",
      "deltax           42        0      200     None     True     None     None\n",
      "sigma_bec     11.48        0       28     None     True     None     None\n",
      "sigma_th      29.01        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec         75.5     65.5     85.5     None     True     None     None\n",
      "x0_th          75.5     65.5     85.5     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 75.649, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 75.043, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "amp_bec: 3.223, (init = 1.802), bounds = [0.00 : 4.68] \n",
      "amp_th: 0.355, (init = 1.802), bounds = [0.00 : 4.68] \n",
      "sigma_bec: 11.293, (init = 11.475), bounds = [0.00 : 28.00] \n",
      "sigma_th: 8.731, (init = 29.008), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 46304 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.802        0    6.216     None     True     None     None\n",
      "amp_th                 0.4182        0    6.216     None     True     None     None\n",
      "atom_number_bec          1194     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          146.6     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.8907     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.731        0      200     None     True     None     None\n",
      "sigmax_bec              22.13        0       54     None     True     None     None\n",
      "sigmay_bec              11.29        0       28     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 3.802        0    6.216     None     True     None     None\n",
      "amp_th                 0.4182        0    6.216     None     True     None     None\n",
      "atom_number_bec          1194     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          146.6     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.8907     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.731        0      200     None     True     None     None\n",
      "sigmax_bec              22.13        0       54     None     True     None     None\n",
      "sigmay_bec              11.29        0       28     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.919, (init = 3.802), bounds = [0.00 : 6.22] \n",
      "amp_th: 0.302, (init = 0.418), bounds = [0.00 : 6.22] \n",
      "x0_bec: 100.954, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.048, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 102.189, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 74.351, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 24.985, (init = 22.131), bounds = [0.00 : 54.00] \n",
      "sigmay_bec: 11.842, (init = 11.293), bounds = [0.00 : 28.00] \n",
      "sigma_th: 10.043, (init = 8.731), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.919, (init = 3.802), bounds = [0.00 : 6.22] \n",
      "amp_th: 0.302, (init = 0.418), bounds = [0.00 : 6.22] \n",
      "x0_bec: 100.954, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.048, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 102.189, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 74.351, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 24.985, (init = 22.131), bounds = [0.00 : 54.00] \n",
      "sigmay_bec: 11.842, (init = 11.293), bounds = [0.00 : 28.00] \n",
      "sigma_th: 10.043, (init = 8.731), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 103694\n",
      "   N_th: 9957\n",
      "   N_ges: 113652\n",
      "   Cond. frac: 91.24 %\n",
      "\n",
      "Temperature: 35.97 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 5\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 44560 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [99.49748744 75.5033557 ]\n",
      "BEC widths: [28 14]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.774        0    4.612     None     True     None     None\n",
      "amp_th        1.774        0    4.612     None     True     None     None\n",
      "deltax           42        0      200     None     True     None     None\n",
      "sigma_bec     11.48        0       28     None     True     None     None\n",
      "sigma_th      29.01        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec         75.5     65.5     85.5     None     True     None     None\n",
      "x0_th          75.5     65.5     85.5     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 75.826, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 75.876, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "amp_bec: 3.340, (init = 1.774), bounds = [0.00 : 4.61] \n",
      "amp_th: 0.193, (init = 1.774), bounds = [0.00 : 4.61] \n",
      "sigma_bec: 11.386, (init = 11.475), bounds = [0.00 : 28.00] \n",
      "sigma_th: 8.417, (init = 29.008), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45772 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 4.061        0    6.546     None     True     None     None\n",
      "amp_th                 0.2343        0    6.546     None     True     None     None\n",
      "atom_number_bec          1334     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          76.31     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.9459     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.417        0      200     None     True     None     None\n",
      "sigmax_bec              22.95        0       56     None     True     None     None\n",
      "sigmay_bec              11.39        0       28     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 4.061        0    6.546     None     True     None     None\n",
      "amp_th                 0.2343        0    6.546     None     True     None     None\n",
      "atom_number_bec          1334     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          76.31     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.9459     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                8.417        0      200     None     True     None     None\n",
      "sigmax_bec              22.95        0       56     None     True     None     None\n",
      "sigmay_bec              11.39        0       28     None     True     None     None\n",
      "x0_bec                   99.5     89.5    109.5     None     True     None     None\n",
      "x0_th                    99.5     89.5    109.5     None     True     None     None\n",
      "y0_bec                   75.5     65.5     85.5     None     True     None     None\n",
      "y0_th                    75.5     65.5     85.5     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 3.959, (init = 4.061), bounds = [0.00 : 6.55] \n",
      "amp_th: 0.271, (init = 0.234), bounds = [0.00 : 6.55] \n",
      "x0_bec: 99.954, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 76.048, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 101.409, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.044, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 25.489, (init = 22.951), bounds = [0.00 : 56.00] \n",
      "sigmay_bec: 11.941, (init = 11.386), bounds = [0.00 : 28.00] \n",
      "sigma_th: 8.062, (init = 8.417), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 3.959, (init = 4.061), bounds = [0.00 : 6.55] \n",
      "amp_th: 0.271, (init = 0.234), bounds = [0.00 : 6.55] \n",
      "x0_bec: 99.954, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_bec: 76.048, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "x0_th: 101.409, (init = 99.497), bounds = [89.50 : 109.50] \n",
      "y0_th: 75.044, (init = 75.503), bounds = [65.50 : 85.50] \n",
      "sigmax_bec: 25.489, (init = 22.951), bounds = [0.00 : 56.00] \n",
      "sigmay_bec: 11.941, (init = 11.386), bounds = [0.00 : 28.00] \n",
      "sigma_th: 8.062, (init = 8.417), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 107761\n",
      "   N_th: 5769\n",
      "   N_ges: 113530\n",
      "   Cond. frac: 94.92 %\n",
      "\n",
      "Temperature: 23.18 nK\n",
      "\n",
      " \n",
      "file high_cond_1 \n",
      " image: 6\n",
      "shape: (200, 150)\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45232 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y smaller x, 1d fit along y\n",
      "\n",
      "1d fit initialization\n",
      "center = [100.50251256  76.51006711]\n",
      "BEC widths: [29 14]\n",
      "\n",
      "1d init fit values\n",
      "Name          Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec       1.773        0    4.609     None     True     None     None\n",
      "amp_th        1.773        0    4.609     None     True     None     None\n",
      "deltax           42        0      200     None     True     None     None\n",
      "sigma_bec     11.48        0       28     None     True     None     None\n",
      "sigma_th      29.01        0      inf     None    False 0.632*sigma_bec + 0.518*deltax     None\n",
      "x0_bec        76.51    66.51    86.51     None     True     None     None\n",
      "x0_th         76.51    66.51    86.51     None     True     None     None\n",
      "1d fitted values\n",
      "x0_bec: 76.407, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 75.691, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "amp_bec: 3.376, (init = 1.773), bounds = [0.00 : 4.61] \n",
      "amp_th: 0.106, (init = 1.773), bounds = [0.00 : 4.61] \n",
      "sigma_bec: 11.466, (init = 11.475), bounds = [0.00 : 28.00] \n",
      "sigma_th: 7.247, (init = 29.008), bounds = [0.00 : inf] \n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 45976 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Init Params\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 4.021        0    5.904     None     True     None     None\n",
      "amp_th                 0.1265        0    5.904     None     True     None     None\n",
      "atom_number_bec          1377     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          30.54     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.9783     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                7.247        0      200     None     True     None     None\n",
      "sigmax_bec              23.77        0       58     None     True     None     None\n",
      "sigmay_bec              11.47        0       28     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "\n",
      "Name                    Value      Min      Max   Stderr     Vary     Expr Brute_Step\n",
      "amp_bec                 4.021        0    5.904     None     True     None     None\n",
      "amp_th                 0.1265        0    5.904     None     True     None     None\n",
      "atom_number_bec          1377     -inf      inf     None    False amp_bec / 5 * 2 * 3.14159265359 * sigmax_bec * sigmay_bec     None\n",
      "atom_number_th          30.54     -inf      inf     None    False amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * sigma_th * sigma_th     None\n",
      "condensate_fraction    0.9783     -inf      inf     None    False atom_number_bec / (atom_number_bec + atom_number_th)     None\n",
      "rot_angle                 -36      -66       -6     None    False     None     None\n",
      "sigma_th                7.247        0      200     None     True     None     None\n",
      "sigmax_bec              23.77        0       58     None     True     None     None\n",
      "sigmay_bec              11.47        0       28     None     True     None     None\n",
      "x0_bec                  100.5     90.5    110.5     None     True     None     None\n",
      "x0_th                   100.5     90.5    110.5     None     True     None     None\n",
      "y0_bec                  76.51    66.51    86.51     None     True     None     None\n",
      "y0_th                   76.51    66.51    86.51     None     True     None     None\n",
      "bval first fit\n",
      "amp_bec: 4.093, (init = 4.021), bounds = [0.00 : 5.90] \n",
      "amp_th: 0.380, (init = 0.127), bounds = [0.00 : 5.90] \n",
      "x0_bec: 101.030, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.967, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 97.521, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 76.807, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 25.728, (init = 23.770), bounds = [0.00 : 58.00] \n",
      "sigmay_bec: 12.084, (init = 11.466), bounds = [0.00 : 28.00] \n",
      "sigma_th: 1.502, (init = 7.247), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "amp_bec: 4.093, (init = 4.021), bounds = [0.00 : 5.90] \n",
      "amp_th: 0.380, (init = 0.127), bounds = [0.00 : 5.90] \n",
      "x0_bec: 101.030, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_bec: 75.967, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "x0_th: 97.521, (init = 100.503), bounds = [90.50 : 110.50] \n",
      "y0_th: 76.807, (init = 76.510), bounds = [66.51 : 86.51] \n",
      "sigmax_bec: 25.728, (init = 23.770), bounds = [0.00 : 58.00] \n",
      "sigmay_bec: 12.084, (init = 11.466), bounds = [0.00 : 28.00] \n",
      "sigma_th: 1.502, (init = 7.247), bounds = [0.00 : 200.00] \n",
      "rot_angle: -36.000, (init = -36.000), bounds = [-66.00 : -6.00] \n",
      "\n",
      "\n",
      "Atom numbers:\n",
      "   N_bec: 113800\n",
      "   N_th: 281\n",
      "   N_ges: 114080\n",
      "   Cond. frac: 99.75 %\n",
      "\n",
      "Temperature: 0.80 nK\n"
     ]
    }
   ],
   "source": [
    "times = []\n",
    "x = np.linspace(0,shape[2],shape[2])\n",
    "y = np.linspace(0,shape[1], shape[1])\n",
    "\n",
    "X,Y = np.meshgrid(x, y)\n",
    "X_1d = X.flatten()\n",
    "Y_1d = Y.flatten()\n",
    "result = []\n",
    "for i in range(0, shape[0]):\n",
    "# for i in [0]:\n",
    "    print('\\n ')\n",
    "    print(f'file {file} \\n image: {i}')\n",
    "    start = time.time()\n",
    "    init = fitm.guess(cropOD[i].flatten(), X_1d, Y_1d, rot_angle=36, vary_rot=False)\n",
    "    init.pretty_print()\n",
    "\n",
    "    res = fitm.fit(cropOD[i].flatten(), x=X_1d, y=Y_1d, params=init)\n",
    "    fitm.print_bval(res)\n",
    "    stop = time.time()\n",
    "    fitm.return_atom_number(res, X_1d, Y_1d)\n",
    "    fitm.return_temperature(res, omg=1036.5, tof=26e-3, is_print=False)\n",
    "    fitm.return_temperature(res, tof=26e-3)\n",
    "\n",
    "    # print(f'   time = {stop-start:.3f} s')\n",
    "\n",
    "    result.append(res)\n",
    "    times.append(stop-start)\n",
    "\n",
    "times = np.array(times)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1490008 characters]",
      "text/plain": [
       "<Figure size 2000x2800 with 42 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# fig, axs = plt.subplots(shape[0] , 5, figsize=(14, 4 * shape[0] ),dpi = 100)\n",
    "\n",
    "fig, axs = plt.subplots(shape[0] , 6, figsize=(20,4 * shape[0] ),dpi = 100)\n",
    "fig.suptitle(f'{file}: ν = ({data_x.trap_f[0]}, {data_x.trap_f[1]}, {data_x.trap_f[2]}) Hz, T = {data_x.temp[0]*1e9:.0f}nK, tof = {data_x.tof * 1e3:.0f}ms, a = {data_x.a_fac :.0f}a$_0$, N = {data_x.N:.0e} ', y=-0.005*shape[0]+0.965, fontsize=24)\n",
    "# fig.suptitle('test', va='bottom')\n",
    "\n",
    "for i in range(0,shape[0]):\n",
    "\n",
    "    axs[i,0].set_title(f'image {i}, cond. frac = {fitm.cond_frac(result[i], X, Y) *1e2:.2f} %', loc='left', fontsize=18)\n",
    "\n",
    "    lmfit.fit_report(result[i])\n",
    "    bval = result[i].best_values\n",
    "    fit = dp.density_profile_BEC_2d(X,Y, **bval)\n",
    "    vmax = np.max(fit)\n",
    "\n",
    "    if bval['amp_bec'] > bval['amp_th']:\n",
    "        cen_str = 'bec'\n",
    "    else:\n",
    "        cen_str = 'th'\n",
    "    cen_x = round(bval[f'x0_{cen_str}'])\n",
    "    cen_y = round(bval[f'y0_{cen_str}'])\n",
    "\n",
    "    ax = axs[i,0]\n",
    "    ax.pcolormesh(X, Y, cropOD[i], vmin=0, vmax=vmax, cmap='jet', shading='auto')\n",
    "    #plt.colorbar(art, ax=ax, label='z')\n",
    "\n",
    "\n",
    "    # Plot gaussian 2d Fit + legend including Width parameters\n",
    "    ax = axs[i,1]\n",
    "\n",
    "    ax.pcolormesh(X, Y, fit, vmin=0, vmax=vmax, cmap='jet', shading='auto')\n",
    "    #plt.colorbar(art, ax=ax, label='z')\n",
    "\n",
    "    ax = axs[i,2]\n",
    "\n",
    "    ax.pcolormesh(X, Y, fit-cropOD[i], vmin=0, vmax=0.2, cmap='jet', shading='auto')\n",
    "\n",
    "\n",
    "    ax = axs[i,3]\n",
    "\n",
    "    ax.plot(x, cropOD[i, cen_y, :])\n",
    "    ax.plot(x, fit[cen_y, :], label='bimodal')\n",
    "    ax.plot(x, dp.thermal(x, bval['x0_th'], bval['amp_th'], bval['sigma_th']), label='thermal')\n",
    "    ax.legend(fontsize=8)\n",
    "\n",
    "    ax = axs[i,4]\n",
    "\n",
    "    ax.plot(y, cropOD[i, :, cen_x])\n",
    "    ax.plot(y, fit[:, cen_x], label='bimodal')\n",
    "    ax.plot(y, dp.thermal(y, bval['y0_th'], bval['amp_th'], bval['sigma_th']), label='thermal')\n",
    "    ax.legend(fontsize=8)\n",
    "\n",
    "    ax = axs[i,5]\n",
    "    Na = fitm.return_atom_number(result[i], X, Y, is_print=False)\n",
    "    ax.axis('off')\n",
    "    col_labels = ['Sim', 'Fit']\n",
    "    row_labels = ['N', f'N$_{{bec}}$', f'N$_{{th}}$','f', 'T (nk)']\n",
    "    table_vals = [[f'{data_x.N:.2e}',f\"{Na['N']:.2e}\"],\n",
    "                  [f'{data_x.cond_frac.data[i] * data_x.N:.2e}',f\"{Na['N_bec']:.2e}\"],\n",
    "                  [f'{(1-data_x.cond_frac.data[i]) * data_x.N:.2e}',f\"{Na['N_th']:.2e}\"],\n",
    "                  [f'{data_x.cond_frac.data[i] *1e2:.1f} %', f\"{Na['cond_f'] *1e2:.2f} %\"],\n",
    "                  [f'{data_x.temp[i] *1e9:.0f} nK', f'{fitm.return_temperature(result[i], tof=data_x.tof, is_print=False)*1e9:.1f} nK']\n",
    "                  ]\n",
    "\n",
    "\n",
    "    my_table = ax.table(cellText=table_vals,\n",
    "                        colWidths=[0.4]*2,\n",
    "                        rowLabels=row_labels,\n",
    "                        colLabels=col_labels,\n",
    "                        loc='upper right')\n",
    "    my_table.scale(1,2)\n",
    "    ax.text(0.1,0.1,f'fitting time = {times[i]:.2f} s', fontsize=14)\n",
    "\n",
    "t_fonts=20\n",
    "axs[0,0].set_title(f'Data \\n ', fontsize=t_fonts)\n",
    "axs[0,1].set_title('Fit \\n ', fontsize=t_fonts)\n",
    "axs[0,2].set_title('Data - Fit \\n ', fontsize=t_fonts)\n",
    "axs[0,3].set_title('cut along x \\n ', fontsize=t_fonts)\n",
    "axs[0,4].set_title('cut along y \\n ', fontsize=t_fonts)\n",
    "\n",
    "\n",
    "# plt.tight_layout()\n",
    "# plt.savefig(f'fit_output/final/{file}_{saveprefix}.png')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3.e-08, 3.e-08, 3.e-08, 3.e-08, 3.e-08, 3.e-08, 3.e-08])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_x.temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
