We're Hiring!

OMERO.matlab: getDimensionOrder throws Unloaded exception

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.

OMERO.matlab: getDimensionOrder throws Unloaded exception

Postby gyellen » Fri Nov 07, 2014 2:59 pm

Hi -
I'm retrieving image data from OMERO and it's working ok except for getting the dimension order.

Code: Select all
            s = obj.sessionHolder.session;
            img = getImages(s, obj.imageID);
            pixelsList = img.copyPixels();
            pixels = pixelsList.get(0);
            obj.szXYZCT = getPixelsSize(pixels);
            pixelsId = pixels.getId().getValue();
            store = s.createRawPixelsStore();
            store.setPixelsId(pixelsId, false);
            dord = pixels.getDimensionOrder();

The last line works, but then
Code: Select all
            dordval = dord.getValue();

throws an UnloadedEntityException. I've run across the Unloaded error before, but I'm not sure how to avoid it.

I'm also assuming that if I do retrieve this value, it will be an ordinal number and I will have to use the Enumeration to learn the string value.

Thanks for help!
Gary
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby sbesson » Mon Nov 10, 2014 8:54 am

Hi Gary,

the Pixels object for each image is not loaded by default. The following code snippet should give you a series of calls allowing to load it and retrieve the dimension order.

Code: Select all
s = obj.sessionHolder.session;
img = getImages(s, obj.imageID);
pixelsId = img.getPrimaryPixels().getId().getValue();  % Retrieve the primary pixels ID
pixels = s.getPixelsService().retrievePixDescription(pixelsId)  % Load the pixels object
dord = pixels.getDimensionOrder();


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

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby gyellen » Mon Nov 10, 2014 11:57 am

Thanks, Sebastien. I'm having a similar problem with image.linkDataset. How do I get the dataset links loaded?
Best, Gary
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby gyellen » Mon Nov 10, 2014 1:23 pm

Hi again Sebastian - more specifically, here is the code I used to create a new image on the server (which works),
Code: Select all
% helper functions
rint = @(x) omero.rtypes.rint(x);
rstring = @(x) omero.rtypes.rstring(x);

p = omero.sys.ParametersI();
p.add('type',rstring('uint8'));
q=['from PixelsType as p where p.value= :type'];

queryService = session.getQueryService;
pixelsType = queryService.findByQuery(q,p);

pixelsService = session.getPixelsService;

iId = pixelsService.createImage(uint32(128),uint32(128),uint32(1),uint32(15), ...
   toJavaList(uint32(1)),pixelsType,java.lang.String('gyModC3.ome.tif [5]'), ... % name
   java.lang.String('seg of z0 c0 t0:14'));  % description

containerService = session.getContainerService;

imgnew = containerService.getImages('Image',toJavaList(java.lang.Long(iId.getValue)),omero.sys.Parameters);
pixelsId = imgnew.get(0).getPrimaryPixels().getId().getValue();

% prepare to write the pixel data
store = session.createRawPixelsStore;
store.setPixelsId(pixelsId, true);

% make some junk data for testing, then write it
plane = uint8(eye(128,128)*10);
store.setPlane(plane(:),0,0,0);
plane(30:50,30:50)=2;
plane(100:110,10:40)=3;
for k=1:14; store.setPlane(plane(:),0,0,k); end
store.close;


and the code to link to a dataset (which doesn't):
Code: Select all
% now link to data set **** USE A LEGAL DATASET NUMBER ***
dset = session.getDatasets(262);

% next line has had problems
imgnew.get(0).linkDataset(dset);

===== error message =====
Java exception occurred:
omero.UnloadedCollectionException: Error updating collection:datasetLinksSeq
Collection is currently null. This can be seen
by testing "datasetLinksSeqLoaded". This implies
that this collection was unloaded. Please refresh this object
in order to update this collection.


   at omero.model.ImageI.throwNullCollectionException(ImageI.java:38)

   at omero.model.ImageI.linkDataset(ImageI.java:931)

   at omero.model.Image.linkDataset(Image.java:316)


Thanks for any advice,
Gary
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby sbesson » Mon Nov 10, 2014 1:39 pm

Hi Gary,

if the goal is lo link an image to a dataset on the server, you may want to adapt this section of the CreateImage.m example to your needs.

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

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby gyellen » Tue Nov 11, 2014 1:04 pm

Thanks, Sebastien.
I'm making progress, but still run across Unloaded exceptions that I don't know how to avoid.
My current example is retrieving the annotation links for an ROI object. I've done:

Code: Select all
service = session.getRoiService();
roiResult = service.findByImage(image.getId.getValue, []);
rois = roiResult.rois;
roi0 = rois.get(0);
dscr = char(roi.getDescription().getValue());
maskObj = roi.getShape(0);   
z = maskObj.getTheZ.getValue;
c = maskObj.getTheC.getValue;
t = maskObj.getTheT.getValue;


but I don't know how to load the linkedAnnotationList (roi.isAnnotated=1 but roi.isAnnotationLinksLoaded=0).
I've looked for a retrieve method on the roiService, analogous to the pixels example, but cannot find one.

Thanks again - sorry to be a nuisance!
Gary
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby sbesson » Wed Nov 12, 2014 3:01 pm

Hi Gary,

as a general rule, unless otherwise stated, you should assume linked objects will be unloaded when retrieving objects from the database. If loading linked objects is not available via the API methods (see for instance getProjects), you will need the write the appropriate query to fetch and return both the objects and the linked objects.

If you have examples of images/scripts allowing to reproduce your use case, it would be useful for helping you with the adequate query.

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

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby gyellen » Fri Nov 14, 2014 12:48 pm

Hi Sebastien - The code (below) that you recommended does run, but if I then try "dord.getValue;", I get an UnloadedEntityException (and dord.isLoaded returns 0).
best,
gary

sbesson wrote:Hi Gary,

the Pixels object for each image is not loaded by default. The following code snippet should give you a series of calls allowing to load it and retrieve the dimension order.

Code: Select all
s = obj.sessionHolder.session;
img = getImages(s, obj.imageID);
pixelsId = img.getPrimaryPixels().getId().getValue();  % Retrieve the primary pixels ID
pixels = s.getPixelsService().retrievePixDescription(pixelsId)  % Load the pixels object
dord = pixels.getDimensionOrder();


Best,
Sebastien
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby sbesson » Fri Nov 14, 2014 2:40 pm

Hi Yuriy,

You are correct. I just checked and `retrievePixDescription()` does not load the dimension order. The following snippet should retrieve the Pixels object with properly loaded DimensionOrder:

Code: Select all
query = ['select p from Pixels as p'...
  ' left outer join fetch p.dimensionOrder as d'...
  ' where p.id = :id'];
parameters = omero.sys.ParametersI();
parameters.addId(pixelsId);
pixels = s.getQueryService.findByQuery(query, parameters);
dimensionOrder = pixels.getDimensionOrder().getValue().getValue();


Let me know if this works,
Sebastien
User avatar
sbesson
Team Member
 
Posts: 421
Joined: Tue Feb 28, 2012 7:20 pm

Re: OMERO.matlab: getDimensionOrder throws Unloaded exceptio

Postby gyellen » Sun Nov 16, 2014 4:50 am

Hi Sebastien,
I finally got around to testing this, and the code works... but OMERO gives the incorrect value for the dimension order. I have uploaded a file to QA, with dimension orders of image0=XYCTZ, image1=XYTCZ, image2=XYCTZ. These are correctly seen in the XML block of the .ome.tif, and read properly by Bio-Formats import to Fiji. But OMERO reports all three images as XYZCT.
Best,
Gary
gyellen
 
Posts: 24
Joined: Fri Oct 24, 2014 1:19 am

Next

Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest