Skip to content
Snippets Groups Projects
Commit f55ee7e2 authored by Hugo chauvet's avatar Hugo chauvet
Browse files

add the new normalisation for multi pos excitation

parent de233263
No related branches found
No related tags found
No related merge requests found
......@@ -77,11 +77,14 @@ def darkwhite(images, dark, white, darkofwhite, white_z, force, lower, smooth, v
dark = smoothed_names[1]
darkofwhite = smoothed_names[2]
print(f'🪩 Normalize images with:')
print(f'- dark: {dark}')
print(f'- white: {white}')
if version == 2:
print(f'- white for power estimation: {original_white}')
assert 'smooth' not in original_white.name.lower(), "Need to use a non smoothed white to estimate the power of the beam"
print(f'- dark of white: {darkofwhite}')
darkwhite_names = [Path(dark).name, Path(white).name, Path(darkofwhite).name]
......
......@@ -282,13 +282,31 @@ def correct_dark_white(images: str, dark: str = '', white: str = '' ,
dow_stack = dow_stack.map_blocks(remove_cosmic, 2, dtype=dow_stack.dtype)
diffwhite = white_stack - dow_stack
if version == 2:
print('Two steps normalisation: Spectral power from the mean, then spatial variation of the white')
assert original_white is not None, "Please provide a non-smoothed white"
# Estimation of the power
owhite = mmzarr_read(str(original_white))[0, 0, :, zpos].map_blocks(img_as_float)
whiteMean = owhite.mean(axis=(-2,-1))
powerEstimation = whiteMean / whiteMean.max()
powerEstimation = powerEstimation.compute()
# Create a normed white with a maximum of 1
# for each excitation wavelength
max_white = diffwhite.max(axis=(-2,-1))
min_ratio = white_stack.min() / max_white
normed_white = diffwhite / max_white[:, None, None]
# Cut at the maximum of the minimum ratio
normed_white[normed_white < min_ratio.max()] = min_ratio.max()
else:
print("On step normalisation: spectral and sptatial from the white normed by it's stack maximum")
max_white = diffwhite.max()
min_ratio = white_stack.min() / max_white
normed_white = diffwhite / max_white
normed_white[normed_white < min_ratio] = min_ratio
final_white = normed_white.compute()[None, None, :, None]
final_white = normed_white.compute()[None, None, :, :]
darks = mmzarr_read(str(darkin))
darks_meta = read_mmzarr_metadata(str(darkin))
......@@ -340,6 +358,10 @@ def correct_dark_white(images: str, dark: str = '', white: str = '' ,
diff_im_darks = images - darks
diff_im_darks[diff_im_darks < 0 ] = 0
if version == 2:
# divide the data by the power estimation
diff_im_darks = diff_im_darks / powerEstimation[None, None, None, :, None, None]
# Compute the transfert function
# The transfer function is just the inverse of the white
......
......@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "DITB"
version = "20250108rc1"
version = "20250108rc2"
readme = "README.md"
requires-python = ">=3.11"
authors = [{ name = "Hugo Chauvet", email = "hugo.chauvet@synchrotron-soleil.fr" }]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment