void readParams()
 {
     fn_in   = getParam("-i");
     fn_root = getParam("--oroot");
     invert  = checkParam("--invert");
     min_size  = getDoubleParam("--min_size");
     if (fn_root == "")
         fn_root = fn_in.withoutExtension();
 }
Example #2
0
void ProgXrayImport::readGeoInfo(const FileName &fn, MDRow &rowGeo) const
{
    double tiltAngle;

    switch (dSource)
    {
    case MISTRAL:
        tiltAngle = dMi(anglesArray, fn.getPrefixNumber()-1);
        break;
    case BESSY:
    case GENERIC:
        {
            FileName fnBase = fn.withoutExtension();
            std::ifstream fhPosition;
            fhPosition.open((fnBase+"-positions.txt").c_str());
            if (!fhPosition)
                REPORT_ERROR(ERR_IO_NOTEXIST,fnBase+"-positions.txt");
            int itemsFound=0;
            std::string line;
            std::vector<std::string> tokens;
            while (!fhPosition.eof())
            {
                getline(fhPosition,line);
                splitString(line," ",tokens);
                if (tokens[0]=="xm:sample:rx")
                {
                    tiltAngle=textToFloat(tokens[1]);
                    itemsFound++;
                }
                if (itemsFound==1)
                    break;
            }
            fhPosition.close();
            if (itemsFound!=1)
                REPORT_ERROR(ERR_VALUE_EMPTY,(std::string)"Cannot find tilt angle in "+
                             fnBase+"-positions.txt");
        }
        break;
    }

    rowGeo.setValue(MDL_ANGLE_TILT, tiltAngle);
}
Example #3
0
void ProgXrayImport::readCorrectionInfo(const FileName &fn, double &currentBeam,
                                        double &expTime, double &slitWidth) const
{
    FileName fnBase = fn.withoutExtension();
    std::ifstream fhPosition;
    fhPosition.open((fnBase+"-positions.txt").c_str());

    if (!fhPosition)
        REPORT_ERROR(ERR_IO_NOTEXIST,fnBase+"-positions.txt");
    int itemsFound = 0;
    std::string line;
    std::vector<std::string> tokens;

    while (!fhPosition.eof())
    {
        getline(fhPosition,line);
        splitString(line," ",tokens);
        if (tokens[0]=="sr:current")
        {
            currentBeam = textToFloat(tokens[1]);
            itemsFound++;
        }
        else if (tokens[0]=="xm:ccd:exp_time")
        {
            expTime = textToFloat(tokens[1]);
            itemsFound++;
        }
        else if (tokens[0]=="xm:mono:slitwidth")
        {
            slitWidth = textToFloat(tokens[1]);
            itemsFound++;
        }
        if (itemsFound==3)
            break;
    }
    fhPosition.close();

    if ( itemsFound != 3 )
        REPORT_ERROR(ERR_VALUE_EMPTY,(std::string)"Cannot find all parameters in "+
                     fnBase+"-positions.txt");
}
Example #4
0
	void run()
	{

		// First do a crude search over the given parameter optimization space
		// Optimize the number of pairs here...
		int npart = optimiseTransformationMatrix(true);
		// Get rid of double pairs (two different untilted coordinates are close to a tilted coordinate)
		int nprune = 0;
		nprune = prunePairs(best_x, best_y);
		// Calculate average distance between the pairs
		double avgdist = getAverageDistance(best_x, best_y);
		std::cout << " Before optimization of the passing matrix: "<<std::endl;
		std::cout << "  - Number of pruned pairs= "<<nprune<<std::endl;
		std::cout << "  - best_rot= " << best_rot << " best_tilt= " << best_tilt << " best_x= " << best_x << " best_y= " << best_y << std::endl;
		std::cout << "  - Number of particle pairs= " << npart << " average distance= " <<avgdist<<std::endl;

#define WRITE_MAPPED
#ifdef WRITE_MAPPED
		std::ofstream  fh;
		FileName fn_map;
		fn_map = "mapped.box";
		fh.open(fn_map.c_str(), std::ios::out);
		for (int i = 0; i < p_map.size()/2; i++)
		{
                    fh << p_map[2*i] + best_x -dim/2<< " " << p_map[2*i+1] + best_y -dim/2<< " "<<dim<<" "<<dim<<" -3"<<std::endl;
			//if (pairs[i]>=0)
			//	std::cerr << " i= " << i << " pairs[i]= " << pairs[i] << std::endl;
		}
		fh.close();
#endif

		if (do_opt)
		{
			optimiseTransformationMatrixContinuous();
			npart = getNumberOfPairs();
			nprune = prunePairs();
			avgdist = getAverageDistance();
			std::cout << " After optimization of the passing matrix: "<<std::endl;
			std::cout << "  - Number of pruned pairs= "<<nprune<<std::endl;
			std::cout << "  - Final number of particle pairs= " << npart << " average distance= " <<avgdist<<std::endl;

		}

#ifdef WRITE_MAPPED
		fn_map = "mapped_opt.box";
		fh.open(fn_map.c_str(), std::ios::out);
		for (int i = 0; i < p_map.size()/2; i++)
		{
                    fh << p_map[2*i] -dim/2<< " " << p_map[2*i+1] -dim/2<<" "<<dim<<" "<<dim<<" -3"<< std::endl;
		}
		fh.close();
#endif

		// Write out STAR files with the coordinates
		MetaDataTable MDu, MDt;
		for (int t = 0; t < p_til.size()/2; t++)
		{
			int u = pairs_t2u[t];
			if (u >= 0)
			{
				MDu.addObject();
				MDu.setValue(EMDL_IMAGE_COORD_X, ((double)(p_unt[2*u])));
				MDu.setValue(EMDL_IMAGE_COORD_Y, ((double)(p_unt[2*u+1])));

				MDt.addObject();
				MDt.setValue(EMDL_IMAGE_COORD_X, ((double)(p_til[2*t])));
				MDt.setValue(EMDL_IMAGE_COORD_Y, ((double)(p_til[2*t+1])));
			}
		}
		fn_unt = fn_unt.withoutExtension() + "_pairs.star";
		fn_til = fn_til.withoutExtension() + "_pairs.star";
		MDu.write(fn_unt);
		MDt.write(fn_til);

		std::cout << " Written out coordinate STAR files: " << fn_unt << " and " << fn_til <<std::endl;
		std::cout << " Done!" << std::endl;

	}