ejeschke / ginga

The Ginga astronomical FITS file viewer
BSD 3-Clause "New" or "Revised" License
121 stars 77 forks source link

HDF5 I/O question #48

Closed telegraphic closed 10 years ago

telegraphic commented 10 years ago

Hi, I'm trying to write a file handler for HDF5, via the technique mentioned here: http://ginga.readthedocs.org/en/latest/manual/internals.html#sec-custom-io and was hoping to get some clarification on a few things. Firstly, in the example

class MyIOHandler(object):
    def __init__(self, logger):
        self.logger = logger

    def load_file(self, filespec, header, **kwdargs):
        return (data, naxispath)

    def save_as_file(self, path, data, header, **kwdargs):
        pass

What exactly is naxispath? It wasn't clear from the code what to pass.

Also, this method isn't working for me:


from ginga import AstroImage
AstroImage.set_ioClass(MyIOHandler)
...

image = AstroImage.AstroImage()
image.load_file(path)
...
view.set_image(image)

As AstroImage does not appear to have a method set_ioClass. I do see this method under AstroImage.AstroImage.set_ioClass(), but haven't been able to get this method working.

ejeschke commented 10 years ago

@telegraphic, thanks for writing an HDF5 handler!

My bad on the documentation. It should read:

from ginga.AstroImage import AstroImage 
AstroImage.set_ioClass(MyIOHandler)

because it is the class you are setting the handler on.

As for the naxispath, probably for HDF5 you can return the empty list ([]). The naxispath would normally be a list of indexes into a data cube, and is there for FITS files.

ejeschke commented 10 years ago

One other comment regarding naxispath: since it is a keyword argument to the load_file method, you probably want to treat it as any kind of path that you would need to take to navigate through an HDF5 file. For example, if there are multiple image slices in the HDF5 file, the naxispath would be some kind of list of indexes that would help to navigate down to the particular slice in your load_file method.

If the user passes a valid naxispath (whatever that means to your method) you simply return that value that they passed. If they passed None (default), then you return whatever path you used to access the data slice that you returned.

telegraphic commented 10 years ago

ah ok, so for N-dimensional data, load_file should return a 2D array + a set of indexes that identify how the file is sliced. Looking at io_fits now, I can see how this is used to slice.

Once I've got something that works I'll let you know. Thanks!