int main2()
    {

        MultidimArray<double> preImg, avgCurr, mappedImg;
        MultidimArray<double> outputMovie;
        Matrix1D<double> meanStdev;
        ImageGeneric movieStack;
        Image<double> II;
        MetaData MD; // To save plot information
        FileName motionInfFile, flowFileName, flowXFileName, flowYFileName;
        ArrayDim aDim;

        // For measuring times (both for whole process and for each level of the pyramid)
        clock_t tStart, tStart2;

#ifdef GPU
        // Matrix that we required in GPU part
        GpuMat d_flowx, d_flowy, d_dest;
        GpuMat d_avgcurr, d_preimg;
#endif

        // Matrix required by Opencv
        cv::Mat flow, dest, flowx, flowy;
        cv::Mat flowxPre, flowyPre;
        cv::Mat avgcurr, avgstep, preimg, preimg8, avgcurr8;
        cv::Mat planes[]={flowxPre, flowyPre};

        int imagenum, cnt=2, div=0, flowCounter;
        int h, w, levelNum, levelCounter=1;

        motionInfFile=foname.replaceExtension("xmd");
        std::string extension=fname.getExtension();
        if (extension=="mrc")
            fname+=":mrcs";
        movieStack.read(fname,HEADER);
        movieStack.getDimensions(aDim);
        imagenum = aDim.ndim;
        h = aDim.ydim;
        w = aDim.xdim;
        if (darkImageCorr)
        {
            II.read(darkRefFilename);
            darkImage=II();
        }
        if (gainImageCorr)
        {
            II.read(gianRefFilename);
            gainImage=II();
        }
        meanStdev.initZeros(4);
        //avgcurr=cv::Mat::zeros(h, w,CV_32FC1);
        avgCurr.initZeros(h, w);
        flowxPre=cv::Mat::zeros(h, w,CV_32FC1);
        flowyPre=cv::Mat::zeros(h, w,CV_32FC1);
#ifdef GPU

        // Object for optical flow
        FarnebackOpticalFlow d_calc;
        setDevice(gpuDevice);

        // Initialize the parameters for optical flow structure
        d_calc.numLevels=6;
        d_calc.pyrScale=0.5;
        d_calc.fastPyramids=true;
        d_calc.winSize=winSize;
        d_calc.numIters=1;
        d_calc.polyN=5;
        d_calc.polySigma=1.1;
        d_calc.flags=0;
#endif
        // Initialize the stack for the output movie
        if (saveCorrMovie)
            outputMovie.initZeros(imagenum, 1, h, w);
        // Correct for global motion from a cross-correlation based algorithms
        if (globalShiftCorr)
        {
            Matrix1D<double> shiftMatrix(2);
            shiftVector.reserve(imagenum);
            shiftMD.read(globalShiftFilename);
            FOR_ALL_OBJECTS_IN_METADATA(shiftMD)
            {
                shiftMD.getValue(MDL_SHIFT_X, XX(shiftMatrix), __iter.objId);
                shiftMD.getValue(MDL_SHIFT_Y, YY(shiftMatrix), __iter.objId);
                shiftVector.push_back(shiftMatrix);
            }
        }
        tStart2=clock();
        // Compute the average of the whole stack
        fstFrame++; // Just to adapt to Li algorithm
        lstFrame++; // Just to adapt to Li algorithm
        if (lstFrame>=imagenum || lstFrame==1)
            lstFrame=imagenum;
        imagenum=lstFrame-fstFrame+1;
        levelNum=sqrt(double(imagenum));
        computeAvg(fname, fstFrame, lstFrame, avgCurr);
        // if the user want to save the PSD
        if (doAverage)
        {
            II()=avgCurr;
            II.write(foname);
            return 0;
        }
        xmipp2Opencv(avgCurr, avgcurr);
        cout<<"Frames "<<fstFrame<<" to "<<lstFrame<<" under processing ..."<<std::endl;
        while (div!=groupSize)
        {
            div=int(imagenum/cnt);
            // avgStep to hold the sum of aligned frames of each group at each step
            avgstep=cv::Mat::zeros(h, w,CV_32FC1);

            cout<<"Level "<<levelCounter<<"/"<<levelNum<<" of the pyramid is under processing"<<std::endl;
            // Compute time for each level
            tStart = clock();

            // Check if we are in the final step
            if (div==1)
                cnt=imagenum;
            flowCounter=1;
            for (int i=0;i<cnt;i++)
            {
                //Just compute the average in the last step
                if (div==1)
                {
                    if (globalShiftCorr)
                    {
                        Matrix1D<double> shiftMatrix(2);
                        MultidimArray<double> frameImage;
                        movieStack.readMapped(fname,i+1);
                        movieStack().getImage(frameImage);
                        if (darkImageCorr)
                        	frameImage-=darkImage;
                        if (gainImageCorr)
                        	frameImage/=gainImage;
                        XX(shiftMatrix)=XX(shiftVector[i]);
                        YY(shiftMatrix)=YY(shiftVector[i]);
                        translate(BSPLINE3, preImg, frameImage, shiftMatrix, WRAP);
                    }
                    else
                    {
                        movieStack.readMapped(fname,fstFrame+i);
                        movieStack().getImage(preImg);
                        if (darkImageCorr)
                            preImg-=darkImage;
                        if (gainImageCorr)
                            preImg/=gainImage;
                    }
                    xmipp2Opencv(preImg, preimg);
                }
                else
                {
                    if (i==cnt-1)
                        computeAvg(fname, i*div+fstFrame, lstFrame, preImg);
                    else
                        computeAvg(fname, i*div+fstFrame, (i+1)*div+fstFrame-1, preImg);
                }
                xmipp2Opencv(preImg, preimg);
                // Note: we should use the OpenCV conversion to use it in optical flow
                convert2Uint8(avgcurr,avgcurr8);
                convert2Uint8(preimg,preimg8);
#ifdef GPU

                d_avgcurr.upload(avgcurr8);
                d_preimg.upload(preimg8);
                if (cnt==2)
                    d_calc(d_avgcurr, d_preimg, d_flowx, d_flowy);
                else
                {
                    flowXFileName=foname.removeLastExtension()+formatString("flowx%d%d.txt",div*2,flowCounter);
                    flowYFileName=foname.removeLastExtension()+formatString("flowy%d%d.txt",div*2,flowCounter);
                    readMat(flowXFileName.c_str(), flowx);
                    readMat(flowYFileName.c_str(), flowy);
                    d_flowx.upload(flowx);
                    d_flowy.upload(flowy);
                    d_calc.flags=cv::OPTFLOW_USE_INITIAL_FLOW;
                    d_calc(d_avgcurr, d_preimg, d_flowx, d_flowy);
                }
                d_flowx.download(planes[0]);
                d_flowy.download(planes[1]);
                d_avgcurr.release();
                d_preimg.release();
                d_flowx.release();
                d_flowy.release();
#else

                if (cnt==2)
                    calcOpticalFlowFarneback(avgcurr8, preimg8, flow, 0.5, 6, winSize, 1, 5, 1.1, 0);
                else
                {
                    flowFileName=foname.removeLastExtension()+formatString("flow%d%d.txt",div*2,flowCounter);
                    readMat(flowFileName.c_str(), flow);
                    calcOpticalFlowFarneback(avgcurr8, preimg8, flow, 0.5, 6, winSize, 1, 5, 1.1, cv::OPTFLOW_USE_INITIAL_FLOW);
                }
                split(flow, planes);

#endif
                // Save the flows if we are in the last step
                if (div==groupSize)
                {
                    if (i > 0)
                    {
                        std_dev2(planes,flowxPre,flowyPre,meanStdev);
                        size_t id=MD.addObject();
                        MD.setValue(MDL_OPTICALFLOW_MEANX, double(meanStdev(0)), id);
                        MD.setValue(MDL_OPTICALFLOW_MEANY, double(meanStdev(2)), id);
                        MD.setValue(MDL_OPTICALFLOW_STDX, double(meanStdev(1)), id);
                        MD.setValue(MDL_OPTICALFLOW_STDY, double(meanStdev(3)), id);
                        MD.write(motionInfFile, MD_APPEND);
                    }
                    planes[0].copyTo(flowxPre);
                    planes[1].copyTo(flowyPre);
                }
                else
                {
#ifdef GPU
                    flowXFileName=foname.removeLastExtension()+formatString("flowx%d%d.txt",div,i+1);
                    flowYFileName=foname.removeLastExtension()+formatString("flowy%d%d.txt",div,i+1);
                    saveMat(flowXFileName.c_str(), planes[0]);
                    saveMat(flowYFileName.c_str(), planes[1]);
#else

                    flowFileName=foname.removeLastExtension()+formatString("flow%d%d.txt",div,i+1);
                    saveMat(flowFileName.c_str(), flow);
#endif

                    if ((i+1)%2==0)
                        flowCounter++;
                }
                for( int row = 0; row < planes[0].rows; row++ )
                    for( int col = 0; col < planes[0].cols; col++ )
                    {
                        planes[0].at<float>(row,col) += (float)col;
                        planes[1].at<float>(row,col) += (float)row;
                    }
                cv::remap(preimg, dest, planes[0], planes[1], cv::INTER_CUBIC);
                if (div==1 && saveCorrMovie)
                {
                    mappedImg.aliasImageInStack(outputMovie, i);
                    opencv2Xmipp(dest, mappedImg);
                }
                avgstep+=dest;
            }
            avgcurr=avgstep/cnt;
            cout<<"Processing level "<<levelCounter<<"/"<<levelNum<<" has been finished"<<std::endl;
            printf("Processing time: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
            cnt*=2;
            levelCounter++;
        }
        opencv2Xmipp(avgcurr, avgCurr);
        II() = avgCurr;
        II.write(foname);
        printf("Total Processing time: %.2fs\n", (double)(clock() - tStart2)/CLOCKS_PER_SEC);
        if (saveCorrMovie)
        {
            II()=outputMovie;
            II.write(foname.replaceExtension("mrcs"));
        }

        // Release the memory
        avgstep.release();
        preimg.release();
        avgcurr8.release();
        preimg8.release();
        flow.release();
        planes[0].release();
        planes[1].release();
        flowxPre.release();
        flowyPre.release();
        movieStack.clear();
        preImg.clear();
        avgCurr.clear();
        II.clear();
        return 0;
    }
void ProgValidationNonTilt::run()
{
    //Clustering Tendency and Cluster Validity Stephen D. Scott
    randomize_random_generator();
    //char buffer[400];
    //sprintf(buffer, "xmipp_reconstruct_significant -i %s  --initvolumes %s --odir %s --sym  %s --iter 1 --alpha0 %f --angularSampling %f",fnIn.c_str(), fnInit.c_str(),fnDir.c_str(),fnSym.c_str(),alpha0,angularSampling);
    //system(buffer);

    MetaData md,mdOut,mdOut2;
    FileName fnMd,fnOut,fnOut2;
    fnMd = fnDir+"/angles_iter001_00.xmd";
    fnOut = fnDir+"/clusteringTendency.xmd";
    fnOut2 = fnDir+"/validation.xmd";
    size_t nSamplesRandom = 250;

    md.read(fnMd);
    size_t maxNImg;
    size_t sz = md.size();
    md.getValue(MDL_IMAGE_IDX,maxNImg,sz);

    String expression;
    MDRow rowP,row2;
    SymList SL;
    int symmetry, sym_order;
    SL.readSymmetryFile(fnSym.c_str());
    SL.isSymmetryGroup(fnSym.c_str(), symmetry, sym_order);

    double non_reduntant_area_of_sphere = SL.nonRedundantProjectionSphere(symmetry,sym_order);
    double area_of_sphere_no_symmetry = 4.*PI;
    double correction = std::sqrt(non_reduntant_area_of_sphere/area_of_sphere_no_symmetry);
    double validation = 0;

	MetaData tempMd;
	std::vector<double> sum_u(nSamplesRandom);
	//std::vector<double> sum_w(nSamplesRandom);
	double sum_w=0;
	std::vector<double> H0(nSamplesRandom);
	std::vector<double> H(nSamplesRandom);

	if (rank==0)
		init_progress_bar(maxNImg);

	for (size_t idx=0; idx<=maxNImg;idx++)
	{
		if ((idx+1)%Nprocessors==rank)
		{
			expression = formatString("imageIndex == %lu",idx);
			tempMd.importObjects(md, MDExpression(expression));

			if (tempMd.size()==0)
				continue;

			//compute H_0 from noise
			obtainSumU(tempMd,sum_u,H0);
			//compute H from experimental
			obtainSumW(tempMd,sum_w,sum_u,H,correction);

			std::sort(H0.begin(),H0.end());
			std::sort(H.begin(),H.end());

			double P = 0;
			for(size_t j=0; j<sum_u.size();j++)
				P += H0.at(j)/H.at(j);

			P /= (nSamplesRandom);
			rowP.setValue(MDL_IMAGE_IDX,idx);
			rowP.setValue(MDL_WEIGHT,P);
			mdPartial.addRow(rowP);

			//sum_u.clear();
			//sum_w.clear();
			//H0.clear();
			//H.clear();
			tempMd.clear();

			if (rank==0)
				progress_bar(idx+1);
		}
	}

	if (rank==0)
		progress_bar(maxNImg);

	synchronize();
	gatherClusterability();

	if (rank == 0)
	{
		mdPartial.write(fnOut);
		std::vector<double> P;
		mdPartial.getColumnValues(MDL_WEIGHT,P);
		for (size_t idx=0; idx< P.size();idx++)
		{
		if (P[idx] > 1)
				
			validation += 1;

	        }

		validation /= (maxNImg+1);

	}

    row2.setValue(MDL_IMAGE,fnInit);
    row2.setValue(MDL_WEIGHT,validation);
    mdOut2.addRow(row2);
    mdOut2.write(fnOut2);
}
Example #3
0
 void add_node_parts(Iterator itr, size_t num)
 {
   ThrowRequire(!m_meta.is_commit());
   m_node_parts.insert(m_node_parts.end(), itr, itr + num);
 }
Example #4
0
int Computation::mandel(int xpt,int ypt,double xmin,double xmax,double ymin,double ymax , int _type)
{
    MetaData m;
	
    long double x = 0;
    long double y = 0;
    long double xnew = 0;
    long double ynew = 0;
    double ax;
    double ay;
    int color;
    int h;
    int xp = xpt;
    int yp = ypt;
    double minx = xmin;
    double maxx = xmax;
    double miny = ymin;
    double maxy = ymax;
    double pixCorx = (maxx - minx) / m.getWidth();
    double pixCory = (maxy - miny) / m.getHeight();
    
    ax = (xp * pixCorx) + (minx);
    ay = maxy - (yp * pixCory);
    
    for(h = 1 ; h <= iterations + 1 ; h++)
    {
	if( _type == MANDEL_TYPE1 )
	{
	    xnew = ((x * x) - (y * y)) + ax;
	    ynew = (2 * x * y) + ay;
	} // if
	
	if( _type == MANDEL_TYPE2 )
	{
	    xnew = ( ( x * x * x ) - ( 3 * x * y * y ) ) + ax;
	    ynew = ( ( 3 * x * x * y ) - ( y * y * y ) ) + ay;
	} // if 
	
	if( _type == MANDEL_TYPE3 )
	{
	    xnew = ( ( x * x * x * x ) - ( 6 * x * x * y * y ) + ( y * y * y * y ) ) + ax;
	    ynew = ( ( 4 * x * x * x * y ) - ( 4 * x * y * y * y ) ) + ay;
	} // if 
	
	if( _type == MANDEL_TYPE4 )
	{
	    xnew = ( ( x * x * x * x * x ) - ( 10 * x * x * x * y * y ) + ( 5 * x * y * y * y * y ) ) + ax;
	    ynew = ( ( 5 * x * x * x * x * y ) - ( 10 * x * x * y * y * y ) + ( y * y * y * y * y ) ) + ay;
	} // if
	
	if( _type == MANDEL_TYPE5 )
	{
	    xnew = ( ( x * x * x * x * x * x ) - ( 15 * x * x * x * x * y * y ) + (15 * x * x * y * y * y * y ) - ( y * y * y * y * y * y ) ) + ax;
	    ynew = ( ( 6 * x * x * x * x * x * y ) - ( 20 * x * x * x * y * y * y ) + ( 6 * x * y * y * y * y * y ) ) + ay;
	} // if
	
	x = xnew;
	y = ynew;
	
	if(((x * x) + (y * y)) > 4)
	    break;
    }  // for
    
    
    if(h >= iterations + 1 )
    {
	color =0 ;
    } // if
    
    else
    {
	color = h;
    } // else
    
	return color;	

}
Example #5
0
void outputTrainingData_6cls()
{
    FILE *XFile,*YFile;
    XFile=fopen("dataX.txt","w");
    YFile=fopen("dataY.txt","w");
    for(int i=0; i<2208-4; i++)
    {
        int XCnt=0;
        if(checkUseData(i))
        {
            for(int st=0; st<9; st++)
            {
                for(int j=0; j<4; j++)
                {
                    if(data[st][i+j].AQI==NullV)
                        fprintf(XFile,"%f,",2.5);
                    else
                        fprintf(XFile,"%d,",data[st][i+j].AQI);
                    XCnt++;
                    fprintf(XFile,"%d,",data[st][i+j].temp);
                    XCnt++;
                    fprintf(XFile,"%d,",data[st][i+j].pressure);
                    XCnt++;
                    fprintf(XFile,"%d,",data[st][i+j].humidity);
                    XCnt++;
                    fprintf(XFile,"%f,",data[st][i+j].windSpeed);
                    XCnt++;
                    fprintf(XFile,"%d,",data[st][i+j].windDirection);
                    XCnt++;
                    fprintf(XFile,"%d,",data[st][i+j].weather);
                    XCnt++;
                }
            }
            int dircnt[10];
            memset(dircnt,0,sizeof(dircnt));
            int weacnt[10];
            memset(weacnt,0,sizeof(weacnt));
            for(int st=0; st<9; st++)
            {
                int AqiT[10];
                memset(AqiT,0,sizeof(AqiT));
                int cnt=0;
                double tsum=0,psum=0,hsum=0,wsum=0;
                for(int j=4; j<16; j++)
                {
                    if(data[st][i+j].AQI==NullV)
                        ;
                    else AqiT[data[st][i+j].AQI]++;
                    if(data[st][i+j].temp!=NullV)
                    {
                        cnt++;
                        tsum+=data[st][i+j].temp;
                        psum+=data[st][i+j].pressure;
                        hsum+=data[st][i+j].humidity;
                        wsum+=data[st][i+j].windSpeed;
                    }
                    //      int t=data[st][i+j].windDirection;
                    dircnt[data[st][i+j].windDirection]++;
                    weacnt[data[st][i+j].weather]++;
                }
       //         int sum=n0+n1+n2;
       //         fprintf(YFile,"%f,%f,%f",(n0+0.0)/sum,(n1+0.0)/sum,(n2+0.0)/sum);
                int mostA=0;
                for(int i=1;i<6;i++)
                    if(AqiT[i]>AqiT[mostA])
                        mostA=i;
                fprintf(YFile,"%d",mostA);
                if(st!=8)
                    fprintf(YFile,",");

                MetaData tmp;
                tmp.windSpeed=wsum/cnt;
                tmp.evaluateWindSpeed();
                fprintf(XFile,"%f,%f,",tsum/cnt,tmp.windSpeed);
                XCnt+=2;
                int mostDir=0,mostWea=0;
                for(int i=1; i<9; i++)
                    if(dircnt[i]>dircnt[mostDir])
                        mostDir=i;
                for(int i=1; i<8; i++)
                    if(weacnt[i]>weacnt[mostWea])
                        mostWea=i;
                fprintf(XFile,"%d,%d,",mostDir,mostWea);
                XCnt+=2;
                //              if(st!=8)
                //                  fprintf(XFile,",");
            }
            int y,m,d,h;
            sscanf(data[0][i].time,"%d-%d-%d %d",&y,&m,&d,&h);
            fprintf(XFile,"%d\n",h);
            fprintf(YFile,"\n");
        }
    }
}
Example #6
0
feature_ptr occi_featureset::next()
{
    if (rs_ && rs_->next())
    {
        feature_ptr feature(feature_factory::create(ctx_,feature_id_));
        ++feature_id_;

        if (use_wkb_)
        {
            Blob blob = rs_->getBlob (1);
            blob.open(oracle::occi::OCCI_LOB_READONLY);

            int size = blob.length();
            if (buffer_.size() < size)
            {
                buffer_.resize(size);
            }

            oracle::occi::Stream* instream = blob.getStream(1,0);
            instream->readBuffer(buffer_.data(), size);
            blob.closeStream(instream);
            blob.close();

            geometry_utils::from_wkb(feature->paths(), buffer_.data(), size);
        }
        else
        {
            boost::scoped_ptr<SDOGeometry> geom(dynamic_cast<SDOGeometry*>(rs_->getObject(1)));
            if (geom.get())
            {
                convert_geometry(geom.get(), feature);
            }
        }

        std::vector<MetaData> listOfColumns = rs_->getColumnListMetaData();

        for (unsigned int i = 1; i < listOfColumns.size(); ++i)
        {
            MetaData columnObj = listOfColumns[i];

            std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
            int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);

            /*
              int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
              if (type_code == OCCI_TYPECODE_OBJECT)
              {
              continue;
              }
            */

            switch (type_oid)
            {
            case oracle::occi::OCCIBOOL:
            case oracle::occi::OCCIINT:
            case oracle::occi::OCCIUNSIGNED_INT:
            case oracle::occi::OCCIROWID:
                feature->put(fld_name,rs_->getInt (i + 1));
                break;
            case oracle::occi::OCCIFLOAT:
            case oracle::occi::OCCIBFLOAT:
            case oracle::occi::OCCIDOUBLE:
            case oracle::occi::OCCIBDOUBLE:
            case oracle::occi::OCCINUMBER:
            case oracle::occi::OCCI_SQLT_NUM:
                feature->put(fld_name,rs_->getDouble (i + 1));
                break;
            case oracle::occi::OCCICHAR:
            case oracle::occi::OCCISTRING:
            case oracle::occi::OCCI_SQLT_AFC:
            case oracle::occi::OCCI_SQLT_AVC:
            case oracle::occi::OCCI_SQLT_CHR:
            case oracle::occi::OCCI_SQLT_LVC:
            case oracle::occi::OCCI_SQLT_RDD:
            case oracle::occi::OCCI_SQLT_STR:
            case oracle::occi::OCCI_SQLT_VCS:
            case oracle::occi::OCCI_SQLT_VNU:
            case oracle::occi::OCCI_SQLT_VBI:
            case oracle::occi::OCCI_SQLT_VST:
                feature->put(fld_name,(UnicodeString) tr_->transcode (rs_->getString (i + 1).c_str()));
                break;
            case oracle::occi::OCCIDATE:
            case oracle::occi::OCCITIMESTAMP:
            case oracle::occi::OCCIINTERVALDS:
            case oracle::occi::OCCIINTERVALYM:
            case oracle::occi::OCCI_SQLT_DAT:
            case oracle::occi::OCCI_SQLT_DATE:
            case oracle::occi::OCCI_SQLT_TIME:
            case oracle::occi::OCCI_SQLT_TIME_TZ:
            case oracle::occi::OCCI_SQLT_TIMESTAMP:
            case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ:
            case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ:
            case oracle::occi::OCCI_SQLT_INTERVAL_YM:
            case oracle::occi::OCCI_SQLT_INTERVAL_DS:
            case oracle::occi::OCCIANYDATA:
            case oracle::occi::OCCIBLOB:
            case oracle::occi::OCCIBFILE:
            case oracle::occi::OCCIBYTES:
            case oracle::occi::OCCICLOB:
            case oracle::occi::OCCIVECTOR:
            case oracle::occi::OCCIMETADATA:
            case oracle::occi::OCCIPOBJECT:
            case oracle::occi::OCCIREF:
            case oracle::occi::OCCIREFANY:
            case oracle::occi::OCCISTREAM:
            case oracle::occi::OCCICURSOR:
            case oracle::occi::OCCI_SQLT_FILE:
            case oracle::occi::OCCI_SQLT_CFILE:
            case oracle::occi::OCCI_SQLT_REF:
            case oracle::occi::OCCI_SQLT_CLOB:
            case oracle::occi::OCCI_SQLT_BLOB:
            case oracle::occi::OCCI_SQLT_RSET:
                {
                    MAPNIK_LOG_WARN(occi) << "occi_featureset: Unsupported datatype "
                                          << occi_enums::resolve_datatype(type_oid)
                                          << " (type_oid=" << type_oid << ")";
                    break;
                }
            default: // shouldn't get here
                {
                    MAPNIK_LOG_WARN(occi) << "occi_featureset: Unknown datatype "
                                          << "(type_oid=" << type_oid << ")";
                    break;
                }
            }
        }

        return feature;
    }

    return feature_ptr();
}
Example #7
0
int main(int argc, char *argv[])
{
   char        sig[37];
   MetaData    m;
   struct stat s;
   int         index = 1;
   bool        hasmeta = false;

   if (argc < 2)
   {
       printf("Usage: sigapp [-q] [-n] <mp3 file>\n");
       printf("  -q => quiet mode\n");
       printf("  -l => don't lookup data at musicbrainz\n");
       exit(0);
   }

   if (strcmp(argv[index], "-q") == 0)
   {
       quiet = 1;
       index++;
   }

   if (strcmp(argv[index], "-l") == 0)
   {
       nosubmit = 1;
       index++;
   }

   if (get_metadata(argv[index], &m))
   {
       stat(argv[index], &s);
       m.SetSize(s.st_size);
       if (!quiet)
       {
          printf("Local metadata:\n");
          printf("    Title: %s\n", m.Title().c_str());
          printf("    Album: %s\n", m.Album().c_str());
          printf("   Artist: %s\n", m.Artist().c_str());
          printf("    Genre: %s\n", m.Genre().c_str());
          printf("  Comment: %s\n", m.Comment().c_str());
          printf("    Track: %d\n", m.Track());
          printf("     Time: %d\n", m.Time());
          printf("     Size: %d\n", m.Size());
       }
       hasmeta = true;
   }
   
   if (ff_decode(argv[index], sig, 0, 0, 0, 24000, 0))
   {
       m.SetGUID(sig);
       if (!quiet)
           printf("Signature: ");

       printf("%s\n", sig);
       if (!nosubmit)
       {
           lookup_metadata(&m);
       }
#ifdef SIG_DEBUG
       FILE *logfile = fopen("guid_mapping.txt", "a+");
       fprintf(logfile,"%s\t%s\n", argv[index], sig);
       fclose(logfile);
#endif
   }
   else
   {
       if (!quiet)
          printf("Error calculating signature.\n");
   }

   return 0;
}
Example #8
0
void WorldModel::updateMetaDataForId(ID newId, const MetaData &newData) {
    for (string name : newData.GetValueNames()) {
        metaData[newId].SetValue(name, newData.GetValue(name));
    }
}
Example #9
0
 QVariantMap toDBus(const MetaData &md) const {
     QVariantMap map;
     map["mpris:trackid"] = QVariant::fromValue(QDBusObjectPath(dbusTrackId(md.mrl())));
     map["mpris:length"] = 1000LL*(qint64)md.duration();
     map["xesam:url"] = md.mrl().toString();
     map["xesam:title"] = md.title().isEmpty() ? engine->mediaInfo()->name() : md.title();
     if (!md.album().isEmpty())
         map["xesam:album"] = md.album();
     if (!md.artist().isEmpty())
         map["xesam:artist"] = QStringList(md.artist());
     if (!md.genre().isEmpty())
         map["xesam:genre"] = QStringList(md.genre());
     return map;
 }
Example #10
0
/** Given an array of already set up data sets (from e.g. input data files)
  * and optional X values, add the sets to this list if they do not exist
  * or append any existing sets.
  */
int DataSetList::AddOrAppendSets(std::string const& XlabelIn, Darray const& Xvals,
                                 DataListType const& Sets)
{
  if (debug_ > 0)
    mprintf("DEBUG: Calling AddOrAppendSets for %zu sets, %zu X values, Xlabel= %s.\n",
            Sets.size(), Xvals.size(), XlabelIn.c_str());
  if (Sets.empty()) return 0; // No error for now.
  // If no X label assume 'Frame' for backwards compat.
  std::string Xlabel;
  if (XlabelIn.empty())
    Xlabel.assign("Frame");
  else
    Xlabel = XlabelIn;
  Dimension Xdim;
  // First determine if X values increase monotonically with a regular step
  bool isMonotonic = Xdim.SetDimension(Xvals, Xlabel);
  if (debug_ > 0) {
    mprintf("DEBUG: xstep %g xmin %g\n", Xdim.Step(), Xdim.Min());
    if (isMonotonic) mprintf("DEBUG: Xdim is monotonic.\n");
  }
  for (const_iterator ds = Sets.begin(); ds != Sets.end(); ++ds) {
    if (*ds == 0) continue; // TODO: Warn about blanks?
    if (debug_ > 0) mprintf("DEBUG: AddOrAppend set '%s'", (*ds)->legend());
    if (isMonotonic) (*ds)->SetDim(Dimension::X, Xdim);
    DataSet* existingSet = CheckForSet( (*ds)->Meta() );
    if (existingSet == 0) {
      // New set. If set is scalar 1D but X values are not monotonic,
      // convert to XY mesh if necessary.
      if ( !isMonotonic &&
           (*ds)->Group() == DataSet::SCALAR_1D &&
           (*ds)->Type() != DataSet::XYMESH )
      {
        DataSet* xyptr = AddSet( DataSet::XYMESH, (*ds)->Meta() );
        if (xyptr == 0) {
          mprinterr("Error: Could not convert set %s to XY mesh.\n", (*ds)->legend());
          continue; // TODO exit instead?
        }
        if ( (*ds)->Size() != Xvals.size() ) { // Sanity check
          mprinterr("Error: # of X values does not match set %s size.\n", (*ds)->legend());
          continue;
        }
        DataSet_1D const& set = static_cast<DataSet_1D const&>( *(*ds) );
        DataSet_Mesh& xy = static_cast<DataSet_Mesh&>( *xyptr );
        for (unsigned int i = 0; i != set.Size(); i++)
          xy.AddXY( Xvals[i], set.Dval(i) );
        xy.SetDim(Dimension::X, Xdim);
        if (debug_ > 0) mprintf(", New set, converted to XY-MESH\n");
        // Free memory since set has now been converted.
        delete *ds;
      } else { // No conversion. Just add.
        (*ds)->SetDim(Dimension::X, Xdim);
        AddSet( *ds );
        if (debug_ > 0) mprintf(", New set\n");
      }
    } else {
      if (debug_ > 0) mprintf(", appending to existing set\n");
      // Set exists. Try to append this set to existing set.
      bool canAppend = true;
      if ( (*ds)->Group() == DataSet::GENERIC ) {
        // For GENERIC sets, base Type must match. // TODO: Should this logic be in DataSets?
        if ( (*ds)->Type() != existingSet->Type() )
          canAppend = false;
      } else {
        // For non-GENERIC sets, Group must match
        if ( (*ds)->Group() != existingSet->Group() )
          canAppend = false;
      }
      if (!canAppend)
        mprinterr("Error: Cannot append set of type %s to set of type %s\n",
                  DataArray[(*ds)->Type()].Description,
                  DataArray[existingSet->Type()].Description);
      // If cannot append or attempt to append fails, rename and add as new set.
      if (!canAppend || existingSet->Append( *ds )) { // TODO Dimension check?
        if (canAppend)
          mprintf("Warning: Append currently not supported for type %s\n",
                  DataArray[existingSet->Type()].Description);
        MetaData md = (*ds)->Meta();
        md.SetName( GenerateDefaultName("X") );
        mprintf("Warning: Renaming %s to %s\n", (*ds)->Meta().PrintName().c_str(),
                md.PrintName().c_str());
        (*ds)->SetMeta( md );
       
        AddSet( *ds );
      } else // Set was appended to existing set; memory can be freed.
        delete *ds;
    }
  } // END loop over input sets
  return 0;
}
Example #11
0
 const MetaData MetaDataStore::originalAt(int row) const {
     const MetaData item = _data[row];
     return _backup.contains(item.id()) ? _backup[item.id()] : item;
 }
Example #12
0
 int32_t getBytes() const {
     return metaData.getBytes();
 }
Example #13
0
 void reset() {
     metaData.reset();
 }
Example #14
0
 void setMessage(const char* src, int32_t n) {
     reserve(n);
     memcpy(data, src, n);
     metaData.setBytes(n);
 }
Example #15
0
void PLS::AddItem(vector<PlaylistItem*>* list, char *entry, 
                  char *title, int32 len, char *root)
{
    int32         index;
    uint32        length;
    char          path[_MAX_PATH];
    PlaylistItem *item;

    // if this is not a URL then let's
    // enable people with different platforms 
    // to swap files by changing the path 
    // separator as necessary
    if( strncmp(entry, "http://", 7) &&
        strncmp(entry, "rtp://", 6) &&
        strncmp(entry, "file://", 7))
    {
        for (index = strlen(entry) - 1; index >=0; index--)
        {
            if(entry[index] == '\\' && DIR_MARKER == '/')
                entry[index] = DIR_MARKER;
            else if(entry[index] == '/' && DIR_MARKER == '\\')
                entry[index] = DIR_MARKER;
        }
    }

    // get rid of nasty trailing whitespace
    for (index = strlen(entry) - 1; index >=0; index--)
    {
        if(isspace(entry[index]))
        {
            entry[index] = 0x00;
        }
        else
            break;
    }

    // is there anything left?
    if(strlen(entry))
    {
        // is it a url already?
        if (!strncmp(entry, "http://", 7) ||
            !strncmp(entry, "rtp://", 6) ||
            !strncmp(entry, "file://", 7))
        {
            strcpy(path, entry);
        }
        else 
        {
            // is the path relative?
            if( !strncmp(entry, "..", 2) ||
                (strncmp(entry + 1, ":\\", 2) &&
                 strncmp(entry, DIR_MARKER_STR, 1)))
            {
                strcpy(path, root);
                strcat(path, entry);
            }
            else
            {
                strcpy(path, entry);
            }
            
            // make it a url so we can add it to the playlist
            length = strlen(path) + 15;
            char *itemurl = new char[length];

            if (IsntError(FilePathToURL(path, itemurl, &length)))
                strcpy(path, itemurl);
 
            delete [] itemurl;
        }

        if (title || len > 0)
        {
            MetaData oData;
           
            if (title)
               oData.SetTitle(title);
            if (len > 0)
               oData.SetTime(len);

            item = new PlaylistItem(path, &oData);
        }
        else
            item = new PlaylistItem(path);

        list->push_back(item);
    }
}
Example #16
0
void ProgNmaAlignment::writeImageParameters(const FileName &fnImg) {
	MetaData md;
	size_t objId = md.addObject();
	md.setValue(MDL_IMAGE, fnImg, objId);
	md.setValue(MDL_ENABLED, 1, objId);
	md.setValue(MDL_ANGLE_ROT, parameters(0), objId);
	md.setValue(MDL_ANGLE_TILT, parameters(1), objId);
	md.setValue(MDL_ANGLE_PSI, parameters(2), objId);
	md.setValue(MDL_SHIFT_X, parameters(3), objId);
	md.setValue(MDL_SHIFT_Y, parameters(4), objId);

	int dim = numberOfModes;
	std::vector<double> vectortemp;

	for (int j = 5; j < 5 + dim; j++) {
		vectortemp.push_back(parameters(j));
	}

	md.setValue(MDL_NMA, vectortemp, objId);
	md.setValue(MDL_COST, parameters(5 + dim), objId);

	md.append(fnOutDir+"/nmaDone.xmd");
}
Example #17
0
int main(int argc, char *argv[])
{
  CLParserPtr optParser = initParser();
  string inPath, bottomAlignmentFile, topAlignmentFile, genomeName;
  bool noMarkAncestors;
  try {
    optParser->parseOptions(argc, argv);
    inPath = optParser->getArgument<string>("inFile");
    bottomAlignmentFile = optParser->getOption<string>("bottomAlignmentFile");
    topAlignmentFile = optParser->getOption<string>("topAlignmentFile");
    genomeName = optParser->getArgument<string>("genomeName");
    noMarkAncestors = optParser->getFlag("noMarkAncestors");
  } catch (exception &e) {
    optParser->printUsage(cerr);
    return 1;
  }
  AlignmentPtr mainAlignment = openHalAlignment(inPath, optParser);
  AlignmentConstPtr bottomAlignment;
  AlignmentConstPtr topAlignment;
  bool useTopAlignment = mainAlignment->getRootName() != genomeName;
  bool useBottomAlignment = mainAlignment->getChildNames(genomeName).size() != 0;
  Genome *mainReplacedGenome = mainAlignment->openGenome(genomeName);
  if (useTopAlignment) {
    // Not a root genome. Can update using a top alignment.
    if (topAlignmentFile == "\"\"") {
      throw hal_exception("Cannot replace non-root genome without a top "
                          "alignment file.");
    }
    topAlignment = openHalAlignment(topAlignmentFile,
                                    optParser);
    const Genome *topReplacedGenome = topAlignment->openGenome(genomeName);
    topReplacedGenome->copyDimensions(mainReplacedGenome);
    topReplacedGenome->copySequence(mainReplacedGenome);
    
  }
  if (useBottomAlignment) {
    // Not a leaf genome. Can update using a bottom alignment.
    if (bottomAlignmentFile == "\"\"") {
      throw hal_exception("Cannot replace non-leaf genome without a bottom "
                          "alignment file.");
    }
    bottomAlignment = openHalAlignment(bottomAlignmentFile, optParser);
    const Genome *botReplacedGenome = bottomAlignment->openGenome(genomeName);
    botReplacedGenome->copyDimensions(mainReplacedGenome);
    botReplacedGenome->copySequence(mainReplacedGenome);
  }
  if (!useTopAlignment && !useBottomAlignment) {
    throw hal_exception("Root genome is also a leaf genome.");
  }
  if (useBottomAlignment) {
    copyFromBottomAlignment(bottomAlignment, mainAlignment, genomeName);
  }
  if (useTopAlignment) {
    copyFromTopAlignment(topAlignment, mainAlignment, genomeName);
  }

  // Clear update flag if present, since the genome has just been updated.
  MetaData *metaData = mainReplacedGenome->getMetaData();
  if (metaData->has("needsUpdate")) {
    metaData->set("needsUpdate", "false");
  }

  if (!noMarkAncestors) {
    markAncestorsForUpdate(mainAlignment, genomeName);
  }
  if (useTopAlignment) {
    topAlignment->close();
  }
  if (useBottomAlignment) {
    bottomAlignment->close();
  }
  mainAlignment->close();
}
Example #18
0
// Exec_DataSetCmd::ModifyPoints()
Exec::RetType Exec_DataSetCmd::ModifyPoints(CpptrajState& State, ArgList& argIn, bool drop) {
  const char* mode;
  if (drop)
    mode = "Drop";
  else
    mode = "Kee";
  // Keywords
  std::string name = argIn.GetStringKey("name");
  int start = argIn.getKeyInt("start", 0) - 1;
  int stop = argIn.getKeyInt("stop", -1);
  int offset = argIn.getKeyInt("offset", -1);
  Range points;
  if (start < 0 && stop < 0 && offset < 0) {
    std::string rangearg = argIn.GetStringKey("range");
    if (rangearg.empty()) {
      mprinterr("Error: Must specify range or start/stop/offset.\n");
      return CpptrajState::ERR;
    }
    points.SetRange( rangearg );
    if (points.Empty()) {
      mprinterr("Error: Range '%s' is empty.\n", rangearg.c_str());
      return CpptrajState::ERR;
    }
    mprintf("\t%sping points in range %s\n", mode, rangearg.c_str());
    // User args start from 1
    points.ShiftBy(-1);
  }
  // Get data set to drop/keep points from
  // Loop over all DataSet arguments 
  std::string ds_arg = argIn.GetStringNext();
  while (!ds_arg.empty()) {
    DataSetList dsl = State.DSL().GetMultipleSets( ds_arg );
    for (DataSetList::const_iterator it = dsl.begin(); it != dsl.end(); ++it)
    {
      DataSet* DS = *it;
      if (DS->Size() < 1) {
        mprinterr("Error: Set '%s' is empty.\n", DS->legend());
        return CpptrajState::ERR;
      }
      // Restrict to 1D sets for now TODO more types
      if (DS->Group() != DataSet::SCALAR_1D) {
        mprinterr("Error: Currently only works for 1D scalar data sets.\n");
        return CpptrajState::ERR;
      }
      DataSet_1D* ds1 = (DataSet_1D*)DS;
      // Output data set
      DataSet* out = 0;
      if (name.empty()) {
        // Modifying this set. Create new temporary set.
        out = State.DSL().Allocate( ds1->Type() );
        if (out == 0) return CpptrajState::ERR;
        *out = *ds1;
        mprintf("\tOverwriting set '%s'\n", ds1->legend());
      } else {
        // Write to new set
        MetaData md = ds1->Meta();
        md.SetName( name );
        out = State.DSL().AddSet(ds1->Type(), md);
        if (out == 0) return CpptrajState::ERR;
        mprintf("\tNew set is '%s'\n", out->Meta().PrintName().c_str());
      }
      out->Allocate(DataSet::SizeArray(1, ds1->Size()));
      if (points.Empty()) {
        // Drop by start/stop/offset. Set defaults if needed
        if (start < 0)  start = 0;
        if (stop < 0)   stop = ds1->Size();
        if (offset < 0) offset = 1;
        mprintf("\t%sping points from %i to %i, step %i\n", mode, start+1, stop, offset);
        for (int idx = start; idx < stop; idx += offset)
          points.AddToRange( idx );
      } // TODO check that range values are valid?
      if (State.Debug() > 0) mprintf("DEBUG: Keeping points:");
      Range::const_iterator pt = points.begin();
      int idx = 0;
      int odx = 0;
      if (drop) {
        // Drop points
        for (; idx < (int)ds1->Size(); idx++) {
          if (pt == points.end()) break;
          if (*pt != idx) {
            if (State.Debug() > 0) mprintf(" %i", idx + 1);
            KeepPoint(ds1, out, idx, odx);
          } else
            ++pt;
        }
        // Keep all remaining points
        for (; idx < (int)ds1->Size(); idx++) {
          if (State.Debug() > 0) mprintf(" %i", idx + 1);
          KeepPoint(ds1, out, idx, odx);
        }
      } else {
        // Keep points
        for (; pt != points.end(); pt++) {
          if (*pt >= (int)ds1->Size()) break;
          if (State.Debug() > 0) mprintf(" %i", *pt + 1);
          KeepPoint(ds1, out, *pt, odx);
        }
      }
      if (State.Debug() > 0) mprintf("\n");
      if (name.empty()) {
        // Replace old set with new set
        State.DSL().RemoveSet( ds1 );
        State.DSL().AddSet( out );
      }
    } // END loop over sets
    ds_arg = argIn.GetStringNext();
  } // END loop over set args
  return CpptrajState::OK;
}
Example #19
0
bool SlaveInterface::dispatch(int _cmd, const QByteArray &rawdata)
{
    Q_D(SlaveInterface);
    //kDebug(7007) << "dispatch " << _cmd;

    QDataStream stream(rawdata);

    QString str1;
    qint32 i;
    qint8 b;
    quint32 ul;

    switch(_cmd) {
    case MSG_DATA:
        emit data(rawdata);
        break;
    case MSG_DATA_REQ:
        emit dataReq();
        break;
    case MSG_OPENED:
        emit open();
        break;
    case MSG_FINISHED:
        //kDebug(7007) << "Finished [this = " << this << "]";
        d->offset = 0;
        d->speed_timer.stop();
        emit finished();
        break;
    case MSG_STAT_ENTRY: {
        UDSEntry entry;
        stream >> entry;
        emit statEntry(entry);
        break;
    }
    case MSG_LIST_ENTRIES: {
        quint32 count;
        stream >> count;

        UDSEntryList list;
        UDSEntry entry;
        for (uint i = 0; i < count; i++) {
            stream >> entry;
            list.append(entry);
        }
        emit listEntries(list);
        break;
    }
    case MSG_RESUME: { // From the put job
        d->offset = readFilesize_t(stream);
        emit canResume(d->offset);
        break;
    }
    case MSG_CANRESUME: // From the get job
        d->filesize = d->offset;
        emit canResume(0); // the arg doesn't matter
        break;
    case MSG_ERROR:
        stream >> i >> str1;
        kDebug(7007) << "error " << i << " " << str1;
        emit error(i, str1);
        break;
    case MSG_SLAVE_STATUS: {
        PIDType<sizeof(pid_t)>::PID_t stream_pid;
        pid_t pid;
        QByteArray protocol;
        stream >> stream_pid >> protocol >> str1 >> b;
        pid = stream_pid;
        emit slaveStatus(pid, protocol, str1, (b != 0));
        break;
    }
    case MSG_CONNECTED:
        emit connected();
        break;
    case MSG_WRITTEN: {
        KIO::filesize_t size = readFilesize_t(stream);
        emit written(size);
        break;
    }
    case INF_TOTAL_SIZE: {
        KIO::filesize_t size = readFilesize_t(stream);
        gettimeofday(&d->start_time, 0);
        d->last_time = 0;
        d->filesize = d->offset;
        d->sizes[0] = d->filesize - d->offset;
        d->times[0] = 0;
        d->nums = 1;
        d->speed_timer.start(1000);
        d->slave_calcs_speed = false;
        emit totalSize(size);
        break;
    }
    case INF_PROCESSED_SIZE: {
        KIO::filesize_t size = readFilesize_t(stream);
        emit processedSize( size );
        d->filesize = size;
        break;
    }
    case INF_POSITION: {
        KIO::filesize_t pos = readFilesize_t(stream);
        emit position(pos);
        break;
    }
    case INF_SPEED:
        stream >> ul;
        d->slave_calcs_speed = true;
        d->speed_timer.stop();
        emit speed( ul );
        break;
    case INF_GETTING_FILE:
        break;
    case INF_ERROR_PAGE:
        emit errorPage();
        break;
    case INF_REDIRECTION: {
        KUrl url;
        stream >> url;
        emit redirection( url );
        break;
    }
    case INF_MIME_TYPE:
        stream >> str1;
        emit mimeType(str1);
        if (!d->connection->suspended())
            d->connection->sendnow(CMD_NONE, QByteArray());
        break;
    case INF_WARNING:
        stream >> str1;
        emit warning(str1);
        break;
    case INF_MESSAGEBOX: {
        kDebug(7007) << "needs a msg box";
        QString text, caption, buttonYes, buttonNo, dontAskAgainName;
        int type;
        stream >> type >> text >> caption >> buttonYes >> buttonNo;
        if (stream.atEnd()) {
            messageBox(type, text, caption, buttonYes, buttonNo);
        } else {
            stream >> dontAskAgainName;
            messageBox(type, text, caption, buttonYes, buttonNo, dontAskAgainName);
        }
        break;
    }
    case INF_INFOMESSAGE: {
        QString msg;
        stream >> msg;
        emit infoMessage(msg);
        break;
    }
    case INF_META_DATA: {
        MetaData m;
        stream >> m;
        if (m.contains(QLatin1String("ssl_in_use"))) {
            const QLatin1String ssl_("ssl_");
            const MetaData constM = m;
            for (MetaData::ConstIterator it = constM.lowerBound(ssl_); it != constM.constEnd(); ++it) {
                if (it.key().startsWith(ssl_)) {
                    d->sslMetaData.insert(it.key(), it.value());
                } else {
                    // we're past the ssl_* entries; remember that QMap is ordered.
                    break;
                }
            }
        }
        emit metaData(m);
        break;
    }
    case MSG_NET_REQUEST: {
        QString host;
        QString slaveid;
        stream >> host >> slaveid;
        requestNetwork(host, slaveid);
        break;
    }
    case MSG_NET_DROP: {
        QString host;
        QString slaveid;
        stream >> host >> slaveid;
        dropNetwork(host, slaveid);
        break;
    }
    case MSG_NEED_SUBURL_DATA: {
        emit needSubUrlData();
        break;
    }
    case MSG_HOST_INFO_REQ: {
        QString hostName;
        stream >> hostName;
        HostInfo::lookupHost(hostName, this, SLOT(slotHostInfo(QHostInfo)));
        break;
    }
    default:
        kWarning(7007) << "Slave sends unknown command (" << _cmd << "), dropping slave";
        return false;
    }
    return true;
}
Example #20
0
// Exec_DataSetCmd::ChangeModeType()
Exec::RetType Exec_DataSetCmd::ChangeModeType(CpptrajState const& State, ArgList& argIn) {
  std::string modeKey = argIn.GetStringKey("mode");
  std::string typeKey = argIn.GetStringKey("type");
  if (modeKey.empty() && typeKey.empty()) {
    mprinterr("Error: No valid keywords specified.\n");
    return CpptrajState::ERR;
  }
  // First determine mode if specified.
  MetaData::scalarMode dmode = MetaData::UNKNOWN_MODE;
  if (!modeKey.empty()) {
    dmode = MetaData::ModeFromKeyword( modeKey );
    if (dmode == MetaData::UNKNOWN_MODE) {
      mprinterr("Error: Invalid mode keyword '%s'\n", modeKey.c_str());
      return CpptrajState::ERR;
    }
  }
  // Next determine type if specified.
  MetaData::scalarType dtype = MetaData::UNDEFINED;
  if (!typeKey.empty()) {
    dtype = MetaData::TypeFromKeyword( typeKey, dmode );
    if (dtype == MetaData::UNDEFINED) {
      mprinterr("Error: Invalid type keyword '%s'\n", typeKey.c_str());
      return CpptrajState::ERR;
    }
  }
  // Additional options for type 'noe'
  AssociatedData_NOE noeData;
  if (dtype == MetaData::NOE) {
    if (noeData.NOE_Args(argIn))
      return CpptrajState::ERR;
  }
  if (dmode != MetaData::UNKNOWN_MODE)
    mprintf("\tDataSet mode = %s\n", MetaData::ModeString(dmode));
  if (dtype != MetaData::UNDEFINED)
    mprintf("\tDataSet type = %s\n", MetaData::TypeString(dtype));
  // Loop over all DataSet arguments 
  std::string ds_arg = argIn.GetStringNext();
  while (!ds_arg.empty()) {
    DataSetList dsl = State.DSL().GetMultipleSets( ds_arg );
    for (DataSetList::const_iterator ds = dsl.begin(); ds != dsl.end(); ++ds)
    {
      if (dmode != MetaData::UNKNOWN_MODE) {
        // Warn if mode does not seem appropriate for the data set type.
        if ( dmode >= MetaData::M_DISTANCE &&
             dmode <= MetaData::M_RMS &&
             (*ds)->Group() != DataSet::SCALAR_1D )
          mprintf("Warning: '%s': Expected scalar 1D data set type for mode '%s'\n",
                  (*ds)->legend(), MetaData::ModeString(dmode));
        else if ( dmode == MetaData::M_VECTOR &&
                  (*ds)->Type() != DataSet::VECTOR )
          mprintf("Warning: '%s': Expected vector data set type for mode '%s'\n",
                  (*ds)->legend(), MetaData::ModeString(dmode));
        else if ( dmode == MetaData::M_MATRIX &&
                  (*ds)->Group() != DataSet::MATRIX_2D )
          mprintf("Warning: '%s': Expected 2D matrix data set type for mode '%s'\n",
                  (*ds)->legend(), MetaData::ModeString(dmode));
      }
      if ( dtype == MetaData::NOE ) (*ds)->AssociateData( &noeData );
      mprintf("\t\t'%s'\n", (*ds)->legend());
      MetaData md = (*ds)->Meta();
      md.SetScalarMode( dmode );
      md.SetScalarType( dtype );
      (*ds)->SetMeta( md );
    }
    ds_arg = argIn.GetStringNext();
  }
  return CpptrajState::OK;
}
void occi_datasource::bind() const
{
    if (is_bound_) return;

    // connect to environment
    if (use_connection_pool_)
    {
        try
        {
            Environment* env = occi_environment::get_environment();

            pool_ = env->createStatelessConnectionPool(
                        *params_.get<std::string>("user"),
                        *params_.get<std::string>("password"),
                        *params_.get<std::string>("host"),
                        *params_.get<int>("max_size",10),
                        *params_.get<int>("initial_size",1),
                        1,
                        StatelessConnectionPool::HOMOGENEOUS);
        }
        catch (SQLException &ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }
    else
    {
        try
        {
            Environment* env = occi_environment::get_environment();
            
            conn_ = env->createConnection(
                        *params_.get<std::string>("user"),
                        *params_.get<std::string>("password"),
                        *params_.get<std::string>("host"));
        }
        catch (SQLException &ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }

    std::string table_name = mapnik::table_from_sql(table_);

    // get SRID and/or GEOMETRY_FIELD from metadata table only if we need to
    if (! srid_initialized_ || geometry_field_ == "")
    {
        std::ostringstream s;
        s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE";
        s << " LOWER(table_name) = LOWER('" << table_name << "')";
        
        if (geometry_field_ != "")
            s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";

#ifdef MAPNIK_DEBUG
        std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif

        try
        {
            occi_connection_ptr conn;
            if (use_connection_pool_) conn.set_pool(pool_);
            else                      conn.set_connection(conn_, false);

            ResultSet* rs = conn.execute_query (s.str());
            if (rs && rs->next ())
            {
                if (! srid_initialized_)
                {
                    srid_ = rs->getInt(1);
                    srid_initialized_ = true;
                }
                
                if (geometry_field_ == "")
                {
                    geometry_field_ = rs->getString(2);
                }
            }
        }
        catch (SQLException &ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }

    // get columns description
    {
        std::ostringstream s;
        s << "SELECT " << fields_ << " FROM (" << table_name << ") WHERE rownum < 1";

#ifdef MAPNIK_DEBUG
        std::clog << "OCCI Plugin: " << s.str() << std::endl;
#endif

        try
        {
            occi_connection_ptr conn;
            if (use_connection_pool_) conn.set_pool(pool_);
            else                      conn.set_connection(conn_, false);

            ResultSet* rs = conn.execute_query (s.str());
            if (rs)
            {
                std::vector<MetaData> listOfColumns = rs->getColumnListMetaData();

                for (unsigned int i = 0; i < listOfColumns.size(); ++i)
                {
                    MetaData columnObj = listOfColumns[i];

                    std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
                    int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);

                    /*
                    int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
                    if (type_code == OCCI_TYPECODE_OBJECT)
                    {
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
                        continue;
                    }
                    */

                    switch (type_oid)
                    {
                    case oracle::occi::OCCIBOOL:
                    case oracle::occi::OCCIINT:
                    case oracle::occi::OCCIUNSIGNED_INT:
                    case oracle::occi::OCCIROWID:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
                        break;
                    case oracle::occi::OCCIFLOAT:
                    case oracle::occi::OCCIBFLOAT:
                    case oracle::occi::OCCIDOUBLE:
                    case oracle::occi::OCCIBDOUBLE:
                    case oracle::occi::OCCINUMBER:
                    case oracle::occi::OCCI_SQLT_NUM:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
                        break;
                    case oracle::occi::OCCICHAR:
                    case oracle::occi::OCCISTRING:
                    case oracle::occi::OCCI_SQLT_AFC:
                    case oracle::occi::OCCI_SQLT_AVC:
                    case oracle::occi::OCCI_SQLT_CHR:
                    case oracle::occi::OCCI_SQLT_LVC:
                    case oracle::occi::OCCI_SQLT_RDD:
                    case oracle::occi::OCCI_SQLT_STR:
                    case oracle::occi::OCCI_SQLT_VCS:
                    case oracle::occi::OCCI_SQLT_VNU:
                    case oracle::occi::OCCI_SQLT_VBI:
                    case oracle::occi::OCCI_SQLT_VST:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
                        break;
                    case oracle::occi::OCCIDATE:
                    case oracle::occi::OCCITIMESTAMP:
                    case oracle::occi::OCCIINTERVALDS:
                    case oracle::occi::OCCIINTERVALYM:
                    case oracle::occi::OCCI_SQLT_DAT:
                    case oracle::occi::OCCI_SQLT_DATE:
                    case oracle::occi::OCCI_SQLT_TIME:
                    case oracle::occi::OCCI_SQLT_TIME_TZ:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ:
                    case oracle::occi::OCCI_SQLT_INTERVAL_YM:
                    case oracle::occi::OCCI_SQLT_INTERVAL_DS:
                    case oracle::occi::OCCIANYDATA:
                    case oracle::occi::OCCIBLOB:
                    case oracle::occi::OCCIBFILE:
                    case oracle::occi::OCCIBYTES:
                    case oracle::occi::OCCICLOB:
                    case oracle::occi::OCCIVECTOR:
                    case oracle::occi::OCCIMETADATA:
                    case oracle::occi::OCCIPOBJECT:
                    case oracle::occi::OCCIREF:
                    case oracle::occi::OCCIREFANY:
                    case oracle::occi::OCCISTREAM:
                    case oracle::occi::OCCICURSOR:
                    case oracle::occi::OCCI_SQLT_FILE:
                    case oracle::occi::OCCI_SQLT_CFILE:
                    case oracle::occi::OCCI_SQLT_REF:
                    case oracle::occi::OCCI_SQLT_CLOB:
                    case oracle::occi::OCCI_SQLT_BLOB:
                    case oracle::occi::OCCI_SQLT_RSET:
#ifdef MAPNIK_DEBUG
                        std::clog << "OCCI Plugin: unsupported datatype " << occi_enums::resolve_datatype(type_oid)
                             << " (type_oid=" << type_oid << ")" << std::endl;
#endif
                        break;
                    default:
#ifdef MAPNIK_DEBUG
                        std::clog << "OCCI Plugin: unknown datatype (type_oid=" << type_oid << ")" << std::endl;
#endif
                        break;
                    }
                }
            }
        }
        catch (SQLException &ex)
        {
            throw datasource_exception(ex.getMessage());
        }
    }

    is_bound_ = true;
}
Example #22
0
void WorkingBuilding::initialize(const MetaData& mdata)
{
  Building::initialize( mdata );

  setMaximumWorkers( (unsigned int)mdata.getOption( "employers" ) );
}
Example #23
0
/* Produce all images ------------------------------------------------------ */
void Micrograph::produce_all_images(int label, double minCost,
                                    const FileName &fn_rootIn, const FileName &fn_image, double ang,
                                    double tilt, double psi, bool rmStack)
{
    MetaData SF;
    Image<double> I;
    Micrograph *M;

    // Set Source image
    if (fn_image == "")
        M = this;
    else
    {
        M = new Micrograph;
        M->open_micrograph(fn_image/*, swapbyte*/);
        M->set_window_size(X_window_size, Y_window_size);
        M->set_transmitance_flag(compute_transmitance);
        M->set_inverse_flag(compute_inverse);
    }

    // Set scale for particles
    int MXdim, MYdim, thisXdim, thisYdim;
    M->size(MXdim, MYdim);
    this->size(thisXdim, thisYdim);
    double scaleX = (double) MXdim / thisXdim;
    double scaleY = (double) MYdim / thisYdim;

    // Compute max and minimum if compute_transmitance
    // or compute_inverse flags are ON
    double Dmax=0., Dmin=0.;
    if (compute_transmitance || compute_inverse)
    {
        (*this).computeDoubleMinMax(Dmin, Dmax);

        if (compute_transmitance)
        {
            if (Dmin > 1)
                Dmin = log10(Dmin);
            if (Dmax > 1)
                Dmax = log10(Dmax);
        }
    }
    // Scissor all particles
    if (ang != 0)
        std::cout << "Angle from Y axis to tilt axis " << ang << std::endl
        << "   applying appropriate rotation\n";
    int nmax = ParticleNo();
    FileName fn_aux;
    FileName _ext = fn_rootIn.getFileFormat();
    FileName fn_out;
    FileName fn_root = fn_rootIn.removeFileFormat().removeLastExtension();
    if (fn_rootIn.hasStackExtension())
        fn_out=fn_root.addExtension(_ext);
    else
    	fn_out=fn_rootIn.addExtension("stk");

    if (rmStack)
        fn_out.deleteFile();
    size_t ii = 0;
    size_t id;
    for (int n = 0; n < nmax; n++)
        if (coords[n].valid && coords[n].cost > minCost && coords[n].label == label)
        {
            fn_aux.compose(++ii, fn_out);
            id = SF.addObject();
            // If the ctfRow was set, copy the info to images metadata
            if (ctfRow.containsLabel(MDL_CTF_DEFOCUSU))
                SF.setRow(ctfRow, id);
            SF.setValue(MDL_IMAGE, fn_aux, id);
            SF.setValue(MDL_MICROGRAPH, M->fn_micrograph, id);
            SF.setValue(MDL_XCOOR, coords[n].X, id);
            SF.setValue(MDL_YCOOR, coords[n].Y, id);
            bool t = M->scissor(coords[n], I(), Dmin, Dmax, scaleX, scaleY);
            if (!t)
            {
                std::cout << "Particle " << fn_aux
                << " is very near the border, "
                << "corresponding image is set to blank\n";
                SF.setValue(MDL_ENABLED, -1, id);
            }
            else
                SF.setValue(MDL_ENABLED, 1, id);
            //  if (ang!=0) I().rotate(-ang);
            I.write(fn_out, ii, true, WRITE_APPEND);
        }
    SF.write(fn_out.withoutExtension() + ".xmd");


    // Free source image??
    if (fn_image != "")
    {
        M->close_micrograph();
        delete M;
    }
}
void ProgSortByStatistics::processInputPrepare(MetaData &SF)
{
    PCAMahalanobisAnalyzer tempPcaAnalyzer;
    tempPcaAnalyzer.clear();

    Image<double> img;
    MultidimArray<double> img2;
    MultidimArray<int> radial_count;
    MultidimArray<double> radial_avg;
    Matrix1D<int> center(2);
    center.initZeros();

    if (verbose>0)
        std::cout << " Processing training set ..." << std::endl;

    int nr_imgs = SF.size();
    if (verbose>0)
        init_progress_bar(nr_imgs);
    int c = XMIPP_MAX(1, nr_imgs / 60);
    int imgno = 0, imgnoPCA=0;
    MultidimArray<float> v;
    MultidimArray<int> distance;
    int dim;

    bool thereIsEnable=SF.containsLabel(MDL_ENABLED);
    bool first=true;
    FOR_ALL_OBJECTS_IN_METADATA(SF)
    {
        if (thereIsEnable)
        {
            int enabled;
            SF.getValue(MDL_ENABLED,enabled,__iter.objId);
            if (enabled==-1)
                continue;
        }
        img.readApplyGeo(SF,__iter.objId);
        if (targetXdim!=-1 && targetXdim!=XSIZE(img()))
        	selfScaleToSize(LINEAR,img(),targetXdim,targetXdim,1);
        MultidimArray<double> &mI=img();
        mI.setXmippOrigin();
        mI.statisticsAdjust(0,1);

        // Overall statistics
        Histogram1D hist;
        compute_hist(mI,hist,-4,4,31);

        // Radial profile
        img2.resizeNoCopy(mI);
        FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(img2)
        {
            double val=DIRECT_MULTIDIM_ELEM(mI,n);
            DIRECT_MULTIDIM_ELEM(img2,n)=val*val;
        }
        if (first)
        {
            radialAveragePrecomputeDistance(img2, center, distance, dim);
            first=false;
        }
        fastRadialAverage(img2, distance, dim, radial_avg, radial_count);

        // Build vector
        v.initZeros(XSIZE(hist)+XSIZE(img2)/2);
        int idx=0;
        FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(hist)
        v(idx++)=(float)DIRECT_A1D_ELEM(hist,i);
        for (size_t i=0; i<XSIZE(img2)/2; i++)
            v(idx++)=(float)DIRECT_A1D_ELEM(radial_avg,i);

        tempPcaAnalyzer.addVector(v);

        if (imgno % c == 0 && verbose>0)
            progress_bar(imgno);
        imgno++;
        imgnoPCA++;
    }
    if (verbose>0)
        progress_bar(nr_imgs);

    MultidimArray<double> vavg,vstddev;
    tempPcaAnalyzer.computeStatistics(vavg,vstddev);
    tempPcaAnalyzer.evaluateZScore(2,20,false);
    pcaAnalyzer.insert(pcaAnalyzer.begin(), tempPcaAnalyzer);
}
void ProgValidationNonTilt::obtainSumU(const MetaData & tempMd,std::vector<double> & sum_u,std::vector<double> & H0)
{

	const size_t tempMdSz= tempMd.size();
    double xRan,yRan,zRan;
    double x,y;
    double sumWRan;
    double * xRanArray = new double[tempMdSz];
    double * yRanArray = new double[tempMdSz];
    double * zRanArray  = new double[tempMdSz];
    std::vector<double> weightV;
    double a;

    for (size_t n=0; n<sum_u.size(); n++)
    {
        sumWRan = 0;
        for (size_t nS=0; nS<tempMd.size(); nS++)
        {
             /*
                x = sin(tilt*PI/180)*cos(rot*PI/180);
        		y = sin(tilt*PI/180)*sin(rot*PI/180);
        		z = std::abs(cos(tilt*PI/180));
             */

        	//http://mathworld.wolfram.com/SpherePointPicking.html
        	x = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;
        	y = 2*(double(std::rand())-RAND_MAX/2)/RAND_MAX;

        	while (x*x+y*y >= 1 )
        	{
            	x = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
            	y = 2*(std::rand()-RAND_MAX/2)/RAND_MAX;
        	}

        	xRan = 2*x*std::sqrt(1-x*x-y*y);
        	yRan = 2*y*std::sqrt(1-x*x-y*y);
        	zRan = std::abs(1-2*(x*x+y*y));

/*        	tilt = (double(std::rand())/RAND_MAX)*(PI);
        	rot  = (std::rand()-RAND_MAX/2)*(2*PI/RAND_MAX);
        	xRan = sin(tilt)*cos(rot);
        	yRan = sin(tilt)*sin(rot);
        	zRan = std::abs(cos(tilt));
*/
        	//std::cout << tilt << " " << rot << std::endl;
        	//std::cout << xRan << " " << yRan << " " << zRan << " " << std::endl;
            //zRan=(std::rand()-RAND_MAX/2);
            //norm = std::sqrt(xRan*xRan+yRan*yRan+zRan*zRan);
            //xRan = (xRan/norm);
            //yRan = (yRan/norm);
            //zRan = std::abs(zRan/norm);

            xRanArray[nS] = xRan;
            yRanArray[nS] = yRan;
            zRanArray[nS] = zRan;
            //tempMd.getColumnValues(MDL_WEIGHT, weightV);
            tempMd.getColumnValues(MDL_MAXCC, weightV);

            std::random_shuffle(weightV.begin(), weightV.end());
        }

        sumWRan = 0;
        double WRan, tempWRan, tempW1, tempW2;
        for (size_t nS1=0; nS1<tempMd.size(); nS1++)
        {
            tempWRan = 1e3;
            for (size_t nS2=0; nS2<tempMd.size(); nS2++)
            {
                a = std::abs(std::acos(xRanArray[nS1]*xRanArray[nS2]+yRanArray[nS1]*yRanArray[nS2]+zRanArray[nS1]*zRanArray[nS2]));
                if ( (a<tempWRan) && (a != 0))
                {
                    tempWRan = a;
                    tempW2 = weightV[nS2];
                    tempW1 = weightV[nS1];
                    WRan = a*std::exp(std::abs(tempW1-tempW2))*std::exp(-(tempW1+tempW2));
                }
            }
            sumWRan += WRan;
        }
        sum_u.at(n)=sumWRan;
    }

    size_t idx = 0;
    while (idx < sum_u.size())
    {
        std::random_shuffle(sum_u.begin(), sum_u.end());

        if(sum_u.at(0) != sum_u.at(1))
        {
            H0[idx] = sum_u.at(0)/(sum_u.at(0)+sum_u.at(1));
            idx += 1;
        }
    }

    delete xRanArray;
    delete yRanArray;
    delete zRanArray;

}
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);
    }
}
Example #27
0
occi_datasource::occi_datasource(parameters const& params)
    : datasource (params),
      type_(datasource::Vector),
      fields_(*params.get<std::string>("fields", "*")),
      geometry_field_(*params.get<std::string>("geometry_field", "")),
      srid_initialized_(false),
      extent_initialized_(false),
      bbox_token_("!bbox!"),
      scale_denom_token_("!scale_denominator!"),
      pixel_width_token_("!pixel_width!"),
      pixel_height_token_("!pixel_height!"),
      desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
      use_wkb_(*params.get<mapnik::boolean>("use_wkb", false)),
      row_limit_(*params.get<mapnik::value_integer>("row_limit", 0)),
      row_prefetch_(*params.get<int>("row_prefetch", 100)),
      pool_(0),
      conn_(0)
{
#ifdef MAPNIK_STATS
    mapnik::progress_timer __stats__(std::clog, "occi_datasource::init");
#endif

    if (! params.get<std::string>("user")) throw datasource_exception("OCCI Plugin: no <user> specified");
    if (! params.get<std::string>("password")) throw datasource_exception("OCCI Plugin: no <password> specified");
    if (! params.get<std::string>("host")) throw datasource_exception("OCCI Plugin: no <host> string specified");

    boost::optional<std::string> table = params.get<std::string>("table");
    if (! table)
    {
        throw datasource_exception("OCCI Plugin: no <table> parameter specified");
    }
    else
    {
        table_ = *table;
    }
    estimate_extent_ = *params.get<mapnik::boolean>("estimate_extent",false);
    use_spatial_index_ = *params.get<mapnik::boolean>("use_spatial_index",true);
    use_connection_pool_ = *params.get<mapnik::boolean>("use_connection_pool",true);

    boost::optional<std::string> ext = params.get<std::string>("extent");
    if (ext) extent_initialized_ = extent_.from_string(*ext);

    boost::optional<int> srid = params.get<int>("srid");
    if (srid)
    {
        srid_ = *srid;
        srid_initialized_ = true;
    }

    // connect to environment
    if (use_connection_pool_)
    {
        try
        {
            pool_ = occi_environment::instance().create_pool(
                *params.get<std::string>("user"),
                *params.get<std::string>("password"),
                *params.get<std::string>("host"),
                *params.get<int>("max_size", 5),
                *params.get<int>("initial_size", 1),
                1);
        }
        catch (SQLException& ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }
    else
    {
        try
        {
            conn_ = occi_environment::instance().create_connection(
                *params.get<std::string>("user"),
                *params.get<std::string>("password"),
                *params.get<std::string>("host"));
        }
        catch (SQLException& ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }

    // extract real table name
    table_name_ = mapnik::sql_utils::table_from_sql(table_);

    // get SRID and/or GEOMETRY_FIELD from metadata table only if we need to
    if (! srid_initialized_ || geometry_field_ == "")
    {
#ifdef MAPNIK_STATS
        mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_srid_and_geometry_field");
#endif

        std::ostringstream s;
        s << "SELECT srid, column_name FROM " << METADATA_TABLE << " WHERE";
        s << " LOWER(table_name) = LOWER('" << table_name_ << "')";

        if (geometry_field_ != "")
        {
            s << " AND LOWER(column_name) = LOWER('" << geometry_field_ << "')";
        }

        MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str();

        try
        {
            occi_connection_ptr conn;
            if (use_connection_pool_) conn.set_pool(pool_);
            else                      conn.set_connection(conn_, false);

            ResultSet* rs = conn.execute_query(s.str());
            if (rs && rs->next ())
            {
                if (! srid_initialized_)
                {
                    srid_ = rs->getInt(1);
                    srid_initialized_ = true;
                }

                if (geometry_field_ == "")
                {
                    geometry_field_ = rs->getString(2);
                }
            }
        }
        catch (SQLException& ex)
        {
            throw datasource_exception("OCCI Plugin: " + ex.getMessage());
        }
    }

    // get columns description
    {
#ifdef MAPNIK_STATS
        mapnik::progress_timer __stats__(std::clog, "occi_datasource::get_column_description");
#endif

        std::ostringstream s;
        s << "SELECT " << fields_ << " FROM (" << table_name_ << ") WHERE ROWNUM < 1";

        MAPNIK_LOG_DEBUG(occi) << "occi_datasource: " << s.str();

        try
        {
            occi_connection_ptr conn;
            if (use_connection_pool_) conn.set_pool(pool_);
            else                      conn.set_connection(conn_, false);

            ResultSet* rs = conn.execute_query(s.str());
            if (rs)
            {
                std::vector<MetaData> listOfColumns = rs->getColumnListMetaData();

                for (unsigned int i = 0; i < listOfColumns.size(); ++i)
                {
                    MetaData columnObj = listOfColumns[i];

                    std::string fld_name = columnObj.getString(MetaData::ATTR_NAME);
                    int type_oid = columnObj.getInt(MetaData::ATTR_DATA_TYPE);

                    /*
                      int type_code = columnObj.getInt(MetaData::ATTR_TYPECODE);
                      if (type_code == OCCI_TYPECODE_OBJECT)
                      {
                      desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Object));
                      continue;
                      }
                    */

                    switch (type_oid)
                    {
                    case oracle::occi::OCCIBOOL:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Boolean));
                        break;
                    case oracle::occi::OCCIINT:
                    case oracle::occi::OCCIUNSIGNED_INT:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
                        break;
                    case oracle::occi::OCCIFLOAT:
                    case oracle::occi::OCCIBFLOAT:
                    case oracle::occi::OCCIDOUBLE:
                    case oracle::occi::OCCIBDOUBLE:
                    case oracle::occi::OCCINUMBER:
                    case oracle::occi::OCCI_SQLT_NUM:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
                        break;
                    case oracle::occi::OCCICHAR:
                    case oracle::occi::OCCISTRING:
                    case oracle::occi::OCCI_SQLT_AFC:
                    case oracle::occi::OCCI_SQLT_AVC:
                    case oracle::occi::OCCI_SQLT_CHR:
                    case oracle::occi::OCCI_SQLT_LNG:
                    case oracle::occi::OCCI_SQLT_LVC:
                    case oracle::occi::OCCI_SQLT_STR:
                    case oracle::occi::OCCI_SQLT_VCS:
                    case oracle::occi::OCCI_SQLT_VNU:
                    case oracle::occi::OCCI_SQLT_VBI:
                    case oracle::occi::OCCI_SQLT_VST:
                    case oracle::occi::OCCIROWID:
                    case oracle::occi::OCCI_SQLT_RDD:
                    case oracle::occi::OCCI_SQLT_RID:
                    case oracle::occi::OCCIDATE:
                    case oracle::occi::OCCI_SQLT_DAT:
                    case oracle::occi::OCCI_SQLT_DATE:
                    case oracle::occi::OCCI_SQLT_TIME:
                    case oracle::occi::OCCI_SQLT_TIME_TZ:
                    case oracle::occi::OCCITIMESTAMP:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ:
                    case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ:
                        desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
                        break;
                    case oracle::occi::OCCIINTERVALDS:
                    case oracle::occi::OCCIINTERVALYM:
                    case oracle::occi::OCCI_SQLT_INTERVAL_YM:
                    case oracle::occi::OCCI_SQLT_INTERVAL_DS:
                    case oracle::occi::OCCIANYDATA:
                    case oracle::occi::OCCIBLOB:
                    case oracle::occi::OCCIBFILE:
                    case oracle::occi::OCCIBYTES:
                    case oracle::occi::OCCICLOB:
                    case oracle::occi::OCCIVECTOR:
                    case oracle::occi::OCCIMETADATA:
                    case oracle::occi::OCCIPOBJECT:
                    case oracle::occi::OCCIREF:
                    case oracle::occi::OCCIREFANY:
                    case oracle::occi::OCCISTREAM:
                    case oracle::occi::OCCICURSOR:
                    case oracle::occi::OCCI_SQLT_FILE:
                    case oracle::occi::OCCI_SQLT_CFILE:
                    case oracle::occi::OCCI_SQLT_REF:
                    case oracle::occi::OCCI_SQLT_CLOB:
                    case oracle::occi::OCCI_SQLT_BLOB:
                    case oracle::occi::OCCI_SQLT_RSET:
                        MAPNIK_LOG_WARN(occi) << "occi_datasource: Unsupported datatype "
                                              << occi_enums::resolve_datatype(type_oid)
                                              << " (type_oid=" << type_oid << ")";
                        break;
                    default:
                        MAPNIK_LOG_WARN(occi) << "occi_datasource: Unknown datatype "
                                              << "(type_oid=" << type_oid << ")";
                        break;
                    }
                }
            }
        }
        catch (SQLException& ex)
        {
            throw datasource_exception(ex.getMessage());
        }
    }
}
//majorAxis and minorAxis is the estimated particle size in px
void ProgSortByStatistics::processInprocessInputPrepareSPTH(MetaData &SF, bool trained)
{
    //#define DEBUG
    PCAMahalanobisAnalyzer tempPcaAnalyzer0;
    PCAMahalanobisAnalyzer tempPcaAnalyzer1;
    PCAMahalanobisAnalyzer tempPcaAnalyzer2;
    PCAMahalanobisAnalyzer tempPcaAnalyzer3;
    PCAMahalanobisAnalyzer tempPcaAnalyzer4;

    //Morphology
    tempPcaAnalyzer0.clear();
    //Signal to noise ratio
    tempPcaAnalyzer1.clear();
    tempPcaAnalyzer2.clear();
    tempPcaAnalyzer3.clear();
    //Histogram analysis, to detect black points and saturated parts
    tempPcaAnalyzer4.clear();

    double sign = 1;//;-1;
    int numNorm = 3;
    int numDescriptors0=numNorm;
    int numDescriptors2=4;
    int numDescriptors3=11;
    int numDescriptors4 = 10;

    MultidimArray<float> v0(numDescriptors0);
    MultidimArray<float> v2(numDescriptors2);
    MultidimArray<float> v3(numDescriptors3);
    MultidimArray<float> v4(numDescriptors4);

    if (verbose>0)
    {
        std::cout << " Sorting particle set by new xmipp method..." << std::endl;
    }

    int nr_imgs = SF.size();
    if (verbose>0)
        init_progress_bar(nr_imgs);

    int c = XMIPP_MAX(1, nr_imgs / 60);
    int imgno = 0, imgnoPCA=0;

    bool thereIsEnable=SF.containsLabel(MDL_ENABLED);
    bool first=true;

    // We assume that at least there is one particle
    size_t Xdim, Ydim, Zdim, Ndim;
    getImageSize(SF,Xdim,Ydim,Zdim,Ndim);

    //Initialization:
    MultidimArray<double> nI, modI, tempI, tempM, ROI;
    MultidimArray<bool> mask;
    nI.resizeNoCopy(Ydim,Xdim);
    modI.resizeNoCopy(Ydim,Xdim);
    tempI.resizeNoCopy(Ydim,Xdim);
    tempM.resizeNoCopy(Ydim,Xdim);
    mask.resizeNoCopy(Ydim,Xdim);
    mask.initConstant(true);

    MultidimArray<double> autoCorr(2*Ydim,2*Xdim);
    MultidimArray<double> smallAutoCorr;

    Histogram1D hist;
    Matrix2D<double> U,V,temp;
    Matrix1D<double> D;

    MultidimArray<int> radial_count;
    MultidimArray<double> radial_avg;
    Matrix1D<int> center(2);
    MultidimArray<int> distance;
    int dim;
    center.initZeros();

    v0.initZeros(numDescriptors0);
    v2.initZeros(numDescriptors2);
    v3.initZeros(numDescriptors3);
    v4.initZeros(numDescriptors4);

    ROI.resizeNoCopy(Ydim,Xdim);
    ROI.setXmippOrigin();
    FOR_ALL_ELEMENTS_IN_ARRAY2D(ROI)
    {
        double temp = std::sqrt(i*i+j*j);
        if ( temp < (Xdim/2))
            A2D_ELEM(ROI,i,j)= 1;
        else
            A2D_ELEM(ROI,i,j)= 0;
    }

    Image<double> img;
    FourierTransformer transformer(FFTW_BACKWARD);

    FOR_ALL_OBJECTS_IN_METADATA(SF)
    {
        if (thereIsEnable)
        {
            int enabled;
            SF.getValue(MDL_ENABLED,enabled,__iter.objId);
            if ( (enabled==-1)  )
            {
                imgno++;
                continue;
            }
        }

        img.readApplyGeo(SF,__iter.objId);
        if (targetXdim!=-1 && targetXdim!=XSIZE(img()))
        	selfScaleToSize(LINEAR,img(),targetXdim,targetXdim,1);

        MultidimArray<double> &mI=img();
        mI.setXmippOrigin();
        mI.statisticsAdjust(0,1);
        mask.setXmippOrigin();
        //The size of v1 depends on the image size and must be declared here
        int numDescriptors1 = XSIZE(mI)/2; //=100;
        MultidimArray<float> v1(numDescriptors1);
        v1.initZeros(numDescriptors1);

        double var = 1;
        normalize(transformer,mI,tempI,modI,0,var,mask);
        modI.setXmippOrigin();
        tempI.setXmippOrigin();
        nI = sign*tempI*(modI*modI);
        tempM = (modI*modI);

        A1D_ELEM(v0,0) = (tempM*ROI).sum();
        int index = 1;
        var+=2;
        while (index < numNorm)
        {
            normalize(transformer,mI,tempI,modI,0,var,mask);
            modI.setXmippOrigin();
            tempI.setXmippOrigin();
            nI += sign*tempI*(modI*modI);
            tempM += (modI*modI);
            A1D_ELEM(v0,index) = (tempM*ROI).sum();
            index++;
            var+=2;
        }

        nI /= tempM;
        tempPcaAnalyzer0.addVector(v0);
        nI=(nI*ROI);

        auto_correlation_matrix(mI,autoCorr);
        if (first)
        {
            radialAveragePrecomputeDistance(autoCorr, center, distance, dim);
            first=false;
        }
        fastRadialAverage(autoCorr, distance, dim, radial_avg, radial_count);

        for (int n = 0; n < numDescriptors1; ++n)
            A1D_ELEM(v1,n)=(float)DIRECT_A1D_ELEM(radial_avg,n);

        tempPcaAnalyzer1.addVector(v1);

#ifdef DEBUG

        //String name = "000005@Images/Extracted/run_002/extra/BPV_1386.stk";
        String name = "000010@Images/Extracted/run_001/extra/KLH_Dataset_I_Training_0028.stk";
        //String name = "001160@Images/Extracted/run_001/DefaultFamily5";

        std::cout << img.name() << std::endl;

        if (img.name()==name2)
        {
            FileName fpName    = "test_1.txt";
            mI.write(fpName);
            fpName    = "test_2.txt";
            nI.write(fpName);
            fpName    = "test_3.txt";
            tempM.write(fpName);
            fpName    = "test_4.txt";
            ROI.write(fpName);
            //exit(1);
        }
#endif
        nI.binarize(0);
        int im = labelImage2D(nI,nI,8);
        compute_hist(nI, hist, 0, im, im+1);
        size_t l;
        int k,i,j;
        hist.maxIndex(l,k,i,j);
        A1D_ELEM(hist,j)=0;
        hist.maxIndex(l,k,i,j);
        nI.binarizeRange(j-1,j+1);

        double x0=0,y0=0,majorAxis=0,minorAxis=0,ellipAng=0;
        size_t area=0;
        fitEllipse(nI,x0,y0,majorAxis,minorAxis,ellipAng,area);

        A1D_ELEM(v2,0)=majorAxis/((img().xdim) );
        A1D_ELEM(v2,1)=minorAxis/((img().xdim) );
        A1D_ELEM(v2,2)= (fabs((img().xdim)/2-x0)+fabs((img().ydim)/2-y0))/((img().xdim)/2);
        A1D_ELEM(v2,3)=area/( (double)((img().xdim)/2)*((img().ydim)/2) );

        for (int n=0 ; n < numDescriptors2 ; n++)
        {
            if ( std::isnan(std::abs(A1D_ELEM(v2,n))))
                A1D_ELEM(v2,n)=0;
        }

        tempPcaAnalyzer2.addVector(v2);

        //mI.setXmippOrigin();
        //auto_correlation_matrix(mI*ROI,autoCorr);
        //auto_correlation_matrix(nI,autoCorr);
        autoCorr.window(smallAutoCorr,-5,-5, 5, 5);
        smallAutoCorr.copy(temp);
        svdcmp(temp,U,D,V);

        for (int n = 0; n < numDescriptors3; ++n)
            A1D_ELEM(v3,n)=(float)VEC_ELEM(D,n); //A1D_ELEM(v3,n)=(float)VEC_ELEM(D,n)/VEC_ELEM(D,0);

        tempPcaAnalyzer3.addVector(v3);


        double minVal=0.;
        double maxVal=0.;
        mI.computeDoubleMinMax(minVal,maxVal);
        compute_hist(mI, hist, minVal, maxVal, 100);

        for (int n=0 ; n <= numDescriptors4-1 ; n++)
        {
            A1D_ELEM(v4,n)= (hist.percentil((n+1)*10));
        }
        tempPcaAnalyzer4.addVector(v4);

#ifdef DEBUG

        if (img.name()==name1)
        {
            FileName fpName    = "test.txt";
            mI.write(fpName);
            fpName    = "test3.txt";
            nI.write(fpName);
        }
#endif
        imgno++;
        imgnoPCA++;

        if (imgno % c == 0 && verbose>0)
            progress_bar(imgno);
    }

    tempPcaAnalyzer0.evaluateZScore(2,20,trained);
    tempPcaAnalyzer1.evaluateZScore(2,20,trained);
    tempPcaAnalyzer2.evaluateZScore(2,20,trained);
    tempPcaAnalyzer3.evaluateZScore(2,20,trained);
    tempPcaAnalyzer4.evaluateZScore(2,20,trained);

    pcaAnalyzer.push_back(tempPcaAnalyzer0);
    pcaAnalyzer.push_back(tempPcaAnalyzer1);
    pcaAnalyzer.push_back(tempPcaAnalyzer1);
    pcaAnalyzer.push_back(tempPcaAnalyzer3);
    pcaAnalyzer.push_back(tempPcaAnalyzer4);

}
Example #29
0
// Perform complete search =================================================
void ProgNmaAlignment::performCompleteSearch(const FileName &fnRandom,
		int pyramidLevel) const {
	String program;
	String arguments;
	const char * randStr = fnRandom.c_str();

	// Reduce the image
	FileName fnDown = formatString("%s_downimg.xmp", fnRandom.c_str());
	if (pyramidLevel != 0) {
		Image<double> I;
		I.read(currentImgName);
		selfPyramidReduce(BSPLINE3, I(), pyramidLevel);
		I.write(fnDown);
	} else
		copyImage(currentImgName.c_str(), fnDown.c_str());

	mkdir((fnRandom+"_ref").c_str(), S_IRWXU);

	double angSampling=2*RAD2DEG(atan(1.0/((double) imgSize / pow(2.0, (double) pyramidLevel+1))));
	angSampling=std::max(angSampling,discrAngStep);
	program = "xmipp_angular_project_library";
	arguments = formatString(
			"-i %s_deformedPDB.vol -o %s_ref/ref.stk --sampling_rate %f -v 0",
			randStr, randStr, angSampling);
	if (projMatch)
		arguments +=formatString(
						" --compute_neighbors --angular_distance -1 --experimental_images %s_downimg.xmp", randStr);

	runSystem(program, arguments, false);

	String refSelStr = formatString("%s_ref/ref.doc", randStr);

	if (fnmask != "") {
		program = "xmipp_transform_mask";
		arguments = formatString("-i %s --mask binary_file %s", refSelStr.c_str(),
				fnmask.c_str());
		runSystem(program, arguments, false);
	}

	// Perform alignment
	String fnOut=formatString("%s_angledisc.xmd",randStr);
	if (!projMatch) {
		program = "xmipp_angular_discrete_assign";
		arguments = formatString(
						"-i %s_downimg.xmp --ref %s -o %s --psi_step 5 --max_shift_change %d --search5D -v 0",
						randStr, refSelStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel))));
	} else {
		String refStkStr = formatString("%s_ref/ref.stk", randStr);
		program = "xmipp_angular_projection_matching";
		arguments =	formatString(
				        "-i %s_downimg.xmp --ref %s -o %s --search5d_step 1 --max_shift %d -v 0",
				        randStr, refStkStr.c_str(), fnOut.c_str(), (int)round((double) imgSize / (10.0 * pow(2.0, (double) pyramidLevel))));
	}
	runSystem(program, arguments, false);
	if (projMatch)
	{
		MetaData MD;
		MD.read(fnOut);
		bool flip;
		size_t id=MD.firstObject();
		MD.getValue(MDL_FLIP,flip,id);
		if (flip)
		{
			// This is because continuous assignment does not understand flips

			double shiftX, rot, tilt, psi, newrot, newtilt, newpsi;
			// Change sign in shiftX
			MD.getValue(MDL_SHIFT_X,shiftX,id);
			MD.setValue(MDL_SHIFT_X,-shiftX,id);

			// Change Euler angles
			MD.getValue(MDL_ANGLE_ROT,rot,id);
			MD.getValue(MDL_ANGLE_TILT,tilt,id);
			MD.getValue(MDL_ANGLE_PSI,psi,id);
			Euler_mirrorY(rot,tilt,psi,newrot,newtilt,newpsi);
			MD.setValue(MDL_ANGLE_ROT,newrot,id);
			MD.setValue(MDL_ANGLE_TILT,newtilt,id);
			MD.setValue(MDL_ANGLE_PSI,newpsi,id);
			MD.write(fnOut);
		}
	}
}
//! [0]
void PlaylistItemDelegateSmall::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{


	if(!index.isValid()) return;

	QRect rect(option.rect);

	painter->save();
	painter->translate(0, 0);

	QStringList strlist = index.model()->data(index, Qt::WhatsThisRole).toStringList();
	MetaData md;
		md.fromStringList(strlist);

	bool cur_track = (strlist[strlist.length()-2].toInt() == 1);
	bool insert = (strlist.last().toInt() == 1);

	_pl_entry->setContent(md, index.row() +1 );

	int offset = (this->_parent->verticalScrollBar()->isVisible()) ?
						this->_parent->verticalScrollBar()->width() + 4 : 4;

	_pl_entry->setWidth(_parent->width() - offset);

	QString style;
	QString col_fg;

	bool is_selected = ((option.state & QStyle::State_Selected) != 0);

	QPalette palette = _parent->palette();

	QColor col_background = palette.color(QPalette::Active, QPalette::Background);
	QColor col_highlight = palette.color(QPalette::Active, QPalette::Highlight);
	QColor col_highlight_lighter = palette.color(QPalette::Active, QPalette::Highlight).light();

	int highlight_val = col_highlight.lightness();
	int highlight_lighter_val = col_highlight_lighter.lightness();
	int background_val = col_background.lightness();


	if(cur_track)
		style = QString("background-color: ") +
				col_highlight_lighter.name() + ";" +
				get_fg_color(highlight_lighter_val);


	else if(!is_selected)
		style = QString("background-color: transparent;") + get_fg_color(background_val);

	// standard selected
	else
		style = QString("background-color: ") +
				col_highlight.name() + "; " +
				get_fg_color(highlight_val);


	int y = rect.topLeft().y() +  _pl_entry->height()-1;

	_pl_entry->setStyleSheet(style);
	_pl_entry->render(painter, rect.topLeft() );

	if(insert) {
		painter->drawLine(QLine(0, y, _pl_entry->width(), y));
	}

	painter->restore();
}