Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ProgResolutionFsc Class Reference

#include <resolution_fsc.h>

Inheritance diagram for ProgResolutionFsc:
Inheritance graph
[legend]
Collaboration diagram for ProgResolutionFsc:
Collaboration graph
[legend]

Public Member Functions

void defineParams ()
 
void readParams ()
 
void writeFiles (const FileName &fnRoot, const MultidimArray< double > &freq, const MultidimArray< double > &frc, const MultidimArray< double > &frc_noise, const MultidimArray< double > &dpr, const MultidimArray< double > &error_l2, double max_sam, bool do_dpr, double rFactor)
 
bool process_img ()
 
bool process_sel ()
 
void run ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_ref
 
FileName fn_root
 
FileName fn_img
 
FileName fn_out
 
double sam
 
double max_sam
 
double min_sam
 
bool do_dpr
 
bool do_set_of_images
 
bool do_o
 
bool do_rfactor
 
FileName fn_sel
 
bool apply_geo
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Definition at line 33 of file resolution_fsc.h.

Member Function Documentation

◆ defineParams()

void ProgResolutionFsc::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 30 of file resolution_fsc.cpp.

31 {
32  apply_geo = true;
33 
34  addUsageLine("Calculate the resolution of one or more volumes or images with respect to a single reference.");
35  addUsageLine("+ ");
36  addUsageLine("+Three methods are employed:");
37  addUsageLine("+ ");
38  addUsageLine("+* Differential Phase Residual (DPR)",true);
39  addUsageLine("+In this method the the resolution is defined as the spatial frequency at which the average phase");
40  addUsageLine("+discrepancy between the two transforms exceeds 45 degrees.");
41  addUsageLine("+* Fourier Ring Correlation (FRC)", true);
42  addUsageLine("+In this method the resolution is defined as the spatial frequency at which annular samplings of");
43  addUsageLine("+the two Fourier transforms register negligible cross-correlation.");
44  addUsageLine("+* Spectral Signal-to-Noise Ratio (SSNR)", true);
45  addUsageLine("+This method is based on the measurement of the signal-to-noise ratio as a function of spatial");
46  addUsageLine("+frequency. The SSNR is determined by comparing the Fourier transform of individual images with ");
47  addUsageLine("+that of the global average image. (this option is only available for 2D images not for volumes,");
48  addUsageLine("+ see the program ssnr if you are interested in computing the signal to noise ratio in 3D).");
49  addUsageLine("+ ");
50  addUsageLine("+To calculate \"the resolution of a reconstruction\", use --set_of_images, where the program divides the");
51  addUsageLine("+corresponding set of projection images into two subsets and reconstructs two volumes from these subsets.");
52  addUsageLine("+This program may then be used to calculate the DPR and FRC between these two volumes. The resulting plots");
53  addUsageLine("+are commonly used to assess the high-resolution limit of the initial reconstruction (see Frank's book for more details).");
54  addUsageLine(" ");
55  addUsageLine("The program writes out filename.frc files, for each input volume or image, or selfilename.frc, the");
56  addUsageLine("set_of_images mode. These ACSII files contain the DPR, FRC and SSNR as a function of resolution (in 1/Angstrom).");
57  addUsageLine(" The .frc files also contain a column for the FRC expected for pure noise.");
58 
59  addParamsLine(" -i <input_file> : either an image/volume or a selection file");
60  addParamsLine(" requires --ref;");
61  addParamsLine("or --set_of_images <selfile> : selfile containing a set of 2D-images");
62  addParamsLine(" [--oroot <root_file=\"\">] : Root of the output metadata. If not set, input file rootname is taken.");
63  addParamsLine(" [-o <output_file=\"\">] : Output file name.");
64 
65  addParamsLine(" [--ref <input_file>] : filename for reference image/volume");
66  addParamsLine(" [--sampling_rate <Ts=1>] : Pixel size (Angstrom)");
67  addParamsLine(" alias -s;");
68  addParamsLine(" [--dont_apply_geo] : for 2D-images: do not apply transformation stored in the header");
69  addParamsLine(" [--do_dpr] : compute dpr, by default only frc is computed");
70  addParamsLine(" [--max_sam <max_sr=-1>] : set fsc to 0 for frequencies above this one (Angstrom), -1 -> all fequencies");
71  addParamsLine(" : --max_sam = 10A -> frequencies higher than 0.1 A^-1 =0");
72  //for R-factor
73  addParamsLine(" [--do_rfactor] : compute R-factor for input volumes");
74  addParamsLine(" [--min_sam <min_sr=-1>] : minimum frequency may use for calculating R-factor (Angstrom)");
75  addParamsLine(" : --min_sam = 10A -> frequencies smaller than 0.1 A^-1 =0");
76 
77  addExampleLine("Resolution of subset2.vol volume with respect to subset1.vol reference volume using 5.6 pixel size (in Angstrom):", false);
78  addExampleLine("xmipp_resolution_fsc --ref subset1.vol -i subset2.vol --sampling_rate 5.6 ");
79  addExampleLine("Resolution of a set of images using 5.6 pixel size (in Angstrom):", false);
80  addExampleLine("xmipp_resolution_fsc --set_of_images selfile.sel --sampling_rate 5.6");
81 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ process_img()

bool ProgResolutionFsc::process_img ( )

Definition at line 166 of file resolution_fsc.cpp.

167 {
168  Image<double> refI,img;
169  //if (apply_geo)
170  // refI.readApplyGeo(fn_ref);
171  //else
172  refI.read(fn_ref);
173  refI().setXmippOrigin();
174  //if (apply_geo)
175  // img.readApplyGeo(fn_img);
176  //else
177  img.read(fn_img);
178  img().setXmippOrigin();
179 
180  MultidimArray<double> freq, frc, dpr, frc_noise, error_l2;
181  double rFactor=-1.;
182  double min_samp = sam/min_sam;
183  if (min_sam <0)
184  min_samp = 0.;
185  if (max_sam <0)
186  max_sam = 2 * sam;
187 
188  frc_dpr(refI(), img(), sam, freq, frc, frc_noise, dpr, error_l2, do_dpr, do_rfactor, min_samp, sam/max_sam, &rFactor);
189 
190  writeFiles((fn_root.empty())?img.name():fn_root, freq, frc, frc_noise, dpr, error_l2, max_sam, do_dpr, rFactor);
191  return true;
192 }
void writeFiles(const FileName &fnRoot, const MultidimArray< double > &freq, const MultidimArray< double > &frc, const MultidimArray< double > &frc_noise, const MultidimArray< double > &dpr, const MultidimArray< double > &error_l2, double max_sam, bool do_dpr, double rFactor)
void frc_dpr(MultidimArray< double > &m1, MultidimArray< double > &m2, double sampling_rate, MultidimArray< double > &freq, MultidimArray< double > &frc, MultidimArray< double > &frc_noise, MultidimArray< double > &dpr, MultidimArray< double > &error_l2, bool dodpr, bool doRfactor, double minFreq, double maxFreq, double *rFactor)
Definition: xmipp_fftw.cpp:491
const FileName & name() const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)

◆ process_sel()

bool ProgResolutionFsc::process_sel ( )

Definition at line 194 of file resolution_fsc.cpp.

195 {
196  MetaDataDb MD(fn_sel), MDout;
197  MultidimArray<double> freq, frc, dpr, frc_noise, ssnr, error_l2;
198  getFourierStatistics(MD, sam, MDout, do_dpr, max_sam);
199  FileName fnRoot=(fn_root.empty())?fn_sel:fn_root;
200  MDout.write(fnRoot+".frc");
201  return true;
202 }
void getFourierStatistics(MetaDataDb &MDin, double sam, MetaData &MDout, bool do_dpr, double max_sam, MDLabel image_label)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const override

◆ readParams()

void ProgResolutionFsc::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippProgram.

Definition at line 83 of file resolution_fsc.cpp.

84 {
85  sam = getDoubleParam("--sampling_rate");
86 
87  apply_geo = !checkParam("--dont_apply_geo");
88 
89  max_sam = getDoubleParam("--max_sam");
90  do_dpr = checkParam("--do_dpr");
91  do_set_of_images = checkParam("--set_of_images");
92  //for calculating r-factor
93  min_sam = getDoubleParam("--min_sam");
94  do_rfactor = checkParam("--do_rfactor");
95 
97  {
98  fn_sel = getParam("--set_of_images");
99  if (checkParam("-i") || checkParam("--ref"))
100  REPORT_ERROR(ERR_ARG_INCORRECT, "--set_of_images should not be provided with -i or --ref");
101  }
102  else
103  {
104  fn_ref = getParam("--ref");
105  fn_img = getParam("-i");
106  }
107 
108  do_o = checkParam("-o");
109  if (do_o)
110  fn_out = getParam("-o");
111  else
112  fn_root = getParam("--oroot");
113 }
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
const char * getParam(const char *param, int arg=0)
Incorrect argument received.
Definition: xmipp_error.h:113
bool checkParam(const char *param)

◆ run()

void ProgResolutionFsc::run ( )
virtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 204 of file resolution_fsc.cpp.

205 {
206  if (!do_set_of_images)
207  process_img();
208  else
209  process_sel();
210 }

◆ writeFiles()

void ProgResolutionFsc::writeFiles ( const FileName fnRoot,
const MultidimArray< double > &  freq,
const MultidimArray< double > &  frc,
const MultidimArray< double > &  frc_noise,
const MultidimArray< double > &  dpr,
const MultidimArray< double > &  error_l2,
double  max_sam,
bool  do_dpr,
double  rFactor 
)

Definition at line 115 of file resolution_fsc.cpp.

122 {
123  MetaDataVec MD;
124 
125  FileName fn_frc;
126  if (do_o)
127  fn_frc = fn_out;
128  else
129  fn_frc = fnRoot + ".frc";
130  size_t id;
132  {
133  if (i>0)
134  {
135  id=MD.addObject();
136  if(max_sam >0 && ((1./dAi(freq, i))<max_sam) )
137  {
138  if(do_dpr)
139  dAi(dpr, i)=0.;
140  dAi(frc, i)=0.;
141  }
142  if(min_sam >0 && ((1./dAi(freq, i))>min_sam) )
143  {
144  if(do_dpr)
145  dAi(dpr, i)=0.;
146  dAi(frc, i)=0.;
147  }
148  MD.setValue(MDL_RESOLUTION_FREQ,dAi(freq, i),id);
149  MD.setValue(MDL_RESOLUTION_FRC,dAi(frc, i),id);
150  if(do_dpr)
151  MD.setValue(MDL_RESOLUTION_DPR,dAi(dpr, i),id);
152  MD.setValue(MDL_RESOLUTION_ERRORL2,dAi(error_l2, i),id);
153  MD.setValue(MDL_RESOLUTION_FRCRANDOMNOISE,dAi(frc_noise, i),id);
154  MD.setValue(MDL_RESOLUTION_FREQREAL,1./dAi(freq, i),id);
155  }
156  }
157  MD.write(fn_frc);
158  MetaDataVec MD2;
159  MD2.setColumnFormat(false);
160  id=MD2.addObject();
161  MD2.setValue(MDL_RESOLUTION_RFACTOR,rFactor,id);
162  fn_frc.compose("rfactor", fn_frc);
163  MD2.write(fn_frc, MD_APPEND);
164 }
#define dAi(v, i)
void compose(const String &str, const size_t no, const String &ext="")
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
#define i
differential phase residual (double)
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Frequency in A (double)
Frequency in 1/A (double)
virtual void setColumnFormat(bool column)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
Error in l2 (double)
Fourier shell correlation noise (double)
Fourier shell correlation (double)

Member Data Documentation

◆ apply_geo

bool ProgResolutionFsc::apply_geo

Definition at line 43 of file resolution_fsc.h.

◆ do_dpr

bool ProgResolutionFsc::do_dpr

Definition at line 40 of file resolution_fsc.h.

◆ do_o

bool ProgResolutionFsc::do_o

Definition at line 40 of file resolution_fsc.h.

◆ do_rfactor

bool ProgResolutionFsc::do_rfactor

Definition at line 40 of file resolution_fsc.h.

◆ do_set_of_images

bool ProgResolutionFsc::do_set_of_images

Definition at line 40 of file resolution_fsc.h.

◆ fn_img

FileName ProgResolutionFsc::fn_img

Definition at line 37 of file resolution_fsc.h.

◆ fn_out

FileName ProgResolutionFsc::fn_out

Definition at line 37 of file resolution_fsc.h.

◆ fn_ref

FileName ProgResolutionFsc::fn_ref

Definition at line 37 of file resolution_fsc.h.

◆ fn_root

FileName ProgResolutionFsc::fn_root

Definition at line 37 of file resolution_fsc.h.

◆ fn_sel

FileName ProgResolutionFsc::fn_sel

Definition at line 42 of file resolution_fsc.h.

◆ max_sam

double ProgResolutionFsc::max_sam

Definition at line 39 of file resolution_fsc.h.

◆ min_sam

double ProgResolutionFsc::min_sam

Definition at line 39 of file resolution_fsc.h.

◆ sam

double ProgResolutionFsc::sam

Definition at line 38 of file resolution_fsc.h.


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