Commit 4a199cef authored by bepinat's avatar bepinat

update on code: remove pyfits for astropy.io.fits

parent d9609639
This diff is collapsed.
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
import argparse
import ipdb
import numpy as np
import pyfits as pf
#import pyfits as pf
import astropy.io.fits as fits
import astropy.wcs as wcs
import astropy.coordinates as coord
import astropy.units as u
......@@ -65,7 +66,7 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
cat = np.genfromtxt(path + catfile, names=True, case_sensitive=False)
try:
hdul = pf.open(path + cubefile)
hdul = fits.open(path + cubefile)
logger.info('Using cube %s ' % (path + cubefile) )
except:
logger.info('Not able to read cube %s !' % (path + cubefile) )
......@@ -92,24 +93,23 @@ def create_config(path, cubefile, varfile, catfile, lines, suffixeout, commonw=T
except:
cdelt = hdr['CDELT3']
logger.debug(" wcs check: %s %d %.4f %.6f " % (cunit,crpix,crval,cdelt))
if 'CTYPE3' in hdr.ascard.keys(): del hdr['CTYPE3']
if 'CRVAL3' in hdr.ascard.keys(): del hdr['CRVAL3']
if 'CRPIX3' in hdr.ascard.keys(): del hdr['CRPIX3']
if 'CUNIT3' in hdr.ascard.keys(): del hdr['CUNIT3']
if 'CDELT3' in hdr.ascard.keys(): del hdr['CDELT3']
if 'CD3_3' in hdr.ascard.keys(): del hdr['CD3_3']
if 'CD3_2' in hdr.ascard.keys(): del hdr['CD3_2']
if 'CD3_1' in hdr.ascard.keys(): del hdr['CD3_1']
if 'CD2_3' in hdr.ascard.keys(): del hdr['CD2_3']
if 'CD1_3' in hdr.ascard.keys(): del hdr['CD1_3']
if '' in hdr.ascard.keys(): del hdr['']
if 'COMMENT' in hdr.ascard.keys(): del hdr['COMMENT']
if 'HISTORY' in hdr.ascard.keys(): del hdr['HISTORY']
if 'CTYPE3' in hdr.keys(): del hdr['CTYPE3']
if 'CRVAL3' in hdr.keys(): del hdr['CRVAL3']
if 'CRPIX3' in hdr.keys(): del hdr['CRPIX3']
if 'CUNIT3' in hdr.keys(): del hdr['CUNIT3']
if 'CDELT3' in hdr.keys(): del hdr['CDELT3']
if 'CD3_3' in hdr.keys(): del hdr['CD3_3']
if 'CD3_2' in hdr.keys(): del hdr['CD3_2']
if 'CD3_1' in hdr.keys(): del hdr['CD3_1']
if 'CD2_3' in hdr.keys(): del hdr['CD2_3']
if 'CD1_3' in hdr.keys(): del hdr['CD1_3']
if '' in hdr.keys(): del hdr['']
if 'COMMENT' in hdr.keys(): del hdr['COMMENT']
if 'HISTORY' in hdr.keys(): del hdr['HISTORY']
wlim = np.zeros(np.shape(cube)[1:])
hdu = pf.PrimaryHDU(data=wlim, header=hdr)
hdul1 = pf.HDUList(hdu)
hdu = fits.PrimaryHDU(data=wlim, header=hdr)
hdul1 = fits.HDUList(hdu)
hdr = hdul1[0].header
w = wcs.WCS(hdr, hdul1)
#w = wcs.WCS(hdr[:28], hdul1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment