[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> |
---|
| 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); |
---|
[517] | 42 | template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2); |
---|
| 43 | template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2, Type 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 | |
---|
[56] | 72 | // POSITION-RELATED ROUTINES |
---|
[222] | 73 | std::string getIAUNameEQ(double ra, double dec, float equinox); |
---|
| 74 | std::string getIAUNameGAL(double ra, double dec); |
---|
| 75 | std::string decToDMS(double dec, std::string type); |
---|
| 76 | double dmsToDec(std::string dms); |
---|
[3] | 77 | double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2); |
---|
| 78 | |
---|
[56] | 79 | // WCS-RELATED ROUTINES |
---|
[204] | 80 | int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix); |
---|
| 81 | int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world); |
---|
| 82 | int wcsToPixMulti(struct wcsprm *wcs, const double *world, |
---|
[146] | 83 | double *pix, const int npts); |
---|
[204] | 84 | int pixToWCSMulti(struct wcsprm *wcs, const double *pix, |
---|
[146] | 85 | double *world, const int npts); |
---|
[204] | 86 | double pixelToVelocity(struct wcsprm *wcs, double &x, double &y, |
---|
[222] | 87 | double &z, std::string velUnits); |
---|
| 88 | double coordToVel(struct wcsprm *wcs, const double coord, std::string outputUnits); |
---|
| 89 | double velToCoord(struct wcsprm *wcs, const float velocity, std::string outputUnits); |
---|
[3] | 90 | |
---|
[56] | 91 | // FILTER SMOOTHING ROUTINES |
---|
| 92 | void waveletSmooth(int dim,float *array, int arraySize, float sigma); |
---|
| 93 | void hanningSmooth(float *array, int arraySize, int hanningSize); |
---|
| 94 | void tophatSmooth(float *array, int arraySize, int width); |
---|
[3] | 95 | |
---|
| 96 | #endif |
---|