Skip to content

Commit

Permalink
handling uint16 data in fits
Browse files Browse the repository at this point in the history
  • Loading branch information
KshitijAggarwal committed Oct 15, 2020
1 parent b4dda7f commit 1c70986
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion your/formats/psrfits.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,13 @@ def read_subint(
data = data + ((sdata[:, 0, :] - sdata[:, 1, :]) / 2).squeeze()
else:
raise ValueError(f"pol={pol} value not supported.")

elif len(shp) == 4 and shp[-1] == 2 and self.poln_order == 'IQUV':
logger.warning("Data is packed as two uint8 arrays. Concatenating them to get uint16.")
logger.warning("Polarization is IQUV. Just using Stokes I.")
data = np.zeros((self.nsamp_per_subint, self.nchan), dtype=np.float32)
data1 = sdata[:, 0, :, 0].astype(np.uint16)
data2 = sdata[:, 0, :, 1].astype(np.uint16)
data += np.left_shift(data2, 8) + data1
else:
data = np.asarray(sdata)
data = data.reshape((self.nsamp_per_subint, self.nchan)).astype(np.float32)
Expand Down
2 changes: 1 addition & 1 deletion your/your.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def __init__(self, your):
if self.nbits <= 8:
self.dtype = np.uint8
elif self.nbits == 16:
if self.format == "fits":
if self.format == "fits" and int(your.fits['SUBINT'].header['TDIM17'][1]) == 1:
self.dtype = np.int16
else:
self.dtype = np.uint16
Expand Down

0 comments on commit 1c70986

Please sign in to comment.