source: Sophya/trunk/SophyaProg/PrgMap/cremskfrsph.cc@ 2981

Last change on this file since 2981 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.3 KB
RevLine 
[1522]1// Creation d'une sphere de masque a partir d'une sphere de valeurs
2// cmv 13/6/01
[1528]3// cremskfrsph -m 0.1 -v 1.,0. sph143k05_e.fits sphmskw.fits
4// cremskfrsph -n -m -1.e-30. -M 1.e-30. -v 1.,0. sph143k05.fits sphmsk.fits
[2615]5#include "sopnamsp.h"
[1522]6#include "machdefs.h"
7#include <unistd.h>
8#include <stdexcept>
[2322]9#include <iostream>
[1522]10#include <stdio.h>
11#include <stdlib.h>
12#include "skymapinit.h"
13#include "skymap.h"
14#include "fitsspherehealpix.h"
15
[1626]16/*!
17 \ingroup PrgMap
18 \file cremskfrsph.cc
19 \brief \b cremskfrsph: Create a masked sphere from a sphere of datas
20 \verbatim
21csh> cremskfrsph -h
22cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits
23 -m min : min value
24 -M max : max value
25 condition for filling masque is: min<=sphere_value<=max
26 (fill mask with valmsk) (bounds are included)
27 -n : negate the condition
28 (switch to: sphere_value<min || max<sphere_value)
[1632]29 -b bmin,bmax : on coupe en latitude entre [bmin,bmax] degres (def=no+cut)
[1626]30 -v valmsk,inimsk:
31 valmsk: value to be put into mask if ok (def=1.)
32 inimsk: initialisation value for the mask (def=0.)
33 \endverbatim
34*/
35
[1522]36void usage();
37void usage()
38{
39cout<<"cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits"<<endl
40 <<" -m min : min value"<<endl
41 <<" -M max : max value"<<endl
[1626]42 <<" condition for filling masque is: min<=sphere_value<=max"<<endl
43 <<" (fill mask with valmsk) (bounds are included)"<<endl
[1522]44 <<" -n : negate the condition"<<endl
[1626]45 <<" (switch to: sphere_value<min || max<sphere_value)"<<endl
[1632]46 <<" -b bmin,bmax : on coupe en latitude entre [bmin,bmax] degres (def=no+cut)"<<endl
[1522]47 <<" -v valmsk,inimsk:"<<endl
48 <<" valmsk: value to be put into mask if ok (def=1.)"<<endl
49 <<" inimsk: initialisation value for the mask (def=0.)"<<endl;
50}
51
52
53int main(int narg, char* arg[])
54{
[1632]55double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0., bmin=1.,bmax=-1.;
[1522]56bool tstmin=false,tstmax=false,negate=false;
[1626]57string dum;
[1522]58int c;
[1632]59while((c = getopt(narg,arg,"hnm:M:v:b:")) != -1) {
[1522]60 switch (c) {
61 case 'n' :
62 negate = true;
63 break;
64 case 'm' :
65 sscanf(optarg,"%lf",&vmin);
66 tstmin = true;
67 break;
68 case 'M' :
69 sscanf(optarg,"%lf",&vmax);
70 tstmax = true;
71 break;
72 case 'v' :
73 sscanf(optarg,"%lf,%lf",&vmask,&vmaskini);
74 break;
[1632]75 case 'b' :
76 sscanf(optarg,"%lf,%lf",&bmin,&bmax);
77 break;
[1522]78 case 'h' :
79 default:
80 usage(); exit(1);
81 }
82}
83
84if(optind+1>=narg) {usage(); exit(1);}
85char * sphval = arg[optind];
86char * sphmsk = arg[optind+1];
87
[1626]88if(negate) dum = ".NOT."; else dum = "";
[1522]89cout<<"Sphere values : "<<sphval<<endl
90 <<"Sphere mask : "<<sphmsk<<endl
[1626]91 <<" ...min("<<tstmin<<") "<<vmin<<endl
92 <<" max("<<tstmax<<") "<<vmax<<endl
[1522]93 <<" ...negate "<<negate<<endl
94 <<" ...mask set value "<<vmask<<endl
[1626]95 <<" mask init value "<<vmaskini<<endl
[1632]96 <<"Cut latitude between "<<bmin<<" and "<<bmax<<" deg"<<endl
[1626]97 <<"Condition on data to set the mask: "
98 <<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
[1522]99
100// Lecture de la sphere Healpix des valeurs
[1626]101SphereHEALPix<r_8> sph;
[1522]102FitsInFile sfits(sphval);
103sfits >> sph;
104cout<<"Opening Sphere HEALPix for testing values :"<<endl
105 <<" Type of map : "<<sph.TypeOfMap()<<endl
106 <<" Number of pixels : "<<sph.NbPixels()<<endl
107 <<" Nlat : "<<sph.SizeIndex()<<endl;
108
109// Ouverture de la sphere Healpix pour le masque
110cout<<"Creating Mask Sphere"<<endl;
111SphereHEALPix<r_8> sphm(sph,false);
112
[1632]113// Filling Mask Sphere with cut on values
[1522]114cout<<"Filling Mask"<<endl;
[1632]115double thetamin = (90.-bmax) * M_PI/180.;
116double thetamax = (90.-bmin) * M_PI/180.;
[1522]117uint_4 nmask = 0;
118for(int_4 i=0;i<sph.NbPixels();i++) {
119 sphm(i) = vmaskini;
[1626]120
121 bool skp = (tstmin || tstmax) ? negate : false;
122 if((tstmin && sph(i)<vmin) || (tstmax && sph(i)>vmax)) skp = !negate;
123 if(skp) continue; // Do nothing
124
[1632]125 if(bmin<bmax) {
126 double theta,phi;
127 sphm.PixThetaPhi(i,theta,phi);
128 if(theta>=thetamin && theta<=thetamax) continue;
129 }
130
[1522]131 sphm(i) = vmask;
132 nmask++;
133}
134cout<<" .... Number of values set in mask : "<<nmask<<endl;
135cout<<" .... Fraction of values set in mask : "
136 <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
137
138// Ecriture de la sphere Healpix sur fits
139{
[1626]140dum = "rm -f "; dum += sphmsk; system(dum.c_str());
[1632]141FitsOutFile swfits(sphmsk,FitsFile::clear);
[1522]142cout<<"Writing Mask Sphere Fits file"<<endl;
143swfits<<sphm;
144}
145
[1632]146return 0;
[1522]147}
Note: See TracBrowser for help on using the repository browser.