@@ -229,24 +229,24 @@ def saferun(self):
229229 hdulist = fits .open (filename_p )
230230
231231 #logger.info('HDU Header = %s', pformat(hdulist[0].header))
232- image_type = hdulist [0 ].header ['IMAGETYP' ]
233232 image_bitpix = hdulist [0 ].header ['BITPIX' ]
233+ image_bayerpat = hdulist [0 ].header .get ('BAYERPAT' )
234234
235235 scidata = hdulist [0 ].data
236236 elif filename_p .suffix in ['.jpg' , '.jpeg' ]:
237237 self .indi_rgb = False
238238
239239 scidata = cv2 .imread (str (filename_p ), cv2 .IMREAD_UNCHANGED )
240240
241- image_type = 'Light Frame'
242241 image_bitpix = 8
242+ image_bayerpat = None
243243 elif filename_p .suffix in ['.png' ]:
244244 self .indi_rgb = False
245245
246246 scidata = cv2 .imread (str (filename_p ), cv2 .IMREAD_UNCHANGED )
247247
248- image_type = 'Light Frame'
249248 image_bitpix = 8
249+ image_bayerpat = None
250250 elif filename_p .suffix in ['.dng' ]:
251251 if not rawpy :
252252 filename_p .unlink ()
@@ -260,7 +260,6 @@ def saferun(self):
260260 hdu = fits .PrimaryHDU (scidata )
261261 hdulist = fits .HDUList ([hdu ])
262262
263- hdulist [0 ].header ['IMAGETYP' ] = 'Light Frame'
264263 hdulist [0 ].header ['EXPTIME' ] = float (exposure )
265264 #hdulist[0].header['XBINNING'] = 1
266265 #hdulist[0].header['YBINNING'] = 1
@@ -270,13 +269,13 @@ def saferun(self):
270269 hdulist [0 ].header ['XBAYROFF' ] = 0
271270 hdulist [0 ].header ['YBAYROFF' ] = 0
272271
273- image_type = hdulist [0 ].header ['IMAGETYP' ]
274272 image_bitpix = hdulist [0 ].header ['BITPIX' ]
273+ image_bayerpat = hdulist [0 ].header .get ('BAYERPAT' )
275274
276275
277276
278277 filename_p .unlink () # no longer need the original file
279- logger .info ('Detected image type : %s, bits : %d ' , image_type , image_bitpix )
278+ logger .info ('Detected image bits : %d, cfa : %s ' , image_bitpix , str ( image_bayerpat ) )
280279
281280
282281
@@ -306,7 +305,7 @@ def saferun(self):
306305 self .sqm_value = self .calculateSqm (scidata , exposure )
307306
308307 # debayer
309- scidata = self .debayer (scidata )
308+ scidata = self .debayer (scidata , image_bayerpat )
310309
311310 else :
312311 # data is probably RGB
@@ -1025,16 +1024,22 @@ def calibrate(self, scidata_uncalibrated, exposure, camera_id, image_bitpix):
10251024 return scidata_calibrated
10261025
10271026
1028- def debayer (self , scidata ):
1029- if not self .config ['CFA_PATTERN' ]:
1027+ def debayer (self , scidata , image_bayerpat ):
1028+ # sanity check
1029+ if not len (scidata .shape ) == 2 :
1030+ # color, already debayered
10301031 return scidata
10311032
1033+ if not image_bayerpat :
1034+ return scidata
1035+
1036+
10321037 if self .config .get ('NIGHT_GRAYSCALE' ) and self .night_v .value :
1033- debayer_algorithm = self .__cfa_gray_map [self . config [ 'CFA_PATTERN' ] ]
1038+ debayer_algorithm = self .__cfa_gray_map [image_bayerpat ]
10341039 elif self .config .get ('DAYTIME_GRAYSCALE' ) and not self .night_v .value :
1035- debayer_algorithm = self .__cfa_gray_map [self . config [ 'CFA_PATTERN' ] ]
1040+ debayer_algorithm = self .__cfa_gray_map [image_bayerpat ]
10361041 else :
1037- debayer_algorithm = self .__cfa_bgr_map [self . config [ 'CFA_PATTERN' ] ]
1042+ debayer_algorithm = self .__cfa_bgr_map [image_bayerpat ]
10381043
10391044 scidata_bgr = cv2 .cvtColor (scidata , debayer_algorithm )
10401045
0 commit comments