ejeschke / ginga

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

QPainter warnings #112

Closed pllim closed 9 years ago

pllim commented 9 years ago

My plugin gives me spurious messages like the ones below, after I modified and displayed the modified buffer, and switched to another image in the thumbnails. I am using the latest dev version. I am hoping you can give some pointers on what might cause this, since you mentioned you made a lot of changes to Ginga recently.

QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
ejeschke commented 9 years ago

Can you post a log snippet (with level setting of 20)? What I'm most looking for is any error messages just prior to the first QPainter warnings. There was a rather huge change to the rendering recently, which will help greatly for future maintainability, and this is probably due to a bug introduced by those changes.

pllim commented 9 years ago

Okay, since it is spurious, I do not know how to recreate it at will, but if it shows up again, I will post more info.

pllim commented 9 years ago

Update: I haven't seen any QPainter messages today, but occasionally when I modify the data and invoke set_data(data) , the displayed image "greys out" as if the cut levels have gone crazy. But I do not see anything out of the ordinary in the log file even when I have loglevel=10. The problem fixes itself when I click on a different thumbnail and then switch back. Very perplexing.

ejeschke commented 9 years ago

@pllim, you may want to force an autocuts to happen if the data values are changing significantly. You can do that by simply:

self.fitsimage.auto_levels()

after setting your data. I don't know if this is the source of "greying out", but certainly displaying new data with old cut levels will not always do the expected. By clicking a new thumbnail and then going back to the old one you are forcing a "new" image to be loaded and so it will recalculate the cuts levels.

pllim commented 9 years ago

@ejeschke , forcing auto_levels() did not solve my problem. This is basically what I am doing (see below), maybe I missed something subtle.

image = self.fitsimage.get_image()
data = image.get_data()
# data is modified in-place here
image.set_data(data, metadata=image.metadata)

# Now in the same method, I am going to do something funky.
# That is, if the image has DQ extension, I also update its DQ flags.

chinfo = self.fv.get_channelInfo(chname)
dqsrc = self.fv.load_image(imfile, idx=dq_extnum)
chinfo.datasrc[dqname] = dqsrc
self.fv.make_callback('add-image', chinfo.name, dqsrc)

dqdata = dqsrc.get_data()
# dqdata is modified in-place here
dqsrc.set_data(dqdata, metadata=dqsrc.metadata)

When the above code runs, I can confirm that DQ extension is loaded and modified (but not set to active display, which is fine with me). I still see SCI being displayed, but occasionally it would "grey out" as I described above. I cannot reproduce this behavior consistently though.

pllim commented 9 years ago

Also, I found a way to consistently reproduce the QPainter messages. First, I started Ginga with some images:

ginga --loglevel=20 --log=ginga.log *.fits

Then, I started the Mosaic plugin and drag in 4 images to create a mosaic. Now in Contents, I see the original images and dp0 (the mosaic). I click on one of the original images to display it, and then I click on dp0 to switch back to displaying mosaic. Now, the mosaic won't display (but I see it in the Info preview window on top left) and I get:

QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setMatrixEnabled: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setMatrixEnabled: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active

Here is part of the log output where I dropped files into the mosaic:

2015-06-09 15:51:19,999 | I | Mosaic.py:371 (drop_cb) | files dropped: [...]
2015-06-09 15:51:20,004 | I | Control.py:514 (load_image) | Loading image from image1.fits kwdargs={'numhdu': None}
2015-06-09 15:51:20,580 | I | Control.py:900 (_switch_image) | Update image start
2015-06-09 15:51:20,580 | I | Control.py:905 (_switch_image) | Setting image...
2015-06-09 15:51:20,600 | E | ImageView.py:693 (redraw_now) | Error redrawing image: could not broadcast input array from shape (0,0,3) into shape (306,317,3)
2015-06-09 15:51:20,602 | E | ImageView.py:698 (redraw_now) | Traceback:
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 681, in redraw_now
    self.redraw_data(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/qtw/ImageViewCanvasQt.py", line 53, in redraw_data
    super(ImageViewCanvas, self).redraw_data(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 713, in redraw_data
    rgbobj = self.get_rgb_object(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 792, in get_rgb_object
    self.overlay_images(self.canvas, self._rgbarr2, whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 937, in overlay_images
    obj.draw_image(self, data, whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/canvas/CanvasObject.py", line 2512, in draw_image
    alpha=self.alpha, flipy=False)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/trcalc.py", line 438, in overlay_image
    a_arr[0:src_ht, 0:src_wd, 0:3] + b_arr[0:src_ht, 0:src_wd, 0:3]
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setMatrixEnabled: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active

Here is part of the log where I try to re-display the mosaic via Contents:

2015-06-09 15:51:48,857 | I | Control.py:900 (_switch_image) | Update image start
2015-06-09 15:51:48,857 | I | Control.py:905 (_switch_image) | Setting image...
2015-06-09 15:51:48,877 | E | ImageView.py:693 (redraw_now) | Error redrawing image: could not broadcast input array from shape (0,0,3) into shape (331,347,3)
2015-06-09 15:51:48,877 | E | ImageView.py:698 (redraw_now) | Traceback:
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 681, in redraw_now
    self.redraw_data(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/qtw/ImageViewCanvasQt.py", line 53, in redraw_data
    super(ImageViewCanvas, self).redraw_data(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 713, in redraw_data
    rgbobj = self.get_rgb_object(whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 792, in get_rgb_object
    self.overlay_images(self.canvas, self._rgbarr2, whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/ImageView.py", line 937, in overlay_images
    obj.draw_image(self, data, whence=whence)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/canvas/CanvasObject.py", line 2512, in draw_image
    alpha=self.alpha, flipy=False)
  File ".../ginga-2.4.20150603003439-py2.7.egg/ginga/trcalc.py", line 438, in overlay_image
    a_arr[0:src_ht, 0:src_wd, 0:3] + b_arr[0:src_ht, 0:src_wd, 0:3]
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setMatrixEnabled: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setMatrixEnabled: Painter not active
QPainter::begin: A paint device can only be painted by one painter at a time.
QPainter::setPen: Painter not active
QPainter::setBrush: Painter not active
pllim commented 9 years ago

Tracing the error messages, I uncommented your print statements in the function overlay_image() in trcalc.py and this looks like the cause of the shape mismatch error. All I was doing was switching from mosaic to a regular image using Contents and then switching back to the mosaic.

1. dst_x, dst_y, dst_wd, dst_ht -762 -500 1060 1060
2. src_wd, src_ht, shape 742 742 (742, 742, 3)
2. dst_x, dst_y 0 0
2. src_wd, src_ht, shape -20 242 (242, 0, 3)