53 int Xoutput_volume_size, Youtput_volume_size, Zoutput_volume_size;
70 double mean_error = 0.0;
71 double global_mean_error,global_mean_error_1stblock;
77 for (
int iact_proj = 0; iact_proj <
artPrm.
numIMG ; iact_proj++)
80 read_proj().setXmippOrigin();
81 read_proj().initZeros();
100 Xoutput_volume_size);
108 vol_basis_noisy = vol_basis;
116 vol_basis_out = vol_basis;
117 ptr_vol_out = &vol_basis_out;
130 ptr_vol_out = &vol_basis_out;
131 vol_basis_out = vol_basis;
137 ptr_vol_out = &vol_basis_out;
138 vol_basis_out = vol_basis;
144 ptr_vol_out = &vol_basis;
151 double mean_error_2ndblock,pow_residual_imgs;
152 bool iv_launched=
false;
156 global_mean_error = 0;
157 global_mean_error_1stblock = 0;
162 std::cout <<
"Running iteration " << it <<
" with lambda= " <<
artPrm.
lambda(it)<<
"\n" << std::endl;
168 for (
int act_proj = 0; act_proj <
artPrm.
numIMG ; act_proj++)
170 POCS.newProjection();
177 std::cout <<
"Introduce next projection to study: ";
182 std::cout <<
"Introduce symmetry to study: ";
183 std::cin >> sym_number;
202 read_proj().setXmippOrigin();
209 noisy_projection().resize(read_proj());
211 noisy_projection().setXmippOrigin();
215 if ( it == 0 && imgInfo.
sym==-1 )
221 noisy_projection.
write(fn_noise);
236 aux_tilt=read_proj.
tilt();
240 std::cout <<
"Skipping Proj no: " << iact_proj
241 <<
"tilt=" << read_proj.
tilt() << std::endl;
248 read_proj().selfWindow(
253 noisy_projection().resize(read_proj());
259 if( imgInfo.
sym != -1)
261 std::cout <<
"Skipping Proj no: " << iact_proj
262 <<
" with symmetry no: " << imgInfo.
sym 267 std::cout <<
"NO Skipping Proj no: " << iact_proj
268 <<
" with symmetry no: " << imgInfo.
sym 295 theo_proj, read_proj, imgInfo.
sym , diff_proj,
296 corr_proj, alig_proj,
298 images, imgInfo.
fn_ctf, maskPtr,
304 global_mean_error_1stblock += diff_proj().sum2()/(
XSIZE(diff_proj())*
YSIZE(diff_proj()));
307 global_mean_error += mean_error;
310 double noise_mean_error;
312 theo_proj, noisy_projection, imgInfo.
sym,
313 diff_proj, corr_proj, alig_proj,
315 images, imgInfo.
fn_ctf,maskPtr,
332 POCS.apply(vol_basis,it,images);
334 POCS.apply(vol_basis_noisy,it,images);
344 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
350 std::cout <<
"Regularization error = " << regError << std::endl;
351 *
artPrm.
fh_hist <<
"Regularization error = " << regError << std::endl;
363 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
371 << imgInfo.
sym <<
"\t\t" << mean_error;
377 std::cout << imgInfo.
fn_proj <<
", sym=" 378 << imgInfo.
sym <<
"\t\t" << mean_error;
380 std::cout <<
"\tPOCS:" << POCS.POCS_mean_error;
381 std::cout << std::endl;
388 std::cout <<
" read ";
389 read_proj().printStats();
390 std::cout <<
"\n theo ";
391 theo_proj().printStats();
392 std::cout <<
"\n corr ";
393 corr_proj().printStats();
394 std::cout <<
"\n alig ";
395 alig_proj().printStats();
396 std::cout <<
"\n diff ";
397 diff_proj().printStats();
398 std::cout <<
"\n subvol(0) ";
399 (*ptr_vol_out)(0)().printStats();
405 std::cout <<
"Stats PPPdiff.xmp: ";
406 diff_proj().printStats();
407 std::cout << std::endl;
408 std::cout <<
"Stats PPPtheo.xmp: ";
409 theo_proj().printStats();
410 std::cout << std::endl;
411 std::cout <<
"Stats PPPread.xmp: ";
412 read_proj().printStats();
413 std::cout << std::endl;
414 std::cout <<
"Stats PPPcorr.xmp: ";
415 corr_proj().printStats();
416 std::cout << std::endl;
417 diff_proj.
write(
"PPPdiff.xmp");
418 theo_proj.
write(
"PPPtheo.xmp");
419 read_proj.
write(
"PPPread.xmp");
420 corr_proj.
write(
"PPPcorr.xmp");
422 alig_proj.
write(
"PPPalign.xmp");
423 vol_basis.
write(
"PPPbasis.basis");
425 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
426 std::cout <<
"Stats PPPvol.vol : ";
427 vol_voxels().printStats();
428 std::cout << std::endl;
429 vol_voxels.
write(
"PPPvol.vol");
433 if (system(
"xmipp_show -img PPPdiff.xmp PPPtheo.xmp PPPread.xmp PPPcorr.xmp -dont_apply_geo -poll &")==-1)
435 if (system(
"xmipp_show -vol PPPvol.vol -poll &")==-1)
439 std::cout <<
"\nHit any key and enter\n";
450 std::cout <<
"\nSaving intermediate ...\n" 451 <<
"Converting basis volume to voxels ...\n";
454 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
459 vol_voxels.
write(
"PPPvol.vol");
464 if (system(
"xmipp_show -i PPPvol.vol --poll &")==-1)
483 mean_error_2ndblock, pow_residual_imgs);
490 *
artPrm.
fh_hist <<
"Finished - Iteration " << it << std::endl;
492 std::cout <<
" Weighted error: " << global_mean_error
493 <<
" 1st block: " << global_mean_error_1stblock
494 <<
" 2nd block: " << mean_error_2ndblock
495 <<
" residual: " << pow_residual_imgs << std::endl;
497 std::cout <<
" Global mean squared error: " 502 <<
" 1st block: " << global_mean_error_1stblock
503 <<
" 2nd block: " << mean_error_2ndblock
504 <<
" residual: " << pow_residual_imgs << std::endl;
511 std::cout <<
" POCS Global mean squared error: " 512 << POCS.POCS_global_mean_error/POCS.POCS_N << std::endl;
514 << POCS.POCS_global_mean_error/POCS.POCS_N << std::endl;
528 vol_basis=vol_basis_out;
532 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
539 DWT(vol_voxels(),vol_wavelets());
540 vol_wavelets_abs()=vol_wavelets();
541 vol_wavelets_abs().selfABS();
548 std::cout <<
"Threshold=" << threshold1 << std::endl;
549 vol_wavelets().threshold(
"abs_below", threshold1, 0.0);
550 IDWT(vol_wavelets(),vol_voxels());
554 Zoutput_volume_size);
563 std::cout <<
"Converting basis volume to voxels ...\n";
565 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
567 vol_voxels.
write(fn_tmp);
581 std::cout <<
"\nTime of " <<
artPrm.
no_it <<
" iterations: \n";
593 Zoutput_volume_size, Youtput_volume_size, Xoutput_volume_size);
601 void ARTReconsBase::singleStep(
GridVolume & vol_in,
GridVolume *vol_out,
Projection & theo_proj,
Projection & read_proj,
int sym_no,
Projection & diff_proj,
Projection & corr_proj,
Projection & alig_proj,
double & mean_error,
int numIMG,
double lambda,
int act_proj,
const FileName & fn_ctf,
const MultidimArray<int> *maskPtr,
bool refine)
610 *
artPrm.
fh_hist <<
" ============================================================\n";
612 *
artPrm.
fh_hist <<
" ============================================================\n\n";
613 *
artPrm.
fh_hist <<
" Parameters -------------------------------------------------\n";
635 <<
" pixels" << std::endl;
637 <<
" pixels" << std::endl;
653 *
artPrm.
fh_hist <<
" Perform weighted least-squares ART "<< std::endl;
709 *
artPrm.
fh_hist <<
" Number of total projections (including symmetrized): " 729 *
artPrm.
fh_hist <<
" Left Symmetry matrix " <<
j << std::endl << L;
730 *
artPrm.
fh_hist <<
" Right Symmetry matrix " <<
j << std::endl << R << std::endl;
745 double dfrot, dftilt, dfpsi;
757 *
artPrm.
fh_hist <<
" Projection angles -----------------------------------------\n";
758 for (
size_t objId : MD.
ids())
764 *
artPrm.
fh_hist <<
"rot= "<<dfrot<<
" tilt= "<<dftilt<<
" psi= "<<dfpsi<<std::endl;
766 *
artPrm.
fh_hist <<
" -----------------------------------------------------------\n";
804 th_ids = (pthread_t *)malloc(
artPrm.
threads *
sizeof( pthread_t));
832 double &mean_error,
int numIMG,
double lambda,
int act_proj,
840 bool remove_footprints =
false;
841 double weight, sqrtweight;
847 "only works with blobs");
858 remove_footprints =
true;
863 (*footprint)().setXmippOrigin();
865 int finalsize = 2 *
CEIL(30 + blob_radius) + 1;
877 finalsize = 2 *
CEIL(15 + blob_radius) + 1;
884 save() = (*footprint)();
885 save.
write(
"PPPfootprint.xmp");
889 *footprint2 = *footprint;
890 (*footprint2)() *= (*footprint2)();
899 corr_proj().initZeros();
902 corr_proj,
YSIZE(read_proj()),
XSIZE(read_proj()),
915 std::cout <<
"Equation system (Ax=b) ----------------------\n";
916 std::cout <<
"Size: "<< (*A).mdimx <<
"x"<<(*A).mdimy<< std::endl;
919 bool null_row =
true;
932 std::cout << std::endl;
935 std::cout <<
"---------------------------------------------\n";
950 std::cout << M << std::endl;
951 read_proj().rangeAdjust(theo_proj());
958 double applied_lambda = lambda / numIMG;
961 diff_proj().resize(read_proj());
967 sqrtweight =
sqrt(weight);
985 mean_error /=
XSIZE(diff_proj()) *
YSIZE(diff_proj());
986 mean_error *= weight;
994 if (maskPtr!=
nullptr)
995 if ((*maskPtr)(
i,
j)<0.5)
1007 mean_error /= Nmean;
1012 corr_proj,
YSIZE(read_proj()),
XSIZE(read_proj()),
1017 if (remove_footprints)
1044 pthread_join(*(th_ids+
c),
nullptr);
Just to locate unclassified errors.
int barrier_init(barrier_t *barrier, int needed)
void init_progress_bar(long total)
MDRowVec row
Header information of projection.
template void * project_SimpleGridThread< double >(void *)
bool positivity
Apply positivity constraint.
int numIMG
Total number of images to process (taking symmetries into account)
void set_DWT_type(int DWT_type)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
Case or algorithm not implemented yet.
size_t projXdim
Projection X dimension.
bool refine
Refine experimental projection before backprojecting.
void getMatrices(int i, Matrix2D< double > &L, Matrix2D< double > &R, bool homogeneous=true) const
Basis basis
Basis function. By default, blobs.
FileName removeLastExtension() const
double alignImages(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, bool wrap, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3)
#define REPORT_ERROR(nerr, ErrormMsg)
double psi(const size_t n=0) const
void updateResidualVector(BasicARTParameters &prm, GridVolume &vol_basis, double &kappa, double &pow_residual_vol, double &pow_residual_imgs)
FileName fn_start
Grid volume as initial guess.
void initHistory(const GridVolume &vol_basis0)
void sqrt(Image< double > &op)
void annotate_processor_time(ProcessorTimeStamp *time)
#define TELL_MANUAL_ORDER
FileName addExtension(const String &ext) const
void setValue(const MDObject &object) override
FileName insertBeforeExtension(const String &str) const
Matrix1D< double > vectorR3(double x, double y, double z)
virtual void print(std::ostream &o) const
void changeFromVoxels(const MultidimArray< double > &vol_voxels, GridVolume &vol_basis, int grid_type, double grid_relative_size, const MultidimArray< double > *vol_mask, const Matrix2D< double > *D, double R, int threads=1) const
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)
bool do_not_use_symproj
Do not use symmetrized projections.
#define MULTIDIM_ARRAY(v)
virtual void applySymmetry(GridVolume &vol_in, GridVolume *vol_out, int grid_type)
double grid_relative_size
Relative size for the grid.
void compose(const String &str, const size_t no, const String &ext="")
struct blobtype blob
Blob parameters.
const FileName & name() const
FileName fn_sym
File containing symmetries.
String integerToString(int I, int _width, char fill_with)
bool shiftedTomograms
Shifted tomograms.
tBasisFunction type
Basis function to use.
double rot(const size_t n=0) const
ImageOver blobprint2
Square of the footprint.
FileName fn_sel
Selection file with all images to process.
std::ofstream * fh_hist
File handler for the history file.
bool variability_analysis
Variability analysis.
int save_intermidiate_every
Frequency for saving intermidiate.
double weight(const size_t n=0) const
size_t projYdim
Projection Y dimension.
void changeToVoxels(GridVolume &vol_basis, MultidimArray< double > *vol_voxels, int Zdim, int Ydim, int Xdim, int threads=1) const
double sampling
Sampling rate.
virtual void readParams(XmippProgram *program)
void init_random_generator(int seed)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
void read(const FileName &fn, bool disable_if_not_K=true)
int block_size
Number of projections for each parallel block.
bool random_sort
True if random sort of projections.
int grid_type
CC, BCC or FCC (in grids.hh)
double tilt(const size_t n=0) const
#define BCC
BCC identifier.
int trueIMG
Number of different images (without symmetries)
#define MAT_ELEM(m, i, j)
FileName fn_surface_mask
File containing surface mask.
double known_volume
Known volume. If -1, not applied.
Matrix1D< double > kappa_list
double sparseEps
Sparse reconstruction.
bool print_system_matrix
Print system matrix.
double tilt
Tilting angle.
bool apply_shifts
Apply shifts stored in the headers of the 2D-images.
GridVolumeT< int > * GVNeq
virtual void postProcess(GridVolume &vol_basis)
#define FCC
FCC identifier.
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
void project_GridVolume(GridVolumeT< T > &vol, const Basis &basis, Projection &proj, Projection &norm_proj, int Ydim, int Xdim, double rot, double tilt, double psi, int FORW, int eq_mode, GridVolumeT< int > *GVNeq, Matrix2D< double > *M, const MultidimArray< int > *mask, double ray_length, int threads)
size_t getPrefixNumber(size_t pos=0) const
int stop_at
Stop after this number of images, if 0 then don't use.
void postProcess(GridVolume &vol_basis)
struct tms ProcessorTimeStamp
ReconsInfo * IMG_Inf
Array with all the sorting information for each projection.
virtual void preProcess(GridVolume &vol_basis0, int level=FULL, int rank=-1)
Produce Plain side information from the Class parameters.
friend std::ostream & operator<<(std::ostream &o, const ARTReconsBase &artRecons)
void progress_bar(long rlen)
void newUpdateVolume(GridVolume *ptr_vol_out, Projection &read_proj)
double Tm
Sampling rate (A/pixel)
#define TELL_SAVE_INTERMIDIATE
FileName fn_ctf
CTF filename.
#define DIRECT_MULTIDIM_ELEM(v, n)
ARTParallelMode parallel_mode
void print_elapsed_time(ProcessorTimeStamp &time, bool _IN_SECS)
void produceSideInfo(GridVolume &vol_basis0, int level=FULL, int rank=-1)
virtual void singleStep(GridVolume &vol_in, GridVolume *vol_out, Projection &theo_proj, Projection &read_proj, int sym_no, Projection &diff_proj, Projection &corr_proj, Projection &alig_proj, double &mean_error, int numIMG, double lambda, int act_proj, const FileName &fn_ctf, const MultidimArray< int > *maskPtr, bool refine)
FileName fn_proj
Projection filename.
void sort(struct DCEL_T *dcel)
double ref_trans_step
Refine the translation alignement after n projection presentations.
#define NEXT_POWER_OF_2(x)
bool noisy_reconstruction
Noisy reconstruction.
int force_sym
Force the reconstruction to be symmetric this number of times.
#define proj_number(base, irot, itilt, ipsi)
void setEulerAngles(double rot, double tilt, double psi, const size_t n=0)
bool unmatched
Apply unmatched projectors to correct for the CTF.
int no_it
Number of iterations.
barrier_t project_barrier
void write(const FileName &fn) const
MultidimArray< int > ordered_list
Order in which projections will be presented to algorithm.
double rot
Rotational angle.
#define TELL_SAVE_AT_EACH_STEP
#define FIRST_XMIPP_INDEX(size)
const SimpleGrid & grid(size_t n) const
void produceSideInfo()
Produce Side information.
project_thread_params * project_threads
void iterations(GridVolume &vol_basis, int rank=-1)
String formatString(const char *format,...)
int ref_trans_after
Refine the translation alignement after n projection presentations.
double tomographicDiffusion(MultidimArray< double > &V, const Matrix1D< double > &alpha, double lambda)
void IDWT(const MultidimArray< double > &v, MultidimArray< double > &result)
void preProcess(GridVolume &vol_basis0, int level=FULL, int rank=-1)
Produce Plain side information from the Class parameters.
void read(const FileName &fn, const bool only_apply_shifts=false, DataMode datamode=DATA, MDRow *row=nullptr)
void forceDWTSparsity(MultidimArray< double > &V, double eps)
const int BLOB_SUBSAMPLING
int sort_last_N
Sort perpendicular with the last N projections. If -1 with all previous.
BasicARTParameters artPrm
FileName fn_ctf
Selection file with all images to process.
bool enable_CTFnoise
Enable CTFnoise part.
#define LAST_XMIPP_INDEX(size)
int barrier_wait(barrier_t *barrier)
double diffusionWeight
Tomographic diffussion.
void readParams(XmippProgram *program)
Incorrect value received.
void generateMask(MultidimArray< double > &v)
int threads
Number of threads to use. Can not be different than 1 when using MPI.
double radius
Spatial radius in Universal System units.
FileName fn_out
Name of the output volume, also used to set the root of rest output files.
SymList SL
A list with the symmetry matrices.
void applyMaskSpace(MultidimArray< double > &v)
#define IMGPIXEL(I, i, j)
std::vector< Projection > residual_imgs
virtual void singleStep(GridVolume &vol_in, GridVolume *vol_out, Projection &theo_proj, Projection &read_proj, int sym_no, Projection &diff_proj, Projection &corr_proj, Projection &alig_proj, double &mean_error, int numIMG, double lambda, int act_proj, const FileName &fn_ctf, const MultidimArray< int > *maskPtr, bool refine)
Matrix1D< double > lambda_list
Relaxation parameter.
bool do_not_generate_subgroup
Do not generate symmetry subgroup.
ImageOver blobprint
Blob footprint.