void roundShifts(MDRow &row) { double aux = 0.; if (row.getValue(MDL_SHIFT_X, aux)) { aux = (double)ROUND(aux); row.setValue(MDL_SHIFT_X, aux); } if (row.getValue(MDL_SHIFT_Y, aux)) { aux = (double)ROUND(aux); row.setValue(MDL_SHIFT_Y, aux); } }
// Continuous assignment =================================================== double ProgNmaAlignment::performContinuousAssignment(const FileName &fnRandom, int pyramidLevel) const { // Perform alignment const char * randStr = fnRandom.c_str(); String fnResults=formatString("%s_anglecont.xmd", randStr); bool costSource=true; String program = "xmipp_angular_continuous_assign"; String arguments = formatString( "-i %s_angledisc.xmd --ref %s_deformedPDB.vol -o %s --gaussian_Fourier %f --gaussian_Real %f --zerofreq_weight %f -v 0", randStr, randStr, fnResults.c_str(), gaussian_DFT_sigma, gaussian_Real_sigma, weight_zero_freq); runSystem(program, arguments, false); // Pick up results MetaData DF(fnResults); MDRow row; DF.getRow(row, DF.firstObject()); row.getValue(MDL_ANGLE_ROT, trial(VEC_XSIZE(trial) - 5)); row.getValue(MDL_ANGLE_TILT, trial(VEC_XSIZE(trial) - 4)); row.getValue(MDL_ANGLE_PSI, trial(VEC_XSIZE(trial) - 3)); row.getValue(MDL_SHIFT_X, trial(VEC_XSIZE(trial) - 2)); trial(VEC_XSIZE(trial) - 2) *= pow(2.0, (double) pyramidLevel); row.getValue(MDL_SHIFT_Y, trial(VEC_XSIZE(trial) - 1)); trial(VEC_XSIZE(trial) - 1) *= pow(2.0, (double) pyramidLevel); double tempvar; if (!costSource) { row.getValue(MDL_MAXCC, tempvar); tempvar = -tempvar; } else row.getValue(MDL_COST, tempvar); return tempvar; }
void ProgSortByStatistics::run() { // Process input selfile .............................................. SF.read(fn); SF.removeDisabled(); MetaData SF2 = SF; SF = SF2; bool trained = false; if (fn_train != "") { SFtrain.read(fn_train); processInprocessInputPrepareSPTH(SFtrain,trained); trained = true; processInprocessInputPrepareSPTH(SF,trained); } else processInprocessInputPrepareSPTH(SF,trained); int imgno = 0; int numPCAs = pcaAnalyzer.size(); MultidimArray<double> finalZscore(SF.size()); MultidimArray<double> ZscoreShape1(SF.size()), sortedZscoreShape1; MultidimArray<double> ZscoreShape2(SF.size()), sortedZscoreShape2; MultidimArray<double> ZscoreSNR1(SF.size()), sortedZscoreSNR1; MultidimArray<double> ZscoreSNR2(SF.size()), sortedZscoreSNR2; MultidimArray<double> ZscoreHist(SF.size()), sortedZscoreHist; finalZscore.initConstant(0); ZscoreShape1.resizeNoCopy(finalZscore); ZscoreShape2.resizeNoCopy(finalZscore); ZscoreSNR1.resizeNoCopy(finalZscore); ZscoreSNR2.resizeNoCopy(finalZscore); ZscoreHist.resizeNoCopy(finalZscore); sortedZscoreShape1.resizeNoCopy(finalZscore); sortedZscoreShape2.resizeNoCopy(finalZscore); sortedZscoreSNR1.resizeNoCopy(finalZscore); sortedZscoreSNR2.resizeNoCopy(finalZscore); sortedZscoreHist.resizeNoCopy(finalZscore); double zScore=0; int enabled; FOR_ALL_OBJECTS_IN_METADATA(SF) { SF.getValue(MDL_ENABLED,enabled,__iter.objId); if ( (enabled==-1) ) { A1D_ELEM(finalZscore,imgno) = 1e3; A1D_ELEM(ZscoreShape1,imgno) = 1e3; A1D_ELEM(ZscoreShape2,imgno) = 1e3; A1D_ELEM(ZscoreSNR1,imgno) = 1e3; A1D_ELEM(ZscoreSNR2,imgno) = 1e3; A1D_ELEM(ZscoreHist,imgno) = 1e3; imgno++; enabled = 0; } else { for (int num = 0; num < numPCAs; ++num) { if (num == 0) { A1D_ELEM(ZscoreSNR1,imgno) = pcaAnalyzer[num].getZscore(imgno); } else if (num == 1) { A1D_ELEM(ZscoreShape2,imgno) = pcaAnalyzer[num].getZscore(imgno); } else if (num == 2) { A1D_ELEM(ZscoreShape1,imgno) = pcaAnalyzer[num].getZscore(imgno); } else if (num == 3) { A1D_ELEM(ZscoreSNR2,imgno) = pcaAnalyzer[num].getZscore(imgno); } else { A1D_ELEM(ZscoreHist,imgno) = pcaAnalyzer[num].getZscore(imgno); } if(zScore < pcaAnalyzer[num].getZscore(imgno)) zScore = pcaAnalyzer[num].getZscore(imgno); } A1D_ELEM(finalZscore,imgno)=zScore; imgno++; zScore = 0; } } pcaAnalyzer.clear(); // Produce output ..................................................... MetaData SFout; std::ofstream fh_zind; if (verbose==2 && !fn_out.empty()) fh_zind.open((fn_out.withoutExtension() + "_vectors.xmd").c_str(), std::ios::out); MultidimArray<int> sorted; finalZscore.indexSort(sorted); int nr_imgs = SF.size(); bool thereIsEnable=SF.containsLabel(MDL_ENABLED); MDRow row; for (int imgno = 0; imgno < nr_imgs; imgno++) { int isort_1 = DIRECT_A1D_ELEM(sorted,imgno); int isort = isort_1 - 1; SF.getRow(row, isort_1); if (thereIsEnable) { int enabled; row.getValue(MDL_ENABLED, enabled); if (enabled==-1) continue; } double zscore=DIRECT_A1D_ELEM(finalZscore,isort); double zscoreShape1=DIRECT_A1D_ELEM(ZscoreShape1,isort); double zscoreShape2=DIRECT_A1D_ELEM(ZscoreShape2,isort); double zscoreSNR1=DIRECT_A1D_ELEM(ZscoreSNR1,isort); double zscoreSNR2=DIRECT_A1D_ELEM(ZscoreSNR2,isort); double zscoreHist=DIRECT_A1D_ELEM(ZscoreHist,isort); DIRECT_A1D_ELEM(sortedZscoreShape1,imgno)=DIRECT_A1D_ELEM(ZscoreShape1,isort); DIRECT_A1D_ELEM(sortedZscoreShape2,imgno)=DIRECT_A1D_ELEM(ZscoreShape2,isort); DIRECT_A1D_ELEM(sortedZscoreSNR1,imgno)=DIRECT_A1D_ELEM(ZscoreSNR1,isort); DIRECT_A1D_ELEM(sortedZscoreSNR2,imgno)=DIRECT_A1D_ELEM(ZscoreSNR2,isort); DIRECT_A1D_ELEM(sortedZscoreHist,imgno)=DIRECT_A1D_ELEM(ZscoreHist,isort); if (zscore>cutoff && cutoff>0) { row.setValue(MDL_ENABLED,-1); if (addToInput) SF.setValue(MDL_ENABLED,-1,isort_1); } else { row.setValue(MDL_ENABLED,1); if (addToInput) SF.setValue(MDL_ENABLED,1,isort_1); } row.setValue(MDL_ZSCORE,zscore); row.setValue(MDL_ZSCORE_SHAPE1,zscoreShape1); row.setValue(MDL_ZSCORE_SHAPE2,zscoreShape2); row.setValue(MDL_ZSCORE_SNR1,zscoreSNR1); row.setValue(MDL_ZSCORE_SNR2,zscoreSNR2); row.setValue(MDL_ZSCORE_HISTOGRAM,zscoreHist); if (addToInput) { SF.setValue(MDL_ZSCORE,zscore,isort_1); SF.setValue(MDL_ZSCORE_SHAPE1,zscoreShape1,isort_1); SF.setValue(MDL_ZSCORE_SHAPE2,zscoreShape2,isort_1); SF.setValue(MDL_ZSCORE_SNR1,zscoreSNR1,isort_1); SF.setValue(MDL_ZSCORE_SNR2,zscoreSNR2,isort_1); SF.setValue(MDL_ZSCORE_HISTOGRAM,zscoreHist,isort_1); } SFout.addRow(row); } //Sorting taking into account a given percentage if (per > 0) { MultidimArray<int> sortedShape1,sortedShape2,sortedSNR1,sortedSNR2,sortedHist, sortedShapeSF1,sortedShapeSF2,sortedSNR1SF,sortedSNR2SF,sortedHistSF; sortedZscoreShape1.indexSort(sortedShape1); sortedZscoreShape2.indexSort(sortedShape2); sortedZscoreSNR1.indexSort(sortedSNR1); sortedZscoreSNR2.indexSort(sortedSNR2); sortedZscoreHist.indexSort(sortedHist); size_t numPartReject = (size_t)std::floor((per/100)*SF.size()); for (size_t numPar = SF.size()-1; numPar > (SF.size()-numPartReject); --numPar) { int isort_1 = DIRECT_A1D_ELEM(sortedShape1,numPar); SFout.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SFout.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedShape2,numPar); SFout.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SFout.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedSNR1,numPar); SFout.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SFout.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedSNR2,numPar); SFout.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SFout.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedHist,numPar); SFout.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SFout.setRow(row,isort_1); if (addToInput) { ZscoreShape1.indexSort(sortedShapeSF1); ZscoreShape2.indexSort(sortedShapeSF2); ZscoreSNR1.indexSort(sortedSNR1SF); ZscoreSNR2.indexSort(sortedSNR2SF); ZscoreHist.indexSort(sortedHistSF); isort_1 = DIRECT_A1D_ELEM(sortedShapeSF1,numPar); SF.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SF.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedShapeSF2,numPar); SF.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SF.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedSNR1SF,numPar); SF.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SF.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedSNR2SF,numPar); SF.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SF.setRow(row,isort_1); isort_1 = DIRECT_A1D_ELEM(sortedHistSF,numPar); SF.getRow(row, isort_1); row.setValue(MDL_ENABLED,-1); SF.setRow(row,isort_1); } } } if (verbose==2) fh_zind.close(); if (!fn_out.empty()) { MetaData SFsorted; SFsorted.sort(SFout,MDL_ZSCORE); SFout.write(fn_out,MD_OVERWRITE); } if (addToInput) { MetaData SFsorted; SFsorted.sort(SF,MDL_ZSCORE); SFsorted.write(fn,MD_APPEND); } }