maptools.h 4.38 KB
Newer Older
Maude Le Jeune's avatar
last  
Maude Le Jeune committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright (C) (2006-2007) Observatoire de Paris
//
// This file is part of TPCT (Tangent Plane C++ Tools) .
// TPCT is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA


Maude Le Jeune's avatar
Maude Le Jeune committed
19 20 21 22 23 24 25
#ifndef MAPTOOLS_H
#define MAPTOOLS_H

#include <healpix_map.h>
#include <string>

#include <cxxutils.h>
Maude Le Jeune's avatar
Maude Le Jeune committed
26
//#include <tga_image.h>
Maude Le Jeune's avatar
Maude Le Jeune committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include <complex>
#include <fftw3.h>

using namespace std;

template<class T> void errorMap(const Healpix_Map<T> & testmap, const Healpix_Map<T> & refmap, Healpix_Map<T> & errmap);

template<class T> void errorMap(const Healpix_Map<T> & testmap, const Healpix_Map<T> & refmap, Healpix_Map<T> & errmap){
  planck_assert(testmap.conformable(refmap),"Non conformant maps");
  errmap = Healpix_Map<T>(testmap.Nside(), testmap.Scheme(),SET_NSIDE);
  for(int i = 0; i< testmap.Npix(); i++){
    errmap[i] = (testmap[i]-refmap[i])/refmap[i];
  }
}

void fastMedian(Healpix_Map<double> & hrmap, Healpix_Map<double> & lrmap, int nside);

/**
 * Read the first hdu containing an image
 */
int readImageFits(string filename, arr2<double> & img);

/**
 * Compute the difference of im1 with im2
 */
void diffImage(arr2<double> & im1, arr2<double> & im2, arr2<double> & res);

/**
 * Compute the rms and mean of an array where its value are defined
 */
double simplesigma(arr2<double> & im, double & mean);
 
/**
 * Iteratively compute the rms of an array
 * In case of non convergence, the number of iteration
 * is limited to 20
 */
double clipsigma(arr2<double> im, double nsigma, double err, double & mean);

/**
 * add a gaussian beam of amplitude a centered in x, y.
 * fwhm, x and y are specified in pixels.
 */
void addGaussianBeam(arr2<double> & im, double fwhm, double x, double y, double a);


/**
 * Return the maximum of the map and store the last coordinates
 * where it is reached.
 */
double maxArgmax(arr2<double> & im, int & x, int & y);

/**
 * Return the minimun of the map and store the last coordinates
 * where it is reached.
 */
double minArgmin(arr2<double> & im, int & x, int & y);

/**
 * put Healpix_undef in every pixel contains in a disc of radius
 * r (in pixel) centered at x, y
 */
void patchSource(arr2<double> & im, double radius, double x, double y);

/**
 * convert an image array into a TGA_image
 */
Maude Le Jeune's avatar
Maude Le Jeune committed
94
//void img2tga(arr2<double> & im, TGA_Image & tim);
Maude Le Jeune's avatar
Maude Le Jeune committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

/**
 * Iteratively detect the sources above nsigma
 * They are supposed to follox a gaussian pattern
 * Aiming to transform a matched filtered map into
 * a catalog. At each iteration the most brilliant
 * source is clipped with a radius linked to radiusonfwhm.
 */
double detectSources(arr2<double> im, vector<int> & xpos, vector<int> &ypos,
		   vector<double> & flux, double nsigma, double fwhm,
		   double radiusonfwhm = 2);
/**
 *
 */
void addGaussianPatternOnSky(Healpix_Map<double> & sky, pointing center,
			     double fwhm, double amplitude, double thres, bool oppos);

void selectDisc(arr2<double> & im, double xcenter, double ycenter, double radius, double value=Healpix_undef );


fftw_plan prepareRealFFT(int nx, int ny, double * in, complex<double> * out);

void cleanRealFFT(double * in, complex<double> * out, fftw_plan plan);
//void map2modes(arr2<double> & im, arr2<complex<double>> &modes, fftw_plan plan);

Maude Le Jeune's avatar
Maude Le Jeune committed
120
//void drawCircle(TGA_Image & img, int x, int y, double rad);
Maude Le Jeune's avatar
Maude Le Jeune committed
121 122 123 124 125 126 127 128 129 130 131 132

void healpixGaussianFit(Healpix_Map<double> & m,double fwhm, double * guess, double * err, double * chisqdof, double var, double nfwhm);

void healpixGaussianFit(Healpix_Map<double> & m, double fwhm, double * guess, double * err, double * chisqdof, Healpix_Map<double> var,double nfwhm);

double getnoisevariance (Healpix_Map<double> & m, double theta, double phi, double radius,double nradius);

int vectorPatch (Healpix_Map<double> &m, double radius, int pm);
int vectorMeanVar (vector<int> listpix, Healpix_Map<double> m, double &mean, double &var);

#endif