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

Last change on this file since 848 was 847, checked in by MatthewWhiting, 13 years ago

New stats functions to find the stats of difference arrays, and to better find statistics in masked arrays. Also moving to size_t etc for the sizes.

File size: 5.6 KB
Line 
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// -----------------------------------------------------------------------
28#ifndef UTILS_H
29#define UTILS_H
30
31#include <wcslib/wcs.h>
32#include <string>
33
34struct wcsprm; // just foreshadow this.
35
36// define the speed of light for WCS-related accessor functions
37const float C_kms = 299792.458;
38
39int linear_regression(int num, float *x, float *y, int ilow, int ihigh,
40                      float &slope, float &errSlope,
41                      float &intercept, float &errIntercept, float &r);
42template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2);
43template <class Type> void zscale(long imagesize, Type *image, Type &z1, Type &z2, Type nullVal);
44template <class T> void sort(T *arr, int begin, int end);
45template <class T1, class T2> void sort(T1 *arr, T2 *matchingArray,
46                                        int begin, int end);
47
48// STATISTICS-RELATED ROUTINES
49template <class T> T absval(T value);
50template <class T> void findMinMax(const T *array, const size_t size,
51                                   T &min, T &max);
52template <class T> float findMean(T *array, size_t size);
53template <class T> float findMean(T *array, bool *mask, size_t size);
54template <class T> float findStddev(T *array, size_t size);
55template <class T> float findStddev(T *array, bool *mask, size_t size);
56template <class T> T findMedian(T *array, size_t size, bool changeArray=false);
57template <class T> T findMedian(T *array, bool *mask, size_t size);
58template <class T> T findMADFM(T *array, size_t size, bool changeArray=false);
59template <class T> T findMADFM(T *array, bool *mask, size_t size);
60template <class T> T findMADFM(T *array, size_t size, T median, bool changeArray=false);
61template <class T> T findMADFM(T *array, bool *mask, size_t size, T median);
62template <class T> void findMedianStats(T *array, size_t size,
63                                        T &median, T &madfm);
64template <class T> void findMedianStats(T *array, size_t size, bool *isGood,
65                                        T &median, T &madfm);
66template <class T> void findNormalStats(T *array, size_t size,
67                                        float &mean, float &stddev);
68template <class T> void findNormalStats(T *array, size_t size, bool *isGood,
69                                        float &mean, float &stddev);
70template <class T> void findAllStats(T *array, size_t size,
71                                     float &mean, float &stddev,
72                                     T &median, T &madfm);
73template <class T> void findAllStats(T *array, size_t size, bool *mask,
74                                     float &mean, float &stddev,
75                                     T &median, T &madfm);
76template <class T> void findMedianStatsDiff(T *first, T *second, size_t size, T &median, T &madfm);
77template <class T> void findMedianStatsDiff(T *first, T *second, size_t size, bool *isGood, T &median, T &madfm);
78template <class T> void findNormalStatsDiff(T *first, T *second, size_t size, float &mean, float &stddev);
79template <class T> void findNormalStatsDiff(T *first, T *second, size_t size, bool *isGood, float &mean, float &stddev);
80
81
82// POSITION-RELATED ROUTINES
83std::string getIAUNameEQ(double ra, double dec, float equinox);
84std::string getIAUNameGAL(double ra, double dec);
85std::string decToDMS(double dec, std::string type);
86double dmsToDec(std::string dms);
87double angularSeparation(double &ra1, double &dec1, double &ra2, double &dec2);
88
89// WCS-RELATED ROUTINES
90int wcsToPixSingle(struct wcsprm *wcs, const double *world, double *pix);
91int pixToWCSSingle(struct wcsprm *wcs, const double *pix, double *world);
92int wcsToPixMulti(struct wcsprm *wcs, const double *world,
93                  double *pix, const int npts);
94int pixToWCSMulti(struct wcsprm *wcs, const double *pix,
95                  double *world, const int npts);
96double pixelToVelocity(struct wcsprm *wcs, double &x, double &y,
97                       double &z, std::string velUnits);
98double coordToVel(struct wcsprm *wcs, const double coord, std::string outputUnits);
99double velToCoord(struct wcsprm *wcs, const float velocity, std::string outputUnits);
100
101// FILTER SMOOTHING ROUTINES
102void waveletSmooth(int dim,float *array, int arraySize, float sigma);
103void hanningSmooth(float *array, int arraySize, int hanningSize);
104void tophatSmooth(float *array, int arraySize, int width);
105
106float *medianBaseline(float *inputArray, int dim, unsigned int boxWidth);
107
108// STRING AND INPUT PARAMETER MANIPULATION ROUTINES
109std::string makelower( std::string s );
110std::string stringize(bool b);
111bool boolify(std::string s);
112std::string readSval(std::stringstream& ss);
113std::string readFilename(std::stringstream& ss);
114bool readFlag(std::stringstream& ss);
115float readFval(std::stringstream& ss);
116int readIval(std::stringstream& ss);
117std::string removeLeadingBlanks(std::string s);
118std::string deblank(std::string s);
119
120#endif
Note: See TracBrowser for help on using the repository browser.