NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [netcdf-java] [thredds] Java to Python tools

Hi John & everyone,


Depending on your application you could also wire Java and Python
> together using inter-process communication.  There is a plethora of
> RPC libraries out there with good Python and Java support.  E.g.
> protocol buffers.
>

We faced the same problem trying to integrate Bio-Formats (a Java library;
http://github.com/openmicroscopy/bioformats) and into CellProfiler (a
Python application; http://github.com/CellProfiler).

The first solution was in-process. However, there are some difficulties
with launching and managing a JVM from native code:
  * You may not know a priori how much memory to assign to the Java max
heap, and it cannot be changed after the JVM has launched.
  * Java never returns RAM to the system; the garbage collector just frees
it internally for Java to reuse.
  * AFAIK, you cannot only ever start one JVM; even if it terminates, you
cannot start a second one.
  * Unless you are very careful, Mac OS X has threading issues with Java
AWT.

Hence, the CellProfiler team developed a second solution, inter-process
this time, called subimager:
   https://github.com/CellProfiler/subimager

Subimager is a lightweight HTTP server that can be queried from Python,
which avoids most of the pitfalls mentioned above (though you still have to
decide on a max heap size, of course).

Lastly, CellProfiler abstracts the integration mechanism into a class that
supports both in-process and inter-process, depending on the circumstances:

https://github.com/CellProfiler/CellProfiler/blob/master/imagej/ijbridge.py

It is now working very well! Maybe you can pursue a similar approach.

For further reading, check out my "Interfacing from non-Java code" page:
   http://loci.wisc.edu/bio-formats/interfacing-non-java-code

It is part of the Bio-Formats developer documentation but would be totally
applicable to netCDF Java or any other Java library, too.

Regards,
Curtis


On Wed, Apr 4, 2012 at 9:18 AM, Don Murray <don.murray@xxxxxxxx> wrote:

> I think John is looking for something that would allow C Python to call
> into the netCDF-Java libraries.  For that, the two options seem to be:
>
> JPype
> JCC
>
> or using interprocess communication.   Here's a good presentation on
> different approaches that I found on the web:
>
> http://www.slideshare.net/**onyame/mixing-python-and-java<http://www.slideshare.net/onyame/mixing-python-and-java>
>
> I think Sean Arms at Unidata was looking at JCC at one point.
>
> Don
>
>
> On 4/4/12 7:38 AM, stephen.pascoe@xxxxxxxxxx wrote:
>
>> The important question is why you need Python.  If it's to access
>> some C library with python bindings (e.g. numpy or netCDF4-python)
>> then Jython isn't appropriate and you'll need one of those
>> Python<->bridges JPype or Jepp.
>>
>> If you need the very latest Python features (particularly Python 3)
>> you'll also find Jython is a bit behind CPython.  Many standard
>> Python frameworks now work with Jython (e.g. Django, SQLAlchemy) but
>> you'd have to check the compatibility of each dependency.
>>
>> Otherwise Jython is the most popular and well maintained choice.
>>
>> Depending on your application you could also wire Java and Python
>> together using inter-process communication.  There is a plethora of
>> RPC libraries out there with good Python and Java support.  E.g.
>> protocol buffers.
>>
>> Stephen.
>>
>> --- Stephen Pascoe  +44 (0)1235 445980 Centre of Environmental Data
>> Archival STFC Rutherford Appleton Laboratory, Harwell Oxford, Didcot
>> OX11 0QX, UK
>>
>>
>> -----Original Message----- From: Robert Casey
>> [mailto:rob@iris.washington.**edu <rob@xxxxxxxxxxxxxxxxxxx>] Sent: 04
>> April 2012 14:31 To:
>> Pascoe, Stephen (STFC,RAL,RALSP); John Caron Cc:
>> netcdf-java@xxxxxxxxxxxxxxxx; thredds@xxxxxxxxxxxxxxxx Subject: Re:
>> [thredds] Java to Python tools
>>
>>
>> Hi John-
>>
>> If you use Jython, it looks to be pretty seamless.  I am just
>> starting to develop in Jython, so I can't claim experience in this
>> department yet.  The first section of this page details Java within
>> Jython.
>>
>> http://www.jython.org/**jythonbook/en/1.0/**JythonAndJavaIntegration.html<http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html>
>>
>>  -Rob
>>
>>
>> On Apr 4, 2012, at 1:02 AM,<stephen.pascoe@xxxxxxxxxx>  wrote:
>>
>>  Hi John,
>>>
>>> Direct experience beyond playing, no; but I've come across several
>>> options:
>>>
>>> * Jpype  : 
>>> http://sourceforge.net/**project/jpype<http://sourceforge.net/project/jpype>--
>>>  embeds a JVM in
>>> Python * Jepp   : http://jepp.soureforge.net -- embeds Python
>>> interpreter in Java * Jython : http://www.jython.org -- A Python
>>> implementation in the JVM.
>>>
>>> I expect you want Jpype as in your case Python is doing the
>>> wrapping.  I tested it out once and it worked for me.  The project
>>> seems isn't exactly active but it still appears to be in use.
>>>
>>> Cheers, Stephen.
>>>
>>> --- Stephen Pascoe  +44 (0)1235 445980 Centre of Environmental Data
>>> Archival STFC Rutherford Appleton Laboratory, Harwell Oxford,
>>> Didcot OX11 0QX, UK
>>>
>>>
>>> -----Original Message----- From: 
>>> thredds-bounces@xxxxxxxxxxxx.**edu<thredds-bounces@xxxxxxxxxxxxxxxx>
>>> [mailto:thredds-bounces@**unidata.ucar.edu<thredds-bounces@xxxxxxxxxxxxxxxx>]
>>>  On Behalf Of John Caron
>>> Sent: 04 April 2012 00:20 To: Java NetCDF; THREDDS community
>>> Subject: [thredds] Java to Python tools
>>>
>>>
>>> Hi all:
>>>
>>> Anyone have experience with ways to wrap java in Python? We are
>>> thinking about how to solve this issue again.
>>>
>>> John
>>>
>>> ______________________________**_________________ thredds mailing
>>> list thredds@xxxxxxxxxxxxxxxx For list information or to
>>> unsubscribe,  visit: 
>>> http://www.unidata.ucar.edu/**mailing_lists/<http://www.unidata.ucar.edu/mailing_lists/>--
>>>  Scanned by iCritical.
>>>
>>> ______________________________**_________________ thredds mailing
>>> list thredds@xxxxxxxxxxxxxxxx For list information or to
>>> unsubscribe,  visit: 
>>> http://www.unidata.ucar.edu/**mailing_lists/<http://www.unidata.ucar.edu/mailing_lists/>
>>>
>>
>>
> --
> Don Murray
> NOAA/ESRL/PSD and CIRES
> 303-497-3596
> http://www.esrl.noaa.gov/psd/**people/don.murray/<http://www.esrl.noaa.gov/psd/people/don.murray/>
>
>
> ______________________________**_________________
> netcdf-java mailing list
> netcdf-java@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe, visit:
> http://www.unidata.ucar.edu/**mailing_lists/<http://www.unidata.ucar.edu/mailing_lists/>
>
  • 2012 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: