ome / omero-figure

An OMERO.web app for creating Figures from images in OMERO
http://figure.openmicroscopy.org
GNU Affero General Public License v3.0
15 stars 30 forks source link

Time reference and decimal places #481

Closed Tom-TBT closed 1 year ago

Tom-TBT commented 1 year ago

Hello again, with this PR I want to solve two issues that can be handled in the dynamic labels:

A picture is worth a thousand words: image

The decimal precision and offset (the "reference frame") are passed as named parameters inside the label:

Finally, I added tests for the labels like @jburel suggested last time. I know that they should be run on github to test that nothing is crashing during the PDF conversion, but how would you run them locally to check visually that the output is the one we expect?

Cheers, Tom

#########################################

EDIT: The following is kept for reference about the discussion in this PR, but the format that was ultimately picked is described above.

UI-wise, here is what I chose:

will-moore commented 1 year ago

Thanks Tom, this looks really nice. Initial testing looks good - I need to do a bit more... It would be nice to have an example in the table that uses both reference and decimal places - otherwise it's not clear that you can combine them or how. E.g. t.s.-3.2 or t.s.2-3 ?

will-moore commented 1 year ago

The failed run X status of this PR seems to be because the test export script is failing at scale = panel['pixel_size_x'] (KeyError) probably because the image has no pixel size metadata.

Actually, I can reproduce the error by adding a label X: [x.unit] to an Image panel which has no pixel size (e.g. a png). So it makes sense to do scale = panel.get('pixel_size_x') and then handle scale is None.

Otherwise, testing all looks good 👍

Tom-TBT commented 1 year ago

The script failed there yes, but I wouldn't do the change in Figure_To_Pdf.py. I think that the test is wrong. The JSON looks like an old version! (pixel_size_x seems introduced in V1, looking at version_transform() in figure_model.js)

With the version transform, all pdf generated from now on should have the new JSON, right? (except if someone forgot to refresh his browser for quite some time now)

So I updated the JSON in the test (and reorganized it to make it look like the model in figure_model.js). If I'm right, there are also values added from panel_model (rotation, zoom, ...)

Let me know what you think about my JSON update, then let's see if the test passes this time 🤞

PS: Working on it, I spotted another bug in Figure_To_Pdf: label with [z.unit] on 2D images made it crash (z_symbol is None) I saved myself the effort of making another PR and fix the bug here. Is that ok for you?

Tom-TBT commented 1 year ago

Check failed again, and this time it comes from my JSON generation. I tried to get pixel_size_x similar to what is done in views.img_data_json, but while the imaging loading in OMERO.figure doesn't crash when the pixel size is NOT SET, here it complains because px is None (or similar).

When pixel size is NOT SET, the panel's JSON (talking about a normal figure) doesn't contain pixel_size_x -> testing on it the [x.unit] label, it displays NaN µm and the Pdf export crashes!

I think that I should handle it the same way as for Z and T, displaying 0 by default (and without adding pixel_size_x to the JSON, so that we keep the warning in the UI image )

Tests are useful :D

will-moore commented 1 year ago

Testing the figure to Pdf with missing pixel_size_x is fixed now 👍 . Just a couple of wording suggestions above.

will-moore commented 1 year ago

After discussing @joshmoore and others this morning, we felt that something like this (which uses css-style formatting) would be easier to remember, more human readable and extensible: [time.unit; offset:3; precision:2]. That was my web-based preference, but Josh also suggested [time.unit; offset=3; precision=2] or you could go for JSON style [time.unit, offset:3, precision:2].

joshmoore commented 1 year ago

you could go for JSON style [time.unit, offset:3, precision:2].

Only slightly marred by there being no quotes :)

Tom-TBT commented 1 year ago

I will be on holiday for the next two weeks. Maybe best not to apply this change right now, so we have time to think about it.

But I like those "self-documenting formats" thanks a lot for the ideas!

Tom-TBT commented 1 year ago

Hello Moore², I ended up picking this style: [time.unit; offset=3; precision=2]. The : sign is already used for the h:m:s format so I wanted to avoid the confusion (though it's not a problem for the parsing, as ; is parsed first).

I also updated the tests, the tip window, and the figure_file_format documentation accordingly. Let me know!

will-moore commented 1 year ago

Sorry, not looked yet - I'm away till Wednesday... Please feel free to ping me again after then.

will-moore commented 1 year ago

Ah - I blindly tried [time.unit; offset=3; precision=2] for a time label (from the comment above) and this didn't get recognised... I realised after a while that time.unit is not valid.

Could you update the PR description with the new format (this can also serve as a reference)

will-moore commented 1 year ago

Functionality testing looks good. Labels are rendered the same in JavaScript and Python. Just a couple of minor comments above.

will-moore commented 1 year ago

Thanks Tom - some others on the team are away just now, but I when they're back we'll discuss if there's any outstanding issues/feedback. Cheers

pwalczysko commented 1 year ago

@Tom-TBT Sorry if I missed it in your previous PR:

Why is there the bounding box around the label such as Width: [width.pixel] please ? See screenshot below, FF, MacOS Big Sur. Is that expected ? Did I miss a hint about the formatting of such label ? It does not look natural or desirable on the figure...

Screenshot 2022-10-21 at 16 37 55

Edit: sorry, I realized that this is because I copied and pasted into the label box couple of leading spaces. This is the cause of the strange formatting of the label later - still, pasting some spaces possibly should not have such consequences ? Will try other label types as well, possibly this is not something introduced in your PR, but just a consequence of the necessity to create the label formula by yourself. Screenshot 2022-10-21 at 16 45 11

Edit 2: Indeed, this happens also with labels such as Image Name, so most probably not caused by this PR. It is just that this PR exposes such flaws as it imposes a different workflow.

Screenshot 2022-10-21 at 16 46 59

pwalczysko commented 1 year ago

Other than https://github.com/ome/omero-figure/pull/481#issuecomment-1287137105, this PR LGTM

Tom-TBT commented 1 year ago

Hi Petr, it looks to me that markdown is responsible for it.

Looking a bit around I found this: https://gist.github.com/dupuy/1855764#block-quotations quote: "Markdown treats four leading spaces as a code example"

So I don't know if bug or feature since we can now add code to the labels!!! ... Well maybe more like a bug, that's a weird way of attaching code to images

We could remove the leading spaces, but that could destroy someone's label alignment workflow. Let me see if I find a way of keeping the spaces without doing some markdown with it. Tell me if you would have that in this PR or in a separate one.

Tom-TBT commented 1 year ago

Well maybe that becomes hard to handle, I went through that tutorial https://www.markdownguide.org/basic-syntax/ and many works: image

pwalczysko commented 1 year ago

thank you @Tom-TBT , this https://github.com/ome/omero-figure/pull/481#issuecomment-1288570316 explains a lot. I would say this all is for another PR, cc @will-moore might even have an issue/plan for this.

will-moore commented 1 year ago

Created an issue for the formatting behaviour the @pwalczysko reported: https://github.com/ome/omero-figure/issues/486 @jburel you happy to merge this?

Tom-TBT commented 1 year ago

Thank you Jean-Marie for the review, I made the changes

jburel commented 1 year ago

@Tom-TBT sorry for the delay. Thanks for making the adjustments

will-moore commented 1 year ago

Thanks @Tom-TBT - this is now released in omero-figure 5.1.0