Browse Source

Merge branch 'add_rotation'

master
Joschka 1 year ago
parent
commit
81bd1ea4ee
  1. 23
      Analyser/FitAnalyser.py
  2. 856
      Analyser/Joschka/test_rotation.ipynb

23
Analyser/FitAnalyser.py

@ -170,7 +170,7 @@ def rotate_coord(x,y, rot_angle):
def density_profile_BEC_2d(x, y=0.0, amp_bec=1.0, amp_th=1.0, x0_bec=0.0, y0_bec=0.0, x0_th=0.0, y0_th=0.0,
sigmax_bec=1.0, sigmay_bec=1.0, sigma_th=1.0, rot_angle=None):
rot_angle *= -1
if rot_angle is not None:
x, y = rotate_coord(x,y, rot_angle)
x0_bec, y0_bec = rotate_coord(x0_bec, y0_bec, rot_angle)
@ -424,7 +424,7 @@ class DensityProfileBEC2dModel(lmfit.Model):
self.set_param_hint('atom_number_th', expr=f'{self.prefix}amp_th * 2 * 3.14159265359 * 1.20206 / 1.643 * {self.prefix}sigma_th * {self.prefix}sigma_th')
self.set_param_hint('condensate_fraction', expr=f'{self.prefix}atom_number_bec / ({self.prefix}atom_number_bec + {self.prefix}atom_number_th)')
def guess(self, data, x, y, rot_angle=0, vary_rot=False, pre_check=False, post_check=False, **kwargs):
def guess(self, data, x, y, rot_angle=0, vary_rot=False, is_debug=False, pre_check=False, post_check=False, **kwargs):
"""Estimate and create initial model parameters for 2d bimodal fit, by doing a 1d bimodal fit along an integrated slice of the image
:param data: Flattened 2d array, in form [a_00, a_10, a_20, ..., a_01, a_02, .. ,a_XY] with a_xy, x_dim=X, y_dim=Y
@ -433,6 +433,11 @@ class DensityProfileBEC2dModel(lmfit.Model):
:type x: 1d numpy array
:param y: flattened Y output of np.meshgrid(x_axis,y_axis) in form: [y1, y1, .., y1 (X times), y2, y2, .., y2 (X times), .. Y times ..]
:type y: 1d numpy array
:param rot_angle: angle in degrees, The image is rotated counterclockwise by this angle to match the two axes of the cloud with x and y
for the guessing procedure. The 2d-fit is done by rotating the fitting function clockwise with this angle
:type rot_angle: float
:param vary_rot: if True the angle is varied in the 2d-fit
:type vary_rot: bool, optional
:param pre_check: if True the amplitude of the 1d fit is used to guess if the image is purely BEC or thermal and
the corresponding amplitude of the 2d fit is set to zero and not varied to speed up the fitting, defaults to False
:type pre_check: bool, optional
@ -444,6 +449,7 @@ class DensityProfileBEC2dModel(lmfit.Model):
"""
self.pre_check = pre_check
self.post_check = post_check
self.is_debug = is_debug
# reshaping the image to 2D in the form [[a_00, a_01, .., a_0Y], [a_10,.., a_1Y], .., [a_X0, .., a_XY]], with a_xy
x_width = len(np.unique(x))
@ -454,6 +460,17 @@ class DensityProfileBEC2dModel(lmfit.Model):
data = np.reshape(data, (y_width, x_width))
data = data.T
if is_debug:
X, Y = np.meshgrid(x_1d,y_1d)
plt.pcolormesh(X,Y, data.T, cmap='jet')
plt.gca().set_aspect('equal')
plt.title(f'Input data')
plt.xlabel('x_axis')
plt.ylabel('y_axis')
plt.show()
# the image is rotated counterclockwise by rot_angle, CAREFUL: The image has the form a_xy (last coordinate y) and therefore the rotation is done counter-clockwise.
# Doing the same with a standard image with a_yx rotates it clockwise!
if rot_angle != 0:
data = rotate(data, rot_angle, reshape=False)
@ -602,7 +619,7 @@ class DensityProfileBEC2dModel(lmfit.Model):
else:
print('Error in small width BEC recogintion, s_width_ind should be 0 or 1')
params[f'{self.prefix}rot_angle'].set(value=-rot_angle, min=-rot_angle-30, max=-rot_angle+30, vary=vary_rot)
params[f'{self.prefix}rot_angle'].set(value=rot_angle, min=rot_angle-30, max=rot_angle+30, vary=vary_rot)
if self.is_debug:
print('')

856
Analyser/Joschka/test_rotation.ipynb
File diff suppressed because one or more lines are too long
View File

Loading…
Cancel
Save