[ome-devel] OmeroWeb API support for thumbnails with rendering parameters possible?

José Salavert Torres josator at ebi.ac.uk
Fri Dec 12 17:15:35 GMT 2014


Hi William,

First of all thanks for your fast and detailed reply.

I save the rendering settings as default each time, in the application they are meant to be always the same.
I want a behaviour without defaults, because the default values are provided by another service.

It wasn’t necessary to set the variable “img" twice, this is the new source code, following your advice:

@login_required()
def render_slice_thumbnail (request, iid, z, t, w=None, h=None, conn=None, _defcb=None, **kwargs):
    """
    Returns an HttpResponse wrapped jpeg with the rendered thumbnail for image ‘iid’ for the z, t slice

    @param request:     http request
    @param iid:         Image ID
    @param z:           Z index
    @param t:           T index
    @param w:           Thumbnail max width. 64 by default
    @param h:           Thumbnail max height
    @return:            http response containing jpeg
    """

    server_id = request.session['connector'].server_id
    direct = True
    if w is None:
        size = (64,)
    else:
        if h is None:
            size = (int(w),)
        else:
            size = (int(w), int(h))
    if size == (96,):
        direct = False

    #OMERO only generates thumbnails for saved rendering settings 
    pi = _get_prepared_image(request, iid, server_id=server_id, saveDefs=True, conn=conn) 
    if pi is None:
        logger.debug("(b)Image %s not found..." % (str(iid)))
        if _defcb:
            jpeg_data = _defcb(size=size)
            prevent_cache = True
        else:
            raise Http404
    img, compress_quality = pi
    
    rdefId = request.REQUEST.get('rdefId', None)
    if rdefId is not None:
        rdefId = int(rdefId)

    #Thumbnail code
    jpeg_data = webgateway_cache.getImage(request, server_id, img, z, t, ctx='thumbslice' + w + 'x' + h)
    if jpeg_data is None:
        prevent_cache = False
        jpeg_data = img.getThumbnail(size=size, z=int(z), t=int(t), direct=direct, rdefId=rdefId)
        if jpeg_data is None:
            logger.debug("(c)Image %s not found..." % (str(iid)))
            if _defcb:
                jpeg_data = _defcb(size=size)
                prevent_cache = True
            else:
                return HttpResponseServerError('Failed to render thumbnail')
        else:
            prevent_cache = img._thumbInProgress
        if not prevent_cache:
            webgateway_cache.setImage(request, server_id, img, z, t, jpeg_data, ctx='thumbslice' + w + 'x' + h)
    else:
        pass
    rsp = HttpResponse(jpeg_data, content_type='image/jpeg')
    return rsp

If this behaviour that sets defaults on each call is ok I would like to rebase my code and prepare a pull request.
Calling the same function without the render attributes uses the last saved ones and the attributes are used to generate the cache element.

Regarding other questions:

1,3,4) Thanks for your advice on the web server.
2) We are currently on 5.1 develop as we need the functionality for float images (I am pulling from git).
I was reading online documentation for an older version (documentation for 5.1 is not online).
However, the _prepareTB() function has a defaul parameter “_r” which do not seem to be used, but was used to reset something to default.

Another question: Where is the code for the server side of these RPC calls (renderJpeg, getThumbnail…)? We may need in the future to implement other functions.

Best wishes,
José Salavert

On 12 Dec 2014, at 13:47, William Moore <will at lifesci.dundee.ac.uk> wrote:

> Hi Jose,
> 
>  OMERO is only designed to generate thumbnails for saved rendering settings, so what you want to do (get a thumbnail with new rendering settings)
> is not directly supported.
> 
> You have basically 2 choices:
>  - Save the rendering settings, then create a thumbnail.
> 	If you add   saveDefs=True  to this line:
> 
> 	pi = _get_prepared_image(request, iid, server_id=server_id, saveDefs=True, conn=conn)
> 
> 	then you will see the effect of the rendering settings ?c=1|-3000:3000
> 
>  - Don't use the thumbnail service, just render a full-size plane with renderJpeg() and scale it yourself (e.g. using PIL).
> 
> 
> In your code sample, you've combined these 2 approaches.
> e.g. you are setting the 'img'  variable twice (notice the different handling of None in each case)
> 
>>     pi = _get_prepared_image(request, iid, server_id=server_id, conn=conn)
>>     if pi is None:
>>         raise Http404
>>     img, compress_quality = pi
> 
> 
>>         img = conn.getObject("Image", iid)
>>         if img is None:
>>             logger.debug("(b)Image %s not found..." % (str(iid)))
> 
> 
> 
> 
> 1) For development, I tend to run the Django development server directly, although we are moving
> away from this practise and others do it differently.
> 
> Here's what I do:
> 
> # for logging to dist/var/log (don't set this in production server)
> export OMERO_HOME=/path/to/OMERO/dist
> 
> # make sure server libs are on python path...
> export PYTHONPATH=$OMERO_HOME/lib/python:$PYTHONPATH
> 
> # … but remove omeroweb libs (so they don't get imported in python)
> $ rm -rf dist/lib/python/omeroweb/
> 
> # run omeroweb directly
> $ cd components/tools/OmeroWeb
> $ python omeroweb/manage.py runserver 0.0.0.0:4080
> 
> 
> 2) Are you using OMERO 5.0 or OMERO 5.1 (develop)?
> In Blitz Gateway
> 	img.getThumbnail(size=size, z=int(z), t=int(t), direct=direct, rdefId=rdefId)
> the rdefId parameter was added in 5.1 and is used in 
> the following line:
> 	tb = self._prepareTB(rdefId=rdefId)
> 
> 
> 3) Web logs are in dist/var/log/OMEROweb.log
> However, since they can be kinda verbose, I tend to simply add print statements
> and view these in the console where the development server is running.
> 
> 
> 4) If you monitor the server logs while refreshing your thumbnail in the browser…
> 
> $ tail -f dist/var/log/Blitz-0.log
> 
> you can see lines like this:
> 
> 2014-12-12 13:40:31,754 INFO  [        ome.services.util.ServiceHandler] (.Server-55)  Meth:	interface ome.api.ThumbnailStore.getThumbnailForSectionByLongestSideDirect
> 2014-12-12 13:40:31,754 INFO  [        ome.services.util.ServiceHandler] (.Server-55)  Args:	[30, 0, 64]
> 2014-12-12 13:40:31,755 INFO  [    ome.security.basic.BasicEventContext] (.Server-55)  cctx:	group=5
> 
> 
>  Hope that helps,
> 
>   Will.
> 
> 
> 
> On 12 Dec 2014, at 12:02, José Salavert Torres <josator at ebi.ac.uk> wrote:
> 
>> Dear Omero Developers,
>> 
>> I am trying to use OMERO Web to visualise image thumbnails of any slice (z,t) and supporting rendering parameters as well, concretely those related with the contrast (?c=1|-3000,3000).
>> So far I managed to add a new django web service to OMERO Web.
>> This new view is able to render these down-sampled versions of the images at any Z and T (this option was already implemented in OMERO Py omero.gateway package in the getThumbnail() function, but not accessible from OMERO Web).
>> The new view is also capable of using the webgateway_cache to store the files using setImage() and getImage() with a special ctx string that is added to the image id.
>> 
>> However, for the EMPIAR 3D viewer I need also to set the contrast of the down-sampled images, so I would need support for (?c=1|-3000,3000) parameters to adjust the contrast of the thumbnail.
>> 
>> If you could provide some feedback on OMERO PY omero.gateway package I would appreciate it. I am digging in the getThumbnail(), _prepareTB() and renderJpeg(). I think that _prepareTB is resetting the context parameters but I am not sure about this.
>> 
>> So far this is the code for the new OMERO Web Call:
>> 
>> 
>> @login_required()
>> def render_slice_thumbnail (request, iid, z, t, w=None, h=None, conn=None, _defcb=None, **kwargs):
>>     """
>>     Returns an HttpResponse wrapped jpeg with the rendered thumbnail for image 'iid'
>> 
>>     @param request:     http request
>>     @param iid:         Image ID
>>     @param z:           Z index
>>     @param t:           T index
>>     @param w:           Thumbnail max width. 64 by default
>>     @param h:           Thumbnail max height
>>     @return:            http response containing jpeg
>>     """
>> 
>>     server_id = request.session['connector'].server_id
>>     direct = True
>>     if w is None:
>>         size = (64,)
>>     else:
>>         if h is None:
>>             size = (int(w),)
>>         else:
>>             size = (int(w), int(h))
>>     if size == (96,):
>>         direct = False
>>         
>>     pi = _get_prepared_image(request, iid, server_id=server_id, conn=conn)
>>     if pi is None:
>>         raise Http404
>>     img, compress_quality = pi
>>     
>>     rdefId = request.REQUEST.get('rdefId', None)
>>     if rdefId is not None:
>>         rdefId = int(rdefId)
>> 
>>     jpeg_data = webgateway_cache.getImage(request, server_id, img, z, t, ctx='thumbslice' + w + 'x' + h)
>>     if jpeg_data is None:
>>         prevent_cache = False
>>         img = conn.getObject("Image", iid)
>>         if img is None:
>>             logger.debug("(b)Image %s not found..." % (str(iid)))
>>             if _defcb:
>>                 jpeg_data = _defcb(size=size)
>>                 prevent_cache = True
>>             else:
>>                 raise Http404
>>         else:
>>             jpeg_data = img.getThumbnail(size=size, z=int(z), t=int(t), direct=direct, rdefId=rdefId)
>>             if jpeg_data is None:
>>                 logger.debug("(c)Image %s not found..." % (str(iid)))
>>                 if _defcb:
>>                     jpeg_data = _defcb(size=size)
>>                     prevent_cache = True
>>                 else:
>>                     return HttpResponseServerError('Failed to render thumbnail')
>>             else:
>>                 prevent_cache = img._thumbInProgress
>>         if not prevent_cache:
>>             webgateway_cache.setImage(request, server_id, img, z, t, jpeg_data, ctx='thumbslice' + w + 'x' + h)
>>     else:
>>         pass
>>     rsp = HttpResponse(jpeg_data, content_type='image/jpeg')
>>     return rsp
>> 
>> 
>> The parameters in the context (?c=1|-3000,3000) are set using the _get_prepared_image function() (which is a function used in render_image call).
>> However the image is not modified.
>> 
>> Some questions:
>> 
>> 1 - How can I compile the OmeroWeb package and run it. I have tryed compiling components/tools/omeroWEB only, but then the command omero web start does not load the updated version. Also the default option for “components/tools/OmeroWeb/build.xml 
>> 
>> 2 - In img.getThumbnail(size=size, z=int(z), t=int(t), direct=direct, rdefId=rdefId) rdefId is not used inside the function, the same for the _r in _prepareTB().
>> 
>> 3- Where are the logs of the "omero web start” command stored? I would like to check if _prepareTB() is reseting the grayscale parameters in the context. Also, how can I manually kill the web server if it hangs?
>> 
>> 4- I am lost when the code reaches OmeroPy/build/lib/omero_api_ThumbnailSotre_ice.py remote procedure calls  (def getThumbnailForSectionDirect(self, theZ, theT, sizeX, sizeY, _ctx=None)). I would like to check also if the context parameters are read by the generate thumbnail function in the server side.
>> 
>> Thank you in advance,
>> José Salavert Torres
>> EMBL-EBI, pdbe/emdb/empiar3d
>> 
>> _______________________________________________
>> ome-devel mailing list
>> ome-devel at lists.openmicroscopy.org.uk
>> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20141212/ad963c59/attachment-0001.html>


More information about the ome-devel mailing list