Skip to content

Instantly share code, notes, and snippets.

@Mark1626
Created December 7, 2022 12:45
Show Gist options
  • Save Mark1626/055aa84f38080afb0c4786ebefc33301 to your computer and use it in GitHub Desktop.
Save Mark1626/055aa84f38080afb0c4786ebefc33301 to your computer and use it in GitHub Desktop.
Convert Fits to BP
#!/usr/bin/env python
# coding: utf-8
from astropy.io import fits
import adios2
import numpy as np
import os
filename = 'casa.fits'
os.system("rm -rf casa.bp")
with adios2.open("casa.bp", "w") as fh:
# Convert the FITS into a BP file
with fits.open(filename) as hdul:
for hdu in hdul:
hdr = hdu.header
for key in hdr.keys():
fh.write(key, str(hdr[key]))
data = hdu.data
# Endian conversion
data = np.ascontiguousarray(hdu.data, dtype=data.dtype.name)
size = list(data.shape)
start = list(np.zeros(data.ndim, dtype=np.int32))
# print(data.size)
fh.write('data', data, size, start, size, end_step=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment