[1522] | 1 | // Creation d'une sphere de masque a partir d'une sphere de valeurs
|
---|
| 2 | // cmv 13/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<<"cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits"<<endl
|
---|
| 17 | <<" -m min : min value"<<endl
|
---|
| 18 | <<" -M max : max value"<<endl
|
---|
| 19 | <<" condition for filling masque is : min<=V<=max"<<endl
|
---|
| 20 | <<" -n : negate the condition"<<endl
|
---|
| 21 | <<" -v valmsk,inimsk:"<<endl
|
---|
| 22 | <<" valmsk: value to be put into mask if ok (def=1.)"<<endl
|
---|
| 23 | <<" inimsk: initialisation value for the mask (def=0.)"<<endl;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | int main(int narg, char* arg[])
|
---|
| 28 | {
|
---|
| 29 | double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0.;
|
---|
| 30 | bool tstmin=false,tstmax=false,negate=false;
|
---|
| 31 | int c;
|
---|
| 32 | while((c = getopt(narg,arg,"hnm:M:v:")) != -1) {
|
---|
| 33 | switch (c) {
|
---|
| 34 | case 'n' :
|
---|
| 35 | negate = true;
|
---|
| 36 | break;
|
---|
| 37 | case 'm' :
|
---|
| 38 | sscanf(optarg,"%lf",&vmin);
|
---|
| 39 | tstmin = true;
|
---|
| 40 | break;
|
---|
| 41 | case 'M' :
|
---|
| 42 | sscanf(optarg,"%lf",&vmax);
|
---|
| 43 | tstmax = true;
|
---|
| 44 | break;
|
---|
| 45 | case 'v' :
|
---|
| 46 | sscanf(optarg,"%lf,%lf",&vmask,&vmaskini);
|
---|
| 47 | break;
|
---|
| 48 | case 'h' :
|
---|
| 49 | default:
|
---|
| 50 | usage(); exit(1);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if(optind+1>=narg) {usage(); exit(1);}
|
---|
| 55 | char * sphval = arg[optind];
|
---|
| 56 | char * sphmsk = arg[optind+1];
|
---|
| 57 |
|
---|
| 58 | {
|
---|
| 59 | cout<<"Sphere values : "<<sphval<<endl
|
---|
| 60 | <<"Sphere mask : "<<sphmsk<<endl
|
---|
| 61 | <<" ...min "<<vmin<<" max "<<vmax<<endl
|
---|
| 62 | <<" ...negate "<<negate<<endl
|
---|
| 63 | <<" ...mask set value "<<vmask<<endl
|
---|
| 64 | <<" mask init value "<<vmaskini<<endl;
|
---|
| 65 | cout<<"Condition : ";
|
---|
| 66 | if(negate) cout<<"!";
|
---|
| 67 | cout<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | // Lecture de la sphere Healpix des valeurs
|
---|
| 71 | SphereHEALPix<r_8> sph;
|
---|
| 72 | FitsInFile sfits(sphval);
|
---|
| 73 | sfits >> sph;
|
---|
| 74 | cout<<"Opening Sphere HEALPix for testing values :"<<endl
|
---|
| 75 | <<" Type of map : "<<sph.TypeOfMap()<<endl
|
---|
| 76 | <<" Number of pixels : "<<sph.NbPixels()<<endl
|
---|
| 77 | <<" Nlat : "<<sph.SizeIndex()<<endl;
|
---|
| 78 |
|
---|
| 79 | // Ouverture de la sphere Healpix pour le masque
|
---|
| 80 | cout<<"Creating Mask Sphere"<<endl;
|
---|
| 81 | SphereHEALPix<r_8> sphm(sph,false);
|
---|
| 82 |
|
---|
| 83 | // Filling Mask Sphere
|
---|
| 84 | cout<<"Filling Mask"<<endl;
|
---|
| 85 | uint_4 nmask = 0;
|
---|
| 86 | for(int_4 i=0;i<sph.NbPixels();i++) {
|
---|
| 87 | sphm(i) = vmaskini;
|
---|
| 88 | r_8 v = sph(i);
|
---|
| 89 | bool intoint = true;
|
---|
| 90 | if(tstmin && v<vmin) intoint=false;
|
---|
| 91 | if(tstmax && v>vmax) intoint=false;
|
---|
| 92 | // [vmin , vmax]
|
---|
| 93 | // intoint : false [ true ] false (si tstmin && tstmax)
|
---|
| 94 | // intoint : false [ true (si tstmin && !tstmax)
|
---|
| 95 | // intoint : true ] false (si !tstmin && tstmax)
|
---|
| 96 | if(negate && intoint) continue;
|
---|
| 97 | else if(!negate && !intoint) continue;
|
---|
| 98 | sphm(i) = vmask;
|
---|
| 99 | nmask++;
|
---|
| 100 | }
|
---|
| 101 | cout<<" .... Number of values set in mask : "<<nmask<<endl;
|
---|
| 102 | cout<<" .... Fraction of values set in mask : "
|
---|
| 103 | <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
|
---|
| 104 |
|
---|
| 105 | // Ecriture de la sphere Healpix sur fits
|
---|
| 106 | {
|
---|
| 107 | string dum = "rm -f "; dum += sphmsk; system(dum.c_str());
|
---|
| 108 | FitsOutFile swfits(sphmsk);
|
---|
| 109 | cout<<"Writing Mask Sphere Fits file"<<endl;
|
---|
| 110 | swfits<<sphm;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | exit(0);
|
---|
| 114 | }
|
---|