Created
December 7, 2022 12:45
-
-
Save Mark1626/055aa84f38080afb0c4786ebefc33301 to your computer and use it in GitHub Desktop.
Convert Fits to BP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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