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

Commit aa572fe3 authored by bliss administrator's avatar bliss administrator

Separated dark and flat corrections. Tested version.

parent 67a0efd1
......@@ -5,74 +5,155 @@ import time
from bliss.setup_globals import *
from bliss.config.static import get_config
from bliss.common.scans import ct
class ImageCorrection():
def __init__(self, tomo):
self.tomo = None
self.dark_image = None
self.flat_image = None
def __init__(self, name, config):
self.__name = name
self.__config = config
self.__dark_image = None
self.__flat_image = None
self.__tomo = None
self.__detector = None
@property
def name(self):
"""
A unique name for the Bliss object
"""
return self.__name
@property
def config(self):
"""
The configuration of Ar Gas Valve
"""
return self.__config
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
def set_tomo(self, tomo):
self.__tomo = tomo
self.__detector = self.__tomo.tomo_ccd.detector
file_format = self.detector.saving.file_format
self.detector.saving.file_format = "EDF"
def take_dark(self):
if self.__tomo == None:
raise RuntimeError("Tomo not set. Please enter tomo object to use with set_tomo()")
self.__dark_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()
self.dark_off()
# take dark image
dark_n = 1
dark_scan = self.tomo.dark_scan(dark_n, exposure_time, save=True)
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
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
except:
self.__detector.saving.file_format = file_format
raise
self.__detector.saving.file_format = file_format
self.__detector.processing.background = self.__dark_image
print(f"Background image = {self.__dark_image}")
def take_flat(self):
if self.__tomo == None:
raise RuntimeError("Tomo not set. Please enter tomo object to use with set_tomo()")
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.flat_off()
# take reference image
ref_n = 1
ref_scan =self.tomo.ref_scan(ref_n, exposure_time, save=True)
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
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
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
self.__detector.saving.file_format = file_format
print(f"Background image = {self.dark_image}")
print(f"Flatfield image = {self.flat_image}")
self.__detector.processing.flatfield = self.__flat_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!")
#def on(self):
#if self.__detector.processing.background == None or self.__detector.processing.flatfield == 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 dark_on(self):
if self.__detector.processing.background == None:
raise RuntimeError("Cannot switch on! Missing image for dark")
self.detector.processing.use_background_substraction = "enable_file"
self.detector.processing.use_flatfield = True
self.__detector.processing.use_background_substraction = "enable_file"
def dark_off(self):
self.__detector.processing.use_background_substraction = "disable"
# be sure that it is applied
ct(self.__tomo.parameters.exposure_time)
def flat_on(self, normalize=True):
if self.__detector.processing.flatfield == None:
raise RuntimeError("Cannot switch on! Missing image for flat")
# set normaization
ff_proxy = self.__detector._get_proxy("flatfield")
ff_proxy.normalize = normalize
def off(self):
self.detector.processing.use_background_substraction = "disable"
self.detector.processing.use_flatfield = False
# start
self.__detector.processing.use_flatfield = True
def flat_off(self):
self.__detector.processing.use_flatfield = False
# be sure that it is applied
ct(self.__tomo.parameters.exposure_time)
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")
background = 'ON'
flatfield = 'ON'
if self.__tomo == None:
info_str = (f"tomo : Not yet given. Please use set_tomo()\n")
return info_str
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.__detector.processing.background}\n")
info_str += (f"flat_image : {self.__detector.processing.flatfield}\n")
if self.__detector.processing.use_background_substraction == 'disable':
background = 'OFF'
if self.__detector.processing.use_flatfield == False:
flatfield = 'OFF'
info_str += (f"use_background_substraction : {background}\n")
info_str += (f"use_flatfield : {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