GitLab will be upgraded on June 23rd evening. During the upgrade the service will be unavailable, sorry for the inconvenience.

Commit 02f2d837 authored by bliss administrator's avatar bliss administrator

Added image correction class to allow background and flat field correction by Lima

parent 430e6e64
import sys
import gevent
import numpy as np
import time
from bliss.setup_globals import *
from bliss.config.static import get_config
class ImageCorrection():
def __init__(self, tomo):
self.tomo = None
self.dark_image = None
self.flat_image = None
self.tomo = tomo
self.detector = self.tomo.tomo_ccd.detector
def prepare(self):
self.dark_image = None
self.flat_image = None
exposure_time = self.tomo.parameters.exposure_time
file_format = self.detector.saving.file_format
self.detector.saving.file_format = "EDF"
try:
self.off()
# take dark image
dark_n = 1
dark_scan = self.tomo.dark_scan(dark_n, exposure_time, save=True)
self.dark_image = self.detector.proxy.saving_directory + "/" + self.detector.proxy.saving_prefix + \
"{:>04}".format(self.detector.proxy.last_image_saved) + self.detector.proxy.saving_suffix
# take reference image
ref_n = 1
ref_scan =self.tomo.ref_scan(ref_n, exposure_time, save=True)
self.flat_image = self.detector.proxy.saving_directory + "/" + self.detector.proxy.saving_prefix + \
"{:>04}".format(self.detector.proxy.last_image_saved) + self.detector.proxy.saving_suffix
except:
self.detector.saving.file_format = file_format
raise
self.detector.saving.file_format = file_format
self.detector.processing.background = self.dark_image
self.detector.processing.flatfield = self.flat_image
print(f"Background image = {self.dark_image}")
print(f"Flatfield image = {self.flat_image}")
def on(self):
if self.dark_image == None or self.flat_image == None:
raise RuntimeError("Cannot switch on! Missing image for dark or flat!")
self.detector.processing.use_background_substraction = "enable_file"
self.detector.processing.use_flatfield = True
def off(self):
self.detector.processing.use_background_substraction = "disable"
self.detector.processing.use_flatfield = False
def __info__(self):
info_str = (f"tomo : {self.tomo.name}\n")
info_str += (f"detector : {self.tomo.tomo_ccd.detector.name}\n")
info_str += (f"dark_image : {self.dark_image}\n")
info_str += (f"flat_image : {self.flat_image}\n")
info_str += (f"use_background_substraction : {self.detector.processing.use_background_substraction }\n")
info_str += (f"use_flatfield : {self.detector.processing.use_flatfield }\n")
return info_str
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment