Browse Source

improve the fit

joschka_dev
Jianshun Gao 1 year ago
parent
commit
6f7c2bbf69
  1. 3129
      20230620_Data_Analysis.ipynb
  2. 67
      Analyser/FitAnalyser.py
  3. 2380
      magenticField.ipynb
  4. 125
      test.ipynb
  5. 2498
      test_fit.ipynb

3129
20230620_Data_Analysis.ipynb
File diff suppressed because one or more lines are too long
View File

67
Analyser/FitAnalyser.py

@ -331,7 +331,10 @@ class DensityProfileBEC2dModel(Model):
self._set_paramhints_prefix() self._set_paramhints_prefix()
def _set_paramhints_prefix(self): def _set_paramhints_prefix(self):
self.set_param_hint('BEC_sigmax', min=0)
# self.set_param_hint('BEC_sigmax', min=0)
self.set_param_hint('deltax', min=0)
self.set_param_hint('BEC_sigmax', expr=f'3 * {self.prefix}thermal_sigmax - {self.prefix}deltax')
self.set_param_hint('BEC_sigmay', min=0) self.set_param_hint('BEC_sigmay', min=0)
self.set_param_hint('thermal_sigmax', min=0) self.set_param_hint('thermal_sigmax', min=0)
# self.set_param_hint('thermal_sigmay', min=0) # self.set_param_hint('thermal_sigmay', min=0)
@ -341,12 +344,26 @@ class DensityProfileBEC2dModel(Model):
self.set_param_hint('thermalAspectRatio', min=0.8, max=1.2) self.set_param_hint('thermalAspectRatio', min=0.8, max=1.2)
self.set_param_hint('thermal_sigmay', expr=f'{self.prefix}thermalAspectRatio * {self.prefix}thermal_sigmax') self.set_param_hint('thermal_sigmay', expr=f'{self.prefix}thermalAspectRatio * {self.prefix}thermal_sigmax')
# self.set_param_hint('betax', value=0)
# self.set_param_hint('BEC_centerx', expr=f'{self.prefix}thermal_sigmax - {self.prefix}betax')
self.set_param_hint('condensate_fraction', expr=f'{self.prefix}BEC_amplitude / ({self.prefix}BEC_amplitude + {self.prefix}thermal_amplitude)') self.set_param_hint('condensate_fraction', expr=f'{self.prefix}BEC_amplitude / ({self.prefix}BEC_amplitude + {self.prefix}thermal_amplitude)')
def guess(self, data, x, y, negative=False, pureBECThreshold=0.5, noBECThThreshold=0.0, **kwargs): def guess(self, data, x, y, negative=False, pureBECThreshold=0.5, noBECThThreshold=0.0, **kwargs):
"""Estimate initial model parameter values from data.""" """Estimate initial model parameter values from data."""
fitModel = TwoGaussian2dModel() fitModel = TwoGaussian2dModel()
pars = fitModel.guess(data, x=x, y=y, negative=negative) pars = fitModel.guess(data, x=x, y=y, negative=negative)
pars['A_amplitude'].set(min=0)
pars['B_amplitude'].set(min=0)
pars['A_centerx'].set(min=pars['A_centerx'].value - 3 * pars['A_sigmax'],
max=pars['A_centerx'].value + 3 * pars['A_sigmax'],)
pars['A_centery'].set(min=pars['A_centery'].value - 3 * pars['A_sigmay'],
max=pars['A_centery'].value + 3 * pars['A_sigmay'],)
pars['B_centerx'].set(min=pars['B_centerx'].value - 3 * pars['B_sigmax'],
max=pars['B_centerx'].value + 3 * pars['B_sigmax'],)
pars['B_centery'].set(min=pars['B_centery'].value - 3 * pars['B_sigmay'],
max=pars['B_centery'].value + 3 * pars['B_sigmay'],)
fitResult = fitModel.fit(data, x=x, y=y, params=pars, **kwargs) fitResult = fitModel.fit(data, x=x, y=y, params=pars, **kwargs)
pars_guess = fitResult.params pars_guess = fitResult.params
@ -356,25 +373,59 @@ class DensityProfileBEC2dModel(Model):
pars = self.make_params(BEC_amplitude=BEC_amplitude, pars = self.make_params(BEC_amplitude=BEC_amplitude,
thermal_amplitude=thermal_amplitude, thermal_amplitude=thermal_amplitude,
BEC_centerx=pars_guess['A_centerx'].value, BEC_centery=pars_guess['A_centery'].value, BEC_centerx=pars_guess['A_centerx'].value, BEC_centery=pars_guess['A_centery'].value,
BEC_sigmax=(pars_guess['A_sigmax'].value / 2.355), BEC_sigmay=(pars_guess['A_sigmay'].value / 2.355),
# BEC_sigmax=(pars_guess['A_sigmax'].value / 2.355),
deltax = 3 * (pars_guess['B_sigmax'].value * s2) - (pars_guess['A_sigmax'].value / 2.355),
BEC_sigmay=(pars_guess['A_sigmay'].value / 2.355),
thermal_centerx=pars_guess['B_centerx'].value, thermal_centery=pars_guess['B_centery'].value, thermal_centerx=pars_guess['B_centerx'].value, thermal_centery=pars_guess['B_centery'].value,
thermal_sigmax=(pars_guess['B_sigmax'].value * s2), thermal_sigmax=(pars_guess['B_sigmax'].value * s2),
thermalAspectRatio=(pars_guess['B_sigmax'].value * s2) / (pars_guess['B_sigmay'].value * s2) thermalAspectRatio=(pars_guess['B_sigmax'].value * s2) / (pars_guess['B_sigmay'].value * s2)
# thermal_sigmay=(pars_guess['B_sigmay'].value * s2) # thermal_sigmay=(pars_guess['B_sigmay'].value * s2)
) )
if BEC_amplitude / (thermal_amplitude + BEC_amplitude) > pureBECThreshold:
if np.abs(1 - pars_guess['A_sigmax'].value / pars_guess['A_sigmay'].value) < 0.1:
pars[f'{self.prefix}BEC_amplitude'].set(value=0)
pars[f'{self.prefix}thermal_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))
nBEC = pars[f'{self.prefix}BEC_amplitude'] / 2 / np.pi / 5.546 / pars[f'{self.prefix}BEC_sigmay'] / pars[f'{self.prefix}BEC_sigmax']
if (pars[f'{self.prefix}condensate_fraction']>0.95) and (np.max(data) > 1.05 * nBEC):
temp = ((np.max(data) - nBEC) * s2pi * pars[f'{self.prefix}thermal_sigmay'] / pars[f'{self.prefix}thermal_sigmax'])
if temp > pars[f'{self.prefix}BEC_amplitude']:
pars[f'{self.prefix}thermal_amplitude'].set(value=pars[f'{self.prefix}BEC_amplitude'] / 2)
else: else:
pars[f'{self.prefix}thermal_amplitude'].set(value=0)
pars[f'{self.prefix}BEC_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))
pars[f'{self.prefix}thermal_amplitude'].set(value=temp * 10)
if BEC_amplitude / (thermal_amplitude + BEC_amplitude) > pureBECThreshold:
pars[f'{self.prefix}thermal_amplitude'].set(value=0)
pars[f'{self.prefix}BEC_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))
if BEC_amplitude / (thermal_amplitude + BEC_amplitude) < noBECThThreshold: if BEC_amplitude / (thermal_amplitude + BEC_amplitude) < noBECThThreshold:
pars[f'{self.prefix}BEC_amplitude'].set(value=0) pars[f'{self.prefix}BEC_amplitude'].set(value=0)
pars[f'{self.prefix}thermal_amplitude'].set(value=(thermal_amplitude + BEC_amplitude)) pars[f'{self.prefix}thermal_amplitude'].set(value=(thermal_amplitude + BEC_amplitude))
pars[f'{self.prefix}BEC_centerx'].set(
min=pars[f'{self.prefix}BEC_centerx'].value - 10 * pars[f'{self.prefix}BEC_sigmax'].value,
max=pars[f'{self.prefix}BEC_centerx'].value + 10 * pars[f'{self.prefix}BEC_sigmax'].value,
)
pars[f'{self.prefix}thermal_centerx'].set(
min=pars[f'{self.prefix}thermal_centerx'].value - 3 * pars[f'{self.prefix}thermal_sigmax'].value,
max=pars[f'{self.prefix}thermal_centerx'].value + 3 * pars[f'{self.prefix}thermal_sigmax'].value,
)
pars[f'{self.prefix}BEC_centery'].set(
min=pars[f'{self.prefix}BEC_centery'].value - 10 * pars[f'{self.prefix}BEC_sigmay'].value,
max=pars[f'{self.prefix}BEC_centery'].value + 10 * pars[f'{self.prefix}BEC_sigmay'].value,
)
pars[f'{self.prefix}thermal_centery'].set(
min=pars[f'{self.prefix}thermal_centery'].value - 3 * pars[f'{self.prefix}thermal_sigmay'].value,
max=pars[f'{self.prefix}thermal_centery'].value + 3 * pars[f'{self.prefix}thermal_sigmay'].value,
)
pars[f'{self.prefix}BEC_sigmay'].set(
max=5 * pars[f'{self.prefix}BEC_sigmay'].value,
)
pars[f'{self.prefix}thermal_sigmax'].set(
max=5 * pars[f'{self.prefix}thermal_sigmax'].value,
)
return update_param_vals(pars, self.prefix, **kwargs) return update_param_vals(pars, self.prefix, **kwargs)

2380
magenticField.ipynb
File diff suppressed because one or more lines are too long
View File

125
test.ipynb

@ -164,7 +164,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@ -2291,23 +2291,130 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"0.6417497231450753+/-0.01090681927109203"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(-ufloat(99.835,0.018) + ufloat(99.969,0.014))/15*1e3\n",
"(-ufloat(99.835,0.018) + ufloat(100.994,0.008))/1.29/1.4"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"data": {
"text/plain": [
"0.6267995570321101+/-0.01750984307955913"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(ufloat(99.835,0.018) - ufloat(98.703,0.026))/1.29/1.4"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.6342746400885927+/-0.010314471766443609"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"((ufloat(99.835,0.018) - ufloat(98.703,0.026))/1.29/1.4 + (-ufloat(99.835,0.018) + ufloat(100.994,0.008))/1.29/1.4) /2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.642+/-0.011\n",
"0.627+/-0.018\n",
"0.634+/-0.010\n",
"0.0444+/-0.0007\n"
]
}
],
"source": [
"a = (-ufloat(99.835,0.018) + ufloat(100.994,0.008))/1.29/1.4\n",
"b = (ufloat(99.835,0.018) - ufloat(98.703,0.026))/1.29/1.4\n",
"\n",
"print(a)\n",
"print(b)\n",
"print((a+b)/2)\n",
"print((a+b)/2 * (1.29-1.24)*1.4)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.637+/-0.011\n",
"0.641+/-0.018\n",
"0.639+/-0.010\n",
"0.0447+/-0.0007\n"
]
}
],
"source": [
"a = (-ufloat(99.969,0.018) + ufloat(101.120,0.008))/1.29/1.4\n",
"b = (ufloat(99.969,0.018) - ufloat(98.811,0.026))/1.29/1.4\n",
"\n",
"print(a)\n",
"print(b)\n",
"print((a+b)/2)\n",
"print((a+b)/2 * (1.29-1.24)*1.4)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0447+/-0.0007\n"
]
}
],
"source": [] "source": []
}, },
{ {

2498
test_fit.ipynb
File diff suppressed because one or more lines are too long
View File

Loading…
Cancel
Save