EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes
EMAN::CTFSNRWeightProcessor Class Reference

#include <processor.h>

Inheritance diagram for EMAN::CTFSNRWeightProcessor:
Inheritance graph
[legend]
Collaboration diagram for EMAN::CTFSNRWeightProcessor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void process_inplace (EMData *image)
 To process an image in-place.
virtual string get_name () const
 Get the processor's name.
virtual string get_desc () const
 Get the descrition of this specific processor.
virtual TypeDict get_param_types () const
 Get processor parameter information in a dictionary.

Static Public Member Functions

static ProcessorNEW ()

Static Public Attributes

static const string NAME = "ctf.snr.weight"

Detailed Description

Author:
David Woolford
Date:
June 15th 2009

Definition at line 6387 of file processor.h.


Member Function Documentation

virtual string EMAN::CTFSNRWeightProcessor::get_desc ( ) const [inline, virtual]

Get the descrition of this specific processor.

This function must be overwritten by a subclass.

Returns:
The description of this processor.

Implements EMAN::Processor.

Definition at line 6397 of file processor.h.

                        {
                                return "Weight the amplitudes of an image based on radial noise and snr curves ";
                        }
virtual string EMAN::CTFSNRWeightProcessor::get_name ( ) const [inline, virtual]

Get the processor's name.

Each processor is identified by a unique name.

Returns:
The processor's name.

Implements EMAN::Processor.

Definition at line 6392 of file processor.h.

References NAME.

                        {
                                return NAME;
                        }
virtual TypeDict EMAN::CTFSNRWeightProcessor::get_param_types ( ) const [inline, virtual]

Get processor parameter information in a dictionary.

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

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Processor.

Definition at line 6407 of file processor.h.

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

                        {
                                TypeDict d;
                                d.put("noise", EMObject::FLOATARRAY, "The noise profile, squared amplitude. As in, what is the EMAN2CTF.background attribute");
                                d.put("snr", EMObject::FLOATARRAY, "Squared amplitude divided by squared noise amplitude. As in, what is the EMAN2CTF.snr attribute");
                                d.put("boost", EMObject::FLOAT, "Multiplicative signal boost");
                                return d;
                        }
static Processor* EMAN::CTFSNRWeightProcessor::NEW ( ) [inline, static]

Definition at line 6402 of file processor.h.

                        {
                                return new CTFSNRWeightProcessor();
                        }
void CTFSNRWeightProcessor::process_inplace ( EMData image) [virtual]

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.

Parameters:
imageThe image to be processed.

Implements EMAN::Processor.

Definition at line 7484 of file processor.cpp.

References EMAN::EMData::ap2ri(), EMAN::EMData::calc_radial_dist(), EMAN::EMData::copy(), EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), InvalidParameterException, EMAN::EMData::is_complex(), EMAN::length(), nx, EMAN::Processor::params, EMAN::EMData::process_inplace(), EMAN::EMData::ri2ap(), EMAN::EMData::ri2inten(), EMAN::Dict::set_default(), sqrt(), x, and y.

                                                         {
        if (params.has_key("noise")==false) throw InvalidParameterException("You must supply the noise argument");
        if (params.has_key("snr")==false) throw InvalidParameterException("You must supply the snr argument");

        float boost = params.set_default("boost",1.0f);

        if (!image->is_complex()) {
                image->do_fft_inplace();
        }
        EMData* cpy = image->copy();
        cpy->ri2inten();
        vector<float> sf = cpy->calc_radial_dist(cpy->get_ysize()/2,0.0,1.0,1);
        transform(sf.begin(),sf.end(),sf.begin(),sqrtf);
        delete cpy;

        image->ri2ap();

        vector<float> noise = params["noise"];
        vector<float> snr = params["snr"];

//      copy(snr.begin(), snr.end(), ostream_iterator<float>(cout, "\n"));
//      copy(noise.begin(), noise.end(), ostream_iterator<float>(cout, "\n"));

        for(vector<float>::iterator it = noise.begin(); it != noise.end(); ++it){
                if ((*it) == 0) *it = 1;
        }
        for(vector<float>::iterator it = snr.begin(); it != snr.end(); ++it){
                if ((*it) < 0) *it = 0;
        }
        // Subtract the mean from the data and store it in data_mm
        transform(snr.begin(),snr.end(),noise.begin(),snr.begin(),std::multiplies<float>());
        transform(snr.begin(),snr.end(),snr.begin(),sqrtf);
//      copy(snr.begin(), snr.end(), ostream_iterator<float>(cout, "\n"));
//      copy(noise.begin(), noise.end(), ostream_iterator<float>(cout, "\n"));

        int i = static_cast<int>(snr.size());

        float * d = image->get_data();
        int nx = image->get_xsize();
//      int ny = image->get_ysize();
        int nxy = image->get_ysize()*nx;
        int nzon2 = image->get_zsize()/2;
        int nyon2 = image->get_ysize()/2;
        float rx, ry, rz, amp;
        int length;
        int twox;
        image->process_inplace("xform.fourierorigin.tocenter");
        for (int z = 0; z< image->get_zsize(); ++z) {
                for (int y = 0; y < image->get_ysize(); ++y) {
                        for (int x = 0; x < image->get_xsize()/2; ++x) {
                                rx = (float)x;
                                ry = (float)nyon2 - (float)y;
                                rz = (float)nzon2 - (float)z;
                                length = static_cast<int>(sqrt(rx*rx + ry*ry + rz*rz));

                                twox = 2*x;
                                size_t idx1 = twox + y*nx+(size_t)z*nxy;
                                if (length >= i || length >= (int)sf.size()) {
                                        d[idx1] = 0;
                                        continue;
                                } else {
                                        amp = boost*snr[length];
//                                      if (amp > 0) amp =sqrtf(amp);
//                                      else amp = 0;
                                }

                                if (sf[length] == 0) {
                                        d[idx1] = 0;
                                        continue;
                                }

//                              size_t idx2 = idx1 + 1;
//                              cout << d[idx1] << " " << sf[length] << endl;
                                d[idx1] /= sf[length];
                                if (d[idx1] < 0) {
                                        d[idx1] *= amp;
                                }else {
                                        d[idx1] *= -amp;
                                }
//                              d[idx2] = phase;

                        }
                }
        }

        image->ap2ri();
        if (image->get_ndim() != 1) image->process_inplace("xform.fourierorigin.tocorner");
        image->do_ift_inplace();
        image->depad();
}

Member Data Documentation

const string CTFSNRWeightProcessor::NAME = "ctf.snr.weight" [static]

Definition at line 6416 of file processor.h.

Referenced by get_name().


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