Initialize the MisRegistration object, which defines misalignments of an optical element.
Parameters:
| Name |
Type |
Description |
Default |
shiftX
|
float
|
Displacement in X axis (left-right) w.r.t optical center [meters]
|
required
|
shiftY
|
float
|
Displacement in Y axis (top-bottom) w.r.t optical center [meters]
|
required
|
rotation
|
float
|
Rotation along optical axis [degres]
|
required
|
radialScaling
|
float
|
Pupil radial scaling. Larger than 1 is magnification. [adimensional]
|
required
|
logger
|
Logger
|
Logger instance for diagnostics.
|
None
|
**kwargs
|
dict
|
Additional keyword arguments.
vx : float, optional
X axis displacement speed [m/s].
vy : float, optional
Y axis displacement speed [m/s].
wz : float, optional
Rotation speed along optical [degree/s].
|
{}
|
Source code in SAOS/MisRegistration.py
| def __init__(self,
shiftX:float,
shiftY:float,
rotation:float,
radialScaling:float,
telescope,
logger=None,
**kwargs):
"""
Initialize the MisRegistration object, which defines misalignments of an optical element.
Parameters
----------
shiftX : float
Displacement in X axis (left-right) w.r.t optical center [meters]
shiftY : float
Displacement in Y axis (top-bottom) w.r.t optical center [meters]
rotation : float
Rotation along optical axis [degres]
radialScaling : float
Pupil radial scaling. Larger than 1 is magnification. [adimensional]
logger : logging.Logger, optional
Logger instance for diagnostics.
**kwargs : dict, optional
Additional keyword arguments.
vx : float, optional
X axis displacement speed [m/s].
vy : float, optional
Y axis displacement speed [m/s].
wz : float, optional
Rotation speed along optical [degree/s].
"""
self.tag = 'misRegistration'
if logger is None:
self.queue_listerner = self.setup_logging()
self.logger = logging.getLogger()
self.external_logger_flag = False
else:
self.external_logger_flag = True
self.logger = logger
self.shiftX = shiftX
self.shiftY = shiftY
self.rotation = rotation
self.radialScaling = radialScaling
self.spatialSampling = telescope.pixelSize
self.vx = kwargs.get('vx', 0.0)
self.vy = kwargs.get('vy', 0.0)
self.wz = kwargs.get('wz', 0.0)
|
queue_listerner
instance-attribute
queue_listerner = setup_logging()
logger
instance-attribute
external_logger_flag
instance-attribute
external_logger_flag = False
shiftX
instance-attribute
shiftY
instance-attribute
rotation
instance-attribute
radialScaling
instance-attribute
radialScaling = radialScaling
spatialSampling
instance-attribute
spatialSampling = pixelSize
update_params
update_params(elapsedTime)
Source code in SAOS/MisRegistration.py
| def update_params(self, elapsedTime):
self.shiftX += self.vx * elapsedTime
self.shiftY += self.vy * elapsedTime
self.rotation += self.wz * elapsedTime
|
set_params
set_params(
shiftX,
shiftY,
rotation,
radialScaling,
vx=None,
vy=None,
wz=None,
)
Source code in SAOS/MisRegistration.py
| def set_params(self, shiftX, shiftY, rotation, radialScaling, vx=None, vy=None, wz=None):
self.shiftX = shiftX
self.shiftY = shiftY
self.rotation = rotation
self.radialScaling = radialScaling
if vx is not None:
self.vx = vx
if vy is not None:
self.vy = vy
if wz is not None:
self.wz = wz
|
apply_misreg
apply_misreg(input_buffer)
Source code in SAOS/MisRegistration.py
| def apply_misreg(self, input_buffer):
temp_buffer = np.copy(input_buffer)
if self.radialScaling != 1:
# Apply magnification
scalingMatrix = cv2.getRotationMatrix2D((input_buffer.shape[1]/2,input_buffer.shape[0]/2), 0, self.radialScaling)
temp_buffer = cv2.warpAffine(input_buffer, scalingMatrix, (input_buffer.shape[1], input_buffer.shape[0]))
if self.rotation != 0:
# Apply rotation
temp_buffer = sp.ndimage.rotate(temp_buffer, self.rotation, reshape=False)
# Apply shift
if self.shiftX != 0 or self.shiftY != 0:
translationMatrix = np.float32([[1, 0, self.shiftX/self.spatialSampling], [0, 1, self.shiftY/self.spatialSampling]])
temp_buffer = cv2.warpAffine(temp_buffer, translationMatrix, (temp_buffer.shape[0], temp_buffer.shape[1]),
flags=cv2.INTER_LINEAR,
borderMode=cv2.BORDER_CONSTANT)
return temp_buffer
|
setup_logging
setup_logging(logging_level=logging.WARNING)
Source code in SAOS/MisRegistration.py
| def setup_logging(self, logging_level=logging.WARNING):
#
# Setup of logging at the main process using QueueHandler
log_queue = Queue()
queue_handler = logging.handlers.QueueHandler(log_queue)
root_logger = logging.getLogger()
root_logger.setLevel(logging_level) # Minimum log level
# Setup of the formatting
formatter = logging.Formatter(
"%(asctime)s - %(levelname)s - %(message)s"
)
# Output to terminal
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
# Qeue handler captures the messages from the different logs and serialize them
queue_listener = logging.handlers.QueueListener(log_queue, console_handler)
root_logger.addHandler(queue_handler)
queue_listener.start()
return queue_listener
|
__del__
Source code in SAOS/MisRegistration.py
| def __del__(self):
if not self.external_logger_flag:
self.queue_listerner.stop()
|