Healpix C++  3.83
hotspots_cxx_module.cc
1 /*
2  * This file is part of Healpix_cxx.
3  *
4  * Healpix_cxx is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Healpix_cxx is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Healpix_cxx; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 /*
22  * Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
23  * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
24  * (DLR).
25  */
26 
27 /*
28  * Copyright (C) 2003-2010 Max-Planck-Society
29  * Author: Martin Reinecke
30  */
31 
32 #include <fstream>
33 #include "paramfile.h"
34 #include "healpix_map.h"
35 #include "healpix_map_fitsio.h"
36 #include "fitshandle.h"
37 #include "levels_facilities.h"
38 #include "announce.h"
39 
40 using namespace std;
41 
42 int hotspots_cxx_module (int argc, const char **argv)
43  {
44  module_startup ("hotspots_cxx", argc, argv);
45  paramfile params (getParamsFromCmdline(argc,argv));
46 
47  string infile = params.find<string>("infile");
48  string mapfile = params.find<string>("outmap","");
49  bool have_mapfile = mapfile!="";
50  string minfile = params.find<string>("minfile","");
51  bool have_minfile = minfile!="";
52  string maxfile = params.find<string>("maxfile","");
53  bool have_maxfile = maxfile!="";
54  planck_assert (have_mapfile || have_minfile || have_maxfile,
55  "no output file specified");
56 
57  Healpix_Map<float> inmap;
58  read_Healpix_map_from_fits(infile,inmap,1,2);
59  Healpix_Map<float> outmap;
60  if (have_mapfile) outmap.Set(inmap.Order(),inmap.Scheme());
61 
62  ofstream minout, maxout;
63  if (have_minfile) minout.open(minfile.c_str());
64  if (have_maxfile) maxout.open(maxfile.c_str());
65 
66  fix_arr<int,8> nb;
67 // FIXME: This should be parallelized
68  for (int m=0; m<inmap.Npix(); ++m)
69  {
70  float value = inmap[m];
71  if (!approx<double>(value, Healpix_undef))
72  {
73  inmap.neighbors(m,nb);
74  bool ismax=true, ismin=true;
75  for (tsize n=0; n<nb.size(); ++n)
76  {
77  if (nb[n] >=0)
78  {
79  float nbval = inmap[nb[n]];
80  if (!approx<double>(nbval, Healpix_undef))
81  {
82  if (nbval>=value) ismax=false;
83  if (nbval<=value) ismin=false;
84  }
85  }
86  }
87  if (have_mapfile)
88  outmap[m] = float((ismax||ismin) ? value : Healpix_undef);
89  if (have_minfile && ismin) minout << m << " " << value << endl;
90  if (have_maxfile && ismax) maxout << m << " " << value << endl;
91  }
92  }
93  if (have_mapfile)
94  write_Healpix_map_to_fits (mapfile,outmap,PLANCK_FLOAT32);
95 
96  return 0;
97  }
void Set(arr< T > &data, Healpix_Ordering_Scheme scheme)
Definition: healpix_map.h:68
void read_Healpix_map_from_fits(fitshandle &inp, Healpix_Map< T > &map, int colnum)
Healpix_Ordering_Scheme Scheme() const
Definition: healpix_base.h:431
void write_Healpix_map_to_fits(fitshandle &out, const Healpix_Map< T > &map, PDT datatype)
const double Healpix_undef
Healpix value representing "undefined".
Definition: healpix_map.h:39
void neighbors(I pix, fix_arr< I, 8 > &result) const
int Order() const
Definition: healpix_base.h:425
I Npix() const
Definition: healpix_base.h:429

Generated on Wed Nov 13 2024 12:18:30 for Healpix C++