Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::EMAN1Ctf Class Reference

EMAN1Ctf is the CTF model used in EMAN1. More...

#include <ctf.h>

Inheritance diagram for EMAN::EMAN1Ctf:

[legend]
Collaboration diagram for EMAN::EMAN1Ctf:
[legend]
List of all members.

Public Member Functions

 EMAN1Ctf ()
 EMAN1Ctf (const vector< float > &vf)
 ~EMAN1Ctf ()
vector< float > compute_1d (int size, float ds, CtfType type, XYData *struct_factor=0)
void compute_2d_real (EMData *image, CtfType type, XYData *struct_factor=0)
void compute_2d_complex (EMData *image, CtfType type, XYData *struct_factor=0)
int from_string (const string &ctf)
string to_string () const
void from_dict (const Dict &dict)
Dict to_dict () const
void from_vector (const vector< float > &vctf)
vector< float > to_vector () const
void copy_from (const Ctf *new_ctf)
bool equal (const Ctf *ctf1) const
float get_defocus () const
float get_bfactor () const

Public Attributes

float amplitude
float ampcont
float noise1
float noise2
float noise3
float noise4

Private Member Functions

float calc_amp1 ()
float calc_lambda ()
float calc_g1 ()
float calc_g2 ()
float calc_gamma (float g1, float g2, float s)
float calc_ctf1 (float g, float gamma, float s)
float calc_amplitude (float gamma)
float calc_noise (float s)
float calc_snr (float g1, float gamma, float s)

Detailed Description

EMAN1Ctf is the CTF model used in EMAN1.

Definition at line 112 of file ctf.h.


Constructor & Destructor Documentation

EMAN1Ctf::EMAN1Ctf  ) 
 

Definition at line 43 of file ctf.cpp.

References ampcont, amplitude, noise1, noise2, noise3, and noise4.

00044 {
00045         defocus = 0;
00046         bfactor = 0;
00047         amplitude = 0;
00048         ampcont = 0;
00049         noise1 = 0;
00050         noise2 = 0;
00051         noise3 = 0;
00052         noise4 = 0;
00053         voltage = 0;
00054         cs = 0;
00055         apix = 0;
00056 }

EMAN::EMAN1Ctf::EMAN1Ctf const vector< float > &  vf  )  [inline]
 

Definition at line 129 of file ctf.h.

00129 {from_vector(vf);}      //for unpickling

EMAN1Ctf::~EMAN1Ctf  ) 
 

Definition at line 59 of file ctf.cpp.

00060 {
00061 }


Member Function Documentation

float EMAN::EMAN1Ctf::calc_amp1  )  [inline, private]
 

Definition at line 158 of file ctf.h.

References sqrt().

Referenced by compute_1d(), and compute_2d_complex().

00159                 {
00160                         return (sqrt(1 - ampcont * ampcont/10000.0f));
00161                 }

float EMAN::EMAN1Ctf::calc_amplitude float  gamma  )  [inline, private]
 

Definition at line 196 of file ctf.h.

References amplitude(), sqrt(), and v.

Referenced by compute_2d_complex().

00197                 {
00198                         float t1 = sqrt(1.0f - ampcont * ampcont/10000.0f) * sin(gamma);
00199                         float v = amplitude * (t1 + ampcont/100.0f * cos(gamma));
00200                         return v;
00201                 }

float EMAN::EMAN1Ctf::calc_ctf1 float  g,
float  gamma,
float  s
[inline, private]
 

Definition at line 190 of file ctf.h.

References amplitude().

Referenced by compute_1d(), and compute_2d_complex().

00191                 {
00192                         float r = amplitude * exp(-(bfactor/4.0f * s * s)) * (g * sin(gamma) + ampcont/100.0f * cos(gamma));
00193                         return r;
00194                 }

float EMAN::EMAN1Ctf::calc_g1  )  [inline, private]
 

Definition at line 169 of file ctf.h.

Referenced by compute_1d(), and compute_2d_complex().

00170                 {
00171                         float lambda = calc_lambda();
00172                         float g1 = 2.5e6f * cs * lambda * lambda * lambda;
00173                         return g1;
00174                 }

float EMAN::EMAN1Ctf::calc_g2  )  [inline, private]
 

Definition at line 176 of file ctf.h.

Referenced by compute_1d(), and compute_2d_complex().

00177                 {
00178                         float lambda = calc_lambda();
00179                         float g2 = 5000.0f * -defocus * lambda;
00180                         return g2;
00181                 }

float EMAN::EMAN1Ctf::calc_gamma float  g1,
float  g2,
float  s
[inline, private]
 

Definition at line 183 of file ctf.h.

Referenced by compute_1d(), and compute_2d_complex().

00184                 {
00185                         float s2 = s * s;
00186                         float gamma = (float) (-2 * M_PI * (g1 * s2 * s2 + g2 * s2));
00187                         return gamma;
00188                 }

float EMAN::EMAN1Ctf::calc_lambda  )  [inline, private]
 

Definition at line 163 of file ctf.h.

References sqrt().

00164                 {
00165                         float lambda = 12.2639f / sqrt(voltage * 1000.0f + 0.97845f * voltage * voltage);
00166                         return lambda;
00167                 }

float EMAN::EMAN1Ctf::calc_noise float  s  )  [inline, private]
 

Definition at line 203 of file ctf.h.

References sqrt().

Referenced by compute_1d(), and compute_2d_complex().

00204                 {
00205                         float ns = (float) M_PI / 2 * noise4 * s;
00206                         float ns2 = ns * ns;
00207                         float n = noise3 * exp(-ns2 - s * noise2 - sqrt(fabs(s)) * noise1);
00208                         return n;
00209                 }

float EMAN::EMAN1Ctf::calc_snr float  g1,
float  gamma,
float  s
[inline, private]
 

Definition at line 211 of file ctf.h.

Referenced by compute_1d().

00212                 {
00213                         float ctf1 = calc_ctf1(g1, gamma, s);
00214                         float ctf2 = ctf1 * ctf1 / calc_noise(s);
00215                         return ctf2;
00216                 }

vector< float > EMAN1Ctf::compute_1d int  size,
float  ds,
CtfType  type,
XYData struct_factor = 0
[virtual]
 

Implements EMAN::Ctf.

Definition at line 174 of file ctf.cpp.

References Assert, calc_amp1(), calc_ctf1(), calc_g1(), calc_g2(), calc_gamma(), calc_noise(), calc_snr(), EMAN::XYData::get_yatx(), LOGERR, and sqrt().

00175 {
00176         Assert(size > 0);
00177 
00178         float tmp_f1 = CTFOS * sqrt((float) 2) * size / 2;
00179         int np = (int) ceil(tmp_f1) + 2;
00180         vector < float >r;
00181 
00182         r.resize(np);
00183 
00184 //      float ds = 1 / (apix * size * CTFOS);
00185         float s = 0;
00186         float g1 = calc_g1();
00187         float g2 = calc_g2();
00188         float amp1 = calc_amp1();
00189 
00190         switch (type) {
00191         case CTF_AMP:
00192                 for (int i = 0; i < np; i++) {
00193                         float gamma = calc_gamma(g1, g2, s);
00194                         r[i] = calc_ctf1(amp1, gamma, s);
00195                         s += ds;
00196                 }
00197                 break;
00198 
00199         case CTF_SIGN:
00200                 for (int i = 0; i < np; i++) {
00201                         float gamma = calc_gamma(g1, g2, s);
00202                         r[i] = calc_ctf1(amp1, gamma, s)>0?1.0f:-1.0f;
00203                         s += ds;
00204                 }
00205                 break;
00206 
00207         case CTF_BACKGROUND:
00208                 for (int i = 0; i < np; i++) {
00209                         r[i] = calc_noise(s);
00210                         s += ds;
00211                 }
00212                 break;
00213 
00214         case CTF_SNR:
00215         case CTF_SNR_SMOOTH:
00216 //              if (!sf) {
00217 //                      LOGERR("CTF computation error, no SF found\n");
00218 //                      return r;
00219 //              }
00220 
00221                 for (int i = 0; i < np; i++) {
00222                         float gamma = calc_gamma(g1, g2, s);
00223                         r[i] = calc_snr(amp1, gamma, s);
00224                         if (s && sf) {
00225                                 r[i] *= pow(10.0f, sf->get_yatx(s));
00226                         }
00227                         s += ds;
00228                 }
00229 
00230                 break;
00231 
00232         case CTF_WIENER_FILTER:
00233                 if (!sf) {
00234                         LOGERR("CTF computation error, no SF found\n");
00235                         return r;
00236                 }
00237 
00238                 for (int i = 0; i < np; i++) {
00239                         float gamma = calc_gamma(g1, g2, s);
00240                         r[i] = calc_snr(amp1, gamma, s);
00241                         if (s && sf) {
00242                                 r[i] *= pow(10.0f, sf->get_yatx(s));
00243                         }
00244 
00245                         r[i] = 1.0f / (1.0f + 1.0f / r[i]);
00246                         s += ds;
00247                 }
00248                 break;
00249 
00250         case CTF_TOTAL:
00251                 if (!sf) {
00252                         LOGERR("CTF computation error, no SF found\n");
00253                         return r;
00254                 }
00255 
00256                 for (int i = 0; i < np; i++) {
00257                         float gamma = calc_gamma(g1, g2, s);
00258                         if (sf) {
00259                                 r[i] = calc_ctf1(amp1, gamma, s);
00260                                 r[i] = r[i] * r[i] * pow(10.0f, sf->get_yatx(s)) + calc_noise(s);
00261                         }
00262                         else {
00263                                 r[i] = calc_ctf1(amp1, gamma, s);
00264                                 r[i] = r[i] * r[i] + calc_noise(s);
00265                         }
00266                         s += ds;
00267                 }
00268                 break;
00269         default:
00270                 break;
00271         }
00272 
00273         return r;
00274 }

void EMAN1Ctf::compute_2d_complex EMData image,
CtfType  type,
XYData struct_factor = 0
[virtual]
 

Implements EMAN::Ctf.

Definition at line 285 of file ctf.cpp.

References calc_amp1(), calc_amplitude(), calc_ctf1(), calc_g1(), calc_g2(), calc_gamma(), calc_noise(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::XYData::get_yatx(), EMAN::EMData::get_ysize(), EMAN::EMData::is_complex(), LOGERR, nx, ny, EMAN::EMData::to_one(), EMAN::EMData::update(), v, x, and y.

00286 {
00287         if (!image) {
00288                 LOGERR("image is null. cannot computer 2D complex CTF");
00289                 return;
00290         }
00291 
00292         if (image->is_complex() == false) {
00293                 LOGERR("compute_2d_complex can only work on complex images");
00294                 return;
00295         }
00296 
00297         int nx = image->get_xsize();
00298         int ny = image->get_ysize();
00299 
00300         if (nx != ny + 2) {
00301                 LOGERR("compute_2d_complex only works on (nx, nx-2) images");
00302                 return;
00303         }
00304 
00305         float ds = 1.0f / (apix * ny);
00306         image->to_one();
00307 
00308         float *d = image->get_data();
00309         float g1 = calc_g1();
00310         float g2 = calc_g2();
00311 
00312         if (type == CTF_BACKGROUND) {
00313                 for (int y = 0; y < ny; y++) {
00314                         int ynx = y * nx;
00315 
00316                         for (int x = 0; x < nx / 2; x++) {
00317 #ifdef  _WIN32
00318                                 float s = (float) _hypot(x, y - ny / 2.0f) * ds;
00319 #else
00320                                 float s = (float) hypot(x, y - ny / 2.0f) * ds;
00321 #endif
00322                                 d[x * 2 + ynx] = calc_noise(s);
00323                                 d[x * 2 + ynx + 1] = 0;                 // The phase is somewhat arbitrary
00324                         }
00325                 }
00326         }
00327         else if (type == CTF_AMP) {
00328                 for (int y = 0; y < ny; y++) {
00329                         int ynx = y * nx;
00330 
00331                         for (int x = 0; x < nx / 2; x++) {
00332 #ifdef  _WIN32
00333                                 float s = (float)_hypot((float) x, (float) y - ny / 2) * ds;
00334 #else
00335                                 float s = (float)hypot((float) x, (float) y - ny / 2) * ds;
00336 #endif  //_WIN32
00337                                 float gamma = calc_gamma(g1, g2, s);
00338                                 float v = fabs(calc_amplitude(gamma));
00339                                 d[x * 2 + ynx] = v;
00340                                 d[x * 2 + ynx + 1] = 0;
00341                         }
00342                 }
00343         }
00344         else if (type == CTF_SIGN) {
00345                 for (int y = 0; y < ny; y++) {
00346                         int ynx = y * nx;
00347                         for (int x = 0; x < nx / 2; x++) {
00348 #ifdef  _WIN32
00349                                 float s = (float)_hypot(x, y - ny / 2.0f) * ds;
00350 #else
00351                                 float s = (float)hypot(x, y - ny / 2.0f) * ds;
00352 #endif
00353                                 float gamma = calc_gamma(g1, g2, s);
00354                                 float v = calc_amplitude(gamma);
00355                                 d[x * 2 + ynx] = v > 0 ? 1.0f : -1.0f;
00356                                 d[x * 2 + ynx + 1] = 0;
00357                         }
00358                 }
00359 
00360         }
00361         else if (type == CTF_SNR || type == CTF_SNR_SMOOTH) {
00362                 float amp1 = calc_amp1();
00363 
00364                 for (int y = 0; y < ny; y++) {
00365                         int ynx = y * nx;
00366 
00367                         for (int x = 0; x < nx / 2; x++) {
00368 
00369 #ifdef  _WIN32
00370                                 float s = (float)_hypot(x, y - ny / 2.0f) * ds;
00371 #else
00372                                 float s = (float)hypot(x, y - ny / 2.0f) * ds;
00373 #endif
00374                                 float gamma = calc_gamma(g1, g2, s);
00375                                 float f = calc_ctf1(amp1, gamma, s);
00376                                 float noise = calc_noise(s);
00377                                 f = f * f / noise;
00378 
00379                                 if (s && sf) {
00380                                         f *= pow(10.0f, sf->get_yatx(s));
00381                                 }
00382                                 d[x * 2 + ynx] *= f;
00383                                 d[x * 2 + ynx + 1] = 0;
00384                         }
00385                 }
00386         }
00387         else if (type == CTF_WIENER_FILTER) {
00388                 float amp1 = calc_amp1();
00389 
00390                 for (int y = 0; y < ny; y++) {
00391                         int ynx = y * nx;
00392 
00393                         for (int x = 0; x < nx / 2; x++) {
00394 
00395 #ifdef  _WIN32
00396                                 float s = (float)_hypot(x, y - ny / 2.0f) * ds;
00397 #else
00398                                 float s = (float)hypot(x, y - ny / 2.0f) * ds;
00399 #endif
00400                                 float gamma = calc_gamma(g1, g2, s);
00401                                 float f = calc_ctf1(amp1, gamma, s);
00402                                 float noise = calc_noise(s);
00403                                 f = f * f / noise;
00404 
00405                                 if (s) {
00406                                         f *= pow(10.0f, sf->get_yatx(s));
00407                                 }
00408                                 f = 1.0f / (1.0f + 1.0f / f);
00409                                 d[x * 2 + ynx] *= f;
00410                                 d[x * 2 + ynx + 1] = 0;
00411                         }
00412                 }
00413         }
00414         else if (type == CTF_TOTAL) {
00415                 float amp1 = calc_amp1();
00416 
00417                 for (int y = 0; y < ny; y++) {
00418                         int ynx = y * nx;
00419 
00420                         for (int x = 0; x < nx / 2; x++) {
00421 
00422 #ifdef  _WIN32
00423                                 float s = (float)_hypot(x, y - ny / 2.0f) * ds;
00424 #else
00425                                 float s = (float)hypot(x, y - ny / 2.0f) * ds;
00426 #endif
00427                                 float gamma = calc_gamma(g1, g2, s);
00428                                 float f = calc_ctf1(amp1, gamma, s);
00429                                 float noise = calc_noise(s);
00430                                 f = f * f;
00431 
00432                                 if (sf && s) {
00433                                         f *= pow(10.0f, sf->get_yatx(s));
00434                                 }
00435                                 f+=noise;
00436 
00437                                 d[x * 2 + ynx] *= f;
00438                                 d[x * 2 + ynx + 1] = 0;
00439                         }
00440                 }
00441         }
00442 
00443         image->update();
00444 }

void EMAN1Ctf::compute_2d_real EMData image,
CtfType  type,
XYData struct_factor = 0
[virtual]
 

Implements EMAN::Ctf.

Definition at line 277 of file ctf.cpp.

00278 {
00279 
00280 
00281 }

void EMAN1Ctf::copy_from const Ctf new_ctf  )  [virtual]
 

Implements EMAN::Ctf.

Definition at line 155 of file ctf.cpp.

References ampcont, amplitude, EMAN::Ctf::apix, EMAN::Ctf::bfactor, EMAN::Ctf::cs, EMAN::Ctf::defocus, noise1, noise2, noise3, noise4, and EMAN::Ctf::voltage.

00156 {
00157         if (new_ctf) {
00158                 const EMAN1Ctf *c = static_cast<const EMAN1Ctf *>(new_ctf);
00159                 defocus = c->defocus;
00160                 bfactor = c->bfactor;
00161                 amplitude = c->amplitude;
00162                 ampcont = c->ampcont;
00163                 noise1 = c->noise1;
00164                 noise2 = c->noise2;
00165                 noise3 = c->noise3;
00166                 noise4 = c->noise4;
00167                 voltage = c->voltage;
00168                 cs = c->cs;
00169                 apix = c->apix;
00170         }
00171 }

bool EMAN1Ctf::equal const Ctf ctf1  )  const [virtual]
 

Implements EMAN::Ctf.

Definition at line 448 of file ctf.cpp.

References ampcont, amplitude, EMAN::Ctf::apix, EMAN::Ctf::bfactor, EMAN::Ctf::cs, EMAN::Ctf::defocus, noise1, noise2, noise3, noise4, and EMAN::Ctf::voltage.

00449 {
00450         if (ctf1) {
00451                 const EMAN1Ctf *c = static_cast<const EMAN1Ctf *>(ctf1);
00452                 if (defocus == c->defocus &&
00453                         bfactor == c->bfactor &&
00454                         amplitude == c->amplitude &&
00455                         ampcont == c->ampcont &&
00456                         noise1 == c->noise1 &&
00457                         noise2 == c->noise2 &&
00458                         noise3 == c->noise3 &&
00459                         noise4 == c->noise4 && voltage == c->voltage && cs == c->cs && apix == c->apix) {
00460                         return true;
00461                 }
00462         }
00463         return false;
00464 }

void EMAN1Ctf::from_dict const Dict dict  )  [virtual]
 

Implements EMAN::Ctf.

Definition at line 77 of file ctf.cpp.

References ampcont, amplitude, noise1, noise2, noise3, and noise4.

00078 {
00079         defocus = dict["defocus"];
00080         bfactor = dict["bfactor"];
00081         amplitude = dict["amplitude"];
00082         ampcont = dict["ampcont"];
00083         noise1 = dict["noise1"];
00084         noise2 = dict["noise2"];
00085         noise3 = dict["noise3"];
00086         noise4 = dict["noise4"];
00087         voltage = dict["voltage"];
00088         cs = dict["cs"];
00089         apix = dict["apix"];
00090 }

int EMAN1Ctf::from_string const string &  ctf  )  [virtual]
 

Implements EMAN::Ctf.

Definition at line 64 of file ctf.cpp.

References Assert.

00065 {
00066         Assert(ctf != "");
00067         char type;
00068         int i = sscanf(ctf.c_str(), "%c%f %f %f %f %f %f %f %f %f %f %f",
00069                                    &type,&defocus, &bfactor, &amplitude, &ampcont, &noise1,
00070                                    &noise2, &noise3, &noise4, &voltage, &cs, &apix);
00071         if (i != 11) {
00072                 return 1;
00073         }
00074         return 0;
00075 }

void EMAN1Ctf::from_vector const vector< float > &  vctf  )  [virtual]
 

Implements EMAN::Ctf.

Definition at line 110 of file ctf.cpp.

References ampcont, amplitude, noise1, noise2, noise3, and noise4.

Referenced by EMAN::EMData::get_ctf().

00111 {
00112         defocus = vctf[0];
00113         bfactor = vctf[1];
00114         amplitude = vctf[2];
00115         ampcont = vctf[3];
00116         noise1 = vctf[4];
00117         noise2 = vctf[5];
00118         noise3 = vctf[6];
00119         noise4 = vctf[7];
00120         voltage = vctf[8];
00121         cs = vctf[9];
00122         apix = vctf[10];
00123 }

float EMAN::EMAN1Ctf::get_bfactor  )  const [inline]
 

Definition at line 152 of file ctf.h.

00153                 {
00154                         return bfactor;
00155                 }

float EMAN::EMAN1Ctf::get_defocus  )  const [inline]
 

Definition at line 148 of file ctf.h.

00149                 {
00150                         return defocus;
00151                 }

Dict EMAN1Ctf::to_dict  )  const [virtual]
 

Implements EMAN::Ctf.

Definition at line 92 of file ctf.cpp.

00093 {
00094         Dict dict;
00095         dict["defocus"] = defocus;
00096         dict["bfactor"] = bfactor;
00097         dict["amplitude"] = amplitude;
00098         dict["ampcont"] = ampcont;
00099         dict["noise1"] = noise1;
00100         dict["noise2"] = noise2;
00101         dict["noise3"] = noise3;
00102         dict["noise4"] = noise4;
00103         dict["voltage"] = voltage;
00104         dict["cs"] = cs;
00105         dict["apix"] = apix;
00106 
00107         return dict;
00108 }

string EMAN1Ctf::to_string  )  const [virtual]
 

Implements EMAN::Ctf.

Definition at line 145 of file ctf.cpp.

References ampcont, amplitude, noise1, noise2, noise3, and noise4.

00146 {
00147         char ctf[1024];
00148         sprintf(ctf, "O%1.3g %1.3g %1.3g %1.3g %1.3g %1.3g %1.3g %1.3g %1.3g %1.3g %1.3g",
00149                         defocus, bfactor, amplitude, ampcont, noise1, noise2, noise3, noise4, voltage, cs,
00150                         apix);
00151 
00152         return string(ctf);
00153 }

vector< float > EMAN1Ctf::to_vector  )  const [virtual]
 

Implements EMAN::Ctf.

Definition at line 125 of file ctf.cpp.

References ampcont, amplitude, noise1, noise2, noise3, and noise4.

00126 {
00127         vector<float> vctf;
00128 
00129         vctf.push_back(defocus);
00130         vctf.push_back(bfactor);
00131         vctf.push_back(amplitude);
00132         vctf.push_back(ampcont);
00133         vctf.push_back(noise1);
00134         vctf.push_back(noise2);
00135         vctf.push_back(noise3);
00136         vctf.push_back(noise4);
00137         vctf.push_back(voltage);
00138         vctf.push_back(cs);
00139         vctf.push_back(apix);
00140 
00141         return vctf;
00142 }


Member Data Documentation

float EMAN::EMAN1Ctf::ampcont
 

Definition at line 118 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().

float EMAN::EMAN1Ctf::amplitude
 

Definition at line 117 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().

float EMAN::EMAN1Ctf::noise1
 

Definition at line 119 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().

float EMAN::EMAN1Ctf::noise2
 

Definition at line 120 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().

float EMAN::EMAN1Ctf::noise3
 

Definition at line 121 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().

float EMAN::EMAN1Ctf::noise4
 

Definition at line 122 of file ctf.h.

Referenced by copy_from(), EMAN1Ctf(), equal(), from_dict(), from_vector(), to_string(), and to_vector().


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:14 2010 for EMAN2 by  doxygen 1.3.9.1