amaurea / enlib

5 stars 12 forks source link

wcs incompatible with flipper #5

Closed msyriac closed 7 years ago

msyriac commented 7 years ago

I tried using enmap.to_flipper to convert an enmap to a liteMap, but it fails. Flipper requires a header inside the wcs object.

ERROR: AttributeError: 'WCS' object has no attribute 'header' [flipper.liteMap]
ERROR:astropy:AttributeError: 'WCS' object has no attribute 'header'
Traceback (most recent call last):
  File "tests/testLens.py", line 66, in <module>
    templateLm = enmap.to_flipper(kappaMap)
  File "/gpfs01/astro/workarea/msyriac/miniconda2/lib/python2.7/site-packages/enlib/enmap.py", line 936, in to_flipper
    omap[i] = flipper.liteMap.liteMapFromDataAndWCS(iflat[i], iflat.wcs)
  File "/direct/astro+u/msyriac/software/flipper/flipper/liteMap.py", line 570, in liteMapFromDataAndWCS
    ltmap.header = ltmap.wcs.header
AttributeError: 'WCS' object has no attribute 'header'
amaurea commented 7 years ago

I have fixed this now, in commit 10b9eb760792489157931fe77025847e39bc413d.

msyriac commented 7 years ago

It looks like it is still incompatible.

Say I make a new enmap

>>> px = 0.5
>>> arc = 300
>>> hwidth = arc/2.
>>> deg = utils.degree
>>> arcmin =  utils.arcmin
>>> shape, wcs = enmap.geometry(pos=[[-hwidth*arcmin,-hwidth*arcmin], hwidth*arcmin,hwidth*arcmin]], res=px*arcmin, proj="car")
>>> thetaMap = enmap.posmap(shape, wcs)
>>> thetaMapMod = np.sum(thetaMap**2,0)**0.5

and then try to make a liteMap out of it

>>> templateLm = enmap.to_flipper(thetaMap).reshape(-1)[0]
>>> templateLm.info()
Dimensions (Ny,Nx) = (600,600)
Pixel Scales: (0.499167,35.500833) arcmins. 
Map Bounds: [(x0,y0), (x1,y1)]: [(357.504167,-2.495833),(2.495833,2.495833)] (degrees)
Map Bounds: [(x0,y0), (x1,y1)]: [(23:50:01.000,-02:29:45.00),(00:09:59.000,+02:29:45.00)]
Map area = 1772.083264 sq. degrees.
Map mean = 0.000045
Map std = 0.001294

The x-pixel scale has been messed up. So flipper is expecting something different in the wcs?

amaurea commented 7 years ago

OK, I've found out what this is. Flipper doesn't like it when cdelt[0] > 0. When you built the geometry, you specified a coordinate system with RA increasing in the pixel direction (because pos[1,1]>pos[0,1]), so you got a map that flipper doesn't like. I flipper's problems with cdelt[0] < 0 to be a bug in flipper.

I can make to_flipper flip the map in the x direction to ensure that cdelt[0] < 0. But that may be confusing in its own right. What do you think?

msyriac commented 7 years ago

Now we know why it's called flipper! I think your proposed solution of flipping the map in the x direction is the way to go, rather than trying to fix flipper, which may break other people's code that depends on it.

amaurea commented 7 years ago

Ok, the flipping is implemented.