Page 1 of 2

Bioformats API

PostPosted: Wed Oct 06, 2010 8:44 pm
by icaoberg
when accessing the omero shell, is there access to the bioformats api?

Re: Biomodels API

PostPosted: Wed Oct 06, 2010 8:47 pm
by jmoore
Do you mean the bioformats API? If so, no. It's strictly available in Java. What are you trying to achieve?

~J.

Re: Biomodels API

PostPosted: Wed Oct 06, 2010 8:51 pm
by icaoberg
i want to retrieve an image from the server and export it to a desired format, say a numpy array.

Re: Biomodels API

PostPosted: Thu Oct 07, 2010 5:43 am
by jmoore
Do you mean something like https://trac.openmicroscopy.org.uk/omero/browser/trunk/components/tools/OmeroPy/src/omero/util/script_utils.py#L395 ? This retrieves an "image", i.e. what OMERO calls a plane, as a NumPy array.

~J

Re: Biomodels API

PostPosted: Thu Oct 07, 2010 6:44 pm
by icaoberg
script_utils has a method for converting a tiff to a numpy array. i guess there is a way to map the byte array containing the image to tiff. so i could that. but i am looking for a method the parses the byte array directly to a numpy array without writing to disk, that is without writing an image to file.

Re: Bioformats API

PostPosted: Thu Oct 07, 2010 7:06 pm
by jmoore
The method I pointed to does take the byte array returned by rawPixelsStore.getPlane() and converts it to a NumPy array:


Code: Select all

395   def downloadPlane(rawPixelsStore, pixels, z, c, t):
...
406       rawPlane = rawPixelsStore.getPlane(z, c, t);
...
411       convertType ='>'+str(sizeX*sizeY)+pixelstypetopython.toPython(pixelType);
412       convertedPlane = unpack(convertType, rawPlane);
413       numpyType = pixelstypetopython.toNumpy(pixelType)
414       remappedPlane = numpy.array(convertedPlane, numpyType);
415       remappedPlane.resize(sizeY, sizeX);
416       return remappedPlane;


Where are you getting your byte array from? If not from RawPixelsStore, then I you can just copy that bottom portion and make it into your own method.

Cheers,
~Josh.

Re: Bioformats API

PostPosted: Thu Oct 07, 2010 7:53 pm
by icaoberg
i was trying to get the byte stream from the importer like in Run_Matlab.py but this is way cooler! Awesome should be a technical term. I'll try it and let you know. :lol:

Re: Bioformats API

PostPosted: Mon Oct 25, 2010 6:14 am
by icaoberg
i tried it and got this error.

Code: Select all
In [122]: plane = utils.downloadPlane( rawPixelsStore, pixels, 0, 0, 0 );
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (8, 0))

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (22, 0))

---------------------------------------------------------------------------
UnloadedEntityException                   Traceback (most recent call last)

/afs/cs.cmu.edu/user/bhcho/<ipython console> in <module>()

/usr0/local/omero.server/OMERO.server-Beta-4.2.0/lib/python/omero/util/script_utils.pyc in downloadPlane(rawPixelsStore, pixels, z, c, t)
    404     sizeY = pixels.getSizeY().getValue();
    405     pixelsId = pixels.getId().getValue();
--> 406     pixelType = pixels.getPixelsType().getValue().getValue();
    407     convertType ='>'+str(sizeX*sizeY)+pixelstypetopython.toPython(pixelType);
    408     convertedPlane = unpack(convertType, rawPlane);

/usr0/local/omero.server/OMERO.server-Beta-4.2.0/lib/python/omero_model_PixelsTypeI.pyc in getValue(self, current)
    109
    110       def getValue(self, current = None):
--> 111           self.errorIfUnloaded()
    112           return self._value
    113

/usr0/local/omero.server/OMERO.server-Beta-4.2.0/lib/python/omero_model_PixelsTypeI.pyc in errorIfUnloaded(self)
     36       def errorIfUnloaded(self):
     37           if not self._loaded:
---> 38               raise _omero.UnloadedEntityException("Object unloaded:"+str(self))
     39
     40       def throwNullCollectionException(self,propertyName):

UnloadedEntityException: Object unloaded:object #0 (::omero::model::PixelsType)
{
    _id = object #1 (::omero::RLong)
    {
        _val = 5
    }
    _details = <nil>
    _loaded = False
    _value = <nil>
}

Re: Bioformats API

PostPosted: Mon Oct 25, 2010 6:31 am
by jmoore
Hi Ivan,

can you show me your entire code snippet? Where are you getting your Pixels object from? It's "unloaded" which means that none of the fields are present. See http://trac.openmicroscopy.org.uk/omero/wiki/ObjectModel#States for more information. http://hudson.openmicroscopy.org.uk/job/OMERO/javadoc/ome/api/IPixels.html#retrievePixDescription(long) will return a properly loaded Pixel instance.

Cheers,
~Josh

Re: Bioformats API

PostPosted: Mon Oct 25, 2010 7:20 am
by icaoberg
Code: Select all
   rawPixelsStore = session.createRawPixelsStore()
   image = gateway.getImage( iid )
   pixels = image.getPixels( 0 )
   pid = pixels.getId().getValue()
   rawPixelsStore.setPixelsId( pid, True )
   plane = utils.downloadPlane( rawPixelsStore, pixels, 0, 0, 0 );