source: Sophya/trunk/SophyaProg/PrgMap/msksphere.cc@ 2322

Last change on this file since 2322 was 2322, checked in by cmv, 23 years ago
  • passage xxstream.h en xxstream
  • compile avec gcc_3.2, gcc_2.96 et cxx En 3.2 le seek from ::end semble marcher (voir Eval/COS/pbseekios.cc)

rz+cmv 11/2/2003

File size: 4.5 KB
Line 
1// Creation d'une sphere de masquee a partir d'une sphere de masques
2// cmv 15/6/01
3#include "machdefs.h"
4#include <unistd.h>
5#include <stdexcept>
6#include <iostream>
7#include <stdio.h>
8#include <stdlib.h>
9#include "skymapinit.h"
10#include "skymap.h"
11#include "fitsspherehealpix.h"
12
13/*!
14 \ingroup PrgMap
15 \file msksphere.cc
16 \brief \b msksphere: mask a sphere of datas with a mask sphere.
17 \verbatim
18csh> msksphere -h
19msksphere [-m min -M max -v valmsk] sphval.fits sphmask.fits sphout.fits
20 sphval.fits : inpout sphere of datas where the pixels have to be masked
21 sphmask.fits : inpout masked sphere used to mask pixels
22 sphout.fits : output masked sphere of datas
23 -m min : min mask_sphere_value for MASKING the sphere pixel
24 -M max : max mask_sphere_value for MASKING the sphere pixel
25 condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)
26 -n : negate the previous condition, condition for MASKING sphere pixel
27 becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)
28 Default (no -m and -M): mask pixel if mask_sphere_value<0.
29 -v valmsk : set sphere value for masked pixels (def=0.)
30 \endverbatim
31*/
32
33void usage();
34void usage()
35{
36cout<<"msksphere [-m min -M max -v valmsk]"
37 <<" sphval.fits sphmask.fits sphout.fits"<<endl
38 <<" sphval.fits : inpout sphere of datas where the pixels have to be masked"<<endl
39 <<" sphmask.fits : inpout masked sphere used to mask pixels"<<endl
40 <<" sphout.fits : output masked sphere of datas"<<endl
41 <<" -m min : min mask_sphere_value for MASKING the sphere pixel"<<endl
42 <<" -M max : max mask_sphere_value for MASKING the sphere pixel"<<endl
43 <<" condition for MASKING sphere pixel is (min<=mask_sphere_value<=max)"<<endl
44 <<" -n : negate the previous condition, condition for MASKING sphere pixel"<<endl
45 <<" becomes: (mask_sphere_value<minval || maxval<mask_sphere_value)"<<endl
46 <<" Default (no -m and -M): mask pixel if mask_sphere_value<0."<<endl
47 <<" -v valmsk : set sphere value for masked pixels (def=0.)"<<endl;
48}
49
50int main(int narg, char* arg[])
51{
52double vmask=0.,vmin=-1.e30,vmax=1.e30;
53bool tstmin=false,tstmax=false,negate=false;
54string dum;
55int c;
56while((c = getopt(narg,arg,"hnm:M:v:")) != -1) {
57 switch (c) {
58 case 'n' :
59 negate = true;
60 break;
61 case 'm' :
62 sscanf(optarg,"%lf",&vmin);
63 tstmin = true;
64 break;
65 case 'M' :
66 sscanf(optarg,"%lf",&vmax);
67 tstmax = true;
68 break;
69 case 'v' :
70 sscanf(optarg,"%lf",&vmask);
71 break;
72 case 'h' :
73 default:
74 usage(); exit(1);
75 }
76}
77
78if(optind+2>=narg) {usage(); exit(1);}
79char * sphval = arg[optind];
80char * sphmsk = arg[optind+1];
81char * sphout = arg[optind+2];
82
83if(!tstmin && !tstmax) {tstmin=true; vmin=0.; negate=true;}
84
85if(negate) dum = ".NOT."; else dum="";
86cout<<"Sphere values : "<<sphval<<endl
87 <<"Sphere mask : "<<sphmsk<<endl
88 <<"Sphere out : "<<sphout<<endl
89 <<" ...min("<<tstmin<<") "<<vmin<<endl
90 <<" max("<<tstmax<<") "<<vmax<<endl
91 <<" ...mask set value "<<vmask<<endl
92 <<" Condition for masking pixel is :"<<endl
93 <<" "<<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
94
95// Lecture de la sphere Healpix des valeurs
96SphereHEALPix<r_8> sph;
97{FitsInFile sfits(sphval); sfits >> sph;}
98cout<<"Opening Sphere HEALPix for testing values :"<<endl
99 <<" Type of map : "<<sph.TypeOfMap()<<endl
100 <<" Number of pixels : "<<sph.NbPixels()<<endl
101 <<" Nlat : "<<sph.SizeIndex()<<endl;
102
103// Lecture de la sphere Healpix des masques
104SphereHEALPix<r_8> msph;
105{FitsInFile sfits(sphmsk); sfits >> msph;}
106cout<<"Opening Sphere HEALPix for mask :"<<endl
107 <<" Type of map : "<<msph.TypeOfMap()<<endl
108 <<" Number of pixels : "<<msph.NbPixels()<<endl
109 <<" Nlat : "<<msph.SizeIndex()<<endl;
110if(msph.SizeIndex()!=sph.SizeIndex()) {
111 cout<<"Sphere of values and sphere of mask must have same NLat"<<endl;
112 exit(1);
113}
114
115// Filling Mask Sphere
116cout<<"Testing For Masked Pixels"<<endl;
117uint_4 nmask = 0;
118for(int_4 i=0;i<sph.NbPixels();i++) {
119
120 bool skp = (tstmin || tstmax) ? negate : false;
121 if((tstmin && msph(i)<vmin) || (tstmax && msph(i)>vmax)) skp = !negate;
122 if(skp) continue; // Do nothing
123
124 sph(i) = vmask;
125 nmask++;
126}
127cout<<" .... Number of values masked : "<<nmask<<endl;
128cout<<" .... Fraction of values masked : "
129 <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
130
131// Ecriture de la sphere Healpix sur fits
132{
133dum = "rm -f "; dum += sphout; system(dum.c_str());
134FitsOutFile sfits(sphout, FitsFile::clear);
135cout<<"Writing Output Masked Sphere Fits file"<<endl;
136sfits<<sph;
137}
138
139exit(0);
140}
Note: See TracBrowser for help on using the repository browser.