Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Chromagnon without GUI #26

Open
juliomateoslangerak opened this issue Mar 19, 2021 · 1 comment
Open

Running Chromagnon without GUI #26

juliomateoslangerak opened this issue Mar 19, 2021 · 1 comment

Comments

@juliomateoslangerak
Copy link

Hi,
Id like to know if it is possible to run chromagnon from python just as a module without GUI and all the overhead of bioformats.
I love the application and I would like to implement it into my analysis scripts. That is, import it as a module, run it on a number of numpy arrays using another set of reference arrays or even better a configuration file/object.

Is this possible?

@macronucleus
Copy link
Owner

Thank you for using Chromagnon.
Yes, of course, you can run Chromagnon from python, although a numpy array needs to be saved in a file, preferably with appropriate header information.
Assuming you have installed the source code, then you can simply do:

import Chromagnon as ch
ch.aligner.Chromagnon.__init__.__doc__

Alternatively, please take a look at the documentation for class Chromagnon in Chromagnon.aligner.py (line 52 in v0.89).
You will find how to run it interactively.

You can also omit installing JDK, javabridge, and python-bioformats, lxml, then it will not use bioformats.
You will see warning concerning biofomats not installed, but don't worry.
You can disable this warning by changing line 89 (as of v0.89) of Chromagnon.imgio.bioformatsIO.py as follows:

    if 0:#not commonfuncs.main_is_frozen():
        import traceback, warnings
        #traceback.print_exc()
        errs = traceback.format_exc()
        warnings.warn(errs, UserWarning)

To save numpy arrays in files, you can use any other packages or the imgio package of Chromagnon like this:

import numpy as np
from Chromagnon import imgio

outfn = 'test.tif' # the extension should be 'tif' or 'dv'
a = np.empty((2,10,256,256), np.uint16) # assuming the axes of (w,z,y,x)
with imgio.Writer(outfn) as h:
    h.setDim(nx=256, ny=256, nz=10, nt=1, nw=2, dtype=np.uint16, wave=[515,600])
    h.setPixelSize(pz=0.25, py=0.08, px=0.08) # in micron
    for w in range(h.nw):
        h.write3DArr(a[w], t=0, w=w)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants