From c0b291f5472cd426d348ff9c89ab2920f0a7c77d Mon Sep 17 00:00:00 2001 From: gao <81c52427-d970-4b21-86dc-fd526913f4c9@localhost> Date: Tue, 26 Jul 2022 09:57:45 +0200 Subject: [PATCH] Debug for calculating atom number. Add background subtraction function. Correct the pixel size of the camera --- .idea/workspace.xml | 19 +++++++-- build/lib/dylab/AbsorptionImaging.py | 60 ++++++++++++++++++++++------ dylab/AbsorptionImaging.py | 21 +++++++++- dylab/Camera.py | 4 +- setup.py | 10 ++++- test_absorption_imaging.py | 1 + 6 files changed, 92 insertions(+), 23 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 712d3b7..67fa883 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,9 +1,12 @@ - + + + + @@ -100,7 +110,8 @@ - diff --git a/build/lib/dylab/AbsorptionImaging.py b/build/lib/dylab/AbsorptionImaging.py index fbed9be..2c4513d 100644 --- a/build/lib/dylab/AbsorptionImaging.py +++ b/build/lib/dylab/AbsorptionImaging.py @@ -52,6 +52,13 @@ class absorption_imaging: self.image_dark = None self.image_absorption = None + # + self.image_absorption_cut = None + self.x_start = None + self.y_start = None + self.x_end = None + self.y_end = None + # import the data of transition # The transition should be an object of TransitionClass.py in module TransitionConstant # self.transition = transition @@ -93,10 +100,6 @@ class absorption_imaging: self.image_background = self.image_background.astype(float) self.image_dark = self.image_dark.astype(float) - if not (self.intensity is None): - intensity = np.ones(self.image_atoms.shape) - self.intensity = intensity * self.intensity - def close(self): self.save() @@ -107,6 +110,19 @@ class absorption_imaging: if self.atom_number is not None: self.data_handle.save_result('atom_number', self.atom_number, 'results/absorption_imaging/') + # select the effective data in an rectangle area defined by coordinates of two conner + # The select region will be presented as a red box in the plotting + def select_effective_data(self, left_up_conner, right_down_conner): + + self.x_start = left_up_conner[0] + self.x_end = right_down_conner[0] + self.y_start = left_up_conner[1] + self.y_end = right_down_conner[1] + + self.image_absorption_cut = self.image_absorption[self.y_start:self.y_end, self.x_start:self.x_end] + + return self.image_absorption_cut + # The function do the analyzation for absorption imaging # It will return a two-dimensional array, which stores the absorption imaging def get_image_absorption(self): @@ -133,9 +149,9 @@ class absorption_imaging: def get_beam_power(self, laser_pulse_duration): if self.beam_energy is None: - self.beam_energy = self.image_background-self.image_dark + self.beam_energy = self.image_background - self.image_dark self.beam_energy[self.beam_energy < 0] = 0 - self.beam_energy = self.camera.reading2photon(self.image_background-self.image_dark) + self.beam_energy = self.camera.reading2photon(self.image_background - self.image_dark) self.beam_energy = self.beam_energy * constant.h * self.transition['frequency'] self.beam_energy = np.sum(self.beam_energy) @@ -155,23 +171,31 @@ class absorption_imaging: if self.atom_number is not None and not force_to_run: return self.atom_number - if self.image_absorption is None and not force_to_run: + if self.image_absorption is None or not force_to_run: self.image_absorption = self.get_image_absorption() - OD_act = self.image_absorption + if self.image_absorption_cut is None: + self.image_absorption_cut = self.image_absorption + self.x_start = 0 + self.x_end = self.image_absorption.shape[1] + self.y_start = 0 + self.y_end = self.image_absorption.shape[0] + + OD_act = self.image_absorption_cut cross_section = self.transition.get_cross_section(self.detuning, self.intensity) - self.atom_number = np.sum(cross_section * OD_act) * self.camera['pixel_size_V'] * self.camera['pixel_size_H'] + self.atom_number = np.sum(1 / cross_section * OD_act) * self.camera['pixel_size_V'] * self.camera[ + 'pixel_size_H'] return self.atom_number # Plot the result - def plot_result(self): + def plot_result(self, vmin=None, vmax=None): cmap = plt.cm.get_cmap("jet") - grid = plt.GridSpec(3, 3, wspace=0.2, hspace=0.2) + grid = plt.GridSpec(3, 3, wspace=0.3, hspace=0.3) ax1 = plt.subplot(grid[0, 0]) pos = ax1.imshow(self.image_atoms, cmap=cmap) @@ -188,9 +212,19 @@ class absorption_imaging: ax3.set_title('Dark') plt.colorbar(pos, ax=ax3) - ax4 = plt.subplot(grid[0:3, 1:3]) - pos = ax4.imshow(self.image_absorption, cmap=cmap) + ax4 = plt.subplot(grid[0:2, 1:3]) + pos = ax4.imshow(self.image_absorption, cmap=cmap, vmin=vmin, vmax=vmax) ax4.set_title('Absorption Imaging') plt.colorbar(pos, ax=ax4) + ax4.plot([self.x_start, self.x_start], [self.y_start, self.y_end], color='black') + ax4.plot([self.x_end, self.x_end], [self.y_start, self.y_end], color='black') + ax4.plot([self.x_start, self.x_end], [self.y_start, self.y_start], color='black') + ax4.plot([self.x_start, self.x_end], [self.y_end, self.y_end], color='black') + + ax5 = plt.subplot(grid[2:3, 1:3]) + atom_number_str = '{:g}'.format(self.atom_number) + ax5.text(0, 0.55, 'Atom Number : '+atom_number_str, horizontalalignment='left', verticalalignment='center', + transform=ax5.transAxes, fontsize=40) + plt.axis('off') plt.show() diff --git a/dylab/AbsorptionImaging.py b/dylab/AbsorptionImaging.py index 2c4513d..9a5b313 100644 --- a/dylab/AbsorptionImaging.py +++ b/dylab/AbsorptionImaging.py @@ -52,7 +52,7 @@ class absorption_imaging: self.image_dark = None self.image_absorption = None - # + # select effective region self.image_absorption_cut = None self.x_start = None self.y_start = None @@ -79,7 +79,6 @@ class absorption_imaging: def __enter__(self): self.get_image_absorption() - self.get_atom_number() return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -110,6 +109,20 @@ class absorption_imaging: if self.atom_number is not None: self.data_handle.save_result('atom_number', self.atom_number, 'results/absorption_imaging/') + def corner_subtract(self, image, x_fraction, y_fraction): + + mean = 0 + mean += np.average(image[0:int(image.shape[0] * y_fraction), 0:int(image.shape[1] * x_fraction)]) + mean += np.average(image[0:int(image.shape[0] * y_fraction), + int(image.shape[1] - image.shape[1] * x_fraction):int(image.shape[1])]) + mean += np.average(image[int(image.shape[0] - image.shape[0] * y_fraction):int(image.shape[1]), + 0:int(image.shape[1] * x_fraction)]) + mean += np.average(image[int(image.shape[0] - image.shape[0] * y_fraction):int(image.shape[1]), + int(image.shape[1] - image.shape[1] * x_fraction):int(image.shape[1])]) + mean = mean / 4 + + return mean + # select the effective data in an rectangle area defined by coordinates of two conner # The select region will be presented as a red box in the plotting def select_effective_data(self, left_up_conner, right_down_conner): @@ -181,6 +194,10 @@ class absorption_imaging: self.y_start = 0 self.y_end = self.image_absorption.shape[0] + back_ground = self.corner_subtract(self.image_absorption_cut, 0.1, 0.1) + self.image_absorption_cut = self.image_absorption_cut - back_ground + self.image_absorption = self.image_absorption - back_ground + OD_act = self.image_absorption_cut cross_section = self.transition.get_cross_section(self.detuning, self.intensity) diff --git a/dylab/Camera.py b/dylab/Camera.py index f7ed53a..b286bd3 100644 --- a/dylab/Camera.py +++ b/dylab/Camera.py @@ -19,8 +19,8 @@ class c11440_36u(dict): def __init__(self, wavelength): super().__init__() - self['pixel_size_V'] = 5.8e-6 - self['pixel_size_H'] = 5.8e-6 + self['pixel_size_V'] = 5.86e-6 + self['pixel_size_H'] = 5.86e-6 self['pixel_num_H'] = 1920 self['pixel_num_v'] = 1200 diff --git a/setup.py b/setup.py index 3e9ae29..2ab153f 100644 --- a/setup.py +++ b/setup.py @@ -5,17 +5,23 @@ with open("README.md", "r") as fh: setuptools.setup( name="dylab", - version="0.0.1", + version="0.0.2", author="QF-group (AG Chomaz), Heidelberg university", author_email="gao@physi.uni-heidelberg.de", description="An internal toolbox package used for analyzation data of an ultracold atom experiment.", # long_description=long_description, long_description_content_type="text/markdown", - # url="https://github.com/pypa/sampleproject", + url="https://git.physi.uni-heidelberg.de/gao/dylab", packages=setuptools.find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", ], + install_requires=[ + 'numpy', + 'matplotlib', + 'lmfit', + 'laserbeamsize' + ], ) diff --git a/test_absorption_imaging.py b/test_absorption_imaging.py index f0837aa..e2dc29d 100644 --- a/test_absorption_imaging.py +++ b/test_absorption_imaging.py @@ -9,6 +9,7 @@ with AbsorptionImaging.absorption_imaging(path, 'MOT_3D_Camera', 'in_situ_absorp absorption_imaging_transition, mot_3D_camera, 0, 0) as absorption_image: absorption_image.select_effective_data((800, 500), (1000, 700)) + absorption_image.get_atom_number() absorption_image.plot_result(-0.05, 0.05) print(absorption_image.atom_number)