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

Last change on this file since 1262 was 1259, checked in by MatthewWhiting, 11 years ago

Ticket #107 - Implementing the median baseline algorithm, with a few tweaks to make it work. The interface is now similar to the atrous baseline algorithm (which has been renamed).

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