[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // utils.hh: Prototypes for utility functions. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[3] | 28 | #ifndef UTILS_H |
---|
| 29 | #define UTILS_H |
---|
| 30 | |
---|
| 31 | #include <wcs.h> |
---|
| 32 | #include <string> |
---|
| 33 | |
---|
[274] | 34 | struct wcsprm; // just foreshadow this. |
---|
| 35 | |
---|
[3] | 36 | // define the speed of light for WCS-related accessor functions |
---|
| 37 | const float C_kms = 299792.458; |
---|
| 38 | |
---|
[146] | 39 | int linear_regression(int num, float *x, float *y, int ilow, int ihigh, |
---|
| 40 | float &slope, float &errSlope, |
---|
| 41 | float &intercept, float &errIntercept, float &r); |
---|
[3] | 42 | void zscale(long imagesize, float *image, float &z1, float &z2); |
---|
| 43 | void zscale(long imagesize, float *image, float &z1, float &z2, float nullVal); |
---|
[190] | 44 | template <class T> void sort(T *arr, int begin, int end); |
---|
| 45 | template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray, |
---|
| 46 | int begin, int end); |
---|
[56] | 47 | |
---|
| 48 | // STATISTICS-RELATED ROUTINES |
---|
[205] | 49 | template <class T> T absval(T value); |
---|
[190] | 50 | template <class T> void findMinMax(const T *array, const int size, |
---|
| 51 | T &min, T &max); |
---|
| 52 | template <class T> float findMean(T *array, int size); |
---|
| 53 | template <class T> float findStddev(T *array, int size); |
---|
| 54 | template <class T> T findMedian(T *array, int size); |
---|
| 55 | template <class T> T findMADFM(T *array, int size); |
---|
| 56 | template <class T> void findMedianStats(T *array, int size, |
---|
| 57 | T &median, T &madfm); |
---|
| 58 | template <class T> void findMedianStats(T *array, int size, bool *isGood, |
---|
| 59 | T &median, T &madfm); |
---|
| 60 | template <class T> void findNormalStats(T *array, int size, |
---|
| 61 | float &mean, float &stddev); |
---|
| 62 | template <class T> void findNormalStats(T *array, int size, bool *isGood, |
---|
[275] | 63 | float &mean, float &stddev); |
---|
| 64 | template <class T> void findAllStats(T *array, int size, |
---|
| 65 | float &mean, float &stddev, |
---|
| 66 | T &median, T &madfm); |
---|
| 67 | template <class T> void findAllStats(T *array, int size, bool *mask, |
---|
| 68 | float &mean, float &stddev, |
---|
| 69 | T &median, T &madfm); |
---|
[190] | 70 | |
---|
[3] | 71 | |
---|
[221] | 72 | //-------------------- |
---|
[56] | 73 | // PLOTTING ROUTINES |
---|
[221] | 74 | //-------------------- |
---|
| 75 | // The following are in plottingUtilities.cc |
---|
| 76 | // |
---|
[56] | 77 | void plotLine(const float slope, const float intercept); |
---|
| 78 | void lineOfEquality(); |
---|
| 79 | void lineOfBestFit(int size, float *x, float *y); |
---|
| 80 | void lineOfBestFitPB(const int size, const float *x, const float *y); |
---|
| 81 | void plotVertLine(const float xval, const int colour, const int style); |
---|
| 82 | void plotVertLine(const float xval); |
---|
| 83 | void plotVertLine(const float xval, const int colour); |
---|
| 84 | void plotHorizLine(const float yval, const int colour, const int style); |
---|
| 85 | void plotHorizLine(const float yval); |
---|
| 86 | void plotHorizLine(const float yval, const int colour); |
---|
| 87 | void drawContours(const int size, const float *x, const float *y); |
---|
[3] | 88 | |
---|
[56] | 89 | // POSITION-RELATED ROUTINES |
---|
[222] | 90 | std::string getIAUNameEQ(double ra, double dec, float equinox); |
---|
| 91 | std::string getIAUNameGAL(double ra, double dec); |
---|
| 92 | std::string decToDMS(double dec, std::string type); |
---|
| 93 | double dmsToDec(std::string dms); |
---|
[3] | 94 | double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2); |
---|
| 95 | |
---|
[56] | 96 | // WCS-RELATED ROUTINES |
---|
[204] | 97 | int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix); |
---|
| 98 | int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world); |
---|
| 99 | int wcsToPixMulti(struct wcsprm *wcs, const double *world, |
---|
[146] | 100 | double *pix, const int npts); |
---|
[204] | 101 | int pixToWCSMulti(struct wcsprm *wcs, const double *pix, |
---|
[146] | 102 | double *world, const int npts); |
---|
[204] | 103 | double pixelToVelocity(struct wcsprm *wcs, double &x, double &y, |
---|
[222] | 104 | double &z, std::string velUnits); |
---|
| 105 | double coordToVel(struct wcsprm *wcs, const double coord, std::string outputUnits); |
---|
| 106 | double velToCoord(struct wcsprm *wcs, const float velocity, std::string outputUnits); |
---|
[3] | 107 | |
---|
[56] | 108 | // FILTER SMOOTHING ROUTINES |
---|
| 109 | void waveletSmooth(int dim,float *array, int arraySize, float sigma); |
---|
| 110 | void hanningSmooth(float *array, int arraySize, int hanningSize); |
---|
| 111 | void tophatSmooth(float *array, int arraySize, int width); |
---|
[3] | 112 | |
---|
| 113 | #endif |
---|