Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions enmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,19 +1115,28 @@ def to_flipper(imap, omap=None, unpack=True):
by from_flipper does not give back an exactly identical map to the one
on started with.
"""
import flipper
import flipper.liteMap as lm
from astLib import astWCS
import pyfits
if imap.wcs.wcs.cdelt[0] > 0: imap = imap[...,::-1]
# flipper wants a different kind of wcs object than we have.
header = imap.wcs.to_header(relax=True)
header['NAXIS'] = 2
header['NAXIS1'] = imap.shape[-1]
header['NAXIS2'] = imap.shape[-2]
flipwcs = flipper.liteMap.astLib.astWCS.WCS(header, mode="pyfits")

cardList = pyfits.Header()
keys = ['NAXIS','NAXIS1','NAXIS2','CTYPE1','CTYPE2','CRVAL1','CRVAL2','CRPIX1','CRPIX2','CDELT1','CDELT2','CUNIT1','CUNIT2']
for key in keys:
cardList.append(pyfits.Card(key, header[key]))
hh = pyfits.Header(cards=cardList)

flipwcs = astWCS.WCS(hh, mode="pyfits")
iflat = imap.preflat
if omap is None:
omap = np.empty(iflat.shape[:-2],dtype=object)
for i, m in enumerate(iflat):
omap[i] = flipper.liteMap.liteMapFromDataAndWCS(iflat[i], flipwcs)
omap[i] = lm.liteMapFromDataAndWCS(iflat[i], flipwcs)
omap = omap.reshape(imap.shape[:-2])
if unpack and omap.ndim == 0: return omap.reshape(-1)[0]
else: return omap
Expand Down