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

This is a FSC comparitor for tomography. More...

#include <cmp.h>

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

Public Member Functions

virtual float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters. More...
 
virtual string get_name () const
 Get the Cmp's name. More...
 
virtual string get_desc () const
 
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary. More...
 
- Public Member Functions inherited from EMAN::Cmp
virtual ~Cmp ()
 
virtual Dict get_params () const
 Get the Cmp parameters in a key/value dictionary. More...
 
virtual void set_params (const Dict &new_params)
 Set the Cmp parameters using a key/value dictionary. More...
 

Static Public Member Functions

static CmpNEW ()
 

Static Public Attributes

static const string NAME = "fsc.tomo"
 

Additional Inherited Members

- Protected Member Functions inherited from EMAN::Cmp
void validate_input_args (const EMData *image, const EMData *with) const
 
- Protected Attributes inherited from EMAN::Cmp
Dict params
 

Detailed Description

This is a FSC comparitor for tomography.

I only counts voxels above a threshold, which is obtained from subtomogram metadata

Author
John Flanagan
Date
2012-2-02
Parameters
sigmasThe number of times the standard deviation of Fourier amplitudes to accept
minresThe minimum resolution to accept
maxesThe maximum resolution to accept
apixThe angstroms per pixel to use

Definition at line 447 of file cmp.h.

Member Function Documentation

◆ cmp()

float TomoFscCmp::cmp ( EMData image,
EMData with 
) const
virtual

To compare 'image' with another image passed in through its parameters.

An optional transformation may be used to transform the 2 images.

Parameters
imageThe first image to be compared.
withThe second image to be comppared.
Returns
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 856 of file cmp.cpp.

857{
858 ENTERFUNC;
859 bool usecpu = 1;
860 bool del_imagefft = 0;
861 bool del_withfft = 0;
862 float score = 1.0f;
863
864 //get parameters
865 if (!image->has_attr("spt_wedge_mean") || !image->has_attr("spt_wedge_sigma")) throw InvalidCallException("Rubbish!!! Image Subtomogram does not have mena and/or sigma amps metadata");
866 // BAD DESIGN!!!! The fact that I have to load attrs into a variable before I can do operations on them is silly
867
868 //get threshold information
869 float image_meanwedgeamp = image->get_attr("spt_wedge_mean");
870 float image_sigmawedgeamp = image->get_attr("spt_wedge_sigma");
871
872 // Use with amp stats if avaliable otherwise effectivly ignore
873 float with_meanwedgeamp = image_meanwedgeamp;
874 float with_sigmawedgeamp = image_sigmawedgeamp;
875 if (with->has_attr("spt_wedge_mean") && with->has_attr("spt_wedge_sigma"))
876 {
877 with_meanwedgeamp = with->get_attr("spt_wedge_mean");
878 with_sigmawedgeamp = with->get_attr("spt_wedge_sigma");
879 }
880
881 float apix = params.set_default("apix",image->get_attr_default("apix_x", 1.0f));
882 //get min and max res
883 float minres = params.set_default("minres",std::numeric_limits<float>::max());
884 float maxres = params.set_default("maxres", 0.0f);
885
886 // Find threshold
887 float sigmas = params.set_default("sigmas",5.0f);
888 float img_amp_thres = pow(image_meanwedgeamp + sigmas*image_sigmawedgeamp, 2.0f);
889 float with_amp_thres = pow(with_meanwedgeamp + sigmas*with_sigmawedgeamp, 2.0f);
890
891 // take negative of score
892 float negative = (float)params.set_default("negative", 1.0f);
893 if (negative) negative=-1.0; else negative=1.0;
894 //get apix, use param apix, if not specified use apix_x, if this is not specified then apix=1.0
895
896 //Check to ensure that images are complex
897 EMData* image_fft = image;
898 EMData* with_fft = with;
899
900#ifdef EMAN2_USING_CUDA
901 //do CUDA FFT, does not allow minres, maxres yet
902 if(EMData::usecuda == 1 && image->getcudarwdata() && with->getcudarwdata()) {
903 if(!image->is_complex()){
904 del_imagefft = 1;
905 image_fft = image->do_fft_cuda();
906 }
907 if(!with->is_complex()){
908 del_withfft = 1;
909 with_fft = with->do_fft_cuda();
910 }
911 score = fsc_tomo_cmp_cuda(image_fft->getcudarwdata(), with_fft->getcudarwdata(), img_amp_thres, with_amp_thres, 0.0, 0.0, image_fft->get_xsize(), image_fft->get_ysize(), image_fft->get_zsize());
912 usecpu = 0;
913 }
914#endif
915 if(usecpu){
916 if(!image->is_complex()){
917 del_imagefft = 1;
918 image_fft = image->do_fft();
919 }
920 if(!with->is_complex()){
921 del_withfft = 1;
922 with_fft = with->do_fft();
923 }
924
925 //loop over all voxels
926 int count = 0;
927 double sum_imgamp_sq = 0.0;
928 double sum_withamp_sq = 0.0;
929 double cong = 0.0;
930 float* img_data = image_fft->get_data();
931 float* with_data = with_fft->get_data();
932
933 int nx = image_fft->get_xsize();
934 int ny = image_fft->get_ysize();
935 int nz = image_fft->get_zsize();
936 int ny2 = ny/2;
937 int nz2 = nz/2;
938
939 //compute FSC
940 int ii, kz, ky;
941 for (int iz = 0; iz < nz; iz++) {
942 if(iz > nz2) kz = nz-iz; else kz=iz;
943 for (int iy = 0; iy < ny; iy++) {
944 if(iy > ny2) ky = ny-iy; else ky=iy;
945 for (int ix = 0; ix < nx; ix+=2) {
946 //compute spatial frequency and convert to resolution stat
947 float freq = std::sqrt(kz*kz + ky*ky + ix*ix/4.0f)/float(nz);
948 float reso = apix/freq;
949
950 //only look within a resolution domain
951 if(reso < minres && reso > maxres){
952 ii = ix + (iy + iz * ny)* nx;
953 float img_r = img_data[ii];
954 float img_i = img_data[ii+1];
955 float with_r = with_data[ii];
956 float with_i = with_data[ii+1];
957 double img_amp_sq = img_r*img_r + img_i*img_i;
958 double with_amp_sq = with_r*with_r + with_i*with_i;
959
960 if((img_amp_sq > img_amp_thres) && (with_amp_sq > with_amp_thres)){
961 count ++;
962 sum_imgamp_sq += img_amp_sq;
963 sum_withamp_sq += with_amp_sq;
964 cong += img_r*with_r + img_i*with_i;
965 }
966 }
967 }
968 }
969 }
970
971 if(count > 0){
972 score = (float)(cong/sqrt(sum_imgamp_sq*sum_withamp_sq));
973 }else{
974 score = 1.0f;
975 }
976 }
977
978 //avoid mem leaks
979 if(del_imagefft) delete image_fft;
980 if(del_withfft) delete with_fft;
981
982 return negative*score;
983 EXITFUNC;
984}
Dict params
Definition: cmp.h:132
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
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
float fsc_tomo_cmp_cuda(const float *data1, const float *data2, const float data1threshold, const float data2threshold, const float minres, const float maxres, const int nx, const int ny, const int nz)
EMData * sqrt() const
return square root of current image
#define InvalidCallException(desc)
Definition: exception.h:348
#define ENTERFUNC
Definition: log.h:48
#define EXITFUNC
Definition: log.h:49

References ENTERFUNC, EXITFUNC, fsc_tomo_cmp_cuda(), InvalidCallException, EMAN::Cmp::params, EMAN::Dict::set_default(), and sqrt().

◆ get_desc()

virtual string EMAN::TomoFscCmp::get_desc ( ) const
inlinevirtual

Implements EMAN::Cmp.

Definition at line 457 of file cmp.h.

458 {
459 return "EXPERIMENTAL - Fsc with consideration given for the missing wedge. Not ready for routine use.";
460 }

◆ get_name()

virtual string EMAN::TomoFscCmp::get_name ( ) const
inlinevirtual

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 452 of file cmp.h.

453 {
454 return NAME;
455 }
static const string NAME
Definition: cmp.h:478

References NAME.

◆ get_param_types()

TypeDict EMAN::TomoFscCmp::get_param_types ( ) const
inlinevirtual

Get Cmp 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.

Implements EMAN::Cmp.

Definition at line 467 of file cmp.h.

468 {
469 TypeDict d;
470 d.put("normalize", EMObject::EMDATA,"Return the negative value (which is EMAN2 convention), Defalut is true(1)");
471 d.put("sigmas", EMObject::FLOAT, "The number of times the standard deviation of Fourier amplitudes to accept");
472 d.put("minres", EMObject::FLOAT, "The minimum resolution to accept (1/A) Default is inf");
473 d.put("maxres", EMObject::FLOAT, "The maximum resolution to accept (1/A) Default=0.0");
474 d.put("apix", EMObject::FLOAT, "The angstroms per pixel to use. Default = apix_x(1.0 if not present)");
475 return d;
476 }

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

◆ NEW()

static Cmp * EMAN::TomoFscCmp::NEW ( )
inlinestatic

Definition at line 462 of file cmp.h.

463 {
464 return new TomoFscCmp();
465 }

Member Data Documentation

◆ NAME

const string TomoFscCmp::NAME = "fsc.tomo"
static

Definition at line 478 of file cmp.h.

Referenced by get_name().


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