regular backup
This commit is contained in:
parent
6f7c2bbf69
commit
ca924246d5
2219
20230629_Data_Analysis.ipynb
Normal file
2219
20230629_Data_Analysis.ipynb
Normal file
File diff suppressed because one or more lines are too long
3676
20230630_Data_Analysis.ipynb
Normal file
3676
20230630_Data_Analysis.ipynb
Normal file
File diff suppressed because one or more lines are too long
3217
20230630_Data_Analysis_2.ipynb
Normal file
3217
20230630_Data_Analysis_2.ipynb
Normal file
File diff suppressed because one or more lines are too long
3666
2D-MOT power.ipynb
Normal file
3666
2D-MOT power.ipynb
Normal file
File diff suppressed because one or more lines are too long
779
3DMOT optimize.ipynb
Normal file
779
3DMOT optimize.ipynb
Normal file
File diff suppressed because one or more lines are too long
1025
smooth-cool-warm-table-float-1024.csv
Normal file
1025
smooth-cool-warm-table-float-1024.csv
Normal file
File diff suppressed because it is too large
Load Diff
177
test_fit.ipynb
177
test_fit.ipynb
@ -1021,37 +1021,154 @@
|
||||
"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",
|
||||
"# 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",
|
||||
" # 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()"
|
||||
" \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)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user