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

Blitzgateway api missing to export and import images? #2179

Open
jithumurugan opened this issue Mar 29, 2021 · 7 comments
Open

Blitzgateway api missing to export and import images? #2179

jithumurugan opened this issue Mar 29, 2021 · 7 comments

Comments

@jithumurugan
Copy link

I could not find any functions specified in documentation to export and import images via python. I can see that, I would be able to render image, but if I want to download a list of .scn images under a dataset and save all of them in a folder, is it somehow possible in the current version. Since we have a lot of clients, not sure if this is somehow possible using gateway api or any other module?

https://github.com/ome/ome-documentation/blob/develop/omero/developers/PythonBlitzGateway.rst

Please let me know if this is possible, ideally my requirement is to download/upload a set of images under a dataset in python. I would expect this to be part of Blitzgateway, If available could someone add this information as part of the gateway documentation above? Thanks

Regards
Jithu

@will-moore
Copy link
Member

Hi,
I recently wrote a script that does both downloading files for all the Images in a Dataset, and also re-imports them to another server (for users who wanted to transfer data from one OMERO server to another): https://gist.github.com/will-moore/dab2148ef566125b60625f7773aa1b64

NB: The import uses https://gitlab.com/openmicroscopy/incubator/omero-python-importer/-/blob/master/import.py which is not part of the BlitzGateway or an installable library yet, so you need to download it (see instructions in the script).

Discussion was at https://forum.image.sc/t/transfer-a-project-dataset-between-omero-instances/30295/13

We'll need to discuss what to do with that import script, since it is becoming more widely used cc @joshmoore

@jithumurugan
Copy link
Author

Hello Will,

Thank you so much for providing the scripts and sharing the necessary links, I missed one thing, ideally exporting all the data under a dataset and also the regions/annotations done on them. Do you think, if I extend the script you provided, would it be possible to get the regions and additional annotation done on these images also?

Regards
Jithu

@will-moore
Copy link
Member

Please feel free to adapt the script to your needs. Although the "transfer" workflow of the script (from one OMERO server to another) is not what you are needing, right?
For your workflow I imagine you'd want to just use some parts of that script, and remove other parts?
In what format would you want to download the regions / annotations?
Do you need any help with that part, or do the current docs have what you need?

@jithumurugan
Copy link
Author

Hello Will,

In my case, I would like to export the images & regions out of OMERO, run some processing algorithms to generate some results (images + ROIs) and send them back to omero server. Right now I am preparing a container to do the external processing and inside which I need to download the data, process it and then send the data back. For which I was looking for some gateway functions which can do the export and import. what would be your suggestion for my requirements, is it the right approach or should I go for a different approach?

The script you have provided is very good and would be helpful for my scenarios, but in general would it not be better to have some gateway functions like gateway.download('download_loc_local_dir', 'image_id'): specific image download /gateway.download('download_loc_local_dir', 'dataset_id'): batch download from dataset and also something like gateway.upload('local_dir_image_location', 'data_set_id') for downloading and uploading images and also the regions/annotations? Thanks

@will-moore
Copy link
Member

This approach sounds fine. What format does your processing software need to read the ROIs? JSON? XML? yml?
You can access ROIs via Python API as in https://docs.openmicroscopy.org/omero/5.6.3/developers/Python.html#rois

I created a new issue for adding functions to the gateway: ome/omero-py#284

@jithumurugan
Copy link
Author

Thanks Will, this would be really great if we have such export import functionalities in gateway. I would always go for JSON and too I think this would be really the representation widely used by many in the community. Thanks for giving the link also,

@will-moore
Copy link
Member

You can convert omero.model objects into JSON using https://github.com/ome/omero-marshal

For example:

from omero_marshal import get_encoder
import json

image_id = 153

roi_service = conn.getRoiService()
result = roi_service.findByImage(image_id, None)

with open(f'Image_{image_id}_ROIs.json', 'w') as json_file:
    rois_json = []
    for roi in result.rois:
        encoder = get_encoder(roi.__class__)
        rois_json.append(encoder.encode(roi))
    json_file.write(json.dumps({'rois': rois_json}))

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

No branches or pull requests

2 participants