Skip to content
Snippets Groups Projects
Commit 85292e6c authored by David Hammer's avatar David Hammer
Browse files

LPD: add gain stage preview

parent ef67fc89
No related branches found
No related tags found
1 merge request!12Snapshot: field test deployed version as of end of run 202201
...@@ -5,6 +5,7 @@ import numpy as np ...@@ -5,6 +5,7 @@ import numpy as np
from karabo.bound import ( from karabo.bound import (
DOUBLE_ELEMENT, DOUBLE_ELEMENT,
KARABO_CLASSINFO, KARABO_CLASSINFO,
OUTPUT_CHANNEL,
OVERWRITE_ELEMENT, OVERWRITE_ELEMENT,
STRING_ELEMENT, STRING_ELEMENT,
VECTOR_STRING_ELEMENT, VECTOR_STRING_ELEMENT,
...@@ -12,7 +13,7 @@ from karabo.bound import ( ...@@ -12,7 +13,7 @@ from karabo.bound import (
from . import base_gpu, base_calcat, utils from . import base_gpu, base_calcat, utils
from ._version import version as deviceVersion from ._version import version as deviceVersion
from .base_correction import BaseCorrection, add_correction_step_schema from .base_correction import BaseCorrection, add_correction_step_schema, preview_schema
class LpdConstants(enum.Enum): class LpdConstants(enum.Enum):
...@@ -57,6 +58,9 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -57,6 +58,9 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner):
input_data_dtype, input_data_dtype,
output_data_dtype, output_data_dtype,
) )
self.gain_map_gpu = cupy.empty(self.processed_shape, dtype=cupy.float32)
self.preview_buffer_getters.append(self._get_gain_map_for_preview)
self.map_shape = (constant_memory_cells, pixels_x, pixels_y, 3) self.map_shape = (constant_memory_cells, pixels_x, pixels_y, 3)
self.offset_map_gpu = cupy.zeros(self.map_shape, dtype=cupy.float32) self.offset_map_gpu = cupy.zeros(self.map_shape, dtype=cupy.float32)
self.gain_amp_map_gpu = cupy.ones(self.map_shape, dtype=cupy.float32) self.gain_amp_map_gpu = cupy.ones(self.map_shape, dtype=cupy.float32)
...@@ -73,6 +77,9 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -73,6 +77,9 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner):
def _get_corrected_for_preview(self): def _get_corrected_for_preview(self):
return self.processed_data_gpu return self.processed_data_gpu
def _get_gain_map_for_preview(self):
return self.gain_map_gpu
def correct(self, flags): def correct(self, flags):
self.correction_kernel( self.correction_kernel(
self.full_grid, self.full_grid,
...@@ -87,6 +94,7 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner): ...@@ -87,6 +94,7 @@ class LpdGpuRunner(base_gpu.BaseGpuRunner):
self.flatfield_map_gpu, self.flatfield_map_gpu,
self.bad_pixel_map_gpu, self.bad_pixel_map_gpu,
self.bad_pixel_mask_value, self.bad_pixel_mask_value,
self.gain_map_gpu,
self.processed_data_gpu, self.processed_data_gpu,
), ),
) )
...@@ -283,6 +291,13 @@ class LpdCorrection(BaseCorrection): ...@@ -283,6 +291,13 @@ class LpdCorrection(BaseCorrection):
.commit(), .commit(),
) )
(
OUTPUT_CHANNEL(expected)
.key("preview.outputGainMap")
.dataSchema(preview_schema)
.commit(),
)
LpdCalcatFriend.add_schema(expected, LpdCorrection._managed_keys) LpdCalcatFriend.add_schema(expected, LpdCorrection._managed_keys)
add_correction_step_schema( add_correction_step_schema(
expected, LpdCorrection._managed_keys, LpdCorrection._correction_field_names expected, LpdCorrection._managed_keys, LpdCorrection._correction_field_names
...@@ -401,7 +416,11 @@ class LpdCorrection(BaseCorrection): ...@@ -401,7 +416,11 @@ class LpdCorrection(BaseCorrection):
pulse_table, pulse_table,
warn_func=self.log_status_warn, warn_func=self.log_status_warn,
) )
preview_raw, preview_corrected = self.kernel_runner.compute_previews( (
preview_raw,
preview_corrected,
preview_gain_map,
) = self.kernel_runner.compute_previews(
preview_slice_index, preview_slice_index,
) )
...@@ -415,6 +434,7 @@ class LpdCorrection(BaseCorrection): ...@@ -415,6 +434,7 @@ class LpdCorrection(BaseCorrection):
( (
("preview.outputRaw", preview_raw), ("preview.outputRaw", preview_raw),
("preview.outputCorrected", preview_corrected), ("preview.outputCorrected", preview_corrected),
("preview.outputGainMap", preview_gain_map),
), ),
metadata, metadata,
) )
......
...@@ -12,6 +12,7 @@ extern "C" { ...@@ -12,6 +12,7 @@ extern "C" {
const float* flatfield_map, const float* flatfield_map,
const unsigned int* bad_pixel_map, const unsigned int* bad_pixel_map,
const float bad_pixel_mask_value, const float bad_pixel_mask_value,
float* gain_map, // similar to preview for AGIPD
{{output_data_dtype}}* output) { {{output_data_dtype}}* output) {
const size_t X = {{pixels_x}}; const size_t X = {{pixels_x}};
const size_t Y = {{pixels_y}}; const size_t Y = {{pixels_y}};
...@@ -33,6 +34,7 @@ extern "C" { ...@@ -33,6 +34,7 @@ extern "C" {
const unsigned short raw_data_value = data[data_index]; const unsigned short raw_data_value = data[data_index];
const unsigned char gain = (raw_data_value >> 12) & 0x0003; const unsigned char gain = (raw_data_value >> 12) & 0x0003;
float corrected = (float)(raw_data_value & 0x0fff); float corrected = (float)(raw_data_value & 0x0fff);
float gain_for_preview = (float)gain;
const size_t gm_map_stride_gain = 1; const size_t gm_map_stride_gain = 1;
const size_t gm_map_stride_x = 3 * gm_map_stride_gain; const size_t gm_map_stride_x = 3 * gm_map_stride_gain;
...@@ -49,6 +51,7 @@ extern "C" { ...@@ -49,6 +51,7 @@ extern "C" {
if (gain > 2 || ((corr_flags & BPMASK) && bad_pixel_map[gm_map_index])) { if (gain > 2 || ((corr_flags & BPMASK) && bad_pixel_map[gm_map_index])) {
// now also checking for illegal gain value // now also checking for illegal gain value
corrected = bad_pixel_mask_value; corrected = bad_pixel_mask_value;
gain_for_preview = bad_pixel_mask_value;
} else { } else {
// TODO: save GPU memory by combining maps // TODO: save GPU memory by combining maps
if (corr_flags & OFFSET) { if (corr_flags & OFFSET) {
...@@ -68,6 +71,7 @@ extern "C" { ...@@ -68,6 +71,7 @@ extern "C" {
} }
} }
} }
gain_map[data_index] = gain_for_preview;
{% if output_data_dtype == "half" %} {% if output_data_dtype == "half" %}
output[data_index] = __float2half(corrected); output[data_index] = __float2half(corrected);
{% else %} {% else %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment