GithubHelp home page GithubHelp logo

python-bioformats's Introduction

Travis CI Status


Python-bioformats is a Python wrapper for Bio-Formats, a standalone Java library for reading and writing life sciences image file formats. Bio-Formats is capable of parsing both pixels and metadata for a large number of formats, as well as writing to several formats. Python-bioformats uses the python-javabridge to start a Java virtual machine from Python and interact with it. Python-bioformats was developed for and is used by the cell image analysis software CellProfiler (cellprofiler.org). While we are gratified that others outside the CellProfiler team find it useful, we maintain python-bioformats essentially for the CellProfiler project and cannot guarantee support for other users. Please consider visiting our forum at forum.image.sc for additional support help.

PyPI record: https://pypi.python.org/pypi/python-bioformats

Documentation: http://pythonhosted.org/python-bioformats/

GitHub repository: https://github.com/CellProfiler/python-bioformats

Report bugs here: https://github.com/CellProfiler/python-bioformats/issues

python-bioformats is licensed under the GNU General Public License (GPL). Many files are licensed under the more permissive BSD license. See the accompanying files COPYING and LICENSE for details.

Copyright (c) 2009-2021 Broad Institute. All rights reserved.

python-bioformats's People

Contributors

0x00b1 avatar aetherunbound avatar alejoe91 avatar alimuldal avatar bethac07 avatar caspervdw avatar ehrenfeu avatar emilroz avatar genevievebuckley avatar hackermd avatar jakirkham avatar jnj16180340 avatar joshmoore avatar jrbotros avatar ljosa avatar mcquin avatar pskeshu avatar thomasmfish avatar xericzephyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-bioformats's Issues

Setting AcquiredTime only works for first image

Setting the "AquiredDate" attribute for Image elements works only for the first image

import bioformats

metadata = bioformats.OMEXML()
metadata.image_count = 10
for i in xrange(metadata.image_count):
    metadata.image(i).AcquiredDate = bioformats.omexml.xsd_now()
metadata.image(0).AcquiredDate
type(metadata.image(0).AcquiredDate)
'2015-10-11T23:01:17.237239'
str

For all other images the value is None.

metadata.image(1).AcquiredDate
type(metadata.image(1).AcquiredDate)
NoneType

Trying to save image results in JavaException

I tried to do the following, but ran into the exception below. I think this line ( https://github.com/CellProfiler/python-bioformats/blob/master/bioformats/formatwriter.py#L94 ) may be suspect. However, I could be wrong.

>>> import javabridge
>>> javabridge.start_vm()
>>> import numpy as np
>>> import bioformats
>>> b = (np.random.random((110,120)) * ( np.iinfo(np.int16).max - np.iinfo(np.int16).min ) + np.iinfo(np.int16).min).astype(np.int16)
>>> bioformats.formatwriter.write_image("test.tiff", b, bioformats.omexml.PT_INT16)
Exception in thread "Thread-1" org.mozilla.javascript.EvaluatorException: Function importClass must be called with a class; had "[JavaPackage loci.formats.services.OMEXMLService]" instead. (<java-python-bridge>#1)
    at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
    at org.mozilla.javascript.Context.reportRuntimeError(Context.java:913)
    at org.mozilla.javascript.Context.reportRuntimeError(Context.java:969)
    at org.mozilla.javascript.Context.reportRuntimeError1(Context.java:932)
    at org.mozilla.javascript.ImporterTopLevel.js_importClass(ImporterTopLevel.java:162)
    at org.mozilla.javascript.ImporterTopLevel.execIdCall(ImporterTopLevel.java:237)
    at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:97)
    at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
    at org.mozilla.javascript.gen._java_python_bridge__1._c_script_0(<java-python-bridge>:1)
    at org.mozilla.javascript.gen._java_python_bridge__1.call(<java-python-bridge>)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
    at org.mozilla.javascript.gen._java_python_bridge__1.call(<java-python-bridge>)
    at org.mozilla.javascript.gen._java_python_bridge__1.exec(<java-python-bridge>)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1079)
---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
<ipython-input-10-a1c0e18e7b26> in <module>()
----> 1 bioformats.formatwriter.write_image("test.tiff", b, bioformats.omexml.PT_INT16)

/zopt/conda/envs/nanshenv/lib/python2.7/site-packages/bioformats/formatwriter.pyc in write_image(pathname, pixels, pixel_type, c, z, t, size_c, size_z, size_t, channel_names)
    108                           xml=xml,
    109                           index=index,
--> 110                           buffer=pixel_buffer))
    111 
    112 def convert_pixels_to_buffer(pixels, pixel_type):

/zopt/conda/envs/nanshenv/lib/python2.7/site-packages/javabridge-1.0.11-py2.7-macosx-10.5-x86_64.egg/javabridge/jutil.pyc in run_script(script, bindings_in, bindings_out, class_loader)
    352              "Ljava/lang/Object;)"
    353              "Ljava/lang/Object;",
--> 354              scope, script, "<java-python-bridge>", 0, None)
    355         result = unwrap_javascript(result)
    356         for k in list(bindings_out):

/zopt/conda/envs/nanshenv/lib/python2.7/site-packages/javabridge-1.0.11-py2.7-macosx-10.5-x86_64.egg/javabridge/jutil.pyc in call(o, method_name, sig, *args)
    853     ret_sig = sig[sig.find(')')+1:]
    854     nice_args = get_nice_args(args, args_sig)
--> 855     result = fn(*nice_args)
    856     x = env.exception_occurred()
    857     if x is not None:

/zopt/conda/envs/nanshenv/lib/python2.7/site-packages/javabridge-1.0.11-py2.7-macosx-10.5-x86_64.egg/javabridge/jutil.pyc in fn(*args)
    820             x = env.exception_occurred()
    821             if x is not None:
--> 822                 raise JavaException(x)
    823             return result
    824     else:

JavaException: Function importClass must be called with a class; had "[JavaPackage loci.formats.services.OMEXMLService]" instead. (<java-python-bridge>#1)

Unable to install using pip

Hello,
When I try to install python-bioformats using pip, it fails with the follow error:


pip install python_bioformats
Collecting python-bioformats
  Using cached python-bioformats-1.0.8.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jn/pt_9j7j52wz9jq8bzlg7bf1h0000gn/T/pip-build-6pz2zxe9/python-bioformats/setup.py", line 47, in <module>
        version=get_version().decode("utf-8"),
    AttributeError: 'str' object has no attribute 'decode'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jn/pt_9j7j52wz9jq8bzlg7bf1h0000gn/T/pip-build-6pz2zxe9/python-bioformats/

Any suggestions?

Thanks,
Rob

Updating loci_tools.jar

Hi all,

For my nikon nd2 files, I need a newer loci_tools.jar. The version distributed with python-bioformats gives me a division by zero (java) exception, while the newest version 5.0.6 works fine. I guess more users will have this problem, especially when setting up python-bioformats.

I wonder if there is a reason against updating the JAR file on a regular basis? And if there is any way to do this dynamically?

I get my loci_tools.jar from here:
http://downloads.openmicroscopy.org/bio-formats/5.0.6/#components

python 3.5.1 and python-bioformats

Hi,

I recently installed python-bioformats, but I got the following error using Python 3.5.1 :: Anaconda 2.5.0 (64-bit) on import bioformats

python : Traceback (most recent call last):
At line:1 char:1

  • python temp.py 2> output.txt

    • CategoryInfo : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    • FullyQualifiedErrorId : NativeCommandError

    File "temp.py", line 3, in
    import bioformats
    File "C:\Users\kraftlj\Anaconda3\lib\site-packages\python_bioformats-0.0.0-py3.5.egg\bioformats__init__.py", line
    20, in
    from . import formatreader as _formatreader
    File "C:\Users\kraftlj\Anaconda3\lib\site-packages\python_bioformats-0.0.0-py3.5.egg\bioformats\formatreader.py",
    line 450
    __omero_server, __omero_port, __omero_username, __omero_password]):
    ^
    SyntaxError: invalid syntax

Method getImageID is missing

Hi guys, I just encountered the following problem:

jmd.getImageID()
Traceback (most recent call last):
File "C:\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2869, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
jmd.getImageID()
File "C:\Anaconda2\lib\site-packages\javabridge\wrappers.py", line 62, in
fn = lambda naame=name: lambda *args: self.__call(naame, *args)
File "C:\Anaconda2\lib\site-packages\javabridge\wrappers.py", line 152, in __call
raise TypeError("No matching method found for %s" % method_name)
TypeError: No matching method found for getImageID

I tried to find it but noticed that this method is missing. Nevertheless the AutoiCompletion in python offers the method ...

Is this right? And will this be added to the interface?

Sebi

Error importing bioformats

I installed python-bioformats using:
$ pip install python-bioformats

Then I tried:

>>> import javabridge
>>> import bioformats

This gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/bioformats/__init__.py", line 20, in <module>
    from . import formatreader as _formatreader
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/bioformats/formatreader.py", line 450
    __omero_server, __omero_port, __omero_username, __omero_password]):
                  ^
SyntaxError: invalid syntax

$ nosetests biofromats gives similar but more verbose error:

E
======================================================================
ERROR: Failure: SyntaxError (invalid syntax (formatreader.py, line 450))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/nose/loader.py", line 407, in loadTestsFromName
    module = resolve_name(add.module)

  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/nose/util.py", line 312, in resolve_name
    module = __import__('.'.join(parts_copy))
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/bioformats/__init__.py", line 20, in <module>
    from . import formatreader as _formatreader
  File "/Users/Sasank/anaconda/lib/python3.4/site-packages/bioformats/formatreader.py", line 450
    __omero_server, __omero_port, __omero_username, __omero_password]):
                  ^
SyntaxError: invalid syntax

----------------------------------------------------------------------
Ran 1 test in 0.004s

FAILED (errors=1)

I'm using Anaconda python 3.4 in Mac OS X 10.11.3.

Please resolve this.

Sasank.

Unclear problem with bioformats.get_omexml_metadata

Hi guys,

I just cannot figure out what causes the problem shiwn below. Any ideas?

Sebi

Python 2.7.11 |Anaconda 2.4.1 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)] on win32
In[2]: import bioformats
In[3]: filename = r'c:\Users\M1SRH\Documents\Spyder_Projects_Testdata\CZI_Read\2x2_SNAP_CH=2_Z=5.czi'
In[4]: omexml = bioformats.get_omexml_metadata(filename)
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3066, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
omexml = bioformats.get_omexml_metadata(filename)
File "C:\Anaconda\lib\site-packages\bioformats\formatreader.py", line 963, in get_omexml_metadata
with ImageReader(path=path, url=url, perform_init=False) as rdr:
File "C:\Anaconda\lib\site-packages\bioformats\formatreader.py", line 622, in init
self.path)
File "C:\Anaconda\lib\site-packages\javabridge\jutil.py", line 1680, in make_instance
klass = get_env().find_class(class_name)
AttributeError: 'NoneType' object has no attribute 'find_class'

Error reading CIF

import bioformats
import javabridge

filename = "example.cif"

reader = bioformats.formatreader.get_image_reader("example", path=filename)

reader.read(c=0, series=0)
reader.read(c=0, series=2)

raises

/Users/mcquin/code/CellProfiler/python-bioformats/bioformats/formatreader.pyc in read(self, c, z, t, series, index, rescale, wants_max_intensity, channel_names, XYWH)
    815             index = self.rdr.getIndex(z,c,t)
    816             image = np.frombuffer(openBytes_func(index), dtype)
--> 817             image.shape = (height, width)
    818         elif self.rdr.getRGBChannelCount() > 1:
    819             n_planes = self.rdr.getRGBChannelCount()

ValueError: total size of new array must be unchanged

However, on second access

reader.read(c=0, series=2)

works as expected.

Possible strategies to include new features of BioFormats 5.3.1

Hi,

you probably know that the new BioFormats 5.3.1 has some features that allow switching on/off reading tile images as a whole or as single series (like it was in the past). Additionally it can read pyramid levels from tile images. Both things are very useful features, but so far the cannot be used from the wonderful python-bioformats library, right?

There are already some suggestions on how this might work out but this still needs to be dicussed in detail. See also: ome/bioformats#2697

I would be very interested in your thoughts about this and on your possible roadmap to integrate this new things.

Sebi

Unicode errors parsing metadata with Python 2.7

Hello! I think that something went wrong in 2eae542 (the python 3 string handling commit); we were hitting encoding errors reading metadata like m = get_omexml_metadata("my_file.oif"); o = OMEXML(m).

The exception was being thrown from here: https://github.com/CellProfiler/python-bioformats/blame/master/bioformats/omexml.py#L318-L320

For the m we were getting back, type(m) was unicode and ElementTree was choking on it. If we passed m.encode('utf-8') into OMEXML(), our XML was getting encoded a second time, and the second encode choked.

The prior version of the conditional was if isinstance(xml, unicode); after making that change locally, our images processed fine. I'm not sure how you'd prefer to finesse that to make it py3k-friendly. :)

/cc @alimuldal @hsiehj6

AttributeError: 'ImageReader' object has no attribute 'rdr'

Dear Mr. Kamentsky,
I encountered an error when running my python with bioformats:

jmd = jv.JWrapper(rdr.rdr.getMetadataStore())
AttributeError: 'ImageReader' object has no attribute 'rdr'

I could find ImageReader class in formatreader.py under the folder \site-packages\bioformats, but no attribute 'rdr' there.
If I ran it in command line, I got error as follows:

File "C:\Program Files\Anaconda\Lib\site-packages\javabridge\wrappers.py", line 81, in getattr
raise AttributeError()

If I run test macro as follows:

import os
import javabridge as jv
paths = jv.JClassWrapper('java.lang.System').getProperty('java.class.path').split(";")
for path in paths:
print "%s: %s" %("exists" if os.path.isfile(path) else "missing", path)

I can get:

exists: C:\Program Files\Anaconda\lib\site-packages\javabridge\jars\rhino-1.7R4.jar
exists: C:\Program Files\Anaconda\lib\site-packages\javabridge\jars\runnablequeue.jar
exists: C:\Program Files\Anaconda\lib\site-packages\javabridge\jars\cpython.jar
exists: C:\Users\zcjitang\Documents\Software\Bioformats\bioformats_package_5.1.1.jar

Then I do not know what's wrong with it. Could you help? Thank you very much.
I had installed the latest PyWin32, Bioformats, Javabridge, vLFD, Numpy and matplotlib based on my requirements from http://www.lfd.uci.edu/~gohlke/pythonlibs/.

Error reading file metadata

Hello, I am trying to convert an nd2 file containing several field of views with 6 channels each and a variable amount of slides (it is quite big, around 18 GB).

When I read the metadata and get the image count with...

o = bioformats.OMEXML(bioformats.get_omexml_metadata( path='pathToTheFile.nd2'))
print(o.image_count)

...it says that only 1 image is present. Also it detects only one slide per channel.
But if I open the file with ImageJ or FIJI, then I see all the images and channels...

Any idea on what might be causing this?
Am I missing anything?

Many thanks in advance :)

add physical pixel size

Hi all,
first of all, thanks a lot for bioformats. I'm using it for analyzing confocal laser microscopy data and needed the actual physical pixel size to avoid scale invariance. I added some lines after all the other getter and setter in omexml.py to get these information. These lines are attached.

bioformats_patch.py.tar.gz

Should this merged into the master branch!? Is this possible or not needed?

Cheers,
helme

Inefficient retrieval of WellSample attribute values

Getting attribute values of a WellSample object is very inefficient. This becomes a major bottleneck when working with a large number of images, for example in case of a 384 well plate.

Here is small test program that demonstrates the problems and a potential solution:

#!/usr/bin/env python
import bioformats
import itertools
import logging
import argparse
import time

FORMAT = '%(asctime)-15s | %(message)s'
logging.basicConfig(format=FORMAT)

logger = logging.getLogger('test')

logging_level_verbosity = {
    0: logging.CRITICAL,
    1: logging.INFO,
    2: logging.DEBUG,
}


if __name__ == '__main__':

    parser = argparse.ArgumentParser('bioformats test program')
    parser.add_argument('-v', dest='verbosity', action='count', default=0,
                        help='increase logging verbosity')
    parser.add_argument('--hashing', action='store_true',
                        help='store reference image IDs in dictionary')

    args = parser.parse_args()
    logger.setLevel(logging_level_verbosity[args.verbosity])

    start_time_1 = time.time()

    metadata = bioformats.OMEXML()

    logger.info('prepare first plate')

    plate = metadata.PlatesDucktype(metadata.root_node).newPlate(name='default')
    plate.RowNamingConvention = 'letter'
    plate.ColumnNamingConvention = 'number'
    plate.Rows = 16
    plate.Columns = 24
    n_samples = 48

    logger.info('process first plate')
    well_count = 0
    sample_count = 0
    lookup = dict()
    for r, c in itertools.product(range(plate.Rows), range(plate.Columns)):
        logger.info('process well # %d: %s%.2d', well_count+1, chr(r+1+64), c+1)
        well = metadata.WellsDucktype(plate).new(row=r, column=c)
        samples = metadata.WellSampleDucktype(well.node)
        for s in xrange(n_samples):
            logger.debug('process sample # %d', s)
            samples.new(index=s)
            samples[s].ImageRef = 'Image:%d' % sample_count
            # Store the attribute value in a dictionary for subsequent hashing
            lookup[(r, c, s)] = samples[s].ImageRef
            sample_count += 1
        well_count += 1

    end_time_1 = time.time() - start_time_1
    logger.info('processing first plate took %s seconds', end_time_1)

    start_time_2 = time.time()

    logger.info('prepare second plate')

    new_metadata = bioformats.OMEXML()

    new_plate = new_metadata.PlatesDucktype(
                        new_metadata.root_node).newPlate(name='default')
    new_plate.RowNamingConvention = 'letter'
    new_plate.ColumnNamingConvention = 'number'
    new_plate.Rows = plate.Rows
    new_plate.Columns = plate.Columns
    n_samples = len(plate.Well[0].Sample)

    logger.info('process second plate')
    for w, well_id in enumerate(plate.Well):
        logger.info('process well # %d: %s', w+1, well_id)
        well = new_metadata.WellsDucktype(plate).new(
                        row=plate.Well[w].Row, column=plate.Well[w].Column)
        samples = new_metadata.WellSampleDucktype(well.node)
        for s in xrange(n_samples):
            logger.debug('process well sample # %d', s)
            samples.new(index=s)
            if args.hashing:
                samples[s].ImageRef = lookup[(well.Row, well.Column, s)]
            else:
                samples[s].ImageRef = plate.Well[w].Sample[s].ImageRef

    end_time_2 = time.time() - start_time_2
    logger.info('processing second plate took %s seconds', end_time_2)

Running the program with --hashing argument

test_bioformats.py -v --hashing

takes less than 5 minutes

2015-12-02 11:04:13,044 | processing second plate took 206.617892981 seconds

while running it in default mode

test_bioformats.py -v

takes almost 1 hour

2015-12-02 12:17:57,098 | processing second plate took 3459.09807611 seconds

I assume the problem lies in the implementation of the __getitem__ method of the WellDucttype and WellSampleDucktype classes.

Question: Error messages when trying to read and image

Hi guys,

I just tried to test the python-bioformats library and got stuck with I problem. I am not a programmer, so my question might be silly ...
When I open the file inside Fiji using the BioFormats Importer it works fine, so the file itself is ok. And I also managed to read it using: http://www.lfd.uci.edu/~gohlke/pythonlibs/#bioformats

But when I use python-bioformats I get those error messages:

java.lang.IllegalArgumentException: 0.0 must not be null and positive.
at ome.xml.model.primitives.PositiveFloat.(PositiveFloat.java:41)
at loci.formats.in.MRCReader.initFile(MRCReader.java:286)
at loci.formats.FormatReader.setId(FormatReader.java:1072)
java.lang.NoClassDefFoundError: Glacier2/PermissionDeniedException
Caused by: java.lang.ClassNotFoundException: Glacier2.PermissionDeniedException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\python_bioformats-0.0.0-py2.7.egg\bioformats\formatreader.py", line 908, in load_using_bioformats
with ImageReader(path=path) as rdr:
File "C:\Python27\lib\site-packages\python_bioformats-0.0.0-py2.7.egg\bioformats\formatreader.py", line 634, in init
self.init_reader()
File "C:\Python27\lib\site-packages\python_bioformats-0.0.0-py2.7.egg\bioformats\formatreader.py", line 675, in init_reader
je, "Glacier2/PermissionDeniedException"):
File "C:\Python27\lib\site-packages\javabridge\jutil.py", line 811, in is_instance_of
raise JavaException(jexception)
javabridge.jutil.JavaException: Glacier2/PermissionDeniedException

Thanks for the help,

Sebastian

Reading metadata

First I should commend the creation of this package. I had just about given up (at least temporarily) on using bioformats due to the lack of python support, when I realised this package had been released. Thanks for that!

I do, however, have some issues with actually using the package. I have tried files from two instruments, and in all cases I am unable to read metadata from individual planes. Note that this metadata is readable by the BioFormats library itself, because I can see it using the BioFormats Import plugin in ImageJ.

To take an easy example, consider one of the bioformats sample files, say:

http://www.openmicroscopy.org/Schemas/Samples/2015-01/bioformats-artificial/multi-channel-time-series.ome.tif.zip

This file contains the following metadata

<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2013-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2013-06 http://www.openmicroscopy.org/Schemas/OME/2013-06/ome.xsd">
<Image ID="Image:0" Name="multi-channel-time-series">
<AcquisitionDate>2015-02-11T12:01:03</AcquisitionDate>
<Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="3" SizeT="7" SizeX="439" SizeY="167" SizeZ="1" Type="int8">
<Channel ID="Channel:0:0" SamplesPerPixel="1">
<LightPath/>
<Channel ID="Channel:0:1" SamplesPerPixel="1">
<LightPath/>
<Channel ID="Channel:0:2" SamplesPerPixel="1">
<LightPath/>
<TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1">
<UUID FileName="multi-channel-time-series.ome.tif">urn:uuid:df28ea90-2117-416d-b839-5a02a648bf1f</UUID>
<TiffData FirstC="1" FirstT="0" FirstZ="0" IFD="1" PlaneCount="1">
<UUID FileName="multi-channel-time-series.ome.tif">urn:uuid:df28ea90-2117-416d-b839-5a02a648bf1f</UUID>
[snip]

Based on the documentation, I expected that using the code below, I would be able to traverse this tree of information:

import javabridge
import bioformats
javabridge.start_vm(class_path=bioformats.JARS)
omexmlstr=bioformats.get_omexml_metadata('multi-channel-time-series.ome.tif')
o=bioformats.OMEXML(omexmlstr)
pixels=o.image().Pixels
pixels.get_channel_count()
>>> 1
pixels.get_plane_count()
>>> 0
pixels.SizeT
>>> 21

As you can see, the code does not give the correct number of channels, nor the correct number of planes or SizeT.

Now, this example is perhaps somewhat artificial (the XML string that is extracted is correct, so I could in principle traverse its tree manually). However, for all other cases I have tried, I have been unable to read any of the information of the individual planes, and get_plane_count() always returns 0. Am I, somehow, using the package incorrectly?

Accessing Metadata and chnage in API

Hi,

I am using the BioFormats package 5.1.1 from python (via python-bioformats) and noticed, that my old code does not work any more.

To get the scaling I used before (throws an error):

getPixelsPhysicalSizeX(0).getValue().floatValue()

but this seems to be now:

getPixelsPhysicalSizeX(0).value().floatValue()

Is this correct and why was it changed? Or is this only related to the BioFormats package itself?

Cheers,

Sebastian

Question regarding the OME-TIFF writer

Hi guys,

Melissa Linkert pointed me towards you since she thinke this issue might be relateted to:

ttps://github.com//issues/23

Is this the case?

Sebi

Here is my original mail for the OME people:

Hi guys,

i encounter a strange behavior and I am not sure, if this is a bug or I do something wrong.

This is the z-Stack: https://dl.dropboxusercontent.com/u/623476/Beads_63X_NA1.35_xy%3D0.042_z%3D0.1.czi

When I open this via Fiji (up-to-date 20150508) I get a z-Stack with 100 focal planes - OK --> see screenshot

screenshot1

When I load this CZI vai Python Bioformats (bioformats_package 5.1.1 + python_bioformats 1.0.4) , it also works fine --> see screenshot

screenshot2

Now I go back to Fiji and use the BioFormats exporter to write an OME-TIFF from the open CZI and save it to disk.

File can be found here: https://dl.dropboxusercontent.com/u/623476/63X_NA1.35_xy%3D0.042_z%3D0.1.ome.tiff

When I open the OME-TIFF in Fiji I get a z-stack with 100 planes and the correct z.spacing (as expected). But when I open the OME-TIFF via python-bioformats The dimensions get mixed up --> see screenshot below.

So I am wondering why the python stuff seems to work for the CZI, but not for the exported OME-TIFF while it always seems to be OK for Fiji itself no matter if I open the CZI or the exported OME-TIFF.

And why is the z-spacing wrong? I think because the python assumes it is a NOT a z-stack.

Sebi

screenshot3

Update to BioFormats 5.1.4

Hi guys,

when will you update the BioFormats 5.1.4? Or is it still recommended to add the newer libraries manually?

Sebi

log4j output

Hi,

Thank you very much for a very handy wrapper.

I've been seeing the following output every time I run a Python script that uses python-bioformats:

log4j:WARN No appenders could be found for logger (loci.common.NIOByteBufferProvider).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

To the best of my ability, I've not been able to find out from the documentation how to handle this. The only way I could silence it was by poking around the code where I found the function init_logger() in the __init__.py file. Placing this after the javabridge.start_vm(...) call silenced this though I don't know where the log files (if any) vanish to.

Please document this so that it can be better handled.

Thanks.

@polarise

Python BioFormats does not work any more

Hi guys,

since today I have a seroius problem on my Windows7 64bit machine. I use javabrige 1.0.9, bioformats 1.0.4 and bioformats_package 5.0.8. Until Friday this worked fine but since today I get:

Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import javabridge as jv
import bioformats
path = r'C:\Users\M1SRH\Documents\Software\Bio-Formats_Package\5.0.8\bioformats_package.jar'
jars = jv.JARS + [path]
jv.start_vm(class_path=jars, max_heap_size='2G')
imagefile = r'C:\Users\M1SRH\Documents\Spyder_Projects_Testdata\CZI_Read\XYZCT_Z=15_C=2_T=20.czi'
rdr = bioformats.get_image_reader(None, path=imagefile)
Failed to get class loci/common/RandomAccessInputStream
java.lang.NoClassDefFoundError: loci/common/RandomAccessInputStream
Caused by: java.lang.ClassNotFoundException: loci.common.RandomAccessInputStream
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\bioformats\formatreader.py", line 900, in get_image_reader
rdr = ImageReader(path=path, url=url)
File "C:\Python27\lib\site-packages\bioformats\formatreader.py", line 621, in init
self.path)
File "C:\Python27\lib\site-packages\javabridge\jutil.py", line 1655, in make_instance
raise JavaException(jexception)
javabridge.jutil.JavaException: loci/common/RandomAccessInputStream

The sample dataset used can be downloaded here:

https://www.dropbox.com/s/fu4ijim5a4n8tka/XYZCT_Z%3D15_C%3D2_T%3D20.czi?dl=0

I hope you can find the problem soon ... Let me know, if you need more infor or help.

Sebi

ImportError javabridge although Cellprofiler installed fine

Hi,

I'm using Ubuntu 16.04 and installed the requirements listed on [https://github.com/CellProfiler/CellProfiler/wiki/Source-installation-(Ubuntu-16.04-LTS)]
Everything installed fine, but when I'm trying to execute Cellprofiler with

$ cellprofiler I get this error:

Traceback (most recent call last):
File "/home/anja/.local/bin/cellprofiler", line 5, in
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2927, in
@_call_aside
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2913, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2940, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 635, in _build_master
ws.require(requires)
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 943, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 829, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'CellProfiler' distribution was not found and is required by the application

and with $ python Cellprofiler.py this error:

Traceback (most recent call last):
File "CellProfiler.py", line 4, in
cellprofiler.main.main()
File "/home/anja/CellProfiler/cellprofiler/main.py", line 175, in main
from cellprofiler.utilities.cpjvm import cp_start_vm
File "/home/anja/CellProfiler/cellprofiler/utilities/cpjvm.py", line 3, in
import javabridge
ImportError: No module named javabridge

re-checking python-bioformats gave:

Requirement already satisfied: python-bioformats in /home/anja/.local/lib/python2.7/site-packages
Requirement already satisfied: javabridge>=1.0 in /home/anja/.local/lib/python2.7/site-packages (from python-bioformats)
Requirement already satisfied: numpy in /usr/lib/python2.7/dist-packages (from javabridge>=1.0->python-bioformats)

Is it anything obvious I'm missing?

Thanks for your help

Make BSD-licensed .jar to replace loci_tools.jar

As discussed in #3, loci_tools.jar is licensed under the GNU GPL, and this is the only thing that forces python-bioformats as a whole to be GPL instead of BSD. At some point, we would like to create a BSD-licensed replacement for loci_tools.jar.

Savvy users that want additional functionality can substitute the real loci_tools.jar.

OMEXML strings generated by python-bioformats cannot be parsed

Generating an OMLXML string

metadata = bioformats.OMEXML()
metadata.to_xml()

produces the following output

'<ome:OME xmlns:ns2="%(NS_BINARY_FILE)s" xmlns:ome="http://www.openmicroscopy.org/Schemas/ome/2013-06s" xmlns:sa="http://www.openmicroscopy.org/Schemas/sa/2013-06s" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2013-06 http://www.openmicroscopy.org/Schemas/OME/2012-03/ome.xsd">\n  <ome:Image ID="Image:0" Name="default.png">\n    <ome:AcquiredDate>%(DEFAULT_NOW)s</ome:AcquiredDate>\n    <ome:Pixels DimensionOrder="XYCTZ" ID="Pixels:0" SizeC="1" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8">\n<ome:Channel ID="Channel:0:0" SamplesPerPixel="1">\n        <ome:LightPath />\n      </ome:Channel>\n      <ns2:BinData BigEndian="false" Length="0" />\n    </ome:Pixels>\n  </ome:Image>\n  <sa:StructuredAnnotations />\n</ome:OME>'

This string cannot be parsed

from lxml import etree

root = etree.fromstring(metadata)

gives

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-e1da52d13adb> in <module>()
----> 1 root = etree.fromstring(metadata)

lxml.etree.pyx in lxml.etree.fromstring (src/lxml/lxml.etree.c:70569)()

parser.pxi in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106392)()

ValueError: can only parse strings

I'm using python-bioformats (1.0.5) installed via pip.

Installing bioformats using pip

According to the docs in http://pythonhosted.org//python-bioformats/ I should be able to do

pip install python-bioformats

I tried it using virtualenv and I get the following

(bioformats)cmu-883713:src icaoberg$ pip install python-bioformats
Downloading/unpacking python-bioformats
  Could not find a version that satisfies the requirement python-bioformats (from versions: 1.0.0pr1, 1.0.0pr2, 1.0.0pr3)
Cleaning up...
No distributions matching the version for python-bioformats
Storing debug log for failure in /Users/icaoberg/.pip/pip.log

Error on "from bioformats import log4j"

When starting CPA with bioformats 1.0.7 installed, I get the following error:

Traceback (most recent call last):
  File "C:/Users/brayma2/Desktop/GitHub/CellProfiler-Analyst/CellProfiler-Analyst.py", line 556, in <module>
    app.Start()
  File "C:/Users/brayma2/Desktop/GitHub/CellProfiler-Analyst/CellProfiler-Analyst.py", line 476, in Start
    from bioformats import log4j
ImportError: cannot import name log4j

I'm assuming this is a bioformats issue?

Question regarding image orientation

Hi guys,

I have some trouble understanding the image orientation of the output array. The test image can be found here: https://dl.dropboxusercontent.com/u/623476/Test_CH%3D6_Z%3D1.czi

The image has 2752 (X) and 2208 pixel (Y). I use python-bioformats 1.0.1 and BioFormats 5.0.4 on a 64bit Windows7 machine.

Here is what I do:

def GetDimOnly(imagefile):

omexml = bioformats.get_omexml_metadata(imagefile)
new_omexml = omexml.encode('utf-8')
md = bioformats.OMEXML(new_omexml)
pixels = md.image(0).Pixels
rdr = bioformats.get_image_reader(None, path=imagefile)
total_series = rdr.rdr.getSeriesCount()
SizeC = pixels.SizeC
SizeT = pixels.SizeT
SizeZ = pixels.SizeZ
SizeX = pixels.SizeX
SizeY = pixels.SizeY
sizes = [SizeX, SizeY, SizeC, SizeZ, SizeT, total_series]

return sizes

rdr = bf.ImageReader(imagefile, perform_init=True)
sizes = GetDimOnly(imagefile)
img = np.empty(sizes[:-1], dtype=BF2NP_DTYPE[rdr.rdr.getPixelType()])
for channel in range(0, sizes[2]):
for zplane in range(0, sizes[3]):
for timepoint in range(0, sizes[4]):
tmp = rdr.read(series=series, c=channel, z=zplane, t=timepoint, rescale=False)
img[:, :, channel, zplane, timepoint] = tmp

return img
rdr.close()

If you look into the line where I use rdr.read to get the current mage an array is returned that has a shape of [2208, 2752]. But what I got from the sizes was [2752, 2208] instead.

Do you now what I did wrong? or is some axes swapping or similar stuff required?

Cheers, Sebi

Usage Question on retrieveing relevant metadata

Hi,

I am just trying to read the metadata of an CZI file using python-bioformats, but I still struggle a bit. I can read most of the information, but not the one I actually need.

Immersion, LensNA, NominalMagnification, PhysicalSizeX, PhysicalSizeX and PysicalSizeZ

Here is part of the python code:

....
imagefile = r'C:\Users\Sebi\CZI_Read\Z-Stack.czi'
omexml = bioformats.get_omexml_metadata(imagefile)
md = bioformats.OMEXML(omexml)
...

Whatever I tried, I just did not figure out, why I can not find those entries. And when I tried to parse the XML via ElementTree (per hand) I got stuck with invalid tokens ('µm') somewhere.

Can you point me into the right direction?

Cheers, Sebi

Here is the file:

https://dl.dropboxusercontent.com/u/623476/Z-Stack_3slices_dz%3D1.5um.czi


I know that BioFormats itself when used from Fiji gives me:

https://dl.dropboxusercontent.com/u/623476/OMEXML.txt

javabridge problem - loci/common/RandomAccessInputStream

Hi Guys,

When I dowbload python-bioformats via pip and run my usual test script, I always get:

C:\Python27\python.exe C:/Users/M1SRH/Documents/Spyder_Projects/BioFormatsRead/test_get_image6d.py
Failed to get class loci/common/RandomAccessInputStream
java.lang.NoClassDefFoundError: loci/common/RandomAccessInputStream
Caused by: java.lang.ClassNotFoundException: loci.common.RandomAccessInputStream
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Traceback (most recent call last):
File "C:/Users/M1SRH/Documents/Spyder_Projects/BioFormatsRead/test_get_image6d.py", line 16, in
MetaInfo = bf.bftools.get_relevant_metainfo_wrapper(filename)
File "C:\Users\M1SRH\Documents\Spyder_Projects\BioFormatsRead\bfimage\bftools.py", line 474, in get_relevant_metainfo_wrapper
jmd, MetaInfo['TotalSeries'], IMAGEID = get_java_metadata_store(filename)
File "C:\Users\M1SRH\Documents\Spyder_Projects\BioFormatsRead\bfimage\bftools.py", line 105, in get_java_metadata_store
rdr = bioformats.get_image_reader(None, path=imagefile)
File "C:\Python27\lib\site-packages\bioformats\formatreader.py", line 906, in get_image_reader
rdr = ImageReader(path=path, url=url)
File "C:\Python27\lib\site-packages\bioformats\formatreader.py", line 622, in init
self.path)
File "C:\Python27\lib\site-packages\javabridge\jutil.py", line 1683, in make_instance
raise JavaException(jexception)
javabridge.jutil.JavaException: loci/common/RandomAccessInputStream

But when I run the same script but add the newest bioformats_package.jar to the path it works (see below). Any idea what the problem might be here? I am using Win7 64bit and Java 8 Update 60 (Build 1.8.0_60-b27)

....
jars = jv.JARS + [BFPATH]
#jars = jv.JARS
jv.start_vm(class_path=jars, max_heap_size=max_heap_size)
VM_STARTED = True

And the next strange effect occurs when I try to use python-bioformats from inside a little Qt application.

  • start Qt application with newest bioformats_package.jar--> same error as mentioned above
  • start usual test script with bioformats_package.jar --> works OK
  • start Qt application again --> now it works ???

Any idea, why it does not work in the first place?

Sebi

Use Maven to assemble Jars for bioformats

(depends on Maven support - issue 7) python-bioformats is BSD-licensed except for loci_tools.jar which is covered by a GPL license. Also, its inclusion in the GIT repository is a little clunky since it could otherwise be fetched from one of the openmicroscopy Maven repositories. Ideally, whoever installs python-bioformats should be able to pick whether to use the BSD-licensed SCIFIO or the more restricted Bio-Formats and going forward, releases of python-bioformats could target and support multiple versions of Bio-Formats / SCIFIO, possibly configurable with command-line switches during setup.

Setup.py should use Maven to assemble the Bio-Formats jars, using the general mechanism in python-javabridge once that has been put in place.

Documentation on building from source

I'm having the same issue as #56, so I tried installing from source with pip install ., and got the following error message:

    _javabridge.c:244:10: fatal error: 'jni.h' file not found
    #include "jni.h"
             ^
    1 warning and 1 error generated.
    error: command 'gcc' failed with exit status 1

I do have Eclipse JDK but don't know how to point the install to it... Any hints?

Passing unicode URL to load_image_url raises exception

Traceback (most recent call last):
File "C:\Users\leek\cpdev\javabridge\CellProfiler\cellprofiler\gui\cpfigure.py", line 1764, in show_image
image = load_image_url(url)
File "c:\Python27\lib\site-packages\bioformats\formatreader.py", line 523, in load_using_bioformats_url
with ImageReader(url=url) as rdr:
File "c:\Python27\lib\site-packages\bioformats\formatreader.py", line 548, in init
path = unicode(utf8_url, 'utf-8')
TypeError: decoding Unicode is not supported

Memory error when iterating through large ND2 stack

Hi,

I have a 50 GB Nikon nd2 file with 1000 frames of dimensions 101x512x512, and I do my image analysis by iterate over the frames using a code that boils down to:

for t in range(sizeT):
    for z in range(sizeZ):
        index = reader.rdr.getIndex(z, c, t)
        image[z]= reader.read(series=0, index=index, rescale=False)
    # some analysis

I start my VM with 512MB heap space like this:

javabridge.start_vm(class_path=bioformats.JARS, max_heap_size='512m')
javabridge.attach()

About halfway the t-loop, I get JavaException: GC overhead limit exceeded. Are there extra things I could do to free memory?

Python stack:

C:\Anaconda\lib\site-packages\bioformats\formatreader.pyc in read(self, c, z, t, series, index, rescale, wants_max_intensity, channel_names)
    775             dtype = '<f8' if little_endian else '>f8'
    776             scale = 1
--> 777         max_sample_value = self.rdr.getMetadataValue('MaxSampleValue')
    778         if max_sample_value is not None:
    779             try:

C:\Anaconda\lib\site-packages\javabridge\jutil.pyc in method(self, *args)
    897     def method(self, *args):
    898         assert isinstance(self.o, _javabridge.JB_Object)
--> 899         result = call(self.o, name, sig, *args)
    900         if fn_post_process is not None:
    901             result = fn_post_process(result)

C:\Anaconda\lib\site-packages\javabridge\jutil.pyc in call(o, method_name, sig, *args)
    828     ret_sig = sig[sig.find(')')+1:]
    829     nice_args = get_nice_args(args, args_sig)
--> 830     result = fn(*nice_args)
    831     x = env.exception_occurred()
    832     if x is not None:

C:\Anaconda\lib\site-packages\javabridge\jutil.pyc in fn(*args)
    795             x = env.exception_occurred()
    796             if x is not None:
--> 797                 raise JavaException(x)
    798             return result
    799     else:

 JavaException: GC overhead limit exceeded

Java stack:

java.lang.OutOfMemoryError: GC overhead limit exceeded
at loci.formats.FormatReader.updateMetadataLists(FormatReader.java:413)
at loci.formats.FormatReader.flattenHashtables(FormatReader.java:405)
at loci.formats.FormatReader.getMetadataValue(FormatReader.java:1065)

JavaException: Image plane too large.

I'm trying to load a ~200MB big NDPI slide scanner file but this fails with this error message:

img = bioformats.load_image('/mnt/schoellingm/idaf/tmp/12-244-3-HE - 2012-03-12 22.30.10.ndpi', series=0)
JavaException: Image plane too large. Only 2GB of data can be extracted at one time. You can workaround the problem by opening the plane in tiles; for further details, see: http://www.openmicroscopy.org/site/support/bio-formats/about/bug-reporting.html#common-issues-to-check

According to the link you should only load a subsection of the image using openBytes(int, int, int, int, int) but even this, too:

import bioformats.formatreader as F
ImageReader = F.make_image_reader_class()
reader = ImageReader()
reader.setId(path)
(reader.getSizeY(), reader.getSizeX())
# (41216, 34816)
data = reader.openBytes(0,0,0,100,100)
JavaException: Image plane too large. Only 2GB of data can be extracted at one time. You can workaround the problem by opening the plane in tiles; for further details, see: http://www.openmicroscopy.org/site/support/bio-formats/about/bug-reporting.html#common-issues-to-check

Could it be that the proxy to the java classes do not support function overloading for the several variants of openBytes with different number of parameters?

byte[]  openBytes(int no)
Obtains the specified image plane from the current file as a byte array.
byte[]  openBytes(int no, byte[] buf)
Obtains the specified image plane from the current file into a pre-allocated byte array of (sizeX * sizeY * bytesPerPixel * RGB channel count).
byte[]  openBytes(int no, byte[] buf, int x, int y, int w, int h)
Obtains a sub-image of the specified image plane into a pre-allocated byte array.
byte[]  openBytes(int no, int x, int y, int w, int h)
Obtains a sub-image of the specified image plane, whose upper-left corner is given by (x, y).

(copied from here)

Add Python 3 support

I have no idea how hard this is, but I'm in the "Python 3" birds-of-a-feather session at SciPy 2014 and realised this is one of the only libraries I use that is not Python 3 compatible.

(or, at the very least, "pip install python-bioformats" works for me in 2 envs but not 3.)

missing logger prevents use

Just running the demo on an image file I have throws an exception.

>>> import os
>>> import javabridge
>>> import bioformats
>>> from bioformats import log4j
>>> javabridge.start_vm(class_path=bioformats.JARS,
...                     run_headless=True)
>>> try:
...     log4j.basic_config()
...     image_path = "/media/New Volume/FYLM-140717-002-fov12-fc0.tif"
...     image, scale = bioformats.load_image(image_path, rescale=False, wants_max_intensity=True)
...     print image.shape
... finally:
...     javabridge.kill_vm()
... 
Failed to get class 65535
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: 65535
Caused by: java.lang.ClassNotFoundException: 65535
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "bioformats/formatreader.py", line 939, in load_using_bioformats
    channel_names)
  File "bioformats/formatreader.py", line 778, in read
    bioformats.logger.warning("WARNING: failed to get MaxSampleValue for image. Intensities may be improperly scaled.")
AttributeError: 'module' object has no attribute 'logger'

python_bioformats works from inside PyCharm but does note from IPython notebook

Hi guys,

i use python-biofromats to read the metadata from our CZI files. When I try this inside PyCharm it works fine
pycharm_output

When I try this from an IPython notebook and run the exact same lines of code, I get the following errors:

Using bioformats_package : bioformats_package.jar
Failed to get class loci/common/RandomAccessInputStream

JavaException Traceback (most recent call last)
in ()
1 # get image meta-information
----> 2 MetaInfo = bf.bftools.get_relevant_metainfo_wrapper(CZIfilename)

c:\Users\M1SRH\Documents\Spyder_Projects\BioFormatsRead\bfimage\bftools.pyc in get_relevant_metainfo_wrapper(filename)
460
461 # get JavaMetaDataStore and SeriesCount
--> 462 jmd, MetaInfo['TotalSeries'], IMAGEID = get_java_metadata_store(filename)
463
464 # get dimension information and MetaInfo

c:\Users\M1SRH\Documents\Spyder_Projects\BioFormatsRead\bfimage\bftools.pyc in get_java_metadata_store(imagefile)
100 jvm_error()
101
--> 102 rdr = bioformats.get_image_reader(None, path=imagefile)
103
104 # for "whatever" reason the number of total series can only be accessed here ...

C:\Python27\lib\site-packages\bioformats\formatreader.pyc in get_image_reader(key, path, url)
904 old_count, rdr = __image_reader_cache[path, url]
905 else:
--> 906 rdr = ImageReader(path=path, url=url)
907 old_count = 0
908 __image_reader_cache[path, url] = (old_count+1, rdr)

C:\Python27\lib\site-packages\bioformats\formatreader.pyc in init(self, path, url, perform_init)
620 self.stream = jutil.make_instance('loci/common/RandomAccessInputStream',
621 '(Ljava/lang/String;)V',
--> 622 self.path)
623
624 self.rdr = None

C:\Python27\lib\site-packages\javabridge\jutil.pyc in make_instance(class_name, sig, *args)
1681 jexception = get_env().exception_occurred()
1682 if jexception is not None:
-> 1683 raise JavaException(jexception)
1684 method_id = get_env().get_method_id(klass, '', sig)
1685 jexception = get_env().exception_occurred()

JavaException: loci/common/RandomAccessInputStream

This feels strange. Can it be that the iypthon notebook does not know where to look for the bioformats_package? The bioformats_package.jar is in the same folder as the bfimage package. See attachment.

pycharm_bioformats_package_location

Any ideas what the problem might be?

Memory error when trying to get metadata from huge file

Hi,

I have a 383GB Leica .lif file, which obviously I would like to process sequentially. (It contains a large number of 1024 x 1024 x 30 x 3channel images.) I figured I would read the metadata and then use bioformats.load_image with the right parameters to load each image series. (Incidentally, it would be great to allow z=None to load up the entire stack! Happy to submit a PR if that would be welcome and you can point me in the right direction!)

Here's my code snippet:

import javabridge as jv
import bioformats as bf
jv.start_vm(class_path=bf.JARS)
md = bf.get_omexml_metadata('Long time Gfap 260314.lif')

And here's the resulting error:

---------------------------------------------------------------------------
JavaException                             Traceback (most recent call last)
<ipython-input-7-640f92a788d5> in <module>()
----> 1 md = bf.get_omexml_metadata('Long time Gfap 260314.lif')

/Users/nuneziglesiasj/anaconda/lib/python2.7/site-packages/bioformats/formatreader.pyc in get_omexml_metadata(path, url)
    943         xml;
    944         """
--> 945         xml = jutil.run_script(script, dict(path=rdr.path, reader = rdr.rdr))
    946         return xml

/Users/nuneziglesiasj/anaconda/lib/python2.7/site-packages/javabridge/jutil.pyc in run_script(script, bindings_in, bindings_out, class_loader)
    338              "Ljava/lang/Object;)"
    339              "Ljava/lang/Object;",
--> 340              scope, script, "<java-python-bridge>", 0, None)
    341         result = unwrap_javascript(result)
    342         for k in list(bindings_out):

/Users/nuneziglesiasj/anaconda/lib/python2.7/site-packages/javabridge/jutil.pyc in call(o, method_name, sig, *args)
    888     ret_sig = sig[sig.find(')')+1:]
    889     nice_args = get_nice_args(args, args_sig)
--> 890     result = fn(*nice_args)
    891     x = env.exception_occurred()
    892     if x is not None:

/Users/nuneziglesiasj/anaconda/lib/python2.7/site-packages/javabridge/jutil.pyc in fn(*args)
    855             x = env.exception_occurred()
    856             if x is not None:
--> 857                 raise JavaException(x)
    858             return result
    859     else:

JavaException: Java heap space

What's the correct way to use python-bioformats to read in a file one series at a time? Or is such functionality not currently supported?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.