From 508110fde8309e54de782ff34273609db32a5e33 Mon Sep 17 00:00:00 2001 From: scriptorron <22291722+scriptorron@users.noreply.github.com> Date: Sun, 17 Dec 2023 16:21:42 +0100 Subject: [PATCH 1/3] added debug messages --- src/indi_pylibcamera/CameraControl.py | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/indi_pylibcamera/CameraControl.py b/src/indi_pylibcamera/CameraControl.py index f753f5a..40d9620 100755 --- a/src/indi_pylibcamera/CameraControl.py +++ b/src/indi_pylibcamera/CameraControl.py @@ -619,6 +619,32 @@ def createRgbFits(self, array, metadata): hdul = fits.HDUList([hdu]) return hdul + def log_FrameInformation(self, array, metadata): + """write frame information to debug log + + Args: + array: raw frame data + metadata: frame metadata + """ + # FIXME: change error to debug + logger.error(f'array shape: {array.shape}') + # + bit_depth = self.present_CameraSettings.RawMode["bit_depth"] + logger.error(f'{bit_depth} bits per pixel') + # + bit_depth = 16 # FIXME + BitUsage = np.zeros(bit_depth) == 0 + Bit = np.r_[range(bit_depth)] + for b in Bit: + BitUsage[b] = ((array & (1 << b)) != 0).any() + UsedBits = ''.join(["1" if b!=0 else "0" for b in BitUsage]) + UsedBits = UsedBits[-1::-1] # MSB first + logger.error(f' data alignment: (MSB) {UsedBits} (LSB) (1=at least one 1 in data, 0=all 0)') + # + logger.error(f'metadata: {metadata}') + # + logger.error(f'camera configuration: {self.picam2.camera_configuration()}') + def __ExposureLoop(self): """exposure loop @@ -716,6 +742,7 @@ def __ExposureLoop(self): # (for instance: size) will fit better to hardware self.picam2.align_configuration(config) # set still configuration + logger.error(f'config requested: {config}') # FIXME self.picam2.configure(config) # changing exposure time or analogue gain needs a restart if IsRestartNeeded: @@ -771,6 +798,7 @@ def __ExposureLoop(self): if not Abort: (array, ), metadata = self.picam2.wait(job) logger.info("got exposed frame") + self.log_FrameInformation(array=array, metadata=metadata) # at least HQ camera reports CCD temperature in meta data self.parent.setVector("CCD_TEMPERATURE", "CCD_TEMPERATURE_VALUE", value=metadata.get('SensorTemperature', 0)) From c6d60501ef7bb2b4ee29f9bdc05cc0fbc547d7c7 Mon Sep 17 00:00:00 2001 From: scriptorron <22291722+scriptorron@users.noreply.github.com> Date: Sun, 17 Dec 2023 17:41:23 +0100 Subject: [PATCH 2/3] determine frame format based on actual and not on requested camera setting --- src/indi_pylibcamera/CameraControl.py | 39 ++++++++++++++++----------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/indi_pylibcamera/CameraControl.py b/src/indi_pylibcamera/CameraControl.py index 40d9620..c60820b 100755 --- a/src/indi_pylibcamera/CameraControl.py +++ b/src/indi_pylibcamera/CameraControl.py @@ -504,7 +504,14 @@ def createBayerFits(self, array, metadata): metadata: metadata """ # type cast and rescale - bit_depth = self.present_CameraSettings.RawMode["bit_depth"] + currentFormat = self.picam2.camera_configuration()["raw"]["format"].split("_") + assert len(currentFormat) == 1, f'Picamera2 returned unexpected format: {currentFormat}!' + assert currentFormat[0][0] == 'S', f'Picamera2 returned unexpected format: {currentFormat}!' + BayerPattern = currentFormat[0][1:5] + BayerPattern = self.parent.config.get("driver", "force_BayerOrder", fallback=BayerPattern) + bit_depth = int(currentFormat[0][5:]) + self.log_FrameInformation(array=array, metadata=metadata, is_raw=True, bit_depth=bit_depth) + # left adjust if needed if bit_depth > 8: bit_pix = 16 array = array.view(np.uint16) * (2 ** (bit_pix - bit_depth)) @@ -520,9 +527,6 @@ def createBayerFits(self, array, metadata): with self.parent.knownVectorsLock: # determine frame type FrameType = self.parent.knownVectors["CCD_FRAME_TYPE"].get_OnSwitchesLabels()[0] - # determine Bayer pattern order - BayerPattern = self.picam2.camera_configuration()["raw"]["format"][1:5] - BayerPattern = self.parent.config.get("driver", "force_BayerOrder", fallback=BayerPattern) # FITS header and metadata FitsHeader = { "BZERO": (2 ** (bit_pix - 1), "offset data range"), @@ -581,6 +585,7 @@ def createRgbFits(self, array, metadata): array: data array metadata: metadata """ + self.log_FrameInformation(array=array, metadata=metadata, is_raw=False) # convert to FITS hdu = fits.PrimaryHDU(array.transpose([2, 0, 1])) # avoid access conflicts to knownVectors @@ -619,27 +624,30 @@ def createRgbFits(self, array, metadata): hdul = fits.HDUList([hdu]) return hdul - def log_FrameInformation(self, array, metadata): + + def log_FrameInformation(self, array, metadata, is_raw=True, bit_depth=16): """write frame information to debug log Args: array: raw frame data metadata: frame metadata + is_raw: raw or RGB frame + bit_depth: bit depth for raw frame """ # FIXME: change error to debug logger.error(f'array shape: {array.shape}') # - bit_depth = self.present_CameraSettings.RawMode["bit_depth"] - logger.error(f'{bit_depth} bits per pixel') + logger.error(f'{self.present_CameraSettings.RawMode["bit_depth"]} bits per pixel expected') # - bit_depth = 16 # FIXME - BitUsage = np.zeros(bit_depth) == 0 - Bit = np.r_[range(bit_depth)] - for b in Bit: - BitUsage[b] = ((array & (1 << b)) != 0).any() - UsedBits = ''.join(["1" if b!=0 else "0" for b in BitUsage]) - UsedBits = UsedBits[-1::-1] # MSB first - logger.error(f' data alignment: (MSB) {UsedBits} (LSB) (1=at least one 1 in data, 0=all 0)') + if is_raw: + arr = array.view(np.uint16) if bit_depth > 8 else array + BitUsage = np.zeros(bit_depth) == 0 + Bit = np.r_[range(bit_depth)] + for b in Bit: + BitUsage[b] = ((arr & (1 << b)) != 0).any() + UsedBits = ''.join(["1" if b!=0 else "0" for b in BitUsage]) + UsedBits = UsedBits[-1::-1] # make MSB first + logger.error(f' data alignment: (MSB) {UsedBits} (LSB) (1=at least one 1 in data, 0=all 0)') # logger.error(f'metadata: {metadata}') # @@ -798,7 +806,6 @@ def __ExposureLoop(self): if not Abort: (array, ), metadata = self.picam2.wait(job) logger.info("got exposed frame") - self.log_FrameInformation(array=array, metadata=metadata) # at least HQ camera reports CCD temperature in meta data self.parent.setVector("CCD_TEMPERATURE", "CCD_TEMPERATURE_VALUE", value=metadata.get('SensorTemperature', 0)) From 4741b241a7efa3a2b4b98651e94da0f8984c7524 Mon Sep 17 00:00:00 2001 From: scriptorron <22291722+scriptorron@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:57:32 +0100 Subject: [PATCH 3/3] removed debug messages --- CHANGELOG | 4 +--- src/indi_pylibcamera/CameraControl.py | 33 +++++++++++++-------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index df16579..ba7cd2c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,4 @@ -2.4.0 -- added INI switch "force_Restart" and implemented camera restart (solves crashes for IMX290 and IMX519) -- forwarding log messages to client +- fixed changed data alignment in Pi 5 raw images 2.3.0 - update FITS header formatting and timestamps diff --git a/src/indi_pylibcamera/CameraControl.py b/src/indi_pylibcamera/CameraControl.py index c60820b..4e22dfc 100755 --- a/src/indi_pylibcamera/CameraControl.py +++ b/src/indi_pylibcamera/CameraControl.py @@ -510,7 +510,7 @@ def createBayerFits(self, array, metadata): BayerPattern = currentFormat[0][1:5] BayerPattern = self.parent.config.get("driver", "force_BayerOrder", fallback=BayerPattern) bit_depth = int(currentFormat[0][5:]) - self.log_FrameInformation(array=array, metadata=metadata, is_raw=True, bit_depth=bit_depth) + #self.log_FrameInformation(array=array, metadata=metadata, is_raw=True, bit_depth=bit_depth) # left adjust if needed if bit_depth > 8: bit_pix = 16 @@ -585,7 +585,7 @@ def createRgbFits(self, array, metadata): array: data array metadata: metadata """ - self.log_FrameInformation(array=array, metadata=metadata, is_raw=False) + #self.log_FrameInformation(array=array, metadata=metadata, is_raw=False) # convert to FITS hdu = fits.PrimaryHDU(array.transpose([2, 0, 1])) # avoid access conflicts to knownVectors @@ -634,24 +634,24 @@ def log_FrameInformation(self, array, metadata, is_raw=True, bit_depth=16): is_raw: raw or RGB frame bit_depth: bit depth for raw frame """ - # FIXME: change error to debug - logger.error(f'array shape: {array.shape}') + logger.debug(f'array shape: {array.shape}') # - logger.error(f'{self.present_CameraSettings.RawMode["bit_depth"]} bits per pixel expected') + logger.debug(f'{self.present_CameraSettings.RawMode["bit_depth"]} bits per pixel requested, {bit_depth} bits per pixel received') # if is_raw: arr = array.view(np.uint16) if bit_depth > 8 else array - BitUsage = np.zeros(bit_depth) == 0 - Bit = np.r_[range(bit_depth)] - for b in Bit: - BitUsage[b] = ((arr & (1 << b)) != 0).any() - UsedBits = ''.join(["1" if b!=0 else "0" for b in BitUsage]) - UsedBits = UsedBits[-1::-1] # make MSB first - logger.error(f' data alignment: (MSB) {UsedBits} (LSB) (1=at least one 1 in data, 0=all 0)') - # - logger.error(f'metadata: {metadata}') - # - logger.error(f'camera configuration: {self.picam2.camera_configuration()}') + BitUsage = ["X"] * bit_depth + for b in range(bit_depth-1, -1, -1): + BitSlice = (arr & (1 << b)) != 0 + if BitSlice.all(): + BitUsage[b] = "1" + elif BitSlice.any(): + BitUsage[b] = "T" + else: + BitUsage[b] = "0" + logger.debug(f' data alignment: (MSB) {"".join(BitUsage)} (LSB) (1 = all 1, 0 = all 0, T = some 1)') + logger.debug(f'metadata: {metadata}') + logger.debug(f'camera configuration: {self.picam2.camera_configuration()}') def __ExposureLoop(self): """exposure loop @@ -750,7 +750,6 @@ def __ExposureLoop(self): # (for instance: size) will fit better to hardware self.picam2.align_configuration(config) # set still configuration - logger.error(f'config requested: {config}') # FIXME self.picam2.configure(config) # changing exposure time or analogue gain needs a restart if IsRestartNeeded: