Differences between revisions 7 and 8
Revision 7 as of 2010-12-20 19:23:25
Size: 2484
Editor: SteveLudtke
Comment:
Revision 8 as of 2013-08-27 04:05:34
Size: 2268
Editor: SteveLudtke
Comment:
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
python
>>> from EMAN2 import *
e2.py # this runs ipython (provided with EMAN2 binaries) and does 'from EMAN2 import *'
Line 13: Line 12:
>>> a*=-1
>>> display(a)
>>> a*=-1 # should update the image widget (if you left it open) immediately
Line 17: Line 15:
>>> c=a.copy() # Note, memory management is automatic, this will delete the old c >>> c=a.copy() # Note, memory management is automatic, this will delete the old c when display() is no longer using it
Line 19: Line 17:
>>> display(c) # Note that this blocks ! See below for nonblocking example
>>> print a.cmp("dot",c,{"negative":0,"normalize":1}) # e2help.py cmp [-v] or dump_cmps()
>>> display(c) # Note that this is not the same 'c' as above. The original c still exists, but you've lost access to it
>>> print a.cmp("dot",c,{"negative":0,"normalize":1}) # e2help.py cmp -v 1 or dump_cmps()
Line 26: Line 24:
If you want to do interactive GUI programming, such as writing a program like 'e2boxer.py --gui' for example, you need to use a PyQT4 event loop. The EMAN2 interactive GUI programming environment is based on [[http://ipython.scipy.org/moin/|ipython]]. You must have ipython 0.7.3 or above to use it:
Line 28: Line 25:
{{{
e2.py
>>> a=[test_image(i) for i in range(3)]
>>> display(a)
>>> a[1]*=-1
}}}
Now, how does this second example differ from the first. The difference is that it's running within a GUI event loop. So, when you issue the 'b=EMImage(a)' command, an image display window opens, but you immediately get another python prompt. When you then do a[1]*=-1, the change is immediately displayed.
The session above is for interactive work. If you want to write your own program that uses EMAN2, the EMAN2/examples directory has a lot of good examples. Try 'average.py' to get started. e2fftsynth.py for a more complicated example with GUI elements.

EMAN2 Programming Quickstart

This page contains some example sessions to get you started using EMAN2 from Python. This is not aimed at mainstream users, but is for those wanting to move into programming in EMAN2.

Here is a sample EMAN2 session:

e2.py                       # this runs ipython (provided with EMAN2 binaries) and does 'from EMAN2 import *'
>>> a=test_image()
>>> display(a)              # Use the middle mouse on the image for controls, right mouse to pan
>>> b=[test_image(),test_image(1),test_image(2)]
>>> display(b)              # Again, middle and right mouse
>>> a*=-1                   # should update the image widget (if you left it open) immediately
>>> c=a.process("filter.lowpass.gauss",{"sigma":.125})        # use 'e2help.py processor [-v]' or from python 'dump_processors()'
>>> display(c)
>>> c=a.copy()              # Note, memory management is automatic, this will delete the old c when display() is no longer using it
>>> c.process_inplace("filter.lowpass.gauss",{"sigma":.125})  # equivalent to above
>>> display(c)              # Note that this is not the same 'c' as above. The original c still exists, but you've lost access to it
>>> print a.cmp("dot",c,{"negative":0,"normalize":1})         # e2help.py cmp -v 1 or dump_cmps()
>>> d=c.do_fft()
>>> e=d.calc_radial_dist(64,0.0,1.0,1)                        # radial power spectrum
>>> print e
>>> plot(e)                 # Note that this is a static image, not an interactive plot

The session above is for interactive work. If you want to write your own program that uses EMAN2, the EMAN2/examples directory has a lot of good examples. Try 'average.py' to get started. e2fftsynth.py for a more complicated example with GUI elements.

Here are some good links into the documentation:

Eman2ProgQuickstart (last edited 2022-02-18 00:36:44 by TunayDurmaz)