/////////////////////////////////////////////////////////////////////// // Function: CompareTime // // Author: $author$ // Date: 6/27/2009 /////////////////////////////////////////////////////////////////////// virtual int CompareTime (const EvTime& time, bool is12=false, bool isPM=false, bool isLocal=false, const EvTimezone* timezone=0) const { int unequal = 0; if (!(unequal = CompareHour(time.GetHour(isPM, is12)))) if (!(unequal = CompareMinute(time.GetMinute()))) unequal = CompareSecond(time.GetSecond()); return unequal; }
int main( int argc, char** argv ) { if( argc < 6 || argc & 1) { std::cout << "usage: " << argv[0] << " <threshold> <nions> <nbright> [<n> <template> ...]" << std::endl; return -1; } size_t threshold = 0, nimages = 0, nions = 0, nbright = 0; std::stringstream s( argv[1] ); s >> threshold; std::stringstream s3( argv[2] ); s3 >> nions; std::stringstream s4( argv[3] ); s4 >> nbright; std::vector<IonDetector::result_type> res; size_t argc_i = 4; while( argc_i < argc ) { std::stringstream s2( argv[argc_i++] ); s2 >> nimages; for( size_t i = 0; i < nimages; ++i ) { char image_name[1024]; sprintf( image_name, argv[argc_i], i ); image_type data = load_file( image_name ); if( !data.extents.first ) { // Failed to load image return -1; } IonDetector det; det.blob_threshold = threshold; image_type result = det.hot_pixels( data ); save_file( "hot.fits", result ); IonDetector::result_type results = det( result ); res.push_back( results ); if( results.size() > nbright ) { std::cout << "Too many ions in: " << image_name << std::endl; } else if( results.size() < nbright ) { std::cout << "Too few ions in: " << image_name << std::endl; } } ++argc_i; } std::vector< std::pair< size_t, IonData > > positions; for( size_t i = 0; i < res.size(); ++i ) { if( res[i].size() != nbright ) continue; for( size_t ion = 0; ion < res[i].size(); ++ion ) { size_t pos = 0; for( ; pos < positions.size(); ++pos ) { if( fabs( positions[pos].second.x - res[i][ion].x ) < 6 && fabs( positions[pos].second.y - res[i][ion].y ) < 6 ) { ++ positions[pos].first; break; } } if( pos == positions.size() ) positions.push_back( std::make_pair( 1, res[i][ion] ) ); } } std::sort( positions.begin(), positions.end() ); std::reverse( positions.begin(), positions.end() ); if( positions.size() > nions ) positions.resize( nions ); std::sort( positions.begin(), positions.end(), CompareSecond() ); std::cout << "Detected ion locations: " << std::endl; for( size_t i = 0; i < positions.size(); ++i ) { std::cout << positions[i].second.x << ", " << positions[i].second.y << std::endl; } std::cout << std::endl; std::cout << "Ion patterns: " << std::endl; std::vector< std::string > bits; for( size_t i = 0; i < res.size(); ++i ) { bits.push_back( "" ); for( size_t pos = 0; pos < positions.size(); ++pos ) { size_t ion = 0; for( ; ion < res[i].size(); ++ion ) { if( fabs( positions[pos].second.x - res[i][ion].x ) < 6 && fabs( positions[pos].second.y - res[i][ion].y ) < 6 ) { bits.back() += "1"; break; } } if( ion == res[i].size() ) bits.back() += "0"; } std::cout << i << ":\t" << bits.back() << std::endl; } size_t reorder = 0; std::string order = bits[0]; for( size_t i = 1; i < bits.size(); ++i ) { if( bits[i] != order ) { ++reorder; order = bits[i]; } } std::cout << "Reordered " << reorder << " times." << std::endl; std::cout << "Probability: " << (float)reorder / (nimages-1) << std::endl; return 0; }