[1535] | 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.h>
|
---|
| 7 | #include <stdio.h>
|
---|
| 8 | #include <stdlib.h>
|
---|
| 9 | #include "skymapinit.h"
|
---|
| 10 | #include "skymap.h"
|
---|
| 11 | #include "fitsspherehealpix.h"
|
---|
| 12 |
|
---|
| 13 | void usage();
|
---|
| 14 | void usage()
|
---|
| 15 | {
|
---|
| 16 | cout<<"msksphere [-m min -M max -v valmsk]"<<endl
|
---|
| 17 | <<" sphval.fits sphmask.fits sphout.fits"<<endl
|
---|
| 18 | <<" -m min : min value"<<endl
|
---|
| 19 | <<" -M max : max value"<<endl
|
---|
| 20 | <<" condition for masking is :"<<endl
|
---|
| 21 | <<" mask_sphere_value <= min"<<endl
|
---|
| 22 | <<" OR"<<endl
|
---|
| 23 | <<" mask_sphere_value >= max"<<endl
|
---|
| 24 | <<" (bounds are included)"<<endl
|
---|
| 25 | <<" Default is mask_sphere_value <=0. (no -m and -M)"<<endl
|
---|
| 26 | <<" -v valmsk : set value for masked pixels (def=0.)"<<endl;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | int main(int narg, char* arg[])
|
---|
| 30 | {
|
---|
| 31 | double vmask=0.,vmin=-1.e30,vmax=1.e30;
|
---|
| 32 | bool tstmin=false,tstmax=false;
|
---|
| 33 | int c;
|
---|
| 34 | while((c = getopt(narg,arg,"hm:M:v:")) != -1) {
|
---|
| 35 | switch (c) {
|
---|
| 36 | case 'm' :
|
---|
| 37 | sscanf(optarg,"%lf",&vmin);
|
---|
| 38 | tstmin = true;
|
---|
| 39 | break;
|
---|
| 40 | case 'M' :
|
---|
| 41 | sscanf(optarg,"%lf",&vmax);
|
---|
| 42 | tstmax = true;
|
---|
| 43 | break;
|
---|
| 44 | case 'v' :
|
---|
| 45 | sscanf(optarg,"%lf",&vmask);
|
---|
| 46 | break;
|
---|
| 47 | case 'h' :
|
---|
| 48 | default:
|
---|
| 49 | usage(); exit(1);
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if(optind+2>=narg) {usage(); exit(1);}
|
---|
| 54 | char * sphval = arg[optind];
|
---|
| 55 | char * sphmsk = arg[optind+1];
|
---|
| 56 | char * sphout = arg[optind+2];
|
---|
| 57 |
|
---|
| 58 | cout<<"Sphere values : "<<sphval<<endl
|
---|
| 59 | <<"Sphere mask : "<<sphmsk<<endl
|
---|
| 60 | <<"Sphere out : "<<sphout<<endl
|
---|
| 61 | <<" ...min("<<tstmin<<") "<<vmin<<" max("<<tstmax<<") "<<vmax<<endl
|
---|
| 62 | <<" ...mask set value "<<vmask<<endl
|
---|
| 63 | <<"Condition for masking pixel is : "
|
---|
| 64 | <<"( Vmsk <= "<<vmin<<" OR Vmsk >= "<<vmax<<" ) bounds are included"<<endl;
|
---|
| 65 |
|
---|
| 66 | // Lecture de la sphere Healpix des valeurs
|
---|
| 67 | SphereHEALPix<r_8> sph;
|
---|
| 68 | {FitsInFile sfits(sphval); sfits >> sph;}
|
---|
| 69 | cout<<"Opening Sphere HEALPix for testing values :"<<endl
|
---|
| 70 | <<" Type of map : "<<sph.TypeOfMap()<<endl
|
---|
| 71 | <<" Number of pixels : "<<sph.NbPixels()<<endl
|
---|
| 72 | <<" Nlat : "<<sph.SizeIndex()<<endl;
|
---|
| 73 |
|
---|
| 74 | // Lecture de la sphere Healpix des masques
|
---|
| 75 | SphereHEALPix<r_8> msph;
|
---|
| 76 | {FitsInFile sfits(sphmsk); sfits >> msph;}
|
---|
| 77 | cout<<"Opening Sphere HEALPix for mask :"<<endl
|
---|
| 78 | <<" Type of map : "<<msph.TypeOfMap()<<endl
|
---|
| 79 | <<" Number of pixels : "<<msph.NbPixels()<<endl
|
---|
| 80 | <<" Nlat : "<<msph.SizeIndex()<<endl;
|
---|
| 81 | if(msph.SizeIndex()!=sph.SizeIndex()) {
|
---|
| 82 | cout<<"Sphere of values and sphere of mask must have same NLat"<<endl;
|
---|
| 83 | exit(1);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | // Filling Mask Sphere
|
---|
| 87 | cout<<"Testing For Masked Pixels"<<endl;
|
---|
| 88 | uint_4 nmask = 0;
|
---|
| 89 | for(int_4 i=0;i<sph.NbPixels();i++) {
|
---|
| 90 | r_8 v = msph(i);
|
---|
| 91 | bool masked=false;
|
---|
| 92 | if(tstmin && v<=vmin) {sph(i) = vmask; masked = true;}
|
---|
| 93 | if(tstmax && v>=vmax) {sph(i) = vmask; masked = true;}
|
---|
| 94 | if(!tstmin && !tstmax && v<=0.)
|
---|
| 95 | {sph(i) = vmask; masked = true;}
|
---|
| 96 | if(masked) nmask++;
|
---|
| 97 | }
|
---|
| 98 | cout<<" .... Number of values masked : "<<nmask<<endl;
|
---|
| 99 | cout<<" .... Fraction of values masked : "
|
---|
| 100 | <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
|
---|
| 101 |
|
---|
| 102 | // Ecriture de la sphere Healpix sur fits
|
---|
| 103 | {
|
---|
| 104 | string dum = "rm -f "; dum += sphout; system(dum.c_str());
|
---|
| 105 | FitsOutFile sfits(sphout);
|
---|
| 106 | cout<<"Writing Output Masked Sphere Fits file"<<endl;
|
---|
| 107 | sfits<<sph;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | exit(0);
|
---|
| 111 | }
|
---|