Debug for calculating atom number.

Add background subtraction function.

Correct the pixel size of the camera
This commit is contained in:
gao 2022-07-26 09:57:45 +02:00
parent ac51408793
commit c0b291f547
6 changed files with 92 additions and 23 deletions

19
.idea/workspace.xml generated
View File

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="68ddce6f-baaa-4bac-af24-443b9be545bf" name="Changes" comment="First working version. Need introductions">
<list default="true" id="68ddce6f-baaa-4bac-af24-443b9be545bf" name="Changes" comment="Debug for calculating atom number.&#10;&#10;Add selecting the effective area function in AbsorptionImaging.py.&#10;&#10;Optimaze plotting function.">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/build/lib/dylab/AbsorptionImaging.py" beforeDir="false" afterPath="$PROJECT_DIR$/build/lib/dylab/AbsorptionImaging.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dylab/AbsorptionImaging.py" beforeDir="false" afterPath="$PROJECT_DIR$/dylab/AbsorptionImaging.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/dylab/Camera.py" beforeDir="false" afterPath="$PROJECT_DIR$/dylab/Camera.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/setup.py" beforeDir="false" afterPath="$PROJECT_DIR$/setup.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test_absorption_imaging.py" beforeDir="false" afterPath="$PROJECT_DIR$/test_absorption_imaging.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -72,7 +75,7 @@
<updated>1658317648754</updated>
<workItem from="1658317653047" duration="53940000" />
<workItem from="1658490102584" duration="2917000" />
<workItem from="1658494814456" duration="16216000" />
<workItem from="1658494814456" duration="18815000" />
</task>
<task id="LOCAL-00001" summary="First working version. Need introductions">
<created>1658494877565</created>
@ -81,7 +84,14 @@
<option name="project" value="LOCAL" />
<updated>1658494877565</updated>
</task>
<option name="localTasksCounter" value="2" />
<task id="LOCAL-00002" summary="Debug for calculating atom number.&#10;&#10;Add selecting the effective area function in AbsorptionImaging.py.&#10;&#10;Optimaze plotting function.">
<created>1658744594836</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1658744594836</updated>
</task>
<option name="localTasksCounter" value="3" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -100,7 +110,8 @@
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="First working version. Need introductions" />
<option name="LAST_COMMIT_MESSAGE" value="First working version. Need introductions" />
<MESSAGE value="Debug for calculating atom number.&#10;&#10;Add selecting the effective area function in AbsorptionImaging.py.&#10;&#10;Optimaze plotting function." />
<option name="LAST_COMMIT_MESSAGE" value="Debug for calculating atom number.&#10;&#10;Add selecting the effective area function in AbsorptionImaging.py.&#10;&#10;Optimaze plotting function." />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>

View File

@ -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()

View File

@ -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)

View File

@ -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

View File

@ -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'
],
)

View File

@ -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)