[SciPy-user] HDULists sharing HDU entries
Fri Jul 11 20:26:48 CDT 2008
I have been making a system for handling astronomical data, the actual
fits manipulation using pyfits. Please correct me if there is another
list this question would be more appropriate on, I did not see a pyfits
list at the project page.
When I started this system I was new to python (but experienced in many
other languages) and in the process I have done some things I am not
sure about. I of course test my ideas to make sure they work, but of
course, such tests can miss some condition in which the idiom ultimately
is bound to fail horribly.
So... I'm curious if something I'm doing with HDULists is ok.
Basically, we have an abstraction for our data, lets call it AstroData
because that's what we call it. It contains a member which is the
HDUList as returned by pyfits when opening a MEF.
I also have some syntax that allows one to get an AstroData instance of
just sub-selections of extensions in the MEF, e.g.:
if ad = AstroData(fitsfilename) then (e.g.) ad["SCI"] returns a separate
AstroData instance from 'ad'. In this case I build the HDUList out of
the HDU entries in the original instance. I make a python list with the
PHU and whatever extensions are being selected (in the sample case,
those where EXTNAME="SCI"), and initialize a new HDUList instance with
this list. Then this unique HDUList is stored in the new AstroData
instance. So each AstroData instance has it's own HDUList, but the HDU
entries in it are shared.
Everything works fine, to write the constructed HDUList is to save just
those extensions listed, as desired, and I can pass the HDUList around
as normal to anything that wants HDUList instances. Of course, if I
change any of the shared extensions, it will be seen in all HDULists
that refer to it, which is confusing to some but is exactly what we want
in this case.
All this runs perfectly fine in practice. Does anyone know any reason
this might get me into trouble? It seems I have nothing to worry about,
but I have a nagging idea that perhaps the HDU is more tightly linked to
the list containing it in some way that I do not yet know.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user