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

Last change on this file since 3721 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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