ProSHADE  0.7.6.2 (DEC 2021)
Protein Shape Detection
ProSHADE_peakSearch.cpp
Go to the documentation of this file.
1 
23 //==================================================== ProSHADE
24 #include "ProSHADE_peakSearch.hpp"
25 
38 std::vector< proshade_double* > ProSHADE_internal_peakSearch::findAllPointsAboveNeighbours ( proshade_complex* map, proshade_unsign dim, proshade_signed peakSize, proshade_double* medianIQR )
39 {
40  //================================================ Initialise local variables
41  std::vector< proshade_double* > ret;
42  std::vector< proshade_double > nonPeakVals;
43  proshade_double* retHlp = nullptr;
44  proshade_double pointHeight = 0.0;
45  proshade_signed x, y, z, peakX, peakY, peakZ, newIter, ptrIter;
46  proshade_signed xDim = static_cast< proshade_signed > ( std::pow ( dim, 2 ) );
47  proshade_signed yDim = static_cast< proshade_signed > ( dim );
48  bool breakPeak;
49 
50  //================================================ Check all points
51  for ( proshade_signed iter = 0; iter < static_cast< proshade_signed > ( pow( static_cast<proshade_unsign> ( dim ), 3 ) ); iter++ )
52  {
53  //============================================ Find point height
54  pointHeight = pow( map[iter][0], 2.0 ) + pow( map[iter][1], 2.0 );
55 
56  //============================================ Find the x, y and z
57  x = static_cast< proshade_signed > ( std::floor ( iter / xDim ) );
58  y = static_cast< proshade_signed > ( std::floor ( ( iter - x * xDim ) / yDim ) );
59  z = static_cast< proshade_signed > ( iter - x * xDim - y * yDim );
60 
61  //==================================== Initialise the output pointer
62  if ( retHlp == nullptr )
63  {
64  retHlp = new proshade_double[static_cast<proshade_unsign>( pow( ((peakSize*2)+1), 3) * 4 )];
65  ProSHADE_internal_misc::checkMemoryAllocation ( retHlp, __FILE__, __LINE__, __func__ );
66  }
67 
68  //============================================ Get the X surrounding values and check for all being lower than point in question
69  breakPeak = false;
70  ptrIter = 4;
71  for ( proshade_signed xCh = -peakSize; xCh <= +peakSize; xCh++ )
72  {
73  if ( breakPeak ) { break; }
74  for ( proshade_signed yCh = -peakSize; yCh <= +peakSize; yCh++ )
75  {
76  if ( breakPeak ) { break; }
77  for ( proshade_signed zCh = -peakSize; zCh <= +peakSize; zCh++ )
78  {
79  if ( breakPeak ) { break; }
80  if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) { continue; }
81 
82  //================================ Find the nieghbout peak indices (with periodicity)
83  peakX = x + xCh; if ( peakX >= yDim ) { peakX = yDim - 1; }; if ( peakX < 0 ) { peakX = 0; }
84  peakY = y + yCh; if ( peakY >= yDim ) { peakY = yDim - 1; }; if ( peakY < 0 ) { peakY = 0; }
85  peakZ = z + zCh; if ( peakZ >= yDim ) { peakZ = yDim - 1; }; if ( peakZ < 0 ) { peakZ = 0; }
86  newIter = peakX * xDim + peakY * yDim + peakZ;
87 
88  //================================ If neighbour has higher value than index in question, break out
89  if ( ( pow ( map[newIter][0], 2.0 ) + pow( map[newIter][1], 2.0 ) ) > pointHeight ) { breakPeak = true; break; }
90 
91  //================================ Save neighbour values for optimisation of peaks later
92  retHlp[ptrIter] = static_cast<proshade_double> ( peakX );
93  retHlp[ptrIter+1] = static_cast<proshade_double> ( peakY );
94  retHlp[ptrIter+2] = static_cast<proshade_double> ( peakZ );
95  retHlp[ptrIter+3] = pow ( map[newIter][0], 2.0 ) + pow( map[newIter][1], 2.0 );
96  ptrIter += 4;
97  }
98  }
99  }
100  if ( breakPeak ) { ProSHADE_internal_misc::addToDoubleVector ( &nonPeakVals, pointHeight ); continue; }
101 
102  //============================================ If passing, save for returning
103  retHlp[0] = static_cast< proshade_double > ( x );
104  retHlp[1] = static_cast< proshade_double > ( y );
105  retHlp[2] = static_cast< proshade_double > ( z );
106  retHlp[3] = pointHeight;
108  retHlp = nullptr;
109  }
110 
111  //================================================ Save non-peak median and IQR
112  ProSHADE_internal_maths::vectorMedianAndIQR ( &nonPeakVals, medianIQR );
113 
114  //================================================ Release memory if need be
115  if ( retHlp != nullptr ) { delete[] retHlp; }
116 
117  //================================================ Done
118  return ( ret );
119 
120 }
121 
132 void ProSHADE_internal_peakSearch::pointsAboveNeighboursRemoveSmallHeight ( std::vector< proshade_double* >* pointVec, proshade_double* medianIQR, proshade_double noIQRs )
133 {
134  //================================================ Determine the threshold
135  proshade_double backgroundThreshold = std::min ( std::max ( medianIQR[0] + ( medianIQR[1] * noIQRs ), 0.05 ), 0.3 );
136 
137  //================================================ Check for passing the threshold
138  for ( proshade_signed iter = static_cast<proshade_signed> ( pointVec->size()-1 ); iter >= 0 ; iter-- )
139  {
140  if ( pointVec->at( static_cast< size_t > ( iter ) )[3] <= backgroundThreshold )
141  {
142  delete[] pointVec->at( static_cast< size_t > ( iter ) );
143  pointVec->erase ( pointVec->begin() + iter );
144  }
145  }
146 
147  //================================================ Done
148  return ;
149 
150 }
151 
161 void ProSHADE_internal_peakSearch::allocatePeakOptimisationMemory ( proshade_double*& avgMat, proshade_double*& hlpMat, proshade_double*& eA, proshade_double*& eB, proshade_double*& eG, proshade_double*& uAV )
162 {
163  //================================================ Allocate the memory
164  avgMat = new proshade_double [9];
165  hlpMat = new proshade_double [9];
166  eA = new proshade_double;
167  eB = new proshade_double;
168  eG = new proshade_double;
169  uAV = new proshade_double [18];
170 
171  //================================================ Check the memory allocation
172  ProSHADE_internal_misc::checkMemoryAllocation ( avgMat, __FILE__, __LINE__, __func__ );
173  ProSHADE_internal_misc::checkMemoryAllocation ( hlpMat, __FILE__, __LINE__, __func__ );
174  ProSHADE_internal_misc::checkMemoryAllocation ( eA, __FILE__, __LINE__, __func__ );
175  ProSHADE_internal_misc::checkMemoryAllocation ( eB, __FILE__, __LINE__, __func__ );
176  ProSHADE_internal_misc::checkMemoryAllocation ( eG, __FILE__, __LINE__, __func__ );
177  ProSHADE_internal_misc::checkMemoryAllocation ( uAV, __FILE__, __LINE__, __func__ );
178 
179  //================================================ Done
180  return ;
181 
182 }
183 
193 void ProSHADE_internal_peakSearch::releasePeakOptimisationMemory ( proshade_double*& avgMat, proshade_double*& hlpMat, proshade_double*& eA, proshade_double*& eB, proshade_double*& eG, proshade_double*& uAV )
194 {
195  //================================================ Release the memory
196  delete[] avgMat;
197  delete[] hlpMat;
198  delete[] eA;
199  delete[] eB;
200  delete[] eG;
201  delete[] uAV;
202 
203  //================================================ Done
204  return ;
205 
206 }
207 
221 void ProSHADE_internal_peakSearch::optimisePeakPositions ( std::vector< proshade_double* >* pointVec, proshade_signed peakSize, proshade_signed band )
222 {
223  //================================================ Initialise local variables
224  proshade_double *avgMat, *hlpMat, *eulA, *eulB, *eulG, *uAndV;
225  proshade_unsign noPoints = static_cast< proshade_unsign > ( std::pow( ( ( peakSize * 2 ) + 1 ), 3 ) * 4 );
226  proshade_double matWeight;
227 
228  //================================================ Allocate the required memory
229  allocatePeakOptimisationMemory ( avgMat, hlpMat, eulA, eulB, eulG, uAndV );
230 
231  //================================================ For each peak
232  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( pointVec->size() ); iter++ )
233  {
234  //============================================ Re-set loop
235  for ( proshade_unsign i = 0; i < 9; i++ ) { avgMat[i] = 0.0; }
236  matWeight = 0.0;
237 
238  //============================================ For each neighbout and the point itself
239  for ( proshade_unsign it = 0; it < noPoints; it += 4 )
240  {
241  //======================================== Get the Euler angles
242  ProSHADE_internal_maths::getEulerZXZFromSOFTPosition ( band, static_cast< proshade_signed > ( pointVec->at(iter)[it+0] ), static_cast< proshade_signed > ( pointVec->at(iter)[it+1] ), static_cast< proshade_signed > ( pointVec->at(iter)[it+2] ), eulA, eulB, eulG );
243 
244  //======================================== Convert Euler angles to rotation matrix
245  ProSHADE_internal_maths::getRotationMatrixFromEulerZXZAngles ( *eulA, *eulB, *eulG, hlpMat );
246 
247  //======================================== Add the matrix to the sum
248  for ( proshade_unsign i = 0; i < 9; i++ ) { avgMat[i] += hlpMat[i] * pointVec->at(iter)[it+3]; }
249 
250  //======================================== Find matrix weight
251  matWeight += pointVec->at(iter)[it+3];
252  }
253 
254  //============================================ Normalise weighted sum matrix by sum of weights
255  for ( proshade_unsign i = 0; i < 9; i++ ) { avgMat[i] /= matWeight; }
256 
257  //============================================ Decompose the average matrix using SVD
258  ProSHADE_internal_maths::realMatrixSVDUandVOnly ( avgMat, 3, uAndV, false );
259  const FloatingPoint< proshade_double > lhs ( uAndV[0] ), rhs ( -777.7 );
260  if ( lhs.AlmostEquals ( rhs ) )
261  {
262  //======================================== SVD Failed. Just use the central value
263  ProSHADE_internal_maths::getEulerZXZFromSOFTPosition ( band, static_cast< proshade_signed > ( pointVec->at(iter)[0] ), static_cast< proshade_signed > ( pointVec->at(iter)[1] ), static_cast< proshade_signed > ( pointVec->at(iter)[2] ), eulA, eulB, eulG );
264  matWeight = pointVec->at(iter)[3];
265  pointVec->at(iter) = new proshade_double [4];
266  ProSHADE_internal_misc::checkMemoryAllocation ( pointVec->at(iter), __FILE__, __LINE__, __func__ );
267  pointVec->at(iter)[0] = *eulA;
268  pointVec->at(iter)[1] = *eulB;
269  pointVec->at(iter)[2] = *eulG;
270  pointVec->at(iter)[3] = matWeight;
271 
272  continue ;
273  }
274 
275  //============================================ SVD Succeeded. Compute U * V^T
276  for ( proshade_unsign i = 0; i < 9; i++ ) { avgMat[i] = 0.0; }
277  ProSHADE_internal_maths::multiplyTwoSquareMatrices ( uAndV, uAndV+9, avgMat, 3 );
278 
279  //============================================ Convert to Euler
280  ProSHADE_internal_maths::getEulerZXZFromRotMatrix ( avgMat, eulA, eulB, eulG );
281 
282  //============================================ Save over input
283  matWeight = pointVec->at(iter)[3];
284  delete[] pointVec->at(iter);
285  pointVec->at(iter) = new proshade_double [4];
286  ProSHADE_internal_misc::checkMemoryAllocation ( pointVec->at(iter), __FILE__, __LINE__, __func__ );
287  pointVec->at(iter)[0] = *eulA;
288  pointVec->at(iter)[1] = *eulB;
289  pointVec->at(iter)[2] = *eulG;
290  pointVec->at(iter)[3] = matWeight;
291  }
292 
293  //================================================ Release memory
294  releasePeakOptimisationMemory ( avgMat, hlpMat, eulA, eulB, eulG, uAndV );
295 
296  //================================================ Done
297  return ;
298 
299 }
300 
316 std::vector< proshade_double* > ProSHADE_internal_peakSearch::getAllPeaksNaive ( proshade_complex* map, proshade_unsign dim, proshade_signed peakSize, proshade_double noIQRs )
317 {
318  //================================================ Find all indices with higher value than all neighbours
319  std::vector< proshade_double* > allHigherIndices;
320  proshade_double* nonPeakMedianIQR = new proshade_double[2];
321  ProSHADE_internal_misc::checkMemoryAllocation ( nonPeakMedianIQR, __FILE__, __LINE__, __func__ );
322  allHigherIndices = findAllPointsAboveNeighbours ( map, dim, peakSize, nonPeakMedianIQR );
323 
324  //================================================ Remove all indices with too small height
325  pointsAboveNeighboursRemoveSmallHeight ( &allHigherIndices, nonPeakMedianIQR, noIQRs );
326 
327  //================================================ Optimise the peaks using the neighbour values
328  optimisePeakPositions ( &allHigherIndices, peakSize, dim/2 );
329 
330  //================================================ Release memory
331  delete[] nonPeakMedianIQR;
332 
333  //================================================ Done
334  return ( allHigherIndices );
335 
336 }
337 
352 void ProSHADE_internal_peakSearch::getBestPeakEulerAngsNaive ( proshade_complex* map, proshade_unsign dim, proshade_double* eulA, proshade_double* eulB, proshade_double* eulG, ProSHADE_settings* settings )
353 {
354  //================================================ Report progress
355  ProSHADE_internal_messages::printProgressMessage ( settings->verbose, 2, "Looking for Euler angles of highest peak.", settings->messageShift );
356 
357  //================================================ Get all peaks
358  std::vector< proshade_double* > allPeaks = getAllPeaksNaive ( map, dim, static_cast< proshade_signed > ( settings->peakNeighbours ), settings->noIQRsFromMedianNaivePeak );
359 
360  //================================================ Report progress
361  std::stringstream hlpSSP;
362  hlpSSP << "Found " << allPeaks.size() << " possible peaks.";
363  ProSHADE_internal_messages::printProgressMessage ( settings->verbose, 3, hlpSSP.str(), settings->messageShift );
364 
365  //================================================ Sanity check
366  if ( allPeaks.size() == 0 )
367  {
368  *eulA = 0.0;
369  *eulB = 0.0;
370  *eulG = 0.0;
371  return ;
372  }
373 
374  //================================================ Find the highest peak from the list
375  proshade_double highestPeak = 0.0;
376  proshade_unsign highestPeakIndex = 0;
377  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign>( allPeaks.size() ); iter++ )
378  {
379  if ( allPeaks.at(iter)[3] > highestPeak ) { highestPeak = allPeaks.at(iter)[3]; highestPeakIndex = iter; }
380  }
381 
382  //================================================ Get Euler ZXZ for the highest peak
383  *eulA = allPeaks.at(highestPeakIndex)[0];
384  *eulB = allPeaks.at(highestPeakIndex)[1];
385  *eulG = allPeaks.at(highestPeakIndex)[2];
386 
387  //================================================ Release memory
388  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( allPeaks.size() ); iter++ )
389  {
390  delete[] allPeaks.at(iter);
391  }
392 
393  //================================================ Report progress
394  std::stringstream hlpSS;
395  hlpSS << "Optimal Euler angles are " << *eulA << " ; " << *eulB << " ; " << *eulG << " with peak height " << highestPeak;
396  ProSHADE_internal_messages::printProgressMessage ( settings->verbose, 3, hlpSS.str(), settings->messageShift );
397 
398  //================================================ Done
399  return ;
400 
401 }
402 
419 void ProSHADE_internal_peakSearch::allocateSmoothingZScoreMemory ( proshade_unsign dim, proshade_double*& scoreOverVals, proshade_signed*& signals, proshade_double*& filteredY, proshade_double*& avgFilter, proshade_double*& stdFilter, proshade_double*& subVec, proshade_double*& medianIQR, proshade_double*& YZMap, proshade_double*& XZMap, proshade_double*& XYMap, proshade_unsign smLag )
420 {
421  //================================================ Allocate the memory
422  signals = new proshade_signed[dim];
423  scoreOverVals = new proshade_double[dim];
424  filteredY = new proshade_double[dim];
425  avgFilter = new proshade_double[dim];
426  stdFilter = new proshade_double[dim];
427  subVec = new proshade_double[smLag];
428  medianIQR = new proshade_double[2];
429  YZMap = new proshade_double[dim * dim * dim];
430  XZMap = new proshade_double[dim * dim * dim];
431  XYMap = new proshade_double[dim * dim * dim];
432 
433  //================================================ Check memory allocation
434  ProSHADE_internal_misc::checkMemoryAllocation ( signals, __FILE__, __LINE__, __func__ );
435  ProSHADE_internal_misc::checkMemoryAllocation ( scoreOverVals, __FILE__, __LINE__, __func__ );
436  ProSHADE_internal_misc::checkMemoryAllocation ( filteredY, __FILE__, __LINE__, __func__ );
437  ProSHADE_internal_misc::checkMemoryAllocation ( avgFilter, __FILE__, __LINE__, __func__ );
438  ProSHADE_internal_misc::checkMemoryAllocation ( stdFilter, __FILE__, __LINE__, __func__ );
439  ProSHADE_internal_misc::checkMemoryAllocation ( subVec, __FILE__, __LINE__, __func__ );
440  ProSHADE_internal_misc::checkMemoryAllocation ( medianIQR, __FILE__, __LINE__, __func__ );
441  ProSHADE_internal_misc::checkMemoryAllocation ( YZMap, __FILE__, __LINE__, __func__ );
442  ProSHADE_internal_misc::checkMemoryAllocation ( XZMap, __FILE__, __LINE__, __func__ );
443  ProSHADE_internal_misc::checkMemoryAllocation ( XYMap, __FILE__, __LINE__, __func__ );
444 
445  //================================================ Done
446  return ;
447 
448 }
449 
463 void ProSHADE_internal_peakSearch::releaseSmoothingZScoreMemory ( proshade_double*& scoreOverVals, proshade_signed*& signals, proshade_double*& filteredY, proshade_double*& avgFilter, proshade_double*& stdFilter, proshade_double*& subVec, proshade_double*& medianIQR, proshade_double*& YZMap, proshade_double*& XZMap, proshade_double*& XYMap )
464 {
465  //================================================ Release the memory
466  delete[] scoreOverVals;
467  delete[] signals;
468  delete[] filteredY;
469  delete[] avgFilter;
470  delete[] stdFilter;
471  delete[] subVec;
472  delete[] medianIQR;
473  delete[] YZMap;
474  delete[] XZMap;
475  delete[] XYMap;
476 
477  //================================================ Done
478  return ;
479 
480 }
481 
501 void ProSHADE_internal_peakSearch::getSmoothedZScore1D ( proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed* signals, proshade_double* filteredY, proshade_double* avgFilter, proshade_double* stdFilter, proshade_double* subVec, proshade_double* medianIQR, proshade_double* scoreOverVals )
502 {
503  //================================================ Re-set the run
504  for ( proshade_unsign i = 0; i < dim; i++ ) { signals[i] = 0; avgFilter[i] = 0.0; stdFilter[i] = 0.0; filteredY[i] = 0.0; }
505  for ( proshade_unsign i = 0; i < smoothingLag; i++ ) { subVec[i] = scoreOverVals[i-smoothingLag+dim]; }
506  ProSHADE_internal_maths::arrayMedianAndIQR ( subVec, smoothingLag, medianIQR );
507  avgFilter[0] = medianIQR[0];
508  stdFilter[0] = medianIQR[1];
509 
510  //================================================ Find peaks for 1D array
511  for ( proshade_unsign i = 0; i < dim; i++)
512  {
513  //============================================ Is this peak?
514  if ( std::abs ( scoreOverVals[i] - avgFilter[i]) > ZScoreThreshold * stdFilter[i] )
515  {
516  if ( scoreOverVals[i] > avgFilter[i] )
517  {
518  signals[i] = 1;
519  }
520  else
521  {
522  signals[i] = -1;
523  }
524 
525  //======================================== Decrease influence for this window
526  if ( i != 0 ) { filteredY[i] = 0.5 * scoreOverVals[i] + (1 - 0.5) * filteredY[i - 1]; }
527  else { filteredY[i] = 0.5 * scoreOverVals[i]; }
528  }
529  else
530  {
531  signals[i] = 0;
532  filteredY[i] = scoreOverVals[i];
533  }
534 
535  //============================================ Filters adjustments
536  for ( proshade_signed subIt = 0; subIt < static_cast<proshade_signed> ( smoothingLag ); subIt++ )
537  {
538  if ( ( static_cast<proshade_signed>(i) + static_cast<proshade_signed>(subIt) - static_cast<proshade_signed>(smoothingLag) + 1 ) < 0 )
539  {
540  subVec[subIt] = scoreOverVals[( i + static_cast< proshade_unsign > ( subIt ) - smoothingLag + 1 ) + dim];
541  }
542  else
543  {
544  subVec[subIt] = filteredY[( i + static_cast< proshade_unsign > ( subIt ) - smoothingLag + 1 )];
545  }
546  }
547  ProSHADE_internal_maths::arrayMedianAndIQR ( subVec, smoothingLag, medianIQR );
548  avgFilter[i+1] = medianIQR[0];
549  stdFilter[i+1] = medianIQR[1];
550  }
551 
552  //================================================ Done
553  return ;
554 
555 }
556 
576 void ProSHADE_internal_peakSearch::getXAxisArraysSmoothedZScorePeaks ( proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed* signals, proshade_double* filteredY, proshade_double* avgFilter, proshade_double* stdFilter, proshade_double* subVec, proshade_double* medianIQR, proshade_double* scoreOverVals, proshade_complex* map, proshade_double* YZMap )
577 {
578  //================================================ For each YZ point
579  for ( proshade_unsign yIt = 0; yIt < dim; yIt++ )
580  {
581  for ( proshade_unsign zIt = 0; zIt < dim; zIt++ )
582  {
583  //======================================== Get all X values for this YZ position
584  for ( proshade_unsign xIt = 0; xIt < dim; xIt++ )
585  {
586  scoreOverVals[xIt] = pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][0], 2.0 ) +
587  pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][1], 2.0 );
588  }
589 
590  //======================================== Run 1D smoothed Z score algorithm
591  getSmoothedZScore1D ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals );
592 
593  //======================================== Save signals to YZMap
594  for ( proshade_unsign xIt = 0; xIt < dim; xIt++ )
595  {
596  YZMap[xIt * static_cast< proshade_unsign > (4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt] = static_cast< proshade_double > ( signals[xIt] );
597  }
598  }
599  }
600 
601  //================================================ Done
602  return ;
603 
604 }
605 
625 void ProSHADE_internal_peakSearch::getYAxisArraysSmoothedZScorePeaks ( proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed* signals, proshade_double* filteredY, proshade_double* avgFilter, proshade_double* stdFilter, proshade_double* subVec, proshade_double* medianIQR, proshade_double* scoreOverVals, proshade_complex* map, proshade_double* XZMap )
626 {
627  //================================================ For each XZ point
628  for ( proshade_unsign xIt = 0; xIt < dim; xIt++ )
629  {
630  for ( proshade_unsign zIt = 0; zIt < dim; zIt++ )
631  {
632  //======================================== Get all Y values for this XZ position
633  for ( proshade_unsign yIt = 0; yIt < dim; yIt++ )
634  {
635  scoreOverVals[yIt] = pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][0], 2.0 ) +
636  pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][1], 2.0 );
637  }
638 
639  //======================================== Run 1D smoothed Z score algorithm
640  getSmoothedZScore1D ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals );
641 
642  //======================================== Save signals to YZMap
643  for ( proshade_unsign yIt = 0; yIt < dim; yIt++ )
644  {
645  XZMap[xIt * static_cast< proshade_unsign > (4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt] = static_cast< proshade_double > ( signals[xIt] );
646  }
647  }
648  }
649 
650  //================================================ Done
651  return ;
652 
653 }
654 
674 void ProSHADE_internal_peakSearch::getZAxisArraysSmoothedZScorePeaks ( proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed* signals, proshade_double* filteredY, proshade_double* avgFilter, proshade_double* stdFilter, proshade_double* subVec, proshade_double* medianIQR, proshade_double* scoreOverVals, proshade_complex* map, proshade_double* XYMap )
675 {
676  //================================================ For each XZ point
677  for ( proshade_unsign xIt = 0; xIt < dim; xIt++ )
678  {
679  for ( proshade_unsign yIt = 0; yIt < dim; yIt++ )
680  {
681  //======================================== Get all Y values for this XZ position
682  for ( proshade_unsign zIt = 0; zIt < dim; zIt++ )
683  {
684  scoreOverVals[yIt] = pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][0], 2.0 ) +
685  pow ( map[xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt][1], 2.0 );
686  }
687 
688  //======================================== Run 1D smoothed Z score algorithm
689  getSmoothedZScore1D ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals );
690 
691  //======================================== Save signals to YZMap
692  for ( proshade_unsign zIt = 0; zIt < dim; zIt++ )
693  {
694  XYMap[xIt * static_cast< proshade_unsign > (4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt] = static_cast< proshade_double > ( signals[xIt] );
695  }
696  }
697  }
698 
699  //================================================ Done
700  return ;
701 
702 }
703 
719 void ProSHADE_internal_peakSearch::findAllPointNeighbours ( proshade_double* YZMap, proshade_double* XZMap, proshade_double* XYMap, proshade_unsign* visitedMap, proshade_signed dim, proshade_signed x, proshade_signed y, proshade_signed z, std::vector< proshade_unsign >* retVals )
720 {
721  //================================================ Initialise local variables
722  proshade_signed newIter = 0;
723  proshade_signed peakX, peakY, peakZ;
724  proshade_signed xDim = static_cast<proshade_signed>(4 * pow ( ( dim / 2 ), 2 ));
725 
726  //================================================ Iterate through all neighbours
727  for ( proshade_signed xCh = -1; xCh <= +1; xCh++ )
728  {
729  for ( proshade_signed yCh = -1; yCh <= +1; yCh++ )
730  {
731  for ( proshade_signed zCh = -1; zCh <= +1; zCh++ )
732  {
733  //==================================== Do not use this point
734  if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) { continue; }
735 
736  //==================================== Find the nieghbout peak indices (with periodicity)
737  peakX = x + xCh; if ( peakX >= dim ) { peakX -= dim; }; if ( peakX < 0 ) { peakX += dim; }
738  peakY = y + yCh; if ( peakY >= dim ) { peakY -= dim; }; if ( peakY < 0 ) { peakY += dim; }
739  peakZ = z + zCh; if ( peakZ >= dim ) { peakZ -= dim; }; if ( peakZ < 0 ) { peakZ += dim; }
740  newIter = peakX * xDim + peakY * dim + peakZ;
741 
742  //==================================== If already visited, next point
743  if ( visitedMap[newIter] == 1 ) { continue; }
744  else { visitedMap[newIter] = 1; }
745 
746  //==================================== If not peak, next point
747  const FloatingPoint< proshade_double > lhs ( YZMap[newIter] + XZMap[newIter] + XYMap[newIter] ), rhs ( 3.0 );
748  if ( lhs.AlmostEquals ( rhs ) ) { continue; }
749 
750  //==================================== This is a valid neighbour! Save
751  ProSHADE_internal_misc::addToUnsignVector ( retVals, static_cast< proshade_unsign > ( newIter ) );
752 
753  //==================================== ... and recurse!
754  findAllPointNeighbours ( YZMap, XZMap, XYMap, visitedMap, dim, peakX, peakY, peakZ, retVals );
755  }
756  }
757  }
758 
759  //================================================ Done
760  return ;
761 
762 }
763 
778 void ProSHADE_internal_peakSearch::findAllDisconnectedIslands ( proshade_complex* map, proshade_double* YZMap, proshade_double* XZMap, proshade_double* XYMap, proshade_unsign dim, std::vector< proshade_unsign >* allIslandBests )
779 {
780  //================================================ Initialise local variables
781  std::vector< proshade_unsign > ret;
782  std::vector< proshade_unsign > thisIsland;
783  proshade_unsign* visitedMap = new proshade_unsign[dim*dim*dim];
784  ProSHADE_internal_misc::checkMemoryAllocation ( visitedMap, __FILE__, __LINE__, __func__ );
785  for ( proshade_unsign i = 0; i < ( dim * dim * dim ); i++ ) { visitedMap[i] = 0; }
786  proshade_unsign index, maxIndex;
787  proshade_double maxHeight;
788 
789  //================================================ For each point
790  for ( proshade_unsign xIt = 0; xIt < dim; xIt++ )
791  {
792  for ( proshade_unsign yIt = 0; yIt < dim; yIt++ )
793  {
794  for ( proshade_unsign zIt = 0; zIt < dim; zIt++ )
795  {
796  //==================================== Find index
797  index = xIt * static_cast<proshade_unsign>(4 * pow ( ( dim / 2 ), 2 )) + yIt * dim + zIt;
798 
799  //==================================== If already visited, next point
800  if ( visitedMap[index] == 1 ) { continue; }
801  else { visitedMap[index] = 1; }
802 
803  //==================================== If not peak, next point
804  const FloatingPoint< proshade_double > lhs ( YZMap[index] + XZMap[index] + XYMap[index] ), rhs ( 3.0 );
805  if ( !lhs.AlmostEquals ( rhs ) ) { continue; }
806 
807  //==================================== This is a new island! Save this point
808  thisIsland.clear ( );
809  ProSHADE_internal_misc::addToUnsignVector ( &thisIsland, index );
810 
811  //==================================== ... and find all neighbours
812  findAllPointNeighbours ( YZMap, XZMap, XYMap, visitedMap, static_cast<proshade_signed>(dim), static_cast<proshade_signed>(xIt), static_cast<proshade_signed>(yIt), static_cast<proshade_signed>(zIt), &thisIsland );
813 
814  //==================================== Find the largest of the island peaks
815  maxHeight = 0.0;
816  maxIndex = 0;
817  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( thisIsland.size() ); iter++ )
818  {
819  if ( ( pow( map[thisIsland.at(iter)][0], 2.0 ) + pow( map[thisIsland.at(iter)][1], 2.0) ) > maxHeight )
820  {
821  maxHeight = pow( map[thisIsland.at(iter)][0], 2.0 ) + pow( map[thisIsland.at(iter)][1], 2.0 );
822  maxIndex = thisIsland.at(iter);
823  }
824  }
825 
826  //==================================== Save the results
827  ProSHADE_internal_misc::addToUnsignVector ( allIslandBests, maxIndex );
828  }
829  }
830  }
831 
832  //================================================ Release memory
833  delete[] visitedMap;
834 
835  //================================================ Done
836  return ;
837 
838 }
839 
854 void ProSHADE_internal_peakSearch::findAllSmoothedZScorePeaksWithNeighbours ( proshade_complex* map, proshade_double* YZMap, proshade_double* XZMap, proshade_double* XYMap, proshade_signed dim, proshade_signed peakSize, std::vector< proshade_double* >* allPeaksWithNeighbours )
855 {
856  //================================================ Initialise local variables
857  proshade_signed x, y, z, peakX, peakY, peakZ, newIter, ptrIter;
858  proshade_unsign noNeighbours = static_cast< proshade_unsign > ( std::pow( ( ( peakSize * 2 ) + 1 ), 3 ) * 4 );
859 
860  //================================================ Find all islands and their best representative
861  std::vector < proshade_unsign > allPeaksRepresentatives;
862  findAllDisconnectedIslands ( map, YZMap, XZMap, XYMap, static_cast< proshade_unsign > ( dim ), &allPeaksRepresentatives );
863 
864  //================================================ For each peak
865  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( allPeaksRepresentatives.size() ); iter++ )
866  {
867  //============================================ Reset loop
868  ptrIter = 0;
869 
870  //============================================ Determine x, y and z
871  z = ( static_cast< proshade_signed > ( allPeaksRepresentatives.at(iter) ) % (dim*dim) ) % dim;
872  y = ( static_cast< proshade_signed > ( allPeaksRepresentatives.at(iter) ) - z ) % (dim*dim) / dim;
873  x = ( static_cast< proshade_signed > ( allPeaksRepresentatives.at(iter) ) - z - ( y * dim ) ) / (dim*dim);
874 
875  //============================================ Allocate the memory
876  proshade_double* neighbours = new proshade_double[noNeighbours];
877  ProSHADE_internal_misc::checkMemoryAllocation ( neighbours, __FILE__, __LINE__, __func__ );
878  ProSHADE_internal_misc::addToDblPtrVector ( allPeaksWithNeighbours, neighbours );
879 
880  //============================================ Find all neighbours
881  for ( proshade_signed xCh = -peakSize; xCh <= +peakSize; xCh++ )
882  {
883  for ( proshade_signed yCh = -peakSize; yCh <= +peakSize; yCh++ )
884  {
885  for ( proshade_signed zCh = -peakSize; zCh <= +peakSize; zCh++ )
886  {
887  //================================ Find the nieghbout peak indices (with periodicity)
888  peakX = x + xCh; if ( peakX >= dim ) { peakX -= dim; }; if ( peakX < 0 ) { peakX += dim; }
889  peakY = y + yCh; if ( peakY >= dim ) { peakY -= dim; }; if ( peakY < 0 ) { peakY += dim; }
890  peakZ = z + zCh; if ( peakZ >= dim ) { peakZ -= dim; }; if ( peakZ < 0 ) { peakZ += dim; }
891  newIter = peakX * (dim*dim) + peakY * dim + peakZ;
892 
893  //================================ Save neighbour values for optimisation of peaks later
894  allPeaksWithNeighbours->at(iter)[ptrIter] = static_cast<proshade_double> ( peakX );
895  allPeaksWithNeighbours->at(iter)[ptrIter+1] = static_cast<proshade_double> ( peakY );
896  allPeaksWithNeighbours->at(iter)[ptrIter+2] = static_cast<proshade_double> ( peakZ );
897  allPeaksWithNeighbours->at(iter)[ptrIter+3] = pow ( map[newIter][0], 2.0 ) + pow( map[newIter][1], 2.0 );
898  ptrIter += 4;
899  }
900  }
901  }
902 
903  //============================================ Release memory
904  delete[] neighbours;
905  }
906 
907  //================================================ Done
908  return ;
909 
910 }
911 
923 std::vector< proshade_double* > ProSHADE_internal_peakSearch::getAllPeaksSmoothedZ ( proshade_complex* map, proshade_unsign dim, proshade_double smoothingFraction, proshade_double noIQRs, proshade_signed peakSize )
924 {
925  //================================================ Initialise local variables
926  std::vector< proshade_double* > allHigherIndices;
927  proshade_unsign smoothingLag = static_cast< proshade_unsign > ( std::floor ( smoothingFraction * static_cast< proshade_double > ( dim ) ) );
928  proshade_double ZScoreThreshold = noIQRs;
929  proshade_signed *signals;
930  proshade_double *scoreOverVals, *filteredY, *avgFilter, *stdFilter, *subVec, *medianIQR, *YZMap, *XZMap, *XYMap;
931 
932  //================================================ Sanity check
933  if ( dim <= smoothingLag + 2)
934  {
935  // throw error
936  }
937 
938  //================================================ Allocate required memory
939  allocateSmoothingZScoreMemory ( dim, scoreOverVals, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, YZMap, XZMap, XYMap, smoothingLag );
940 
941  //================================================ Get smoothed Z score peaks for X-axis arrays
942  getXAxisArraysSmoothedZScorePeaks ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals, map, YZMap );
943 
944  //================================================ Get smoothed Z score peaks for Y-axis arrays
945  getYAxisArraysSmoothedZScorePeaks ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals, map, XZMap );
946 
947  //================================================ Get smoothed Z score peaks for Y-axis arrays
948  getZAxisArraysSmoothedZScorePeaks ( dim, smoothingLag, ZScoreThreshold, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, scoreOverVals, map, XYMap );
949 
950  //================================================ Put all dimension peaks together and detect disconnected islands
951  findAllSmoothedZScorePeaksWithNeighbours ( map, YZMap, XZMap, XYMap, static_cast< proshade_signed > ( dim ), peakSize, &allHigherIndices );
952 
953  //================================================ Optimise the peaks using the neighbour values
954  optimisePeakPositions ( &allHigherIndices, peakSize, dim/2 );
955 
956  //================================================ Release the required memory
957  releaseSmoothingZScoreMemory ( scoreOverVals, signals, filteredY, avgFilter, stdFilter, subVec, medianIQR, YZMap, XZMap, XYMap );
958 
959  //================================================ Done
960  return ( allHigherIndices );
961 
962 }
963 
976 void ProSHADE_internal_peakSearch::getBestPeakEulerAngsSmoothedZ ( proshade_complex* map, proshade_unsign dim, proshade_double smoothingFraction, proshade_double noIQRs, proshade_signed peakSize, proshade_double* eulA, proshade_double* eulB, proshade_double* eulG )
977 {
978  //================================================ Get all peaks
979  std::vector< proshade_double* > allPeaks = getAllPeaksSmoothedZ ( map, dim, smoothingFraction, noIQRs, peakSize );
980 
981  //================================================ Find the highest peak from the list
982  proshade_double highestPeak = 0.0;
983  proshade_unsign highestPeakIndex = 0;
984  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign>( allPeaks.size() ); iter++ )
985  {
986  if ( allPeaks.at(iter)[4] > highestPeak ) { highestPeak = allPeaks.at(iter)[4]; highestPeakIndex = iter; }
987  }
988 
989  //================================================ Get Euler ZXZ from Angle-axis
990  proshade_double* rotMat = new proshade_double[9];
991  ProSHADE_internal_misc::checkMemoryAllocation ( rotMat, __FILE__, __LINE__, __func__ );
992  ProSHADE_internal_maths::getRotationMatrixFromAngleAxis ( rotMat, allPeaks.at(highestPeakIndex)[0], allPeaks.at(highestPeakIndex)[1], allPeaks.at(highestPeakIndex)[2], allPeaks.at(highestPeakIndex)[3] );
993  ProSHADE_internal_maths::getEulerZXZFromRotMatrix ( rotMat, eulA, eulB, eulG );
994 
995  //================================================ Release memory
996  delete[] rotMat;
997  for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( allPeaks.size() ); iter++ )
998  {
999  delete[] allPeaks.at(iter);
1000  }
1001 
1002  //================================================ Done
1003  return ;
1004 
1005 }
ProSHADE_settings::noIQRsFromMedianNaivePeak
proshade_double noIQRsFromMedianNaivePeak
When doing peak searching, how many IQRs from the median the threshold for peak height should be (in ...
Definition: ProSHADE_settings.hpp:120
ProSHADE_internal_peakSearch::releaseSmoothingZScoreMemory
void releaseSmoothingZScoreMemory(proshade_double *&scoreOverVals, proshade_signed *&signals, proshade_double *&filteredY, proshade_double *&avgFilter, proshade_double *&stdFilter, proshade_double *&subVec, proshade_double *&medianIQR, proshade_double *&YZMap, proshade_double *&XZMap, proshade_double *&XYMap)
This function releases the memory required for smoothed Z score computation.
Definition: ProSHADE_peakSearch.cpp:463
ProSHADE_internal_misc::addToDblPtrVector
void addToDblPtrVector(std::vector< proshade_double * > *vecToAddTo, proshade_double *elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:143
ProSHADE_internal_peakSearch::getSmoothedZScore1D
void getSmoothedZScore1D(proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed *signals, proshade_double *filteredY, proshade_double *avgFilter, proshade_double *stdFilter, proshade_double *subVec, proshade_double *medianIQR, proshade_double *scoreOverVals)
This function computes the 1D peaks for a 1D input array and returns array of int's as signal.
Definition: ProSHADE_peakSearch.cpp:501
ProSHADE_internal_maths::getEulerZXZFromRotMatrix
void getEulerZXZFromRotMatrix(proshade_double *rotMat, proshade_double *eA, proshade_double *eB, proshade_double *eG)
This function converts rotation matrix to the Euler ZXZ angles representation.
Definition: ProSHADE_maths.cpp:1562
ProSHADE_internal_peakSearch::getAllPeaksNaive
std::vector< proshade_double * > getAllPeaksNaive(proshade_complex *map, proshade_unsign dim, proshade_signed peakSize, proshade_double noIQRs)
This function finds peaks in the 3D map using the "naive" approach.
Definition: ProSHADE_peakSearch.cpp:316
ProSHADE_internal_peakSearch::getAllPeaksSmoothedZ
std::vector< proshade_double * > getAllPeaksSmoothedZ(proshade_complex *map, proshade_unsign dim, proshade_double smoothingFraction, proshade_double noIQRs, proshade_signed peakSize)
This function finds peaks in the 3D map using the smoothed Z score approach.
Definition: ProSHADE_peakSearch.cpp:923
ProSHADE_internal_maths::getRotationMatrixFromEulerZXZAngles
void getRotationMatrixFromEulerZXZAngles(proshade_double eulerAlpha, proshade_double eulerBeta, proshade_double eulerGamma, proshade_double *matrix)
Function to find the rotation matrix from Euler angles (ZXZ convention).
Definition: ProSHADE_maths.cpp:1020
ProSHADE_internal_peakSearch::getYAxisArraysSmoothedZScorePeaks
void getYAxisArraysSmoothedZScorePeaks(proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed *signals, proshade_double *filteredY, proshade_double *avgFilter, proshade_double *stdFilter, proshade_double *subVec, proshade_double *medianIQR, proshade_double *scoreOverVals, proshade_complex *map, proshade_double *XZMap)
This function runs the 1D smoothed Z score algorithm on all Y-axis arrays as its inputs.
Definition: ProSHADE_peakSearch.cpp:625
ProSHADE_internal_peakSearch::findAllPointNeighbours
void findAllPointNeighbours(proshade_double *YZMap, proshade_double *XZMap, proshade_double *XYMap, proshade_unsign *visitedMap, proshade_signed dim, proshade_signed x, proshade_signed y, proshade_signed z, std::vector< proshade_unsign > *retVals)
This is a support function for the Z-score peak detection. It is currently not being used.
Definition: ProSHADE_peakSearch.cpp:719
ProSHADE_internal_peakSearch::allocatePeakOptimisationMemory
void allocatePeakOptimisationMemory(proshade_double *&avgMat, proshade_double *&hlpMap, proshade_double *&eA, proshade_double *&eB, proshade_double *&eG, proshade_double *&uAV)
This function allocates and checks all the peak optimisation memory.
Definition: ProSHADE_peakSearch.cpp:161
ProSHADE_settings::verbose
proshade_signed verbose
Should the software report on the progress, or just be quiet? Value between -1 (nothing) and 4 (loud)
Definition: ProSHADE_settings.hpp:149
ProSHADE_settings::messageShift
proshade_signed messageShift
This value allows shifting the messages to create more readable log for sub-processes.
Definition: ProSHADE_settings.hpp:150
ProSHADE_internal_misc::addToDoubleVector
void addToDoubleVector(std::vector< proshade_double > *vecToAddTo, proshade_double elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:77
ProSHADE_internal_peakSearch::getBestPeakEulerAngsNaive
void getBestPeakEulerAngsNaive(proshade_complex *map, proshade_unsign dim, proshade_double *eulA, proshade_double *eulB, proshade_double *eulG, ProSHADE_settings *settings)
This function finds the highest peaks optimised Euler angles using the "naive" approach.
Definition: ProSHADE_peakSearch.cpp:352
ProSHADE_internal_peakSearch::pointsAboveNeighboursRemoveSmallHeight
void pointsAboveNeighboursRemoveSmallHeight(std::vector< proshade_double * > *pointVec, proshade_double *medianIQR, proshade_double noIQRs)
This function clears the 'higher than neighbour' vector from background values.
Definition: ProSHADE_peakSearch.cpp:132
ProSHADE_internal_peakSearch::findAllSmoothedZScorePeaksWithNeighbours
void findAllSmoothedZScorePeaksWithNeighbours(proshade_complex *map, proshade_double *YZMap, proshade_double *XZMap, proshade_double *XYMap, proshade_signed dim, proshade_signed peakSize, std::vector< proshade_double * > *allPeaksWithNeighbours)
This function firstly determines the highest peak of all smoothed Z score islands and then returns th...
Definition: ProSHADE_peakSearch.cpp:854
ProSHADE_internal_peakSearch::getXAxisArraysSmoothedZScorePeaks
void getXAxisArraysSmoothedZScorePeaks(proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed *signals, proshade_double *filteredY, proshade_double *avgFilter, proshade_double *stdFilter, proshade_double *subVec, proshade_double *medianIQR, proshade_double *scoreOverVals, proshade_complex *map, proshade_double *YZMap)
This function runs the 1D smoothed Z score algorithm on all X-axis arrays as its inputs.
Definition: ProSHADE_peakSearch.cpp:576
ProSHADE_internal_maths::getRotationMatrixFromAngleAxis
void getRotationMatrixFromAngleAxis(proshade_double *rotMat, proshade_double x, proshade_double y, proshade_double z, proshade_double ang)
This function converts the axis-angle representation to the rotation matrix representation.
Definition: ProSHADE_maths.cpp:1459
ProSHADE_settings
This class stores all the settings and is passed to the executive classes instead of a multitude of p...
Definition: ProSHADE_settings.hpp:37
ProSHADE_internal_peakSearch::getZAxisArraysSmoothedZScorePeaks
void getZAxisArraysSmoothedZScorePeaks(proshade_unsign dim, proshade_unsign smoothingLag, proshade_double ZScoreThreshold, proshade_signed *signals, proshade_double *filteredY, proshade_double *avgFilter, proshade_double *stdFilter, proshade_double *subVec, proshade_double *medianIQR, proshade_double *scoreOverVals, proshade_complex *map, proshade_double *XYMap)
This function runs the 1D smoothed Z score algorithm on all Z-axis arrays as its inputs.
Definition: ProSHADE_peakSearch.cpp:674
ProSHADE_internal_maths::realMatrixSVDUandVOnly
void realMatrixSVDUandVOnly(proshade_double *mat, int dim, proshade_double *uAndV, bool fail=true)
Function to compute the real matrix SVD and return the U and V matrices.
Definition: ProSHADE_maths.cpp:871
ProSHADE_internal_peakSearch::getBestPeakEulerAngsSmoothedZ
void getBestPeakEulerAngsSmoothedZ(proshade_complex *map, proshade_unsign dim, proshade_double smoothingFraction, proshade_double noIQRs, proshade_signed peakSize, proshade_double *eulA, proshade_double *eulB, proshade_double *eulG)
This function finds the highest peaks optimised Euler angles using the smoothed Z score approach.
Definition: ProSHADE_peakSearch.cpp:976
ProSHADE_settings::peakNeighbours
proshade_unsign peakNeighbours
Number of points in any direction that have to be lower than the considered index in order to conside...
Definition: ProSHADE_settings.hpp:119
ProSHADE_internal_misc::checkMemoryAllocation
void checkMemoryAllocation(chVar checkVar, std::string fileP, unsigned int lineP, std::string funcP, std::string infoP="This error may occurs when ProSHADE requests memory to be\n : allocated to it and this operation fails. This could\n : happen when not enough memory is available, either due to\n : other processes using a lot of memory, or when the machine\n : does not have sufficient memory available. Re-run to see\n : if this problem persists.")
Checks if memory was allocated properly.
Definition: ProSHADE_misc.hpp:68
ProSHADE_internal_maths::getEulerZXZFromSOFTPosition
void getEulerZXZFromSOFTPosition(proshade_signed band, proshade_signed x, proshade_signed y, proshade_signed z, proshade_double *eulerAlpha, proshade_double *eulerBeta, proshade_double *eulerGamma)
Function to find Euler angles (ZXZ convention) from index position in the inverse SOFT map.
Definition: ProSHADE_maths.cpp:963
ProSHADE_internal_peakSearch::optimisePeakPositions
void optimisePeakPositions(std::vector< proshade_double * > *pointVec, proshade_signed peakSize, proshade_signed band)
This function optimises all the peaks in the input vector using the values of their neighbours.
Definition: ProSHADE_peakSearch.cpp:221
ProSHADE_internal_maths::vectorMedianAndIQR
void vectorMedianAndIQR(std::vector< proshade_double > *vec, proshade_double *&ret)
Function to get vector median and inter-quartile range.
Definition: ProSHADE_maths.cpp:149
ProSHADE_peakSearch.hpp
This header file declares functions required for 3D map peak searching.
ProSHADE_internal_misc::addToUnsignVector
void addToUnsignVector(std::vector< proshade_unsign > *vecToAddTo, proshade_unsign elementToAdd)
Adds the element to the vector.
Definition: ProSHADE_misc.cpp:99
ProSHADE_internal_peakSearch::releasePeakOptimisationMemory
void releasePeakOptimisationMemory(proshade_double *&avgMat, proshade_double *&hlpMap, proshade_double *&eA, proshade_double *&eB, proshade_double *&eG, proshade_double *&uAV)
This function deletes all the peak optimisation memory.
Definition: ProSHADE_peakSearch.cpp:193
ProSHADE_internal_peakSearch::allocateSmoothingZScoreMemory
void allocateSmoothingZScoreMemory(proshade_unsign dim, proshade_double *&scoreOverVals, proshade_signed *&signals, proshade_double *&filteredY, proshade_double *&avgFilter, proshade_double *&stdFilter, proshade_double *&subVec, proshade_double *&medianIQR, proshade_double *&YZMap, proshade_double *&XZMap, proshade_double *&XYMap, proshade_unsign smLag)
This function allocates the memory required for smoothed Z score computation.
Definition: ProSHADE_peakSearch.cpp:419
ProSHADE_internal_peakSearch::findAllDisconnectedIslands
void findAllDisconnectedIslands(proshade_complex *map, proshade_double *YZMap, proshade_double *XZMap, proshade_double *XYMap, proshade_unsign dim, std::vector< proshade_unsign > *allIslandBests)
This function combines the three Z score maps, locates individual islands and returns a vector of hig...
Definition: ProSHADE_peakSearch.cpp:778
ProSHADE_internal_maths::multiplyTwoSquareMatrices
void multiplyTwoSquareMatrices(proshade_double *A, proshade_double *B, proshade_double *res, proshade_unsign dim=3)
Function to compute matrix multiplication.
Definition: ProSHADE_maths.cpp:1696
ProSHADE_internal_peakSearch::findAllPointsAboveNeighbours
std::vector< proshade_double * > findAllPointsAboveNeighbours(proshade_complex *map, proshade_unsign dim, proshade_signed peakSize, proshade_double *medianIQR)
This function finds all indices with higher value then all neighbours.
Definition: ProSHADE_peakSearch.cpp:38
ProSHADE_internal_messages::printProgressMessage
void printProgressMessage(proshade_signed verbose, proshade_signed messageLevel, std::string message, proshade_signed messageShift=0)
General stdout message printing.
Definition: ProSHADE_messages.cpp:71
ProSHADE_internal_maths::arrayMedianAndIQR
void arrayMedianAndIQR(proshade_double *vec, proshade_unsign vecSize, proshade_double *&ret)
Function to get array median and inter-quartile range.
Definition: ProSHADE_maths.cpp:200