FITS Images in pyROOT

Friends,

I am trying to read in some FITS files in python and then performs some quantitative analysis of the images using ROOT, probably by converting them to TH2D objects or something like that. I am using Python 2.7.9/Anaconda 1.9.2 on MacOSX 10.9.5. I am using packages in astropy to read in the fits files, and it works just fine, like this:

[code]>>> import astropy.io.fits

img = astropy.io.fits.open(’./20150129/image-10.fits’)
img.info()
Filename: ./20150129/image-10.fits
No. Name Type Cards Dimensions Format
0 PRIMARY PrimaryHDU 23 (1400, 1400) int16

[/code]
astropy.io.fits seems to break when I import root first, like so:

[code]>>> import ROOT

import astropy.io.fits
img = astropy.io.fits.open(’./20150129/image-10.fits’)
Traceback (most recent call last):
File “”, line 1, in
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py”, line 116, in fitsopen
return HDUList.fromfile(name, mode, memmap, save_backup, **kwargs)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py”, line 248, in fromfile
save_backup=save_backup, **kwargs)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.py”, line 796, in _readfrom
hdu = _BaseHDU.readfrom(ffo, **kwargs)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/hdu/base.py”, line 452, in readfrom
hdr = Header.fromfile(fileobj, endcard=not ignore_missing_end)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py”, line 502, in fromfile
return cls.fromstring(blocks, sep=sep)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py”, line 387, in fromstring
return cls(cards)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py”, line 104, in init
self.append(card, end=True)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/header.py”, line 1139, in append
keyword = Card.normalize_keyword(card.keyword)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/card.py”, line 469, in keyword
self._keyword = self._parse_keyword()
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/io/fits/card.py”, line 865, in _parse_keyword
self._image, AstropyUserWarning)
File “/Users/vmgehman/anaconda/lib/python2.7/site-packages/astropy/logger.py”, line 189, in _showwarning
if getattr(mod, ‘file’, ‘’) == mod_path:
File “/usr/local/root/lib/ROOT.py”, line 215, in getattr
klass = _root.MakeRootClass( attr, cls )
TypeError: requested class ‘ROOT::file’ does not exist[/code]
There clearly seems to be some destructive interference between these two packages, and I can’t sort out what is causing it… Please help!

Vic

Vic,

the pyastro logger code is looping over all modules, blankly assuming all have a file attribute, but ROOT.std does not. Seems to be fixed in more recent pyastro (although there they use a blanket try/except, which has its own problems).

Barring an upgrade, this should get you past this error:import ROOT ROOT.std.__file__ = 'dummy_for_old_pyastro'
Cheers,
Wim