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

#include <movie_filter_dose.h>

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

Public Member Functions

void readParams ()
 Read argument from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void run ()
 Run. More...
 
 ProgMovieFilterDose (double accelerationVoltage)
 constructor More...
 
 ProgMovieFilterDose (void)
 
void init (void)
 
void initVoltage (double accelerationVoltage)
 
double doseFilter (double dose_at_end_of_frame, double critical_dose)
 Compute the dose filter, which is the signal attenuation. More...
 
double criticalDose (double spatial_frequency)
 Given a spatial frequency, return the critical dose in electrons per square Angstroms. More...
 
double optimalDoseGivenCriticalDose (double critical_dose)
 Given the critical dose, return an estimate of the optimal dose (at which the SNR is maximised) More...
 
void applyDoseFilterToImage (int Ydim, int Xdim, const MultidimArray< std::complex< double > > &FFT1, const double dose_start, const double dose_finish)
 Apply a dose filter to the image Fourier transform. 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)
 
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

double critical_dose_a
 
double critical_dose_b
 
double critical_dose_c
 
double critical_dose_at_dc
 
double voltage_scaling_factor
 
double acceleration_voltage
 
double dose_per_frame
 
double pre_exposure_amount
 
FileName user_supplied_input_filename
 
FileName user_supplied_output_filename
 
int user_supplied_first_frame
 
int user_supplied_last_frame
 
double pixel_size
 
double maxFreq
 
bool restore_power
 Restore noise power after filtering?', 'Renormalise the summed image after filtering. More...
 
std::vector< MultidimArray< std::complex< double > > *> frameFourierVec
 
- 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

Movie alignment correlation Parameters.

Definition at line 72 of file movie_filter_dose.h.

Constructor & Destructor Documentation

◆ ProgMovieFilterDose() [1/2]

ProgMovieFilterDose::ProgMovieFilterDose ( double  accelerationVoltage)

constructor

Definition at line 124 of file movie_filter_dose.cpp.

124  {
125  init();
126  initVoltage(accelerationVoltage);
127 }
void initVoltage(double accelerationVoltage)

◆ ProgMovieFilterDose() [2/2]

ProgMovieFilterDose::ProgMovieFilterDose ( void  )

Definition at line 107 of file movie_filter_dose.cpp.

107  {
108  init();
109 }

Member Function Documentation

◆ applyDoseFilterToImage()

void ProgMovieFilterDose::applyDoseFilterToImage ( int  Ydim,
int  Xdim,
const MultidimArray< std::complex< double > > &  FFT1,
const double  dose_start,
const double  dose_finish 
)

Apply a dose filter to the image Fourier transform.

Definition at line 130 of file movie_filter_dose.cpp.

133  {
134  std::complex<double> complex_zero = 0;
135  double x, y;
136  double yy;
137  double current_critical_dose, current_optimal_dose;
138  int sizeX_2 = Xdim / 2;
139  double ixsize = 1.0 / Xdim;
140  int sizeY_2 = Ydim / 2;
141  double iysize = 1.0 / Ydim;
142  for (long int i = 0; i < YSIZE(FFT1); i++) { //i->y,j->x xmipp convention is oposite summove
143  FFT_IDX2DIGFREQ_FAST(i, Ydim, sizeY_2, iysize, y);
144  yy = y * y;
145  for (long int j = 0; j < XSIZE(FFT1); j++) {
146  FFT_IDX2DIGFREQ_FAST(j, Xdim, sizeX_2, ixsize, x);
147 #ifdef DEBUG_FFT_FREQ
148  std::cerr << "(j+1,i+1)(x,y)=" << j +1 << "," << i + 1<< " "
149  << x << " " << y << " = "
150  << DIRECT_A2D_ELEM(FFT1, i, j) << std::endl;
151 #endif
152  if (i == 0 && j == 0)
153  //ROB: I do not understand this step
154  //It forces the origin to 0
155  //Why not keep the value?
156  current_critical_dose = critical_dose_at_dc;
157  else
158  current_critical_dose = criticalDose(
159  sqrt(x * x + yy) / pixel_size);
160  current_optimal_dose = optimalDoseGivenCriticalDose(
161  current_critical_dose);
162  if (abs(dose_finish - current_optimal_dose)
163  < abs(dose_start - current_optimal_dose)) {
164  DIRECT_A2D_ELEM(FFT1, i, j ) *= doseFilter(dose_finish,
165  current_critical_dose);
166  } else
167  DIRECT_A2D_ELEM(FFT1, i, j ) = complex_zero;
168 
169  }
170  }
171 
172 }
#define YSIZE(v)
double criticalDose(double spatial_frequency)
Given a spatial frequency, return the critical dose in electrons per square Angstroms.
void sqrt(Image< double > &op)
static double * y
double optimalDoseGivenCriticalDose(double critical_dose)
Given the critical dose, return an estimate of the optimal dose (at which the SNR is maximised) ...
#define DIRECT_A2D_ELEM(v, i, j)
void abs(Image< double > &op)
doublereal * x
#define i
#define FFT_IDX2DIGFREQ_FAST(idx, size, size_2, isize, freq)
Definition: xmipp_fft.h:54
#define XSIZE(v)
#define j
double doseFilter(double dose_at_end_of_frame, double critical_dose)
Compute the dose filter, which is the signal attenuation.

◆ criticalDose()

double ProgMovieFilterDose::criticalDose ( double  spatial_frequency)

Given a spatial frequency, return the critical dose in electrons per square Angstroms.

Definition at line 90 of file movie_filter_dose.cpp.

90  {
91  return ((critical_dose_a * pow(spatial_frequency, critical_dose_b))
93 }

◆ defineParams()

void ProgMovieFilterDose::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 68 of file movie_filter_dose.cpp.

68  {
69  addUsageLine("Align a set of frames by cross-correlation of the frames");
70  addParamsLine(" -i <movie> : input movie");
71  addParamsLine(" [-o <fn=\"out.mrcs\">] : output filtered movie.");
73  " [--frameRange <n0=-1> <nF=-1>] : First and last frame to align, frame numbers start at 0");
74  addParamsLine(" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
75  addParamsLine(" [--dosePerFrame <dose=2>] : Dose per frame (e/A^2)");
77  " [--accVoltage <voltage=300>] : Acceleration voltage (kV) min_value=200.0e0,max_value=300.0e0)");
78  addParamsLine(" [--preExposure <preExp=0>] : P (e/A^2)");
79 // addParamsLine(
80 // " [--restoreNoiPow] : Restore noise power after filtering? (default=false)");
81  addExampleLine("A typical example", false);
82  addExampleLine("xmipp_cxzczxczccxztobedone");
83 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ doseFilter()

double ProgMovieFilterDose::doseFilter ( double  dose_at_end_of_frame,
double  critical_dose 
)

Compute the dose filter, which is the signal attenuation.

Definition at line 85 of file movie_filter_dose.cpp.

86  {
87  return exp((-0.5 * dose_at_end_of_frame) / critical_dose);
88 }

◆ init()

void ProgMovieFilterDose::init ( void  )

Set up the critical curve function (summovie)

Definition at line 98 of file movie_filter_dose.cpp.

98  {
100  critical_dose_a = 0.24499;
101  critical_dose_b = -1.6649;
102  critical_dose_c = 2.8141;
103  // init with a very large number
105 
106 }
void max(Image< double > &op1, const Image< double > &op2)

◆ initVoltage()

void ProgMovieFilterDose::initVoltage ( double  accelerationVoltage)

Definition at line 111 of file movie_filter_dose.cpp.

111  {
112  if (accelerationVoltage < 301 && accelerationVoltage > 299.) {
113  acceleration_voltage = 300.0;
115  } else if (accelerationVoltage < 201.0 && accelerationVoltage > 199.0) {
116  acceleration_voltage = 200.0;
118  } else
120  "Bad acceleration voltage (must be 200 or 300 kV");
121 
122  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect argument received.
Definition: xmipp_error.h:113

◆ optimalDoseGivenCriticalDose()

double ProgMovieFilterDose::optimalDoseGivenCriticalDose ( double  critical_dose)

Given the critical dose, return an estimate of the optimal dose (at which the SNR is maximised)

Definition at line 94 of file movie_filter_dose.cpp.

94  {
95  return 2.51284 * critical_dose;
96 }

◆ readParams()

void ProgMovieFilterDose::readParams ( )
virtual

Read argument from command line.

Reimplemented from XmippProgram.

Definition at line 36 of file movie_filter_dose.cpp.

36  {
39  user_supplied_first_frame = getIntParam("--frameRange", 0);
40  user_supplied_last_frame = getIntParam("--frameRange", 1);
41  pixel_size = getDoubleParam("--sampling");
42  dose_per_frame = getDoubleParam("--dosePerFrame");
43  acceleration_voltage = getDoubleParam("--accVoltage");
45  pre_exposure_amount = getDoubleParam("--preExposure");
46  //restore_power = checkParam("--restoreNoiPow");
47 
48 }
FileName user_supplied_input_filename
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
void initVoltage(double accelerationVoltage)
FileName user_supplied_output_filename
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgMovieFilterDose::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 173 of file movie_filter_dose.cpp.

173  {
174  show();
175  //read movie
176  MetaDataVec movie;
177  size_t Xdim, Ydim, Zdim, Ndim;
178 
179  //if input is an stack create a metadata.
182  else {
183  ImageGeneric movieStack;
185  movieStack.getDimensions(Xdim, Ydim, Zdim, Ndim);
186  if (user_supplied_input_filename.getExtension() == "mrc" and Ndim == 1)
187  Ndim = Zdim;
188  size_t id;
189  FileName fn;
190  for (size_t i = 0; i < Ndim; i++) {
191  id = movie.addObject();
193  movie.setValue(MDL_IMAGE, fn, id);
194  }
195  }
196  //movie.write("/tmp/movie.md");
199  if (user_supplied_last_frame < 0)
200  user_supplied_last_frame = movie.size() - 1;
201 
202  //Fourier transform
203  //apply filter frame, by frame
204  if (verbose) {
205  std::cout << "Computing Fourier transform of frames ..." << std::endl;
206  init_progress_bar(movie.size());
207  }
208  size_t n = 0;
209  FourierTransformer transformer;
210  FileName fnFrame;
211  FileName fnOutFrame;
212  Image<double> frame;
213  int mode = WRITE_OVERWRITE;
214 
216  for (size_t objId : movie.ids())
217  {
219  movie.getValue(MDL_IMAGE, fnFrame, objId);
220  frame.read(fnFrame);
221  // Now do the Fourier transform and filter
222  transformer.FourierTransform(frame(), FFT1, false);
223 #ifdef PRINT_ORIGINAL_IMAGE
224  std::cerr << "n= (original image)" << n << std::endl << frame() << std::endl;
225 #endif
226 #undef DEBUG
227 //#define DEBUG
228 #ifdef DEBUG
229  //same order than summovie
230  Image<double> VFourierMag;
231  //FFT_magnitude(FFT1,VFourierMag());
232  VFourierMag().resizeNoCopy(FFT1);
233  double * ptrv=(double *)MULTIDIM_ARRAY(FFT1);
234  int counter = 0;
235  double x,y;
236  int m1sizeX = XSIZE(frame()); int m1sizeY = YSIZE(frame());
237  int sizeX_2 = m1sizeX/2; double ixsize = 1.0/m1sizeX;
238  int sizeY_2 = m1sizeY/2; double iysize = 1.0/m1sizeY;
239  for (long int i=0; i<YSIZE(FFT1); i++) {
240  FFT_IDX2DIGFREQ_FAST(i, m1sizeY, sizeY_2,iysize , y);
241  for (long int j=0; j<XSIZE(FFT1); j++) { //i=y, j=x
242  FFT_IDX2DIGFREQ_FAST(j, m1sizeX, sizeX_2,ixsize , x);
243  std::cerr << "(x,y)=" << j +1 << "," << i + 1<< " = " <<
244  DIRECT_A2D_ELEM(FFT1, i, j) <<
245  x*x << " " << y*y << " " << (x*x+y*y) << std::endl;
246  }
247  }
248  exit(1);
250  {
251  counter ++;
252  double re=*ptrv;
253  double im=*(ptrv+1);
254  std::cerr << "DEBUG_JM: n re im: " << counter << " " << re << " " << im << std::endl;
255  DIRECT_MULTIDIM_ELEM(VFourierMag(), n) =
256  log(sqrt(re*re+im*im)+1);
257  ptrv+=2;
258  }
259  VFourierMag.write("/tmp/frame_mag_1.mrc");
260  frame.write("/tmp/frame_1.mrc");
261 #endif
262 #undef DEBUG
263 #ifdef PRINTFFT
264  std::cerr << "fourier before filter " << n << std::endl
265  << FFT1 << std::endl;
266 #endif
267  applyDoseFilterToImage((int)YSIZE(frame()), (int)XSIZE(frame()), FFT1,
268  (n * dose_per_frame) + pre_exposure_amount, //dose_star
269  ((n + 1) * dose_per_frame) + pre_exposure_amount //dose_end
270  );
271 #ifdef PRINTFFTAFTERFILTER
272  std::cerr << "Fourier after filter"<< std::endl << FFT1 << std::endl;
273 #endif
274  transformer.inverseFourierTransform();
275 #ifdef PRINTREALIMAGEAFTERDOEFILTERING
276  std::cerr << "fourier matrix after inverse (very likely garbage)" << std::endl
277  << FFT1 << std::endl;
278  std::cerr << "image after filter " << std::endl
279  << frame() << std::endl;
280 #endif
282  mode = WRITE_APPEND;
283  }
284  ++n;
285  if (verbose)
286  progress_bar(n);
287  }
288  if (verbose)
289  progress_bar(movie.size());
290 
291 }
FileName user_supplied_input_filename
void init_progress_bar(long total)
#define YSIZE(v)
void applyDoseFilterToImage(int Ydim, int Xdim, const MultidimArray< std::complex< double > > &FFT1, const double dose_start, const double dose_finish)
Apply a dose filter to the image Fourier transform.
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
void sqrt(Image< double > &op)
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
#define MULTIDIM_ARRAY(v)
void compose(const String &str, const size_t no, const String &ext="")
virtual IdIteratorProxy< false > ids()
doublereal * x
size_t size() const override
#define i
String getExtension() const
#define FFT_IDX2DIGFREQ_FAST(idx, size, size_2, isize, freq)
Definition: xmipp_fft.h:54
void log(Image< double > &op)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
FileName user_supplied_output_filename
#define XSIZE(v)
void progress_bar(long rlen)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int verbose
Verbosity level.
void mode
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
#define j
bool getValue(MDObject &mdValueOut, size_t id) const override
bool isMetaData(bool failIfNotExists=true) const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define FIRST_IMAGE
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
int * n
Name of an image (std::string)

◆ show()

void ProgMovieFilterDose::show ( )

Show.

Definition at line 51 of file movie_filter_dose.cpp.

51  {
52  if (!verbose)
53  return;
54  std::cout << "Input movie: " << user_supplied_input_filename
55  << std::endl << "Output movie: "
56  << user_supplied_output_filename << std::endl
57  << "Frame range alignment: " << user_supplied_first_frame << " "
58  << user_supplied_last_frame << std::endl
59  << "Sampling: " << pixel_size << std::endl
60  << "Dose per Frame (e/A^2): " << dose_per_frame << std::endl
61  << "Acceleration_Voltage (kV): " << acceleration_voltage
62  << std::endl << "Pre-exposure Amount (e/A^2): "
63  << pre_exposure_amount << std::endl
64  << "Restore Power after Filter: " << restore_power << std::endl;
65 }
FileName user_supplied_input_filename
FileName user_supplied_output_filename
bool restore_power
Restore noise power after filtering?&#39;, &#39;Renormalise the summed image after filtering.
int verbose
Verbosity level.

Member Data Documentation

◆ acceleration_voltage

double ProgMovieFilterDose::acceleration_voltage

Definition at line 84 of file movie_filter_dose.h.

◆ critical_dose_a

double ProgMovieFilterDose::critical_dose_a

Set up the critical curve function (summovie

Definition at line 77 of file movie_filter_dose.h.

◆ critical_dose_at_dc

double ProgMovieFilterDose::critical_dose_at_dc

Definition at line 81 of file movie_filter_dose.h.

◆ critical_dose_b

double ProgMovieFilterDose::critical_dose_b

Definition at line 78 of file movie_filter_dose.h.

◆ critical_dose_c

double ProgMovieFilterDose::critical_dose_c

Definition at line 79 of file movie_filter_dose.h.

◆ dose_per_frame

double ProgMovieFilterDose::dose_per_frame

Definition at line 85 of file movie_filter_dose.h.

◆ frameFourierVec

std::vector< MultidimArray<std::complex<double> > * > ProgMovieFilterDose::frameFourierVec

Definition at line 109 of file movie_filter_dose.h.

◆ maxFreq

double ProgMovieFilterDose::maxFreq

Max freq.

Definition at line 102 of file movie_filter_dose.h.

◆ pixel_size

double ProgMovieFilterDose::pixel_size

Sampling rate

Definition at line 99 of file movie_filter_dose.h.

◆ pre_exposure_amount

double ProgMovieFilterDose::pre_exposure_amount

Definition at line 86 of file movie_filter_dose.h.

◆ restore_power

bool ProgMovieFilterDose::restore_power

Restore noise power after filtering?', 'Renormalise the summed image after filtering.

Definition at line 106 of file movie_filter_dose.h.

◆ user_supplied_first_frame

int ProgMovieFilterDose::user_supplied_first_frame

frames of interest in movie

Definition at line 95 of file movie_filter_dose.h.

◆ user_supplied_input_filename

FileName ProgMovieFilterDose::user_supplied_input_filename

input movie

Definition at line 89 of file movie_filter_dose.h.

◆ user_supplied_last_frame

int ProgMovieFilterDose::user_supplied_last_frame

Definition at line 96 of file movie_filter_dose.h.

◆ user_supplied_output_filename

FileName ProgMovieFilterDose::user_supplied_output_filename

output movie

Definition at line 92 of file movie_filter_dose.h.

◆ voltage_scaling_factor

double ProgMovieFilterDose::voltage_scaling_factor

Definition at line 83 of file movie_filter_dose.h.


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