Skip to content
Snippets Groups Projects
Commit 727b04d5 authored by Marko Mecina's avatar Marko Mecina
Browse files

flip CCD4 nodes in merged view (ED and FT)

parent 37664e85
Branches
No related tags found
No related merge requests found
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Convert unprocessed CE raw data to FITS files. Product type is determined (guessed) based on CE size.
......@@ -12,8 +12,12 @@ import numpy as np
from astropy.io import fits
# expected CE sizes in bytes
SIZE_FF = 4511 * 4608 * 2
SIZE_FT = 639 * 384 * 2 # 1 node
NROWS_FF = 4511
NCOLS_FF = 4608
NROWS_FT = 639
NCOLS_FT = 384
SIZE_FF = NROWS_FF * NCOLS_FF * 2
SIZE_FT = NROWS_FT * NCOLS_FT * 2 # 1 node
SIZE_ED = 64 # 1 event
FILE_PREFIX = 'SMILE_SXI_L1'
......@@ -49,7 +53,7 @@ def convert_ce(cefile, fitsfile=None):
def mk_ff(data):
# create uint16 array from raw data and reshape
arr = np.frombuffer(data, dtype='>H').reshape(4511, -1)
arr = np.frombuffer(data, dtype='>H').reshape(NROWS_FF, NCOLS_FF)
fnode = arr[:, ::2]
enode = arr[:, 1::2][:, ::-1]
ff = np.concatenate((fnode, enode), axis=1)
......@@ -62,23 +66,16 @@ def mk_ff(data):
def mk_ft(data):
arr = np.frombuffer(data, dtype='>H').reshape(-1, 639, 384)
arr = np.frombuffer(data, dtype='>H').reshape(-1, NROWS_FT, NCOLS_FT)
hdl = _mk_hdl('FT')
for n in range(arr.shape[0]):
hdl.append(fits.ImageHDU(data=arr[n, :, :], name='FT_CCD_NODE_{}'.format(n)))
# arrange all nodes to full CCD view
# arrange all nodes to full CCD
if arr.shape[0] == 4:
n00 = arr[0, :, :] # CCD2 F-side
n01 = arr[1, :, ::-1] # CCD2 E-side
n10 = arr[2, ::-1, :] # CCD4 F-side
n11 = arr[3, ::-1, ::-1] # CCD4 E-side
n0 = np.concatenate((n00, n01), 1)
n1 = np.concatenate((n10, n11), 1)
nn = np.concatenate((n0, n1), 0) # [::-1, :]
nn = _assemble_ft_frames_to_fp_view(arr)
hdl.append(fits.ImageHDU(data=nn, name='FULLCCD'))
......@@ -87,14 +84,14 @@ def mk_ft(data):
def mk_ed(data):
# reshape into array of evt packets
arr = np.frombuffer(data, dtype='>H').reshape(-1, 32)
arr = np.frombuffer(data, dtype='>H').reshape(-1, SIZE_ED // 2)
hdl = _mk_hdl('FT')
ts = int(hdl['PRIMARY'].header['OBS_ID'])
bindata = np.array([_mk_bin_entry(evt, ts) for evt in arr], dtype=ED_BIN_DTYPE)
# also add an HDU with event map
nodes = np.zeros((2, 2, 639, 384))
nodes = np.zeros((2, 2, NROWS_FT, NCOLS_FT))
nodes[:] = np.nan
for _, _, ccd, col, row, node, fx in bindata:
......@@ -103,15 +100,7 @@ def mk_ed(data):
except:
print(col, row, 'FAILED')
n00 = nodes[0, 0, :, :] # CCD2 F-side
n01 = nodes[0, 1, :, :][:, ::-1] # CCD2 E-side
n10 = nodes[1, 0, :, :][::-1, :] # CCD4 F-side
n11 = nodes[1, 1, :, :][::-1, ::-1] # CCD4 E-side
n0 = np.concatenate((n00, n01), 1)
n1 = np.concatenate((n10, n11), 1)
ed_img = np.concatenate((n0, n1), 0) # [::-1, :]
ed_img = _assemble_ft_frames_to_fp_view(nodes)
hdl.append(fits.ImageHDU(data=ed_img, name='EVTMAP'))
......@@ -129,6 +118,19 @@ def _mk_bin_entry(data, timestamp):
return timestamp, fc, ccdnr, col, row, node, evts
def _assemble_ft_frames_to_fp_view(arr3d):
n00 = arr3d[0, :, :] # CCD2 F-side (lower left in FP view)
n01 = arr3d[1, :, ::-1] # CCD2 E-side (lower right in FP view)
n10 = arr3d[2, ::-1, ::-1] # CCD4 F-side (upper right in FP view)
n11 = arr3d[3, ::-1, :] # CCD4 E-side (upper left in FP view)
n0 = np.concatenate((n00, n01), axis=1) # CCD2
n1 = np.concatenate((n11, n10), axis=1) # CCD4
return np.concatenate((n0, n1), axis=0)
def _mk_hdl(dmode):
hdl = fits.HDUList()
phdu = fits.PrimaryHDU()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment