We're Hiring!

setting the group on the client object/session?

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

setting the group on the client object/session?

Postby jwarren » Tue Feb 17, 2015 10:52 am

Hi Josh

I've looked at the code from here : https://github.com/openmicroscopy/openm ... ry.py#L235

I'm trying to set the session to use an already setup public_group - how do I do that?

The below code works apart from setting the group bit:

Code: Select all
print "initiating ImageImport object"
        self.root = omero.client(omeroHost)  # ok because adds self
        #self.__clients.add(self.root)
        self.root.setAgent("OMERO.py.root_test")
        self.root.createSession("user", "pass")
        group=self.group_and_name("public_group")
        self.root.ctx["omero.group"]=group
        print "user="+str(self.root)


It would also be great to have an example of uploading an image using soft linking via this api?

Cheers

Jonathan.
jwarren
 
Posts: 102
Joined: Wed Jul 09, 2014 1:35 pm

Re: setting the group on the client object/session?

Postby sbesson » Tue Feb 17, 2015 1:48 pm

Hi Jonathan,

to switch between groups, you may want to use the setSecurityContext(group) method on the initialized session (see https://github.com/openmicroscopy/openm ... ry.py#L488 for an example).

In order to upload an image, you should be able to use a CLI object like in this tread using the key of the session. You can then pass the soft link transfer options to the import command:

Code: Select all
cli = omero.cli.CLI()
cli.loadplugins()
import_args = ["import", "-s", hostname, "-k", "%s" % sessionId]
import_args += ["---errs", stderr, "---file", stdout, file_to_import]
import_args += ["--", "--transfer=ln_s"]
cli.invoke(import_args, strict=True)


Best,
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: setting the group on the client object/session?

Postby jwarren » Tue Feb 17, 2015 1:55 pm

Great - thanks.

I was using the CLI before - but after speaking to Josh in person last week he suggested using the client as in the test script shown above. Loading each file using the CLI was taking too long for us as the Java JVM boots up for each image...

Using the CLI on a per directory basis was fast - but at some points we need more fine control as loading a directory results in the same images being uploaded again. I wish/ is there a "don't load files of same name" option to the CLI?
jwarren
 
Posts: 102
Joined: Wed Jul 09, 2014 1:35 pm

Re: setting the group on the client object/session?

Postby jmoore » Tue Feb 17, 2015 2:27 pm

Hi Jonathan,

jwarren wrote:I was using the CLI before - but after speaking to Josh in person last week he suggested using the client as in the test script shown above. Loading each file using the CLI was taking too long for us as the Java JVM boots up for each image...


Using the CLI and using the omero.cli.CLI object should be quite close in terms of time. Both will need to create a JVM and that was primarily what I wanted to prevent.

Using the CLI on a per directory basis was fast - but at some points we need more fine control as loading a directory results in the same images being uploaded again. I wish/ is there a "don't load files of same name" option to the CLI?


At the moment, there's not such a "don't load files of same name" option, but it's an interesting idea. Thanks. That being said, what sequence of commands is leading to multiple imports? Unless you're recursively descending the same directory multiple times, I wouldn't expect that to happen.

Cheers,
~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: setting the group on the client object/session?

Postby jwarren » Tue Feb 17, 2015 2:57 pm

Hi Josh

Unfortunately we go into the same directories often to upload data as the directory the file is in is the only way to associate the correct omero id with our external db image record. When we have new images then we have to scan the directories to see if there are new ones in them.

Using the CLI with directory loading (not per file basis) and no_thumbnails argument was 6 times faster than on a file basis and thumbnails. Using the CLI using the directory as an argument still falls over after a few thousand images (complained of lost connection) and then I have to restart the job. This means we need to go through the same directories in case the directory contents was only half loaded... resulting in duplicates or triplicates in omero (depending on the number of times we've already run the importer).

How difficult would it be to put a filename check in the importer? Should I try it? Any pointers?
Writing this importer in java and using the java client code itself maybe faster for me to write and use?


Hope this makes sense?
jwarren
 
Posts: 102
Joined: Wed Jul 09, 2014 1:35 pm

Re: setting the group on the client object/session?

Postby jmoore » Tue Feb 17, 2015 3:05 pm

jwarren wrote:Unfortunately we go into the same directories often to upload data as the directory the file is in is the only way to associate the correct omero id with our external db image record. When we have new images then we have to scan the directories to see if there are new ones in them.


Ah, ok. Sorry for having not realized that. What you're doing is sounding a bit more like dropbox now, but of course, only partially, which explains how/why you're script has developed as it has. Speaking of which, is that visible on github?

Using the CLI with directory loading (not per file basis) and no_thumbnails argument was 6 times faster than on a file basis and thumbnails.


Just for comparison, how many files (how large each) and how many seconds is that?

Using the CLI using the directory as an argument still falls over after a few thousand images (complained of lost connection) and then I have to restart the job.


Hmmmm.....that's surprising unless your calling Python script is timing out the session that it created. Looking at that again would be helpful.

This means we need to go through the same directories in case the directory contents was only half loaded... resulting in duplicates or triplicates in omero (depending on the number of times we've already run the importer).

How difficult would it be to put a filename check in the importer? Should I try it? Any pointers?


This should be pretty straight-forward. Perhaps we need to work out some more of the details first though. (For example, would checking on the sha1 suffice? Filenames may not be unique for everyone)

Writing this importer in java and using the java client code itself maybe faster for me to write and use?


That's certainly up to you. But, for example, if you'd like to have a go at the duplicate detection, I can point you to the right location (roughly https://github.com/openmicroscopy/openmicroscopy/blob/v.5.0.8/components/blitz/src/ome/formats/importer/cli/CommandLineImporter.java#L332).

Cheers,
~Josh
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany

Re: setting the group on the client object/session?

Postby jmoore » Fri Feb 20, 2015 9:07 am

Jonathan,

I've tried to scope out a "file exclusion" flag for the importer under https://github.com/openmicroscopy/openm ... /pull/3510 -- thoughts welcome (preferably on the PR).

~Josh.
User avatar
jmoore
Site Admin
 
Posts: 1591
Joined: Fri May 22, 2009 1:29 pm
Location: Germany


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest