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

#include <ctf_sort_psds.h>

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

Public Member Functions

 ProgPSDSort ()
 Downsampling factor used for the PSDs. More...
 
void defineLabelParam ()
 
void readParams ()
 
void defineParams ()
 
void show ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
- Public Member Functions inherited from XmippMetadataProgram
MetaDatagetInputMd ()
 
MetaDataVecgetOutputMd ()
 
 XmippMetadataProgram ()
 Empty constructor. More...
 
virtual int tryRead (int argc, const char **argv, bool reportErrors=true)
 
virtual void init ()
 
virtual void setup (MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
 
virtual ~XmippMetadataProgram ()
 
void setMode (WriteModeMetaData _mode)
 
void setupRowOut (const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
 Prepare rowout. More...
 
virtual void wait ()
 Wait for the distributor to finish. More...
 
virtual void checkPoint ()
 For very long programs, it may be needed to write checkpoints. More...
 
virtual void run ()
 Run over all images. More...
 
- 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)
 
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 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

double filter_w1
 Bandpass filter low frequency (in Fourier space, max 0.5) More...
 
double filter_w2
 Bandpass filter high frequency (in Fourier space, max 0.5) More...
 
double decay_width
 Decay width (raised cosine) More...
 
double mask_w1
 Lower frequency for the mask (in Fourier space, max 0.5) More...
 
double mask_w2
 Higher frequency for the mask (in Fourier space, max 0.5) More...
 
- Public Attributes inherited from XmippMetadataProgram
FileName fn_in
 Filenames of input and output Metadata. More...
 
FileName fn_out
 
FileName baseName
 
FileName pathBaseName
 
FileName oextBaseName
 
bool apply_geo
 Apply geo. More...
 
size_t ndimOut
 Output dimensions. More...
 
size_t zdimOut
 
size_t ydimOut
 
size_t xdimOut
 
DataType datatypeOut
 
size_t mdInSize
 Number of input elements. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual void preProcess ()
 
virtual void postProcess ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void finishProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippMetadataProgram
WriteModeMetaData mode
 Metadata writing mode: OVERWRITE, APPEND. More...
 
FileName oext
 Output extension and root. More...
 
FileName oroot
 
MDLabel image_label
 MDLabel to be used to read/write images, usually will be MDL_IMAGE. More...
 
bool produces_an_output
 Indicate that a unique final output is produced. More...
 
bool produces_a_metadata
 Indicate that the unique final output file is a Metadata. More...
 
bool each_image_produces_an_output
 Indicate that an output is produced for each image in the input. More...
 
bool allow_apply_geo
 
bool decompose_stacks
 Input Metadata will treat a stack file as a set of images instead of a unique file. More...
 
bool delete_output_stack
 Delete previous output stack file prior to process images. More...
 
bool get_image_info
 Get the input image file dimensions to further operations. More...
 
bool save_metadata_stack
 Save the associated output metadata when output file is a stack. More...
 
bool track_origin
 Include the original input image filename in the output stack. More...
 
bool keep_input_columns
 Keep input metadata columns. More...
 
bool remove_disabled
 Remove disabled images from the input selfile. More...
 
bool allow_time_bar
 Show process time bar. More...
 
bool input_is_metadata
 Input is a metadata. More...
 
bool single_image
 Input is a single image. More...
 
bool input_is_stack
 Input is a stack. More...
 
bool output_is_stack
 Output is a stack. More...
 
bool create_empty_stackfile
 
bool delete_mdIn
 
size_t time_bar_step
 Some time bar related counters. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
- 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

Parameter class for the project program

Definition at line 61 of file ctf_sort_psds.h.

Constructor & Destructor Documentation

◆ ProgPSDSort()

ProgPSDSort::ProgPSDSort ( )

Downsampling factor used for the PSDs.

Empty constructor

Definition at line 34 of file ctf_sort_psds.cpp.

35 {
36  produces_an_output=true;
38  keep_input_columns=true;
39 }
bool produces_an_output
Indicate that a unique final output is produced.
bool keep_input_columns
Keep input metadata columns.
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.

Member Function Documentation

◆ defineLabelParam()

void ProgPSDSort::defineLabelParam ( )
virtual

Use micrographs for iterating in the metadata

Reimplemented from XmippMetadataProgram.

Definition at line 41 of file ctf_sort_psds.cpp.

42 {
43  addParamsLine(" [--label+ <image_label=micrograph>] : Label to be used to read/write images.");
44 }
void addParamsLine(const String &line)

◆ defineParams()

void ProgPSDSort::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgPSDSort >.

Definition at line 59 of file ctf_sort_psds.cpp.

60 {
62  addUsageLine("Evaluate the CTFs and PSDs of a set of micrographs.");
63  addUsageLine("This process is strongly coupled to the output produced by the preprocessing micrographs step of the Xmipp protocols. ");
64  addUsageLine("For each input PSD, the program writes its enhanced version since it is used in the computation of some of the criteria.");
65  addUsageLine("+The different criteria for evaluating the PSDs are:");
66  addUsageLine("+ ");
67  addUsageLine("+$ *Damping*: this is the envelope value at the border of the PSD. Micrographs ");
68  addUsageLine("+with a high envelope value at border are either wrongly estimated strongly undersampled.");
69  addUsageLine("+ ");
70  addUsageLine("+$ *First zero average*: this is average in Angstroms of the first zero. ");
71  addUsageLine("+Normally, this value should be between 4x and 10x the sampling rate in Angstroms.");
72  addUsageLine("+ ");
73  addUsageLine("+$ *Maximum frequency*: this is the resolution (in Angstroms) at which the envelope drops below 1% of the maximum envelope");
74  addUsageLine("+ ");
75  addUsageLine("+$ *First zero disagreement*: if the CTF has been estimated by two different methods ");
76  addUsageLine("+(normally Xmipp and Ctffind), then this criterion measures the average disagreement ");
77  addUsageLine("+in Angstroms between the first zero in the two estimates. Low disagreements are ");
78  addUsageLine("+indicative of correct fit.");
79  addUsageLine("+ ");
80  addUsageLine("+$ *First zero ratio*: this measures the astigmatism of the CTF by computing the ratio ");
81  addUsageLine("+between the largest and smallest axes of the first zero ellipse. Ratios close to 1 ");
82  addUsageLine("+indicate no astigmatism.");
83  addUsageLine("+ ");
84  addUsageLine("+$ *Ratio between the standard deviation at 1st zero and 1st minimum*: the variance in the experimental PSD along the");
85  addUsageLine("+first zero and the first CTF minimum should be approximately equal (ratio=1).");
86  addUsageLine("+ ");
87  addUsageLine("+$ *CTF margin*: ratio between the average difference in the experimental PSD between the 1st Thon");
88  addUsageLine("+ring and its previous zero, and the variance of the experimental PSD along the first zero");
89  addUsageLine("+first zero and the first CTF minimum should be approximately equal (ratio=1).");
90  addUsageLine("+ ");
91  addUsageLine("+$ *Fitting score*: the CTF is computed by fitting a theoretical model to the experimentally observed PSD. ");
92  addUsageLine("+This criterion is the fitting score. Smaller scores correspond to better fits.");
93  addUsageLine("+ ");
94  addUsageLine("+$ *Fitting correlation between zeros 1 and 3*: the region between the first and third zeroes ");
95  addUsageLine("+is particularly important since it is where the Thon rings are most visible. ");
96  addUsageLine("+This criterion reports the correlation between the experimental and theoretical PSDs ");
97  addUsageLine("+within this region. High correlations indicate good fits.");
98  addUsageLine("+ ");
99  addUsageLine("+$ *Non-astigmatic validity*: if we consider the CTF cosine part in the direction U and V ");
100  addUsageLine("+and add both as if they were waves, this criterion shows the frequency (in Angstroms) at which ");
101  addUsageLine("+both waves would interfere completely destructively. Beyond this frequency, it cannot be assumed that ");
102  addUsageLine("+a non-astigmatic CTF correction can manage an astigmatic CTF");
103  addUsageLine("+ ");
104  addUsageLine("+$ *PSD correlation at 90 degrees*: The PSD of non-astigmatic micrographs correlate well ");
105  addUsageLine("+with itself after rotating the micrograph 90 degrees. This is so because non-astigmatic ");
106  addUsageLine("+PSDs are circularly symmetrical, while astigmatic micrographs are elliptically symmetrical.");
107  addUsageLine("+High correlation when rotating 90 degrees is an indicator of non-astigmatism.");
108  addUsageLine("+This criterion is computed on the enhanced PSD. See [[ctf_enhance_psd_v3][ctf_enhance_psd]].");
109  addUsageLine("+ ");
110  addUsageLine("+$ *PSD radial integral*: this criterion reports the integral of the radially symmetrized PSD.");
111  addUsageLine("+This criterion can highlight differences among the background noises of micrographs. ");
112  addUsageLine("+This criterion is computed on the enhanced PSD. See [[ctf_enhance_psd_v3][ctf_enhance_psd]].");
113  addUsageLine("+ ");
114  addUsageLine("+$ *PSD variance*: the PSD is estimated by averaging different PSD local estimates in small regions of the micrograph. ");
115  addUsageLine("+This criterion measures the variance of the different PSD local estimates. Untilted micrographs ");
116  addUsageLine("+have equal defoci all over the micrograph, and therefore, the variance is due only to noise. ");
117  addUsageLine("+However, tilted micrographs have an increased PSD variance since different regions of the micrograph ");
118  addUsageLine("+have different defoci. Low variance of the PSD are indicative of non-tilted micrographs");
119  addUsageLine("+ ");
120  addUsageLine("+$ *PSD Principal Component 1 Variance*: when considering the local PSDs previously defined as vectors ");
121  addUsageLine("+in a multidimensional space, we can compute the variance of their projection onto the first principal component axis. ");
122  addUsageLine("+Low variance of this projection is indicative of a uniformity of local PSDs, i.e., this is another measure ");
123  addUsageLine("+of the presence of tilt in the micrograph.");
124  addUsageLine("+ ");
125  addUsageLine("+$ *PSD !PCA Runs test*: when computing the projections onto the first principal component, as discussed in the previous criterion, ");
126  addUsageLine("+one might expect that the sign of the projection is random for untilted micrographs. Micrographs with a marked ");
127  addUsageLine("+non-random pattern of projections are indicative of tilted micrographs. The larger the value of this criterion, the less random the pattern is.");
128  addParamsLine("==+ Enhancement filter parameters");
129  addParamsLine(" [-f1 <freq_low=0.02>] : Low freq. for band pass filtration, max 0.5");
130  addParamsLine(" [-f2 <freq_high=0.2>] : High freq. for band pass filtration, max 0.5");
131  addParamsLine(" [-decay <freq_decay=0.02>] : Decay for the transition bands");
132  addParamsLine(" [-m1 <mfreq_low=0.01>] : Low freq. for mask, max 0.5");
133  addParamsLine(" [-m2 <mfreq_high=0.45>] : High freq. for mask, max 0.5");
134  // COSS addParamsLine(" [--downsampling <K=1>] : Downsampling factor used");
135 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ processImage()

void ProgPSDSort::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
virtual

Process micrograph

Implements XmippMetadataProgram.

Definition at line 153 of file ctf_sort_psds.cpp.

154 {
155  CTFDescription CTF1, CTF2;
156  PSDEvaluation evaluation;
157  FileName fnMicrograph, fnPSD, fnCTF, fnCTF2;
158 
159  evaluation.ctf_envelope_ssnr = fn_in.getDir()+"envelope.xmd";
160 
161  int enabled;
162  rowIn.getValue(MDL_ENABLED,enabled);
163  rowIn.getValue(MDL_MICROGRAPH, fnMicrograph);
164  rowIn.getValue(MDL_PSD,fnPSD);
165  if (enabled==-1 || fnPSD == "NA")
166  {
167  rowOut.setValue(MDL_ENABLED,-1);
168  return;
169  }
170 
171  if (rowIn.containsLabel(MDL_CTF_MODEL))
172  {
173  rowIn.getValue(MDL_CTF_MODEL, fnCTF);
174  if (!fnCTF.exists())
175  {
176  rowOut.setValue(MDL_ENABLED,-1);
177  return;
178  }
179  CTF1.read(fnCTF);
180  }
181  else
182  CTF1.readFromMdRow(rowIn);
183 
184  FileName fnRoot = fnMicrograph.withoutExtension();
185 
186  CTF1.produceSideInfo();
187  evaluation.defocusU=CTF1.DeltafU;
188  evaluation.defocusV=CTF1.DeltafV;
189 
190 
191  if (rowIn.containsLabel(MDL_CTF_MODEL2))
192  rowIn.getValue(MDL_CTF_MODEL2,fnCTF2);
193 
194  if (!fnCTF2.empty() && fnCTF2 != "NA")
195  {
196  CTF2.read(fnCTF2);
197  CTF2.produceSideInfo();
198  }
199 
200  // Evaluate beating due to astigmatism
201  /* The argument of the cosine part of the CTF is: wu=cos(K1*deltafu*u.^2+K2*u.^4)
202  * If there is no astigmatism, then in the V direction we would have wv=cos(K1*deltafv*u.^2+K2*u.^4)
203  * and we should have (wu+wv)/2 = wu.
204  * If there is astigmatism, the sum (wu+wv)/2 will depart from the behavior of wu
205  * http://en.wikipedia.org/wiki/Beat_%28acoustics%29
206  * calling argu and argv the argument of the two waves, we have
207  *
208  * (wu+wv)/2=cos((argu+argv)/2)cos((argu-argv)/2)
209  *
210  * The term cos((argu-argv)/2) acts as an envelope which may even vanish. Let's analyze this envelope
211  * cos(0.5*(K1*deltafu*u.^2+K2*u.^4-K1*deltafv*u.^2+K2*u.^4))=cos(0.5*K1*abs(deltafu-deltafv)*u^2)
212  *
213  * When this envelope is 0, the interference between the two waves is totally destructive (we cannot apply a
214  * non-astigmatic correction to an astigmatic CTF). This happens for
215  *
216  * 0.5*K1*abs(deltafu-deltafv)*u_0^2=pi/2 ---> u_0=sqrt(PI/(K1*abs(deltafu-deltafv)))
217  *
218  * This is the expression of critBeating
219  */
220  evaluation.beating=1.0/sqrt(PI/(CTF1.K1*abs(CTF1.DeltafU-CTF1.DeltafV)));
221 
222  // Read input PSD data
223  Image<double> PSD;
224  PSD.read(fnPSD);
225 
226  // Enhance the PSD
227  ProgCTFEnhancePSD enhancePSD;
228  enhancePSD.filter_w1 = filter_w1;
229  enhancePSD.filter_w2 = filter_w2;
230  enhancePSD.decay_width = decay_width;
231  enhancePSD.mask_w1 = mask_w1;
232  enhancePSD.mask_w2 = mask_w2;
233  enhancePSD.applyFilter(PSD());
234 
235  // Evaluate the radial integral
236  PSD().setXmippOrigin();
237  Matrix1D< int > center_of_rot(2);
238  MultidimArray< double > radial_mean;
239  MultidimArray<int> radial_count;
240  radialAverage(PSD(),center_of_rot,radial_mean,radial_count);
241  radial_mean.selfABS();
242  radial_mean/=radial_mean.computeMax();
243  evaluation.PSDradialIntegral=radial_mean.sum();
244 
245  // Rotate 90 degrees and compute correlation
246  Image<double> PSDrotated;
247  rotate(xmipp_transformation::LINEAR,PSDrotated(),PSD(),90);
248  evaluation.PSDcorrelation90=correlationIndex(PSD(), PSDrotated());
249 
250  // Get the fitting score and other quality criteria computed by ctf_estimate_from_micrograph
251  MetaDataVec MDctf1;
252  MDctf1.read(fnCTF);
253  size_t objId1 = MDctf1.firstRowId();
254 
255 #define GET_CTF_CRITERION(labelll,xxx) \
256  if (rowIn.containsLabel(labelll)) \
257  rowIn.getValue(labelll,xxx); \
258  else if (MDctf1.containsLabel(labelll)) \
259  MDctf1.getValue(labelll,xxx,objId1); \
260  else \
261  xxx=0;
267 
268  // Explore the CTF
269  Matrix1D<double> u(2), freqZero1(2), freqZero2(2), freqMin1(2), pixelZero1(2), pixelMin1(2);
270  double wmax=0.5/CTF1.Tm;
271  double maxModuleZero=0, minModuleZero=1e38;
272  double N=0;
273  evaluation.maxDampingAtBorder=0;
274  evaluation.firstZeroDisagreement=-1;
275  evaluation.firstZeroAvg=0;
276  double firstZeroAvgPSD=0;
277  double firstZeroStddevPSD=0;
278  double firstMinAvgPSD=0;
279  double firstMinStddevPSD=0;
280  double firstZeroMinAvgPSD=0;
281  double firstZeroMinStddevPSD=0;
282  evaluation.maxFreq=1000;
283 
284  CTF1.precomputeValues(0.0,0.0);
285  double idamping0=1.0/CTF1.getValueDampingAt();
286  double f2pixel=CTF1.Tm*XSIZE(PSD()); // COSS *downsampling
287 
289  {
290  double aux;
292  f2pixel*=aux;
293  }
294 
295  MetaDataVec mdEnvelope;
296  Matrix1D< double > envelope(100);
297  envelope.initZeros();
298  double Nalpha = 180;
299  for (double alpha=0; alpha<=PI; alpha+=PI/Nalpha, N++)
300  {
301  VECTOR_R2(u,cos(alpha),sin(alpha));
302 
303  // Get the zero in the direction of u
304  CTF1.lookFor(1, u, freqZero1, 0);
305  double moduleZero=1.0/freqZero1.module();
306  maxModuleZero=XMIPP_MAX(maxModuleZero,moduleZero);
307  minModuleZero=XMIPP_MIN(minModuleZero,moduleZero);
308  evaluation.firstZeroAvg+=moduleZero;
309 
310  // Get the first minimum (it is at higher frequency than the zero)
311  CTF1.lookFor(1, u, freqMin1, -1);
312  pixelZero1=freqZero1*f2pixel;
313  pixelMin1=freqMin1*f2pixel;
314  double psdZero=PSD().interpolatedElement2D(XX(pixelZero1),YY(pixelZero1),0.0);
315  double psdMin=PSD().interpolatedElement2D(XX(pixelMin1),YY(pixelMin1),0.0);
316  firstMinAvgPSD+=psdMin;
317  firstMinStddevPSD+=psdMin*psdMin;
318  firstZeroAvgPSD+=psdZero;
319  firstZeroStddevPSD+=psdZero*psdZero;
320  double zeroMinDiff=psdMin-psdZero;
321  firstZeroMinAvgPSD+=zeroMinDiff;
322  firstZeroMinStddevPSD+=zeroMinDiff*zeroMinDiff;
323 
324  // Evaluate damping
325  double wx=wmax*XX(u);
326  double wy=wmax*YY(u);
327  CTF1.precomputeValues(wx,wy);
328  double damping=CTF1.getValueDampingAt();
329  damping=damping*damping;
330  evaluation.maxDampingAtBorder=XMIPP_MAX(evaluation.maxDampingAtBorder,damping);
331 
332  int idx = 0;
333  for (double w=0; w<wmax; w+=wmax/99.0)
334  {
335  wx=w*XX(u);
336  wy=w*YY(u);
337  CTF1.precomputeValues(wx,wy);
338  double normalizedDamping=fabs(CTF1.getValueDampingAt()*idamping0);
339  if (normalizedDamping>0.1)
340  evaluation.maxFreq=std::min(evaluation.maxFreq,1.0/w);
341 
342  VEC_ELEM(envelope,idx) += double(fabs(CTF1.getValueDampingAt()));
343  idx++;
344  }
345 
346  if (fnCTF2!="") {
347  CTF2.lookFor(1, u, freqZero2, 0);
348  double module2=1.0/freqZero2.module();
349  double diff=ABS(moduleZero-module2);
350  evaluation.firstZeroDisagreement=XMIPP_MAX(evaluation.firstZeroDisagreement,diff);
351  }
352  }
353 
354  int idx=0;
355  for (double w=0; w<wmax; w+=wmax/99.0)
356  {
357  size_t objId2 = mdEnvelope.addObject();
358  mdEnvelope.setValue(MDL_RESOLUTION_FREQ,w,objId2);
359  mdEnvelope.setValue(MDL_CTF_ENVELOPE,VEC_ELEM(envelope,idx)/Nalpha,objId2);
360  idx++;
361  }
362  evaluation.firstZeroAvg/=N;
363  evaluation.firstZeroRatio=maxModuleZero/minModuleZero;
364  firstZeroAvgPSD/=N;
365  firstZeroStddevPSD=sqrt(fabs(firstZeroStddevPSD/N-firstZeroAvgPSD*firstZeroAvgPSD));
366  firstMinAvgPSD/=N;
367  firstMinStddevPSD=sqrt(fabs(firstMinStddevPSD/N-firstMinAvgPSD*firstMinAvgPSD));
368  firstZeroMinAvgPSD/=N;
369  firstZeroMinStddevPSD=sqrt(fabs(firstZeroMinStddevPSD/N-firstZeroMinAvgPSD*firstZeroMinAvgPSD));
370 
371  evaluation.firstMinimumStddev_ZeroStddev=1000;
372  evaluation.firstMinimumDiffStddev_ZeroStddev=1000;
373  if (firstZeroStddevPSD>1e-6)
374  {
375  evaluation.firstMinimumStddev_ZeroStddev=firstMinStddevPSD/firstZeroStddevPSD;
376  evaluation.firstMinimumDiffStddev_ZeroStddev=firstZeroMinAvgPSD/firstZeroStddevPSD;
377  }
378 
379  // Evaluate micrograph normality
380  ImageGeneric M;
381  M.readMapped(fnMicrograph);
382  double avg, stddev, minval, maxval;
383  M().computeStats(avg, stddev, minval, maxval);
384  Histogram1D hist;
385  compute_hist(M(), hist, minval, maxval, 400);
386  hist += 1;
387  hist /= hist.sum();
388 
389  Histogram1D histGaussian;
390  histGaussian.initZeros(hist);
391  histGaussian.hmin=hist.hmin;
392  histGaussian.hmax=hist.hmax;
393  histGaussian.step_size=hist.step_size;
394  histGaussian.istep_size=hist.istep_size;
395  FOR_ALL_ELEMENTS_IN_ARRAY1D(histGaussian) {
396  double x;
397  hist.index2val(i, x);
398  A1D_ELEM(histGaussian,i) = gaussian1D(x, stddev, avg);
399  }
400  evaluation.histogramNormality=0.5*(KLDistance(hist,histGaussian)+
401  KLDistance(histGaussian,hist));
402 
403  // Write criteria
404  rowOut.setValue(MDL_CTF_DEFOCUSU,evaluation.defocusU);
405  rowOut.setValue(MDL_CTF_DEFOCUSV,evaluation.defocusV);
407  rowOut.setValue(MDL_CTF_CRIT_MAXFREQ,evaluation.maxFreq);
409  if (evaluation.firstZeroDisagreement>0)
420  rowOut.setValue(MDL_CTF_CRIT_PSDVARIANCE,evaluation.PSDVariance);
424 
425 
426  //mdEnvelope.write(evaluation.ctf_envelope_ssnr,MD_OVERWRITE);
427  mdEnvelope.write(evaluation.ctf_envelope_ssnr,MD_OVERWRITE);
428  //std::cout << mdEnvelope << std::endl;
429 
430 }
#define VECTOR_R2(v, x, y)
Definition: matrix1d.h:112
double firstZeroAvg
Definition: ctf_sort_psds.h:42
void min(Image< double > &op1, const Image< double > &op2)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
Defocus U (Angstroms)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
double decay_width
Decay width (raised cosine)
Definition: ctf_sort_psds.h:71
double PSDVariance
Definition: ctf_sort_psds.h:52
double K1
Definition: ctf.h:218
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:68
double KLDistance(const Histogram1D &h1, const Histogram1D &h2)
Definition: histogram.cpp:377
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
double histogramNormality
Definition: ctf_sort_psds.h:55
double fittingCorr13
Definition: ctf_sort_psds.h:51
void sqrt(Image< double > &op)
Maximum frequency (in Angstroms) at which non-astigmatic CTF correction is valid. ...
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
First zero average (in Angstroms)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
#define A1D_ELEM(v, i)
PSD correlation at 90 degrees.
doublereal * w
void abs(Image< double > &op)
Name for the CTF Model (std::string)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
FileName ctf_envelope_ssnr
Definition: ctf_sort_psds.h:56
double firstZeroRatio
Definition: ctf_sort_psds.h:41
double hmin
Definition: histogram.h:125
A Power Spectrum Density file name (std::string)
double hmax
Definition: histogram.h:126
double PSDPC1Variance
Definition: ctf_sort_psds.h:53
doublereal * x
#define i
Is this image enabled? (int [-1 or 1])
#define rotate(a, i, j, k, l)
Correlation between the 1st and 3rd ring of the CTF.
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
double fittingScore
Definition: ctf_sort_psds.h:50
double PSDcorrelation90
Definition: ctf_sort_psds.h:40
Score of the fitting.
void index2val(double i, double &v) const
Definition: histogram.h:295
#define GET_CTF_CRITERION(labelll, xxx)
T & getValue(MDLabel label)
FileName fn_in
Filenames of input and output Metadata.
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
#define XX(v)
Definition: matrix1d.h:85
double maxDampingAtBorder
Definition: ctf_sort_psds.h:48
Integral of the radial PSD.
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Minimum damping at border.
double PSDradialIntegral
Definition: ctf_sort_psds.h:49
size_t firstRowId() const override
Normality test between histogram of micrography and gaussian distribution.
#define XSIZE(v)
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
Maximum frequency at which the envelope drops below 0.1 (in Angstroms)
Ratio sigma(firstMinimum)/sigma(firstZero)
void radialAverage(const MultidimArray< double > &VolFourierMag, const MultidimArray< double > &V, MultidimArray< double > &radial_mean)
#define ABS(x)
Definition: xmipp_macros.h:142
double decay_width
Decay width (raised cosine)
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
Definition: ctf.cpp:1172
void precomputeValues(double X, double Y)
Precompute values for a given frequency.
Definition: ctf.h:1002
Name of a micrograph (std::string)
double getValueDampingAt(bool show=false) const
Compute CTF damping at (U,V). Continuous frequencies.
Definition: ctf.h:424
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:65
bool exists() const
First zero disagreement with second model (in Angstroms)
Runs test on the projection of the PSD on the first principal component.
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
double firstMinimumDiffStddev_ZeroStddev
Definition: ctf_sort_psds.h:44
Frequency in 1/A (double)
#define YY(v)
Definition: matrix1d.h:93
Downsampling performed to estimate the CTF.
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:74
Variance in the first principal component of the PSDs.
void setValue(MDLabel label, const T &d, bool addLabel=true)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
virtual bool containsLabel(MDLabel label) const =0
FileName withoutExtension() const
Name for another CTF model (std::string)
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
void lookFor(int n, const Matrix1D< double > &u, Matrix1D< double > &freq, int iwhat=0)
Definition: ctf.cpp:1428
void applyFilter(MultidimArray< double > &PSD)
double PSDPCRunsTest
Definition: ctf_sort_psds.h:54
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
double firstMinimumStddev_ZeroStddev
Definition: ctf_sort_psds.h:43
doublereal * u
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:77
FileName getDir() const
double step_size
Definition: histogram.h:127
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Ratio sigma(firstMinimum-firstZero)/sigma(firstZero)
void initZeros(const MultidimArray< T1 > &op)
#define PI
Definition: tools.h:43
Defocus V (Angstroms)
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
double sum() const
double istep_size
Definition: histogram.h:128
T computeMax() const
double firstZeroDisagreement
Definition: ctf_sort_psds.h:46
double gaussian1D(double x, double sigma, double mu)

◆ readParams()

void ProgPSDSort::readParams ( )
virtual

Read from a command line.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgPSDSort >.

Definition at line 47 of file ctf_sort_psds.cpp.

48 {
50  filter_w1 = getDoubleParam("-f1");
51  filter_w2 = getDoubleParam("-f2");
52  decay_width = getDoubleParam("-decay");
53  mask_w1 = getDoubleParam("-m1");
54  mask_w2 = getDoubleParam("-m2");
55  // COSS downsampling = getDoubleParam("--downsampling");
56 }
double decay_width
Decay width (raised cosine)
Definition: ctf_sort_psds.h:71
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:68
double getDoubleParam(const char *param, int arg=0)
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:65
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:74
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:77

◆ show()

void ProgPSDSort::show ( )

Show parameters.

Definition at line 138 of file ctf_sort_psds.cpp.

139 {
140  if (verbose==0)
141  return;
143  std::cout
144  << "Filter w1: " << filter_w1 << std::endl
145  << "Filter w2: " << filter_w2 << std::endl
146  << "Filter decay: " << decay_width << std::endl
147  << "Mask w1: " << mask_w1 << std::endl
148  << "Mask w2: " << mask_w2 << std::endl ;
149  // COSS << "Downsampling: " << downsampling << std::endl;
150 }
double decay_width
Decay width (raised cosine)
Definition: ctf_sort_psds.h:71
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:68
int verbose
Verbosity level.
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:65
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:74
void show() const override
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
Definition: ctf_sort_psds.h:77

Member Data Documentation

◆ decay_width

double ProgPSDSort::decay_width

Decay width (raised cosine)

Definition at line 71 of file ctf_sort_psds.h.

◆ filter_w1

double ProgPSDSort::filter_w1

Bandpass filter low frequency (in Fourier space, max 0.5)

Definition at line 65 of file ctf_sort_psds.h.

◆ filter_w2

double ProgPSDSort::filter_w2

Bandpass filter high frequency (in Fourier space, max 0.5)

Definition at line 68 of file ctf_sort_psds.h.

◆ mask_w1

double ProgPSDSort::mask_w1

Lower frequency for the mask (in Fourier space, max 0.5)

Definition at line 74 of file ctf_sort_psds.h.

◆ mask_w2

double ProgPSDSort::mask_w2

Higher frequency for the mask (in Fourier space, max 0.5)

Definition at line 77 of file ctf_sort_psds.h.


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