ejeschke / ginga

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

Channel name inconsistent between plugins #121

Closed pllim closed 9 years ago

pllim commented 9 years ago

In my own plugin, the code below gives IndexError because Contents somehow stores channel name as "Image" (with capital "I") but other plugins gets channel name as "image" (with lowercase "i"), and Python is case-sensitive.

def my_plugin_method(self):
    chname = self.fv.get_channelName(self.fitsimage)
    list_plugin_obj = self.fv.gpmon.getPlugin('Contents')
    fileDict = list_plugin_obj.nameDict[chname]

Currently, my workaround is:

chname = string.capwords(self.fv.get_channelName(self.fitsimage))

Granted that this is a non-standard usage of Ginga. What I am trying to do is to grab a list of open images from Contents for use in my plugin. This is my attempt to automatically rebuild my mosaic when it is pushed out of Datasrc (as mentioned in #114).

ejeschke commented 9 years ago

@pllim, could you try commit e337c16e6202f7c1d086c3f02d8caead8509d305? I've also added a method to the Contents plugin called get_contents_by_channel(chname) which you can use in lieu of accessing the plugin object's nameDict directly--an implementation detail that could change in the future.

ejeschke commented 9 years ago

Are you implementing the recreation of the mosaic via the image_future attribute of the Contents nameDict? This is the approach I recommend. If you make something sufficiently general that could be incorporated into the Mosaic plugin let me know. Tnx.

pllim commented 9 years ago

Are you implementing the recreation of the mosaic via the image_future attribute of the Contents nameDict?

@ejeschke , I am not, but I can if you give an example on how to use it. I have seen it in your codes but I don't know how to use it.

pllim commented 9 years ago

Regarding my original issue, your commit did fix it. But I wish to keep this issue open until we have addressed the follow-up issues in the comments.

If you make something sufficiently general that could be incorporated into the Mosaic plugin let me know.

Right now, I have a Mosaic sub-class (for Qt only) that has a "Create Mosaic" button, which creates a mosaic using WCS information from all the images in Contents (if image is no longer in buffer, the plugin loads the image directly from file). This plugin also has a list widget that highlights the footprint of the selected image on the mosaic. If you are interested, I can submit it as a PR. Let me know.

pllim commented 9 years ago

Revisiting this again -- I think the remaining question I have here is, "What is image_future and how to use it in my plugin?"

ejeschke commented 9 years ago

The image_future is a callable with no parameters that, when invoked, will reconstruct the image. It basically provides a way to recreate an image using any method (mosaic, etc.). To take advantage of it, after creating your mosaic and associated AstroImage create the future and attach it to the image using the image metadata set method:

future = Future.Future()
future.freeze(some_func, arg1, arg2, ... kwarg1=val1, kwarg2=val2, ...)
image.set(name=name, image_future=future)
# announce image to ginga
self.fv.add_image(name, image, chname)

Thumbs and Contents will then use the image_future to recreate the image if it drops out of the Datasrc.

pllim commented 9 years ago

Thanks!