question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error drawing circles when coord="wcs"

See original GitHub issue

While developing for eteq/astrowidgets#1 , I encountered error when drawing circles in in coord='wcs' mode. Circle radius is set to 20 (I assume it is in pixels but I have no idea if its unit secretly changes when I switch from “data” to “wcs” mode).

Here are the four points I attempted to draw:

RA (deg) DEC (deg)
3.609821370156458 -30.378452205494682
3.589858963715532 -30.368501816764578
3.5872920549742506 -30.371258703333265
3.58680555297819 -30.366805584777612

What I did was attempting to create a CompoundObject from four individual Circle, each one constructed like this:

Circle(x=ra, y=dec, radius=20, coord='wcs', color='cyan')

This is the error I got from Ginga:

...\ginga\canvas\CanvasObject.py:193: RuntimeWarning: invalid value encountered in sqrt
  radius = np.sqrt(abs(y2 - y1)**2 + abs(x2 - x1)**2)
2018-07-21 12:13:54,733 | E | ImageView.py:1272 (redraw_now) | Error redrawing image: cannot convert float NaN to integer
2018-07-21 12:13:54,747 | E | ImageView.py:1277 (redraw_now) | Traceback:
  File "...\ginga\ImageView.py", line 1258, in redraw_now
    self.redraw_data(whence=whence)
  File "...\ginga\ImageView.py", line 1303, in redraw_data
    self.private_canvas.draw(self)
  File "...\ginga\canvas\DrawingMixin.py", line 723, in draw
    super(DrawingMixin, self).draw(viewer)
  File "...\ginga\canvas\CompoundMixin.py", line 143, in draw
    obj.draw(viewer)
  File "...\ginga\canvas\CompoundMixin.py", line 143, in draw
    obj.draw(viewer)
  File "...\ginga\canvas\types\basic.py", line 1044, in draw
    cr.draw_circle(cx, cy, cradius)
  File "...\ginga\pilw\CanvasRenderPil.py", line 110, in draw_circle
    self.cr.circle((cx, cy), cradius, self.pen, self.brush)
  File "...\ginga\pilw\PilHelp.py", line 124, in circle
    radius = int(radius)

I am using Ginga 2.7.1.dev1944 on Windows 7 64-bit with ipyevents on Jupyter Lab. In case it matters, Astropy is 3.1.dev22186.

I attempted to code dive a bit but got lost at viewer.renderer calls. What am I doing wrong here? Any help would be appreciated. Thanks!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwcraigcommented, Jul 26, 2018

How does Ginga compute this conversion internally?

I’m guessing it is derived from the WCS.

Thinking about that just a bit further, it’s probably not too much more work to subclass the shape to make it take an astropy coordinate object and the radius as a value with a units attached.

This might be nice; I can imagine cases where I want to specify the location in world coordinates but I want the mark to have a fixed pixel size (e.g. for aperture photometry).

An alternative might be to allow radius to have a unit (even if x, y are still separate unitless arguments).

0reactions
pllimcommented, Jul 25, 2018

Am I correct in assuming that if you have a SkyCoord and you add a unit that is in pixels it does the right conversions?

Currently, for coord='wcs', I pass SkyCoord.ra.deg and SkyCoord.dec.deg into Ginga.

To convert radius from degree to pixels, I would need to know the detector pixel scale (which might or might not be available as metadata in the image). How does Ginga compute this conversion internally?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Incorrect canvas coordinates when drawing a circle [duplicate]
The problem is: We have a big canvas (with scroll) inside a div, with a background image, and if we try to draw...
Read more >
arcmap circle draw usage error? - Esri Community
In Arcmap...I create a circle at a particular point in dd. Then I move to a specified radius (or even type it in)....
Read more >
Draw Circle with Fixed Radius Error - TIBCO Community
The data function 'Draw Circles with Fixed Radius on Geographic Coordinates' could not be executed.
Read more >
Drawing Circle using Image[Graphics[]] - incorrect coordinates
I want to draw a circle with center {x,y} in an image. I use the following code: img = Image[Graphics[{ {Red, Thick, Circle[{100,...
Read more >
Problem with circles coordinates - SFML
BTW, I'm not sure what you mean, but I think your problem is that you need to App.draw for every circle (which for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found