hotspots_cxx_module.cc

00001 /*
00002  *  This file is part of Healpix_cxx.
00003  *
00004  *  Healpix_cxx is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  Healpix_cxx is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with Healpix_cxx; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017  *
00018  *  For more information about HEALPix, see http://healpix.sourceforge.net
00019  */
00020 
00021 /*
00022  *  Healpix_cxx is being developed at the Max-Planck-Institut fuer Astrophysik
00023  *  and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt
00024  *  (DLR).
00025  */
00026 
00027 /*
00028  *  Copyright (C) 2003-2010 Max-Planck-Society
00029  *  Author: Martin Reinecke
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 // FIXME: This should be parallelized
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   }

Generated on Thu Oct 8 14:48:52 2015 for Healpix C++