source: trunk/src/Utils/utils.hh @ 190

Last change on this file since 190 was 190, checked in by Matthew Whiting, 18 years ago

Large commit. The addition of a new Statistics namespace & class, plus a number of changes to the code to make the cube-wide statistics calculation work. The FDR calculations are incorporated into the new class, and a number of functions have been made into templates to ease the calculations. Details follow:

  • New namespace and class (StatsContainer? -- templated) in Statistics.hh, that holds mean,median,stddev & madfm, and provide accessor and calculator functions for these. It also holds the threshold values for sigma-clipping and FDR methods, as well as the PValue evaluation functions
  • The correctionFactor incorporated into the namespace, and given a conversion function that other functions can call (eg. the atrous_Xd_reconstruct functions).
  • Templated the statistics functions in getStats.cc.
  • Templated the sort functions, and made swap an inline one defined in utils.hh.
  • A number of changes to cubes.cc and cubes.hh:
    • DataArray? gains a StatsContainer? object, to store stats info.
    • Image has lost its pValue array (not needed as we calculate on the fly) and mask array (not used).
    • Image has also lost all its stats members, but keeps minPix.
    • Functions to go are Image::maskObject, Image::findStats. Removed calls to the former. Latter never used.
    • Cube::setCubeStats does the cube-wide stats calculations, including setupFDR (now a Cube function).
    • Cube loses the specMean etc arrays.
  • The Search functions (ReconSearch? and CubicSearch?) changed to accommodate the exchange of StatsContainer? objects. This changed the prototypes as well.
  • The growObject function incorporates the new StatsContainer? object.
  • Minor change to Merger, in the preparation for calling growObject.
  • A new par introduced: flagUserThreshold -- set to true when the user enters a value for the threshold.
  • Removed thresholding_functions.cc and incorporated its functions into cubes.cc and cubes.hh.
File size: 4.4 KB
Line 
1#ifndef UTILS_H
2#define UTILS_H
3
4#include <param.hh>
5#include <wcs.h>
6#include <string>
7
8// define the speed of light for WCS-related accessor functions
9const float C_kms = 299792.458;
10
11// MENU ROUTINES FOR DIGANOSTIC/TEST PROGRAMS
12std::string menu();
13std::string specMenu();
14std::string orionMenu();
15std::string imageMenu();
16std::string twoblMenu();
17
18int linear_regression(int num, float *x, float *y, int ilow, int ihigh,
19                      float &slope, float &errSlope,
20                      float &intercept, float &errIntercept, float &r);
21void zscale(long imagesize, float *image, float &z1, float &z2);
22void zscale(long imagesize, float *image, float &z1, float &z2, float nullVal);
23template <class T> void swap(T &a, T &b){T t=a;a=b;b=t;};
24template <class T> void sort(T *arr, int begin, int end);
25template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray,
26                                        int begin, int end);
27
28// STATISTICS-RELATED ROUTINES
29template <class T> void findMinMax(const T *array, const int size,
30                                   T &min, T &max);
31template <class T> float findMean(T *array, int size);
32template <class T> float findStddev(T *array, int size);
33template <class T> T findMedian(T *array, int size);
34template <class T> T findMADFM(T *array, int size);
35template <class T> void findMedianStats(T *array, int size,
36                                        T &median, T &madfm);
37template <class T> void findMedianStats(T *array, int size, bool *isGood,
38                                        T &median, T &madfm);
39template <class T> void findNormalStats(T *array, int size,
40                                        float &mean, float &stddev);
41template <class T> void findNormalStats(T *array, int size, bool *isGood,
42                     float &mean, float &stddev);
43
44void findTrimmedHistStats(float *array, const int size,
45                          float &tmean, float &tsigma);
46void getRandomSpectrum(int length, float *x, float *y);
47void getRandomSpectrum(int length, float *x, double *y);
48void getRandomSpectrum(int length, float mean, float sigma,
49                       float *x, double *y);
50void getRandomSpectrum(int length, float mean, float sigma,
51                       float *x, float *y);
52float getNormalRV();
53float getNormalRVtrunc();
54float getNormalRV(float mean, float sigma);
55void getSigmaFactors(int &numScales, float *factors);
56void getSigmaFactors2D(int &numScales, float *factors);
57void getSigmaFactors3D(int &numScales, float *factors);
58void getSigmaFactors1DNew(int &numScales);
59void getSigmaFactors2DNew(int &numScales);
60void getSigmaFactors3DNew(int &numScales);
61
62
63// PLOTTING ROUTINES
64extern "C" int  cpgtest();
65extern "C" void cpgwedglog(const char* side, float disp, float width,
66                           float fg, float bg, const char *label);
67extern "C" void cpghistlog(int npts, float *data, float datamin,
68                           float datamax, int nbin, int pgflag);
69extern "C" void cpgcumul(int npts, float *data, float datamin,
70                         float datamax, int pgflag);
71void plotLine(const float slope, const float intercept);
72void lineOfEquality();
73void lineOfBestFit(int size, float *x, float *y);
74void lineOfBestFitPB(const int size, const float *x, const float *y);
75void plotVertLine(const float xval, const int colour, const int style);
76void plotVertLine(const float xval);
77void plotVertLine(const float xval, const int colour);
78void plotHorizLine(const float yval, const int colour, const int style);
79void plotHorizLine(const float yval);
80void plotHorizLine(const float yval, const int colour);
81void drawContours(const int size, const float *x, const float *y);
82void drawBlankEdges(float *dataArray, int xdim, int ydim, Param &par);
83
84// POSITION-RELATED ROUTINES
85string getIAUNameEQ(double ra, double dec, float equinox);
86string getIAUNameGAL(double ra, double dec);
87string decToDMS(double dec, string type);
88double dmsToDec(string dms);
89double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2);
90
91// WCS-RELATED ROUTINES
92int wcsToPixSingle(wcsprm *wcs, const double *world, double *pix);
93int pixToWCSSingle(wcsprm *wcs, const double *pix, double *world);
94int wcsToPixMulti(wcsprm *wcs, const double *world,
95                  double *pix, const int npts);
96int pixToWCSMulti(wcsprm *wcs, const double *pix,
97                  double *world, const int npts);
98double pixelToVelocity(wcsprm *wcs, double &x, double &y,
99                       double &z, string velUnits);
100double coordToVel(wcsprm *wcs, const double coord, string outputUnits);
101double velToCoord(wcsprm *wcs, const float velocity, string outputUnits);
102
103// FILTER SMOOTHING ROUTINES
104void waveletSmooth(int dim,float *array, int arraySize, float sigma);
105void hanningSmooth(float *array, int arraySize, int hanningSize);
106void tophatSmooth(float *array, int arraySize, int width);
107
108#endif
Note: See TracBrowser for help on using the repository browser.