hotspots_cxx_module.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <fstream>
00033 #include "paramfile.h"
00034 #include "healpix_map.h"
00035 #include "healpix_map_fitsio.h"
00036 #include "fitshandle.h"
00037 #include "levels_facilities.h"
00038 #include "announce.h"
00039
00040 using namespace std;
00041
00042 int hotspots_cxx_module (int argc, const char **argv)
00043 {
00044 module_startup ("hotspots_cxx", argc, argv);
00045 paramfile params (getParamsFromCmdline(argc,argv));
00046
00047 string infile = params.find<string>("infile");
00048 string mapfile = params.find<string>("outmap","");
00049 bool have_mapfile = mapfile!="";
00050 string minfile = params.find<string>("minfile","");
00051 bool have_minfile = minfile!="";
00052 string maxfile = params.find<string>("maxfile","");
00053 bool have_maxfile = maxfile!="";
00054 planck_assert (have_mapfile || have_minfile || have_maxfile,
00055 "no output file specified");
00056
00057 Healpix_Map<float> inmap;
00058 read_Healpix_map_from_fits(infile,inmap,1,2);
00059 Healpix_Map<float> outmap;
00060 if (have_mapfile) outmap.Set(inmap.Order(),inmap.Scheme());
00061
00062 ofstream minout, maxout;
00063 if (have_minfile) minout.open(minfile.c_str());
00064 if (have_maxfile) maxout.open(maxfile.c_str());
00065
00066 fix_arr<int,8> nb;
00067
00068 for (int m=0; m<inmap.Npix(); ++m)
00069 {
00070 float value = inmap[m];
00071 if (!approx<double>(value, Healpix_undef))
00072 {
00073 inmap.neighbors(m,nb);
00074 bool ismax=true, ismin=true;
00075 for (tsize n=0; n<nb.size(); ++n)
00076 {
00077 if (nb[n] >=0)
00078 {
00079 float nbval = inmap[nb[n]];
00080 if (!approx<double>(nbval, Healpix_undef))
00081 {
00082 if (nbval>=value) ismax=false;
00083 if (nbval<=value) ismin=false;
00084 }
00085 }
00086 }
00087 if (have_mapfile)
00088 outmap[m] = float((ismax||ismin) ? value : Healpix_undef);
00089 if (have_minfile && ismin) minout << m << " " << value << endl;
00090 if (have_maxfile && ismax) maxout << m << " " << value << endl;
00091 }
00092 }
00093 if (have_mapfile)
00094 write_Healpix_map_to_fits (mapfile,outmap,PLANCK_FLOAT32);
00095
00096 return 0;
00097 }