imcf / imcf-fiji-scripts

:wrench: :memo: :coffee: :microscope: Scripts for Fiji provided by the Imaging Core Facility, Biozentrum, University of Basel
GNU General Public License v3.0
1 stars 2 forks source link

The Misc module is not being imported properly, so the Stitching cannot run #2

Closed ksenk closed 3 years ago

ksenk commented 5 years ago
console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
[ERROR] null
Traceback (most recent call last):
  File "Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py", line 30, in <module>
ImportError: No module named misc

at org.python.core.Py.ImportError(Py.java:334)
at org.python.core.imp.import_logic(imp.java:913)
at org.python.core.imp.import_module_level(imp.java:970)
at org.python.core.imp.importName(imp.java:1057)
at org.python.core.ImportFunction.__call__(__builtin__.java:1280)
at org.python.core.PyObject.__call__(PyObject.java:450)
at org.python.core.__builtin__.__import__(__builtin__.java:1232)
at org.python.core.imp.importFromAs(imp.java:1149)
at org.python.core.imp.importFrom(imp.java:1124)
at org.python.pycode._pyx0.f$0(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py:140)
at org.python.pycode._pyx0.call_function(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.__builtin__.eval(__builtin__.java:497)
at org.python.core.__builtin__.eval(__builtin__.java:501)
at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at org.scijava.script.ScriptModule.run(ScriptModule.java:160)
at org.scijava.module.ModuleRunner.run(ModuleRunner.java:168)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:127)
at org.scijava.module.ModuleRunner.call(ModuleRunner.java:66)
at org.scijava.thread.DefaultThreadService$3.call(DefaultThreadService.java:238)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
ehrenfeu commented 5 years ago

Hi, sorry that I'm only seeing this now - somehow the message slipped my attention :frowning:

The error message suggests you're missing the imcflibs package in Fiji. How did you install the scripts, did you just download the jar file from github?

The recommended way is by enabling the IMCF Uni Basel update site in Fiji, this will make sure you get all the required dependencies in their correct versions.

Cheers, Niko

auesro commented 3 years ago

Hi Niko,

I just came across exactly the same problem. Installed everything through Fiji adding the IMCF Uni Basel site. Indeed, my Fiji installation says I have the jars/python-imcflibs-0.2.0.jar up to date. However:


  File "Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py", line 30, in <module>
ImportError: No module named misc

    at org.python.core.Py.ImportError(Py.java:329)
    at org.python.core.imp.import_logic(imp.java:1290)
    at org.python.core.imp.import_module_level(imp.java:1369)
    at org.python.core.imp.importName(imp.java:1528)
    at org.python.core.ImportFunction.__call__(__builtin__.java:1285)
    at org.python.core.PyObject.__call__(PyObject.java:433)
    at org.python.core.__builtin__.__import__(__builtin__.java:1232)
    at org.python.core.imp.importFromAs(imp.java:1620)
    at org.python.core.imp.importFrom(imp.java:1595)
    at org.python.pycode._pyx0.f$0(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py:140)
    at org.python.pycode._pyx0.call_function(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1687)
    at org.python.core.__builtin__.eval(__builtin__.java:497)
    at org.python.core.__builtin__.eval(__builtin__.java:501)
    at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:255)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
`
ehrenfeu commented 3 years ago

Hi @auesro

sorry to hear about this - I still cannot reproduce it.

Could you try to open the Script Interpreter and run the import command manually there? I.e. switch the language to Python (either using the drop-down menu at the top left, or by running :lang Python in the input box) and then run any of these commands and see what happens:

from imcflibs.imagej.misc import show_status
import imcflibs
auesro commented 3 years ago

Hi @ehrenfeu

Stupid question but...you are referring to Script Interpreter in Fiji? Where do I get that to open?

auesro commented 3 years ago

Ok, found it, but no luck:

image

auesro commented 3 years ago

The value of imcflibs on the left panel looks weird compared to others:

image

ehrenfeu commented 3 years ago

Actually your second command worked, the reply was <null> - meaning success in this case. So you can actually import the imcflibs package.

auesro commented 3 years ago

Ok, import imcflibs.imagej also works. The problem is importing the misc function...

ehrenfeu commented 3 years ago

Could you try these:

from imcflibs.imagej import misc
import imcflibs.imagej.misc
auesro commented 3 years ago
>>> from imcflibs.imagej import misc
ImportError: cannot import name misc in <script> at line number 1
>>> import imcflibs.imagej.misc
ImportError: No module named misc in <script> at line number 1
ehrenfeu commented 3 years ago

What about these:

dir(imcflibs.imagej)

Here I'm getting this:

['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', 'misc']

And what does it say about the __file__ attribute?

imcflibs.imagej.__file__

...should be something like this:

__pyclasspath__/imcflibs/imagej/__init__.py
auesro commented 3 years ago

Ups, misc is missing .....why?

>>> dir(imcflibs.imagej)
['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__']
>>> imcflibs.imagej.__file__
__pyclasspath__/imcflibs/imagej/__init__.py
ehrenfeu commented 3 years ago

This I really don't know. But it explains why it can't be imported...

What OS are you on? Could you look inside the jars/python-imcflibs-0.2.0.jar file? You can open it with any zip tool...

auesro commented 3 years ago

Windows 10 image

Clearly, misc.py is not there... is there an easy way for me to add it?

auesro commented 3 years ago

Actually, misc.py is not the only one missing according to the github repository.

sjlog.py, split.py and stitching.py are all missing

ehrenfeu commented 3 years ago

Sorry for the interrupted communication, been busy with life and I2K.

Indeed, you are right. The update site is shipping an outdated version of the jar.

Until I get around to actually test what went wrong, and what should be on the update site for real, could you try to replace the jar locally with version 0.5.1 from the Maven repo? If you're feeling adventurous, you could also try version 1.0.0, but that's more likely to cause issues than the 0.x series.

ehrenfeu commented 3 years ago

Oh. I just realized that the download links are broken on the Maven repo.

Sorry, will have to look into this in the next days...

auesro commented 3 years ago

Hi Niko,

I felt super adventurous and went ahead modifying the python-imcf jar. Opened with 7zip, added the missing py files from the github repository. That solved the misc error but then there was a missing import for the sjlog.py module, so I solved it editing the FluoView_OIF_OIB_OIR_Stitcher.py:

from imcflibs.imagej import sjlog
log = sjlog.scijava_logger(logservice)

But then another error: apparently when Fiji modified the jython-slim.jar, that fucked up the calls to "log.info". Replacing the slim file by the older jython-shaded-2.7.1.1.jar solved that.

Then another import was missing for fluoview, so again added it to FluoView_OIF_OIB_OIR_Stitcher.py:

from micrometa import fluoview

Finally, the plugin worked, initially at least, but got an error:

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
[WARNING] FluoView_OIF_OIB_OIR_Stitcher.py, version: 5.1.0
[INFO] micrometa version: 15.0.1
[INFO] imcflibs version: 0.2.0
[INFO] Parameter / selection summary:
[INFO] > Regression threshold: 0.300000011921
[INFO] > Max/Avg displacement ratio: 2.5
[INFO] > Max absolute displacement: 3.5
[INFO] > rotation angle: 0
[INFO] Parsing project file: [C:\Users\AugustoER\Desktop\FV10__20201129_165355\MATL_Mosaic.log]
[INFO] Parsed 0 / 1 mosaics
[INFO] Parsing mosaic 1...
[INFO] Mosaic: 12x7x1
[INFO] Parsing OIB file: C:\Users\AugustoER\Desktop\FV10__20201129_165355\Track0001\Image0001_01.oib
[INFO] Parsing OIB description file "OibInfo.txt".
[INFO] OIB Format Version: 2.0.0.0
[INFO] Finished parsing OIB description file.
[INFO] Parsed image dimensions: {'B': 12, 'C': 3, 'T': 0, 'X': 1024, 'Y': 1024, 'Z': 46}
...
 ...
  ...
[INFO] Parsing OIB file: C:\Users\AugustoER\Desktop\FV10__20201129_165355\Track0051\Image0051_01.oib
[INFO] Parsing OIB description file "OibInfo.txt".
[INFO] OIB Format Version: 2.0.0.0
[INFO] Finished parsing OIB description file.
[INFO] Parsed image dimensions: {'B': 12, 'C': 3, 'T': 0, 'X': 1024, 'Y': 1024, 'Z': 46}
[INFO] Progress: 1 / 1 (1.0)
[INFO] Parsed 1 / 1 mosaics
[INFO] Progress: 2 / 1 (2.0)
[INFO] Parsed 1 mosaics.
[ERROR] Couldn't find any (valid) mosaics in the project file!
[ERROR] Traceback (most recent call last):
  File "Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py", line 101, in <module>
  File "Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py", line 45, in error_exit
SystemExit: Couldn't find any (valid) mosaics in the project file!

    at org.python.core.PySystemState.exit(PySystemState.java:1505)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
    at org.python.core.PyObject.__call__(PyObject.java:497)
    at org.python.core.PyObject.__call__(PyObject.java:501)
    at org.python.core.PyMethod.__call__(PyMethod.java:141)
    at org.python.pycode._pyx0.error_exit$1(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py:45)
    at org.python.pycode._pyx0.call_function(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyBaseCode.call(PyBaseCode.java:139)
    at org.python.core.PyFunction.__call__(PyFunction.java:413)
    at org.python.pycode._pyx0.f$0(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py:144)
    at org.python.pycode._pyx0.call_function(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:171)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1614)
    at org.python.core.__builtin__.eval(__builtin__.java:497)
    at org.python.core.__builtin__.eval(__builtin__.java:501)
    at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:259)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

This mosaic has 76 tiles but not squared format, actually it has exactly this shape (by looking at the .log file):

Untitled-1

Can the plugin stitch this kind of non-squared mosaics? The plugin only checks until the 51st tile....why? Also, what is the "OIB description file "OibInfo.txt"."?

ehrenfeu commented 3 years ago

Oh, the swap from jython-shaded.jar to jython-slim.jar has completely slipped my attention!

The plugin certainly deals with non-squared mosaics, this is actually what we've been mostly processing here.

Fiddling manually inside the JARs is not the easiest thing, I will try to find some time this week to provide you with a collection of my JARs from here.

auesro commented 3 years ago

That would be awesome! Fluoview stitching software is quite limiting...

Looking forward!

auesro commented 3 years ago

Hey Niko @ehrenfeu , if you have some time to have a look at this it would be great!! Thanks, A

imagejan commented 3 years ago

@auesro wrote:

apparently when Fiji modified the jython-slim.jar, that fucked up the calls to "log.info".

See this forum topic for a workaround for the log.info issue.

@ehrenfeu wrote:

Oh. I just realized that the download links are broken on the Maven repo.

The released artifacts can be downloaded from maven.scijava.org: https://maven.scijava.org/#nexus-search;gav~ch.unibas.biozentrum.imcf~python-imcflibs~~~

auesro commented 3 years ago

@imagejan wrote:

See this forum topic for a workaround for the log.info issue.

Yea, that was easily solved by replacing the jython-slim file.

@imagejan wrote:

The released artifacts can be downloaded from maven.scijava.org: https://maven.scijava.org/#nexus-search;gav~ch.unibas.biozentrum.imcf~python-imcflibs~~~

Thanks for this! I downloaded the lastest version and it works. However, it requires massive ammounts of RAM memory. Is there any possibility to reduce such requirement even at the expense of time?

ehrenfeu commented 3 years ago

Hi @auesro @ksenk

this issue should now finally be fixed in the latest packages that were released today.

There is NO NEED for jython-shaded any more, all is working fine again with the Jython shipped by Fiji.

Simply run the Fiji Updater to get the latest versions and you should be good to go.

@auesro nevertheless I would like to have a look why the OIR stitching failed for you. Any chance you can provide me with the dataset that was causing the error mentioned above?

auesro commented 3 years ago

Dear @ehrenfeu

Thanks for getting back to me.

Updated Fiji but it doesnt even start:

[ERROR] Traceback (most recent call last):
  File "Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py", line 55, in <module>
AttributeError: 'module' object has no attribute 'sjlog'

    at org.python.core.Py.AttributeError(Py.java:178)
    at org.python.core.PyObject.noAttributeError(PyObject.java:965)
    at org.python.core.PyObject.__getattr__(PyObject.java:959)
    at org.python.pycode._pyx0.f$0(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py:140)
    at org.python.pycode._pyx0.call_function(Plugins/IMCF_Utilities/Stitching_Registration/FluoView_OIF_OIB_OIR_Stitcher.py)
    at org.python.core.PyTableCode.call(PyTableCode.java:173)
    at org.python.core.PyCode.call(PyCode.java:18)
    at org.python.core.Py.runCode(Py.java:1687)
    at org.python.core.__builtin__.eval(__builtin__.java:497)
    at org.python.core.__builtin__.eval(__builtin__.java:501)
    at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:255)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:57)
    at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:31)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at org.scijava.script.ScriptModule.run(ScriptModule.java:157)
    at org.scijava.module.ModuleRunner.run(ModuleRunner.java:165)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:124)
    at org.scijava.module.ModuleRunner.call(ModuleRunner.java:63)
    at org.scijava.thread.DefaultThreadService.lambda$wrap$2(DefaultThreadService.java:225)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

And of course, you can find the dataset here

ehrenfeu commented 3 years ago

Hi @auesro

sorry, that's clearly my bad. I can reproduce it, will try to fix it immediately.

ehrenfeu commented 3 years ago

Hi @auesro

could you please update your Fiji with the latest versions (I just uploaded new releases of the packages fixing some issues a minute ago) and then try again?

Thanks for providing the dataset. I haven't had the time yet to look into it though...

auesro commented 3 years ago

Alright, it works!!! Thanks!

Now, something I noticed...for a 20.6 GB dataset, the RAM required was 40GB, thats quite massive. Is there any way to reduce that? It also took 766.611 seconds to perform the stitching (no registration) and saving of images. If we could run this on the GPU it would be way faster, right?

auesro commented 3 years ago

Ok, now I tried to run the plugin performing registration. It seems to work initially, and it generates a registration file: Writing registered TileConfiguration: C:\Users\AugustoER\Desktop\1173 FV10__20201129_165355\mosaic_0.registered.txt However, after the Optimizing steps FIJI runs out of memory....which is strange given that the dataset I am using is the same...

ehrenfeu commented 3 years ago

Hi @auesro

requiring about double the amount of memory than the size of the input data is considered normal for the stitcher in our experience.

I would expect basically no speedup (actually rather the opposite) when using GPU for this, as the computationally expensive step (the registration) is only a fraction of the time of the overall process. Most of it is I/O, i.e. reading data from disk, fusing it in memory and writing it back. You usually don't gain much by doing this on the GPU, it only generates additional overhead as it is constantly shuffling around data in and out from the main memory (RAM) to the GPU memory and back.

Plus, the stitcher code is rather old and I doubt that the original author will have the time to do any improvements there, especially that he and his group have been working on BigStitcher for several years now, addressing many things (including memory requirements).

Given that RAM is super cheap (at least compared to a microscope and other lab resources) I'd rather recommend to invest a bit into that. If you can't (or don't want to) do that, you could manually start the "Grid/Collection Stitcher" plugin and load the mosaic_0.txt file (the one generated by our code) using Positions from file / Defined by TileConfiguration.txt and then using Save memory (but be slower) for the "Computation parameters". Don't know how much this will save you, in my experience it was never worth it for us.

However, good to hear the code is working for you now. I'll close the issue again and would redirect you to the Image.sc Forum for further questions that are not directly related to our scripts (e.g. how to optimize memory consumption and / or migrating to BigStitcher).

Thanks for the detailed feedback!

auesro commented 3 years ago

Dear Nico,

Thanks a lot for your detailed explanation. I have enough RAM to run such a dataset as the one I sent you but I was wondering about the RAM-based limitation to the datasets that I will be able to stitch. So far I am fine.

However, you did not comment on my second post regarding the increase in RAM use when the "Run registration" box is checked. My intention was simply to compare if the results would improve when running the registration as opposed to simply using microscope stage coordinates.

Cheers, A

ehrenfeu commented 3 years ago

Hi @auesro

the "registration" step is performing a (normalized) cross-correlation calculation with the overlap of the individual tiles followed by an optimization step (of the positioning), so for a dataset of this size it is expected to take (quite) some memory. However, it usually also improves the result quite a bit as the stage coordinates are easily off by several dozens of pixels.

auesro commented 3 years ago

Got it, @ehrenfeu, thanks for the info!