NumericalComparison<double> CompareWells(const string &queryFile, const string &goldFile, float epsilon, double maxAbsVal) { NumericalComparison<double> compare(epsilon); string queryDir, queryWells, goldDir, goldWells; FillInDirName(queryFile, queryDir, queryWells); FillInDirName(goldFile, goldDir, goldWells); RawWells queryW(queryDir.c_str(), queryWells.c_str()); RawWells goldW(goldDir.c_str(), goldWells.c_str()); struct WellData goldData; goldData.flowValues = NULL; struct WellData queryData; queryData.flowValues = NULL; cout << "Opening query." << endl; queryW.OpenForRead(); cout << "Opening gold." << endl; goldW.OpenForRead(); unsigned int numFlows = goldW.NumFlows(); while( !queryW.ReadNextRegionData(&queryData) ) { assert(!goldW.ReadNextRegionData(&goldData)); for (unsigned int i = 0; i < numFlows; i++) { if (isfinite(queryData.flowValues[i]) && isfinite(goldData.flowValues[i]) && (fabs(queryData.flowValues[i]) < maxAbsVal && fabs(goldData.flowValues[i]) < maxAbsVal)) { compare.AddPair(queryData.flowValues[i], goldData.flowValues[i]); } } } const SampleStats<double> ssX = compare.GetXStats(); const SampleStats<double> ssY = compare.GetYStats(); cout << "query values: " << ssX.GetMean() << " +/- " << ssX.GetSD() << endl; cout << "gold values: " << ssY.GetMean() << " +/- " << ssY.GetSD() << endl; return compare; }
void Traces::Init(Image *img, Mask *mask, int startFrame, int endFrame, int dcOffsetStart, int dcOffsetEnd) { mRefOut = NULL; mFlow = -1; mT0Step = 32; mUseMeshNeighbors = 1; mRow = (img->GetImage())->rows; mCol = (img->GetImage())->cols; startFrame = std::max(startFrame, 0); if( endFrame > 0 ) endFrame = std::min(endFrame, (int)img->GetUnCompFrames()); else endFrame = (int)img->GetUnCompFrames(); mFrames = endFrame - startFrame; mTimes.resize(mFrames); // copy(&raw->timestamps[0], &raw->timestamps[0] + mFrames, mTimes.begin()); // need to take into account variable frame compression here... ?? if (mIndexes.size() != mRow*mCol) { mIndexes.resize(mRow*mCol); } fill(mIndexes.begin(), mIndexes.end(), -1); vector<float> tBuff(mFrames, 0); SampleStats<float> traceStats; std::vector<float> sdTrace(mRow *mCol, 0); // Figure out how much memory to allocate for data pool int count = 0; for (size_t rowIx = 0; rowIx < mRow; rowIx++) { for (size_t colIx = 0; colIx < mCol; colIx++) { size_t traceIdx = RowColToIndex(rowIx, colIx); if (mask == NULL || !((*mask)[traceIdx] & MaskExclude)) { count++; } } } // Allocate memory if (mRawTraces != NULL) { delete [] mRawTraces ; } mRawTraces = new int8_t[count * mFrames]; SampleQuantiles<float> chipTraceSdQuant(10000); count = 0; for (size_t rowIx = 0; rowIx < mRow; rowIx++) { for (size_t colIx = 0; colIx < mCol; colIx++) { size_t traceIdx = RowColToIndex(rowIx, colIx); if (mask == NULL || !((*mask)[traceIdx] & MaskExclude)) { mIndexes[traceIdx] = count++ * mFrames; double mean = 0; if (dcOffsetEnd > 0 && dcOffsetStart > 0) { assert(dcOffsetEnd > dcOffsetStart); for (int frameIx = dcOffsetStart; frameIx < dcOffsetEnd; frameIx++) { mean += img->GetInterpolatedValue(frameIx,colIx,rowIx); } mean = mean / (dcOffsetEnd - dcOffsetStart); } float val = img->GetInterpolatedValue(startFrame,colIx,rowIx) - mean; traceStats.Clear(); for (int frameIx = 0; frameIx < endFrame; frameIx++) { val = (img->GetInterpolatedValue(frameIx,colIx,rowIx) - mean); tBuff[frameIx] = val; traceStats.AddValue(tBuff[frameIx]); } sdTrace[traceIdx] = traceStats.GetSD(); chipTraceSdQuant.AddValue(sdTrace[traceIdx]); SetTraces(traceIdx, tBuff, mRawTraces); } } } mFlags.resize(mRow*mCol, 0); double traceSDThresh = chipTraceSdQuant.GetMedian() - 5 * (chipTraceSdQuant.GetQuantile(.5) - chipTraceSdQuant.GetQuantile(.25)); traceSDThresh = max(0.0, traceSDThresh); int badCount = 0; for (size_t wellIx = 0; wellIx < sdTrace.size(); wellIx++) { if (mask != NULL && ((*mask)[wellIx] & MaskExclude)) { continue; } if (sdTrace[wellIx] <= traceSDThresh) { mFlags[wellIx] = BAD_VAR; badCount++; } } cout << "Found: " << badCount << " wells <= sd: " << traceSDThresh << endl; mT0.resize(0); if(mask != NULL) { if (mMask != NULL) delete mMask; mMask = new Mask(mask); size_t size = mFlags.size(); for (size_t i = 0; i < size; i++) { if ((*mMask)[i] & MaskExclude) { mFlags[i] = NOT_AVAIL; } } } else { mMask = NULL; } mSampleMap.resize(mRow * mCol); mCurrentData = mRawTraces; fill(mSampleMap.begin(), mSampleMap.end(), -1); }
NumericalComparison<double> CompareWells( const string &queryFile, const string &goldFile, float epsilon, double maxAbsVal, DumpMismatches &dump) { NumericalComparison<double> compare(epsilon); string queryDir, queryWells, goldDir, goldWells; FillInDirName(queryFile, queryDir, queryWells); FillInDirName(goldFile, goldDir, goldWells); RawWells queryW(queryDir.c_str(), queryWells.c_str()); RawWells goldW(goldDir.c_str(), goldWells.c_str()); struct WellData goldData; goldData.flowValues = NULL; struct WellData queryData; queryData.flowValues = NULL; cout << "Opening query." << endl; queryW.OpenForRead(); cout << "Opening gold." << endl; goldW.OpenForRead(); // check if any 1.wells is saved as unsigned short bool ushortg = goldW.GetSaveAsUShort(); bool ushortq = queryW.GetSaveAsUShort(); bool difType = false; string fileName; if(ushortg && (!ushortq)) { difType = true; cout << "RawWellsEquivalent WARNING: " << goldFile << " is saved as unsigned short and \n" << queryFile << " is saved as float. \nYou may want to re-run it with a bigger epsilon." << endl; fileName = goldFile; } if(ushortq && (!ushortg)) { difType = true; cout << "RawWellsEquivalent WARNING: " << queryFile << " is saved as unsigned short and \n" << goldFile << " is saved as float. \nYou may want to re-run it with a bigger epsilon." << endl; fileName = queryFile; } unsigned int numFlows = goldW.NumFlows(); while( !queryW.ReadNextRegionData(&queryData) ) { assert(!goldW.ReadNextRegionData(&goldData)); for (unsigned int i = 0; i < numFlows; i++) { if(difType) { float flowValues2 = -1.0; if(ushortg) { flowValues2 = goldData.flowValues[i]; } else if(ushortq) { flowValues2 = queryData.flowValues[i]; } if(isfinite(flowValues2) && fabs(flowValues2) < maxAbsVal) { if(ushortg && isfinite(queryData.flowValues[i]) && fabs(queryData.flowValues[i]) < maxAbsVal) { compare.AddPair(queryData.flowValues[i], flowValues2); } else if(ushortq && isfinite(goldData.flowValues[i]) && fabs(goldData.flowValues[i]) < maxAbsVal) { compare.AddPair(flowValues2, goldData.flowValues[i]); } } } else { if (isfinite(queryData.flowValues[i]) && isfinite(goldData.flowValues[i]) && (fabs(queryData.flowValues[i]) < maxAbsVal && fabs(goldData.flowValues[i]) < maxAbsVal)) { compare.AddPair(queryData.flowValues[i], goldData.flowValues[i]); if (abs(goldData.flowValues[i] - queryData.flowValues[i]) > epsilon) { if (dump.needDump()) dump.dumpMismatchWellData(goldData, queryData, i); } } } } } const SampleStats<double> ssX = compare.GetXStats(); const SampleStats<double> ssY = compare.GetYStats(); cout << "query values: " << ssX.GetMean() << " +/- " << ssX.GetSD() << endl; cout << "gold values: " << ssY.GetMean() << " +/- " << ssY.GetSD() << endl; return compare; }