Difference: CemSparxNotes (1 vs. 9)

Revision 931 Jul 2015 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Setup

  • make sure PYTHONPATH is clear (setenv PYTHONPATH)
  • source EMAN2/eman2.cshrc
  • to run python program that imports sparx or eman2, need to use THEIR version
    • EMAN2/Python/bin/python

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available

making scripts

  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it , get some info, and write new image to file:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    data2 = data * 5 #make new image with 5X intensities of original
    data2.write_image("out.hdf",0)  # write image data to file, hdf5 format
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx/2 # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = Util.compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py

  • get all attribues from an image:
    all_alltrib=data.get_attr_dict()
    
Added:
>
>

Notes stolen from sparx site for convenience

  • REFER TO ORIGINAL WEBSITE FOR UP TO DATE DOCS
  • EMAN2 supports many image formats, including all major EM file formats (SPIDER, IMAGIC, MRC, ...). However, it is recommended to use '''hdf''' file format whenever possible as only this format supports attributes set in file header with sufficient flexibility.

  • We have recently added '''bdb''' file format to our programs. The reading and writing of this file format is much faster than '''hdf''' file format. The '''bdb''' files are stored in a directory called EMAN2DB, there are usually two files for an image stack, one is for the image information, the other is for the header information. However, we don't deal with these two files directly, instead, we use "bdb:filename" outside the EMAN2DB directory to represent the image stack.

    • '''Notice''': It is dangerous to move the EMAN2DB directory, especially between different machines. Hence, if you do need to move the '''bdb''' file, it is recommended that you first convert it to the '''hdf''' file using ''sxcpy.py'' command:

. ''sxcpy.py bdb:filename filename.hdf''

After moving the '''hdf''' file to the desired location, you can use ''sxcpy.py'' command again to convert it back to '''bdb''' file format

. ''sxcpy.py filename.hdf bdb:filename''

READ IMAGE

  • To read a single image from a one-image file:
  . a = EMData()
  . a.read_image("name.hdf")   
  . a.read_image("bdb:name")
 . or
  . a = [[get_image]]("name.hdf") 
  . a = [[get_image]]("bdb:name")

  • To read a single image from a stack file:
  . a = EMData()
  . i=12
  . a.read_image("name.hdf" , i) 
  . a.read_image("bdb:name", i)
  • '''Note''': image numbers are from 0 to ''n''-1, where ''n'' is the total number of images in the stack file.

  • To read all images from a stack file:
  . a = EMData.read_images("name.hdf") 
  . a = EMData.read_images("bdb:name")

  • To obtain the number of images in the stack file
  
. stack = "data.hdf"  
  . stack = "bdb:data"
  . n = EMUtil.get_image_count(stack)
  • '''Note''': it is not possible to obtain other characteristics (image size, image format, ...) without reading one file into the memory.

  • To read header information of an image
 . ima = EMData()
 . ima.read_image(stack, 0, True)
 
  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Added:
>
>

Revision 821 Dec 2011 - Main.DavidStokes

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    
Added:
>
>

Setup

  • make sure PYTHONPATH is clear (setenv PYTHONPATH)
  • source EMAN2/eman2.cshrc
  • to run python program that imports sparx or eman2, need to use THEIR version
    • EMAN2/Python/bin/python
 

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available

making scripts

  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it , get some info, and write new image to file:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    data2 = data * 5 #make new image with 5X intensities of original
    data2.write_image("out.hdf",0)  # write image data to file, hdf5 format
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx/2 # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = Util.compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py

  • get all attribues from an image:
    all_alltrib=data.get_attr_dict()
    

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 717 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available

making scripts

  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it , get some info, and write new image to file:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    data2 = data * 5 #make new image with 5X intensities of original
    data2.write_image("out.hdf",0)  # write image data to file, hdf5 format
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx/2 # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = Util.compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py
Changed:
<
<
>
>
  • get all attribues from an image:
Added:
>
>
all_alltrib=data.get_attr_dict()
 
  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 617 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available

making scripts

  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

Changed:
<
<
  • load an image, view it and get some info:
>
>
  • load an image, view it , get some info, and write new image to file:
 data=EMData() #create an object to hold the image data.read_image("recon_1-20.hdf",0) #reads the first image from the stack recon_1-20.hdf display(data) # view the image using e2display data.get_attr("minimum") # print min value of image data.get_attr("maximum") # max data.get_attr("mean") #mean value of image data.get_attr("sigma") # std dev data.get_attr("nx") # x-size of image -- use ny nz for other dims
Changed:
<
<
data.write_image("out.hdf",0) # write image data to file, hdf5 format
>
>
data2 = data * 5 #make new image with 5X intensities of original
Added:
>
>
data2.write_image("out.hdf",0) # write image data to file, hdf5 format
 

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx/2 # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = Util.compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 517 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available

making scripts

  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it and get some info:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
Added:
>
>
data.write_image("out.hdf",0) # write image data to file, hdf5 format
 

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
Changed:
<
<
r=nx # this will mask only the corners of the image
>
>
r=nx/2 # this will mask only the corners of the image
 mask=model_circle(r,nx,ny) square=model_blank(nx,ny,bckg=1) inv_mask = square-mask # can do math on images!
Changed:
<
<
back_1d = compress_image_mask(data,inv_mask) # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
>
>
back_1d = Util.compress_image_mask(data,inv_mask) # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
 mean = back_1d.get_attr("mean") sd = back_1d.get_attr("sigma") norm = (data - mean) / sd # can also do scalar math on images! norm.write_image("normalised.hdf",0)
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 417 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available
Added:
>
>

making scripts

 
  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it and get some info:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 317 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
Changed:
<
<
  • in EMAN2/eman2.cshrc, Pythonpath should be set to
       ${EMAN@DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
>
>
  • in EMAN2/eman2.cshrc, Pythonpath needs to be corrected from default:
       setenv PYTHONPATH ${EMAN2DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
 

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available
  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it and get some info:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("raw.hdf",0)  #reads the first image from the stack
nx = data.get_attr("nx")
ny=nx # image should be square of course
r=nx # this will mask only the corners of the image
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask  # can do math on images!
back_1d = compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd  # can also do scalar math on images!
norm.write_image("normalised.hdf",0)
 
Added:
>
>
  • a script to do this on an entire stack, rather than one file, is in /cryem/script/normalise_stack.py
 

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 217 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath should be set to
       ${EMAN@DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available
  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it and get some info:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
Changed:
<
<
data.read_image("recon_1-20.hdf",0) #reads the first image from the stack recon_1-20.hdf
>
>
data.read_image("raw.hdf",0) #reads the first image from the stack
Added:
>
>
nx = data.get_attr("nx") ny=nx # image should be square of course r=nx # this will mask only the corners of the image
 mask=model_circle(r,nx,ny) square=model_blank(nx,ny,bckg=1)
Changed:
<
<
inv_mask = square-mask
>
>
inv_mask = square-mask # can do math on images!
 back_1d = compress_image_mask(data,inv_mask) # converts all image data under the mask to a 1D image -- for getting the stats of the corner data mean = back_1d.get_attr("mean") sd = back_1d.get_attr("sigma")
Changed:
<
<
norm = (data - mean) / sd
>
>
norm = (data - mean) / sd # can also do scalar math on images!
 norm.write_image("normalised.hdf",0)

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

Revision 117 Feb 2011 - Main.BillRice

 
META TOPICPARENT name="CemITApplications"
Contents

Install

  • download and install EMAN2 daily release
  • in EMAN2/eman2.cshrc, Pythonpath should be set to
       ${EMAN@DIR}/python/Python-2.7.1-ucs4/lib/python2.7/:${EMAN2DIR}/lib:${EMAN2DIR}/bin:${PYTHONPATH}
    

Use

  • most instructions are on the sparx wiki

conversion of stacks

  • /cryoem/script/prep_sxali.xsh will convert a stack to hdf5 format and add all params:
    #!/bin/tcsh
    # little script to convert a stack to hdf format and get all params ready for sparx alignment
    
    e2proc2d.py $1 $1:r.hdf
    sxheader.py $1:r.hdf --params="active" --one
    sxheader.py $1:r.hdf --params="xform.align2d" --zero
    
    echo made new stack $1:r.hdf, all images active and 2d alignment params zeroed
    

command line

  • to run in interactive mode, run command "sparx"
    • this uses ipython, loads all eman2 and sparx libs, graphics are available
  • for python scripts, need to run the python which came with eman2 and import the proper libs
  • put the following at start of scripts:
    #! ${EMAN2DIR}/python/Python-2.6.5-ucs4/bin/python
    
    from EMAN2 import *
    from sparx import *
    # add any other needed libs
    

some little tools when running interactively

  • load an image, view it and get some info:
    data=EMData()  #create an object to hold the image
    data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
    display(data)  # view the image using e2display
    data.get_attr("minimum") # print min value of image
    data.get_attr("maximum") # max
    data.get_attr("mean")  #mean value of image
    data.get_attr("sigma")  # std dev
    data.get_attr("nx") # x-size of image -- use ny nz for other dims
    

  • stack info
    nimages = EMUtil.get_image_count("recon_1-20.hdf")
    

  • make a mask
    mask = model_circle(r,nx,ny)  # makes a model image of size nx by ny with filled circle (density 1) of radius r
    

  • normalize an image: goal is to mask out particle, then get mean and std deviation of corners of box. Norm_image = (Image-BKG_mean)/(BKG_sd)
  • this way background has mean 0 and sd 1
data=EMData()  #create an object to hold the image
data.read_image("recon_1-20.hdf",0)  #reads the first image from the stack recon_1-20.hdf
mask=model_circle(r,nx,ny)
square=model_blank(nx,ny,bckg=1)
inv_mask = square-mask
back_1d = compress_image_mask(data,inv_mask)  # converts all image data under the mask to a 1D image -- for getting the stats of the corner data
mean = back_1d.get_attr("mean")
sd = back_1d.get_attr("sigma")
norm = (data - mean) / sd
norm.write_image("normalised.hdf",0)
 

  • Set ALLOWTOPICVIEW =

-- BillRice - 17 Feb 2011

 
Copyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding this intranet, Send feedback