Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ellipses being converted into Points? #116

Closed
erickmartins opened this issue Dec 28, 2021 · 6 comments · Fixed by #117
Closed

Ellipses being converted into Points? #116

erickmartins opened this issue Dec 28, 2021 · 6 comments · Fixed by #117

Comments

@erickmartins
Copy link

First of all, I love ome-types! I'm trying to generate an XML from an OMERO Project, and everything has been going well so far except for any Ellipse ROIs. Here's a code snippet:

print('kwargs:', kwargs)
roi = ROI(**kwargs)
print('roi:', roi)

And what that prints:

kwargs: {'id': 463, 'name': None, 'description': None, 'union': [Ellipse(
   id='Shape:1437',
   fill_color=Color('#fff0', rgb=(255, 255, 255, 0.0)),
   stroke_color=Color('yellow', rgb=(255, 255, 0)),
   the_t=0,
   the_z=0,
   radius_x=83.35868762069157,
   radius_y=11.176583815064788,
   x=8.692898522828159,
   y=13.194578115007033,
)]}
roi: id='ROI:463' annotation_ref=[] description=None name=None union=[Point(
   id='Shape:1437',
   fill_color=Color('#fff0', rgb=(255, 255, 255, 0.0)),
   stroke_color=Color('yellow', rgb=(255, 255, 0)),
   the_t=0,
   the_z=0,
   x=8.692898522828159,
   y=13.194578115007033,
)]

It seems that ROI() is internally converting the ellipse into a single point, and I have no idea why! Am I missing something obvious? Everything else seems to work as intended,

@erickmartins
Copy link
Author

OK, when doing the opposite workflow (XML to objects) I have found an extra ROI type weirdness case. Here's a snippet of my XML file:

<ROI ID="ROI:108">
        <Union>
            <Polygon ID="Shape:108" FillColor="-256" StrokeColor="-65281" Text="this one has a comment" TheT="0" TheZ="0" Points="98.12499999999976,21.999999999999943 56.37499999999987,94.74999999999974 74.37499999999983,175.99999999999952 216.87499999999946,189.7499999999995 263.6249999999994,110.2499999999997 248.87499999999935,35.2499999999999 140.87499999999966,100.99999999999973 178.62499999999955,23.749999999999936" />
        </Union>
</ROI>

Then, I ran

ome = from_xml('/path/to/xmlfile.xml')
ome.rois[-1].union

Resulting in

[Polyline(
   id='Shape:108',
   fill_color=Color('#fff0', rgb=(255, 255, 255, 0.0)),
   stroke_color=Color('yellow', rgb=(255, 255, 0)),
   text='this one has a comment',
   the_t=0,
   the_z=0,
   points='98.12499999999976,21.999999999999943 56.37499999999987,94.74999999999974 74.37499999999983,175.99999999999952 216.87499999999946,189.7499999999995 263.6249999999994,110.2499999999997 248.87499999999935,35.2499999999999 140.87499999999966,100.99999999999973 178.62499999999955,23.749999999999936',
)]

As you can see, everything looks right, except for the type - it's giving me a Polyline instead of a Polygon!

@tlambert03
Copy link
Owner

thanks @erickmartins! could you perhaps share the xml file? It does look an error, but it would be much easier to fix if I could reproduce it locally with from_xml

@erickmartins
Copy link
Author

Sure thing! Adding it as a txt since github doesn't like XML files.

(as a sidenote, a few of the Points in this xml were originally Ellipses that got mysteriously converted when generating an ROI object.)

Thanks for looking into it!

test.xml.txt

@tlambert03
Copy link
Owner

the issue is ultimately about how pydantic (the library underlying the model) deals with Unions

ROI.union is defined as Union[Rectangle, Mask, Point, Ellipse, Line, Polyline, Polygon, Label] ... so when constructing an ROI, pydantic looks at each dict and decides what type of shape matches it the best. It goes from left to right (rectangle? mask? point?. etc...). it may be as simple as arranging polgygon in front of polyline, since it's more general, but i'll try it out with your file and see what's best. (you can see that point is also before ellipse)

do you mind if I include this xml in our test suite?

@erickmartins
Copy link
Author

Sure, no problem. Thanks a bunch!

@tlambert03
Copy link
Owner

Fixed in #117 . will push a new release soon. thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants