Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
EMAN::CtfSimProcessor Class Reference

CTF simulation processor. More...

#include <processor.h>

Inheritance diagram for EMAN::CtfSimProcessor:
Inheritance graph
Collaboration diagram for EMAN::CtfSimProcessor:
Collaboration graph

Public Member Functions

string get_name () const
 Get the processor's name. More...
virtual EMDataprocess (const EMData *const image)
 To proccess an image out-of-place. More...
void process_inplace (EMData *image)
 To process an image in-place. More...
TypeDict get_param_types () const
 Get processor parameter information in a dictionary. More...
string get_desc () const
 Get the descrition of this specific processor. More...
- Public Member Functions inherited from EMAN::Processor
virtual ~Processor ()
virtual void process_list_inplace (vector< EMData * > &images)
 To process multiple images using the same algorithm. More...
virtual Dict get_params () const
 Get the processor parameters in a key/value dictionary. More...
virtual void set_params (const Dict &new_params)
 Set the processor parameters using a key/value dictionary. More...

Static Public Member Functions

static ProcessorNEW ()
- Static Public Member Functions inherited from EMAN::Processor
static string get_group_desc ()
 Get the description of this group of processors. More...
static void EMFourierFilterInPlace (EMData *fimage, Dict params)
 Compute a Fourier-filter processed image in place. More...
static EMDataEMFourierFilter (EMData *fimage, Dict params)
 Compute a Fourier-processor processed image without altering the original image. More...

Static Public Attributes

static const string NAME = "math.simulatectf"

Additional Inherited Members

- Public Types inherited from EMAN::Processor
enum  fourier_filter_types {
 Fourier filter Processor type enum. More...
- Protected Attributes inherited from EMAN::Processor
Dict params

Detailed Description

CTF simulation processor.

Takes individual CTF parameters, suitable for use with programs like e2filtertool.py. Can use an internal noise profile or an external profile from a text file.

defocus[in]Defocus in microns (underfocus positive)
ampcont[in]% amplitude contrast (0-100)
bfactor[in]B-factor in A^2, uses MRC convention rather than EMAN1 convention
noiseamp[in]Amplitude of the added empirical pink noise
noiseampwhite[in]Amplitude of added white noise
voltage[in]Microscope voltage in KV
cs[in]Cs of microscope in mm
apix[in]A/pix of data
Steve Ludtke

Definition at line 1804 of file processor.h.

Member Function Documentation

◆ get_desc()

string EMAN::CtfSimProcessor::get_desc ( ) const

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

The description of this processor.

Implements EMAN::Processor.

Definition at line 1838 of file processor.h.

1839 {
1840 return "Applies a simulated CTF with noise to an image. Astigmatism is always zero. The added noise is either white or based on an empirical curve generated from cryoEM data. ";
1841 }

◆ get_name()

string EMAN::CtfSimProcessor::get_name ( ) const

Get the processor's name.

Each processor is identified by a unique name.

The processor's name.

Implements EMAN::Processor.

Definition at line 1807 of file processor.h.

1808 {
1809 return NAME;
1810 }
static const string NAME
Definition: processor.h:1843

References NAME.

◆ get_param_types()

TypeDict EMAN::CtfSimProcessor::get_param_types ( ) const

Get processor parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 1816 of file processor.h.

1817 {
1818 TypeDict d;
1819 d.put("purectf", EMObject::BOOL, "If set, replaces image with simulated CTF instead of multiplying image by CTF");
1820 d.put("defocus", EMObject::FLOAT, "Defocus in microns (underfocus positive)");
1821 d.put("ampcont", EMObject::FLOAT, "% amplitude contrast (0-100)");
1822 d.put("bfactor", EMObject::FLOAT, "B-factor in A^2, uses MRC convention rather than EMAN1 convention");
1823 d.put("noiseamp", EMObject::FLOAT, "Amplitude of the added empirical pink noise");
1824// d.put("noiseampwhite", EMObject::FLOAT, "Amplitude of added white noise");
1825 d.put("voltage", EMObject::FLOAT, "Microscope voltage in KV");
1826 d.put("cs", EMObject::FLOAT, "Cs of microscope in mm");
1827 d.put("apix", EMObject::FLOAT, "A/pix of data");
1828 d.put("phaseflip", EMObject::INT, "If not true, applies fabs(CTF). default true");
1829 d.put("bispectrumfp", EMObject::INT, "If set, the input must be the result of math.bispectrum.slice ffp= mode. Returns something comparable to fp=mode.");
1830 return d;
1831 }
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330

References EMAN::EMObject::BOOL, EMAN::EMObject::FLOAT, EMAN::EMObject::INT, and EMAN::TypeDict::put().

◆ NEW()

static Processor * EMAN::CtfSimProcessor::NEW ( )

Definition at line 1833 of file processor.h.

1834 {
1835 return new CtfSimProcessor();
1836 }
CTF simulation processor.
Definition: processor.h:1805

◆ process()

EMData * CtfSimProcessor::process ( const EMData *const  image)

To proccess an image out-of-place.

For those processors which can only be processed out-of-place, override this function to give the right behavior.

imageThe image will be copied, actual process happen on copy of image.
the image processing result, may or may not be the same size of the input image

Reimplemented from EMAN::Processor.

Definition at line 6879 of file processor.cpp.

6879 {
6880 if (!image) {
6881 LOGWARN("NULL Image");
6882 return NULL;
6883 }
6885 EMData *fft;
6886 if (!image->is_complex()) fft=image->do_fft();
6887 else fft=image->copy();
6889 bool purectf=(bool)params.set_default("purectf",0);
6890 EMAN2Ctf ctf;
6891 ctf.defocus=params["defocus"];
6892 ctf.bfactor=params["bfactor"];
6893 ctf.ampcont=params.set_default("ampcont",10.0f);
6894 ctf.voltage=params.set_default("voltage",200.0f);
6895 ctf.cs=params.set_default("cs",2.0);
6896 ctf.apix=params.set_default("apix",image->get_attr_default("apix_x",1.0));
6897 if (image->has_attr("dsbg")) ctf.dsbg=image->get_attr("dsbg");
6898 else ctf.dsbg=1.0/(ctf.apix*fft->get_ysize()*4.0); //4x oversampling
6899 int doflip=(int)params.set_default("phaseflip",1); // whether to use the CTF or abs(CTF)
6900 float noiseamp=params.set_default("noiseamp",0.0f);
6901 float noiseampwhite=params.set_default("noiseampwhite",0.0f);
6902 int bsfp=(int)params.set_default("bispectrumfp",0); // special mode for bispectrum processing ... obsolete as of 8/16/18
6904 // compute the CTF
6905 vector <float> ctfc = ctf.compute_1d(fft->get_ysize()*12,ctf.dsbg,ctf.CTF_AMP,NULL); // *6 goes to corner, remember you provide 2x the number of points you need
6906 if (!doflip) {
6907 for (vector<float>::iterator it=ctfc.begin(); it!=ctfc.end(); ++it) *it=fabs(*it);
6908 }
6910// for (int i=0; i<ctfc.size(); i++) printf("%d\t%f\n",i,ctfc[i]);
6911// printf("apix %f\tdsbg %f\tdef %f\tbfac %f\tvol %f\tcs %f\n",ctf.apix,ctf.dsbg,ctf.defocus,ctf.bfactor,ctf.voltage,ctf.cs);
6913// printf("%1.3f\t%1.3f\t%1.3f\t%1.3f\t%1.3f\t%d\n",ctf.defocus,ctf.bfactor,ctf.ampcont,ctf.dsbg,ctf.apix,fft->get_ysize());
6914// FILE *out=fopen("x.txt","w");
6915// for (int i=0; i<ctfc.size(); i++) fprintf(out,"%f\t%1.3g\n",0.25*i/(float)fft->get_ysize(),ctfc[i]);
6916// fclose(out);
6918 if (bsfp) {
6919 int fp=fft->get_zsize();
6920 int nx=fft->get_xsize();
6921 int ny=fft->get_ysize();
6922 EMData *ret=new EMData((nx-2)/2,ny*fp,1);
6923// for (int j=ny*2-4; j<ctfc.size(); j++) ctfc[j]*=exp(-pow(j-ny*2+4,2.0)/8.0); // soft Gaussian falloff to CTF modification to avoid corner/edge effects
6924 for (int k=0; k<fp; k++) {
6925 EMData *plnf=fft->get_clip(Region(0,0,k,nx,ny,1));
6926 plnf->set_complex(1);
6927 plnf->set_ri(1);
6928 plnf->set_fftpad(1);
6929// plnf->apply_radial_func(0,0.25f/fft->get_ysize(),ctfc,1);
6930 for (int jy=-ny/2; jy<ny/2; jy++) {
6931 for (int jx=0; jx<nx/2; jx++) {
6932 if (jx==0 && jy<0) continue;
6933 int r1=Util::hypot_fast_int(jx*4,jy*4);
6934 int r2=(k+2)*4;
6935 int r3=Util::hypot_fast_int((jx+k+2)*4,jy*4);
6936 float ctfmod=ctfc[r1]*ctfc[r2]*ctfc[r3];
6937// if (jx==0|| jx==1) printf("%d %d\t%d %d %d\t%g %g %g\t%g\n",jx,jy,r1,r2,r3,ctfc[r1],ctfc[r2],ctfc[r3],ctfmod);
6939 // Turns out that it shouldn't BE rotationally symmetric
6940// // To make this rotationally symmetric we have to integrate over the j+k vector
6941// float avgr=0.0f;
6942// float norm=0.0f;
6943// for (float ang=0.0f; ang<2.0*M_PI; ang+=2.0*M_PI/float(k*8)) {
6944// float jkx=jx*4+k*4.0*cos(ang);
6945// float jky=jy*4+k*4.0*sin(ang);
6947// int r3=int(hypot(jkx,jky)+0.5);
6948// avgr+=ctfc[r3];
6949// norm+=1.0;
6950// }
6951// ctfmod*=(avgr/norm);
6953 if (purectf) plnf->set_complex_at(jx,jy,ctfmod);
6954 else plnf->set_complex_at(jx,jy,plnf->get_complex_at(jx,jy)*ctfmod);
6955// plnf->set_complex_at(jx,jy,plnf->get_complex_at(jx,jy);
6956// plnf->set_complex_at(jx,jy,ctfmod);
6957 }
6958 }
6959// plnf->write_image("tst.hdf",-1);
6961 EMData *pln=plnf->do_ift();
6962 pln->process_inplace("xform.phaseorigin.tocenter");
6963 pln->process_inplace("normalize");
6964 ret->insert_clip(pln,IntPoint(-nx/2,k*ny,0));
6965 delete plnf;
6966 delete pln;
6967 }
6968 delete fft;
6969 return ret;
6970 }
6971 else {
6972 if (purectf) {
6973 for (size_t i=0; i<fft->get_size(); i++) fft->set_value_at_fast(i,i%2==0?1.0f:0.0f);
6974 }
6975 fft->apply_radial_func(0,0.25f/fft->get_ysize(),ctfc,1);
6976 }
6978 // Add noise
6979 if (noiseamp!=0 || noiseampwhite!=0) {
6980 EMData *noise = new EMData(image->get_ysize(),image->get_ysize(),1);
6981 noise->process_inplace("testimage.noise.gauss");
6982 noise->do_fft_inplace();
6984 // White noise
6985 if (noiseampwhite!=0) {
6986 noise->mult((float)noiseampwhite*15.0f); // The 15.0 is to roughly compensate for the stronger pink noise curve
6987 fft->add(*noise);
6988 noise->mult((float)1.0/(noiseampwhite*15.0f));
6989 }
6991 // Pink noise
6992 if (noiseamp!=0) {
6993 vector <float> pinkbg;
6994 pinkbg.resize(500);
6995 float nyimg=0.5f/ctf.apix; // image nyquist
6996 // This pink curve came from a typical image in the GroEL 4A data set
6997 for (int i=0; i<500; i++) pinkbg[i]=noiseamp*(44.0f*exp(-5.0f*nyimg*i/250.0f)+10.0f*exp(-90.0f*nyimg*i/250.0f)); // compute curve to image Nyquist*2
6998 noise->apply_radial_func(0,.002f,pinkbg,1); // Image nyquist is at 250 -> 0.5
6999 fft->add(*noise);
7000 }
7002 }
7004 EMData *ret=fft->do_ift();
7005 delete fft;
7007 return ret;
float cs
Definition: ctf.h:87
float bfactor
Definition: ctf.h:85
float voltage
Definition: ctf.h:86
float apix
Definition: ctf.h:88
float defocus
Definition: ctf.h:84
Definition: ctf.h:65
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
EMAN2Ctf is the default CTF model used in EMAN2.
Definition: ctf.h:237
vector< float > compute_1d(int size, float ds, CtfType type, XYData *struct_factor=0)
Definition: ctf.cpp:731
float ampcont
Definition: ctf.h:243
float dsbg
Definition: ctf.h:247
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
EMData * get_clip(const Region &area, const float fill=0) const
Get an inclusive clip.
Definition: emdata.cpp:592
void apply_radial_func(float x0, float dx, vector< float >array, bool interp=true)
multiplies by a radial function in fourier space.
Definition: emdata.cpp:2677
IntPoint defines an integer-coordinate point in a 1D/2D/3D space.
Definition: geometry.h:192
Region defines a 2D or 3D rectangular region specified by its origin coordinates and all edges' sizes...
Definition: geometry.h:497
static short hypot_fast_int(int x, int y)
Euclidean distance in 2D for integers computed fast using a cached lookup table.
Definition: util.cpp:764
#define LOGWARN
Definition: log.h:53

References EMAN::EMAN2Ctf::ampcont, EMAN::Ctf::apix, EMAN::EMData::apply_radial_func(), EMAN::Ctf::bfactor, EMAN::EMAN2Ctf::compute_1d(), EMAN::Ctf::cs, EMAN::Ctf::CTF_AMP, EMAN::Ctf::defocus, EMAN::EMAN2Ctf::dsbg, EMAN::EMData::get_clip(), EMAN::Util::hypot_fast_int(), LOGWARN, EMAN::Processor::params, EMAN::Dict::set_default(), and EMAN::Ctf::voltage.

Referenced by process_inplace().

◆ process_inplace()

void CtfSimProcessor::process_inplace ( EMData image)

To process an image in-place.

For those processors which can only be processed out-of-place, override this function to just print out some error message to remind user call the out-of-place version.

imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 6871 of file processor.cpp.

6871 {
6872 EMData *tmp=process(image);
6873 memcpy(image->get_data(),tmp->get_data(),(size_t)image->get_xsize()*image->get_ysize()*image->get_zsize()*sizeof(float));
6874 delete tmp;
6875 image->update();
6876 return;
virtual EMData * process(const EMData *const image)
To proccess an image out-of-place.
Definition: processor.cpp:6879

References process().

Member Data Documentation


const string CtfSimProcessor::NAME = "math.simulatectf"

Definition at line 1843 of file processor.h.

Referenced by get_name().

The documentation for this class was generated from the following files: