[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 | |
---|
[394] | 31 | #include <wcslib/wcs.h> |
---|
[3] | 32 | #include <string> |
---|
[1240] | 33 | #include <vector> |
---|
[3] | 34 | |
---|
[274] | 35 | struct wcsprm; // just foreshadow this. |
---|
| 36 | |
---|
[3] | 37 | // define the speed of light for WCS-related accessor functions |
---|
| 38 | const float C_kms = 299792.458; |
---|
| 39 | |
---|
[146] | 40 | int linear_regression(int num, float *x, float *y, int ilow, int ihigh, |
---|
| 41 | float &slope, float &errSlope, |
---|
| 42 | float &intercept, float &errIntercept, float &r); |
---|
[517] | 43 | template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2); |
---|
| 44 | template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2, Type nullVal); |
---|
[190] | 45 | template <class T> void sort(T *arr, int begin, int end); |
---|
| 46 | template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray, |
---|
| 47 | int begin, int end); |
---|
[56] | 48 | |
---|
| 49 | // STATISTICS-RELATED ROUTINES |
---|
[205] | 50 | template <class T> T absval(T value); |
---|
[847] | 51 | template <class T> void findMinMax(const T *array, const size_t size, |
---|
[190] | 52 | T &min, T &max); |
---|
[847] | 53 | template <class T> float findMean(T *array, size_t size); |
---|
[1393] | 54 | template <class T> float findMean(T *array, std::vector<bool> mask, size_t size); |
---|
[849] | 55 | template <class T> float findMeanDiff(T *first, T *second, size_t size); |
---|
[1393] | 56 | template <class T> float findMeanDiff(T *first, T *second, std::vector<bool> mask, size_t size); |
---|
[847] | 57 | template <class T> float findStddev(T *array, size_t size); |
---|
[1393] | 58 | template <class T> float findStddev(T *array, std::vector<bool> mask, size_t size); |
---|
[849] | 59 | template <class T> float findStddevDiff(T *first, T *second, size_t size); |
---|
[1393] | 60 | template <class T> float findStddevDiff(T *first, T *second, std::vector<bool> mask, size_t size); |
---|
[847] | 61 | template <class T> T findMedian(T *array, size_t size, bool changeArray=false); |
---|
[1393] | 62 | template <class T> T findMedian(T *array, std::vector<bool> mask, size_t size); |
---|
[849] | 63 | template <class T> T findMedianDiff(T *first, T *second, size_t size); |
---|
[1393] | 64 | template <class T> T findMedianDiff(T *first, T *second, std::vector<bool> mask, size_t size); |
---|
[847] | 65 | template <class T> T findMADFM(T *array, size_t size, bool changeArray=false); |
---|
[1393] | 66 | template <class T> T findMADFM(T *array, std::vector<bool> mask, size_t size); |
---|
[847] | 67 | template <class T> T findMADFM(T *array, size_t size, T median, bool changeArray=false); |
---|
[1393] | 68 | template <class T> T findMADFM(T *array, std::vector<bool> mask, size_t size, T median); |
---|
[849] | 69 | template <class T> T findMADFMDiff(T *first, T *second, size_t size); |
---|
[1393] | 70 | template <class T> T findMADFMDiff(T *first, T *second, std::vector<bool> mask, size_t size); |
---|
[849] | 71 | template <class T> T findMADFMDiff(T *first, T *second, size_t size, T median); |
---|
[1393] | 72 | template <class T> T findMADFMDiff(T *first, T *second, std::vector<bool> mask, size_t size, T median); |
---|
[847] | 73 | template <class T> void findMedianStats(T *array, size_t size, |
---|
[190] | 74 | T &median, T &madfm); |
---|
[1393] | 75 | template <class T> void findMedianStats(T *array, size_t size, std::vector<bool> isGood, |
---|
[190] | 76 | T &median, T &madfm); |
---|
[847] | 77 | template <class T> void findNormalStats(T *array, size_t size, |
---|
[190] | 78 | float &mean, float &stddev); |
---|
[1393] | 79 | template <class T> void findNormalStats(T *array, size_t size, std::vector<bool> isGood, |
---|
[275] | 80 | float &mean, float &stddev); |
---|
[847] | 81 | template <class T> void findAllStats(T *array, size_t size, |
---|
[275] | 82 | float &mean, float &stddev, |
---|
| 83 | T &median, T &madfm); |
---|
[1393] | 84 | template <class T> void findAllStats(T *array, size_t size, std::vector<bool> mask, |
---|
[275] | 85 | float &mean, float &stddev, |
---|
| 86 | T &median, T &madfm); |
---|
[847] | 87 | template <class T> void findMedianStatsDiff(T *first, T *second, size_t size, T &median, T &madfm); |
---|
[1393] | 88 | template <class T> void findMedianStatsDiff(T *first, T *second, size_t size, std::vector<bool> isGood, T &median, T &madfm); |
---|
[847] | 89 | template <class T> void findNormalStatsDiff(T *first, T *second, size_t size, float &mean, float &stddev); |
---|
[1393] | 90 | template <class T> void findNormalStatsDiff(T *first, T *second, size_t size, std::vector<bool> isGood, float &mean, float &stddev); |
---|
[190] | 91 | |
---|
[3] | 92 | |
---|
[56] | 93 | // POSITION-RELATED ROUTINES |
---|
[222] | 94 | std::string getIAUNameEQ(double ra, double dec, float equinox); |
---|
| 95 | std::string getIAUNameGAL(double ra, double dec); |
---|
[907] | 96 | std::string decToDMS(double dec, std::string type, int decPrecision=2); |
---|
[222] | 97 | double dmsToDec(std::string dms); |
---|
[3] | 98 | double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2); |
---|
| 99 | |
---|
[56] | 100 | // WCS-RELATED ROUTINES |
---|
[204] | 101 | int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix); |
---|
| 102 | int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world); |
---|
| 103 | int wcsToPixMulti(struct wcsprm *wcs, const double *world, |
---|
[146] | 104 | double *pix, const int npts); |
---|
[204] | 105 | int pixToWCSMulti(struct wcsprm *wcs, const double *pix, |
---|
[146] | 106 | double *world, const int npts); |
---|
[204] | 107 | double pixelToVelocity(struct wcsprm *wcs, double &x, double &y, |
---|
[222] | 108 | double &z, std::string velUnits); |
---|
| 109 | double coordToVel(struct wcsprm *wcs, const double coord, std::string outputUnits); |
---|
| 110 | double velToCoord(struct wcsprm *wcs, const float velocity, std::string outputUnits); |
---|
[3] | 111 | |
---|
[56] | 112 | // FILTER SMOOTHING ROUTINES |
---|
| 113 | void waveletSmooth(int dim,float *array, int arraySize, float sigma); |
---|
| 114 | void hanningSmooth(float *array, int arraySize, int hanningSize); |
---|
| 115 | void tophatSmooth(float *array, int arraySize, int width); |
---|
[3] | 116 | |
---|
[1259] | 117 | void findMedianBaseline(int dim, float *inputArray, unsigned int boxWidth, float *baselineValues); |
---|
[621] | 118 | |
---|
[733] | 119 | // STRING AND INPUT PARAMETER MANIPULATION ROUTINES |
---|
| 120 | std::string makelower( std::string s ); |
---|
| 121 | std::string stringize(bool b); |
---|
| 122 | bool boolify(std::string s); |
---|
| 123 | std::string readSval(std::stringstream& ss); |
---|
| 124 | std::string readFilename(std::stringstream& ss); |
---|
| 125 | bool readFlag(std::stringstream& ss); |
---|
| 126 | float readFval(std::stringstream& ss); |
---|
| 127 | int readIval(std::stringstream& ss); |
---|
| 128 | std::string removeLeadingBlanks(std::string s); |
---|
| 129 | std::string deblank(std::string s); |
---|
[1146] | 130 | std::string readStringFromBinaryFile(std::ifstream &infile); |
---|
| 131 | void writeStringToBinaryFile(std::ofstream &outfile, std::string str); |
---|
[1240] | 132 | std::vector<int> selectionToIntVec(std::string &str); |
---|
[621] | 133 | |
---|
[1250] | 134 | // PLOTTING UTILITY FUNCTIONS |
---|
| 135 | void wcsAxes(struct wcsprm *wcs, size_t *axes, int textColour, int axisColour); |
---|
| 136 | |
---|
[1347] | 137 | // Random number generators -- all in get_random_spectrum.cc |
---|
| 138 | void getRandomSpectrum(int length, float *x, float *y); |
---|
| 139 | void getRandomSpectrum(int length, float *x, double *y); |
---|
| 140 | void getRandomSpectrum(int length, float mean, float sigma, |
---|
| 141 | float *x, double *y); |
---|
| 142 | void getRandomSpectrum(int length, float mean, float sigma, |
---|
| 143 | float *x, float *y); |
---|
| 144 | float getNormalRV(); |
---|
| 145 | float getNormalRVtrunc(); |
---|
| 146 | float getNormalRV(float mean, float sigma); |
---|
[1250] | 147 | |
---|
[3] | 148 | #endif |
---|