[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
|
---|
[1522] | 5 | #include "machdefs.h"
|
---|
| 6 | #include <unistd.h>
|
---|
| 7 | #include <stdexcept>
|
---|
| 8 | #include <iostream.h>
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 | #include <stdlib.h>
|
---|
| 11 | #include "skymapinit.h"
|
---|
| 12 | #include "skymap.h"
|
---|
| 13 | #include "fitsspherehealpix.h"
|
---|
| 14 |
|
---|
[1626] | 15 | /*!
|
---|
| 16 | \ingroup PrgMap
|
---|
| 17 | \file cremskfrsph.cc
|
---|
| 18 | \brief \b cremskfrsph: Create a masked sphere from a sphere of datas
|
---|
| 19 | \verbatim
|
---|
| 20 | csh> cremskfrsph -h
|
---|
| 21 | cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits
|
---|
| 22 | -m min : min value
|
---|
| 23 | -M max : max value
|
---|
| 24 | condition for filling masque is: min<=sphere_value<=max
|
---|
| 25 | (fill mask with valmsk) (bounds are included)
|
---|
| 26 | -n : negate the condition
|
---|
| 27 | (switch to: sphere_value<min || max<sphere_value)
|
---|
| 28 | -v valmsk,inimsk:
|
---|
| 29 | valmsk: value to be put into mask if ok (def=1.)
|
---|
| 30 | inimsk: initialisation value for the mask (def=0.)
|
---|
| 31 | \endverbatim
|
---|
| 32 | */
|
---|
| 33 |
|
---|
[1522] | 34 | void usage();
|
---|
| 35 | void usage()
|
---|
| 36 | {
|
---|
| 37 | cout<<"cremskfrsph [-n -m min -M max -v valmsk,inimsk] sphval.fits sphmask.fits"<<endl
|
---|
| 38 | <<" -m min : min value"<<endl
|
---|
| 39 | <<" -M max : max value"<<endl
|
---|
[1626] | 40 | <<" condition for filling masque is: min<=sphere_value<=max"<<endl
|
---|
| 41 | <<" (fill mask with valmsk) (bounds are included)"<<endl
|
---|
[1522] | 42 | <<" -n : negate the condition"<<endl
|
---|
[1626] | 43 | <<" (switch to: sphere_value<min || max<sphere_value)"<<endl
|
---|
[1522] | 44 | <<" -v valmsk,inimsk:"<<endl
|
---|
| 45 | <<" valmsk: value to be put into mask if ok (def=1.)"<<endl
|
---|
| 46 | <<" inimsk: initialisation value for the mask (def=0.)"<<endl;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | int main(int narg, char* arg[])
|
---|
| 51 | {
|
---|
| 52 | double vmin=-1.e30,vmax=1.e30,vmask=1.,vmaskini=0.;
|
---|
| 53 | bool tstmin=false,tstmax=false,negate=false;
|
---|
[1626] | 54 | string dum;
|
---|
[1522] | 55 | int c;
|
---|
| 56 | while((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,%lf",&vmask,&vmaskini);
|
---|
| 71 | break;
|
---|
| 72 | case 'h' :
|
---|
| 73 | default:
|
---|
| 74 | usage(); exit(1);
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | if(optind+1>=narg) {usage(); exit(1);}
|
---|
| 79 | char * sphval = arg[optind];
|
---|
| 80 | char * sphmsk = arg[optind+1];
|
---|
| 81 |
|
---|
[1626] | 82 | if(negate) dum = ".NOT."; else dum = "";
|
---|
[1522] | 83 | cout<<"Sphere values : "<<sphval<<endl
|
---|
| 84 | <<"Sphere mask : "<<sphmsk<<endl
|
---|
[1626] | 85 | <<" ...min("<<tstmin<<") "<<vmin<<endl
|
---|
| 86 | <<" max("<<tstmax<<") "<<vmax<<endl
|
---|
[1522] | 87 | <<" ...negate "<<negate<<endl
|
---|
| 88 | <<" ...mask set value "<<vmask<<endl
|
---|
[1626] | 89 | <<" mask init value "<<vmaskini<<endl
|
---|
| 90 | <<"Condition on data to set the mask: "
|
---|
| 91 | <<dum<<"( "<<vmin<<" <= V <= "<<vmax<<" )"<<endl;
|
---|
[1522] | 92 |
|
---|
| 93 | // Lecture de la sphere Healpix des valeurs
|
---|
[1626] | 94 | SphereHEALPix<r_8> sph;
|
---|
[1522] | 95 | FitsInFile sfits(sphval);
|
---|
| 96 | sfits >> sph;
|
---|
| 97 | cout<<"Opening Sphere HEALPix for testing values :"<<endl
|
---|
| 98 | <<" Type of map : "<<sph.TypeOfMap()<<endl
|
---|
| 99 | <<" Number of pixels : "<<sph.NbPixels()<<endl
|
---|
| 100 | <<" Nlat : "<<sph.SizeIndex()<<endl;
|
---|
| 101 |
|
---|
| 102 | // Ouverture de la sphere Healpix pour le masque
|
---|
| 103 | cout<<"Creating Mask Sphere"<<endl;
|
---|
| 104 | SphereHEALPix<r_8> sphm(sph,false);
|
---|
| 105 |
|
---|
| 106 | // Filling Mask Sphere
|
---|
| 107 | cout<<"Filling Mask"<<endl;
|
---|
| 108 | uint_4 nmask = 0;
|
---|
| 109 | for(int_4 i=0;i<sph.NbPixels();i++) {
|
---|
| 110 | sphm(i) = vmaskini;
|
---|
[1626] | 111 |
|
---|
| 112 | bool skp = (tstmin || tstmax) ? negate : false;
|
---|
| 113 | if((tstmin && sph(i)<vmin) || (tstmax && sph(i)>vmax)) skp = !negate;
|
---|
| 114 | if(skp) continue; // Do nothing
|
---|
| 115 |
|
---|
[1522] | 116 | sphm(i) = vmask;
|
---|
| 117 | nmask++;
|
---|
| 118 | }
|
---|
| 119 | cout<<" .... Number of values set in mask : "<<nmask<<endl;
|
---|
| 120 | cout<<" .... Fraction of values set in mask : "
|
---|
| 121 | <<(r_8)nmask/sph.NbPixels()*100.<<" %"<<endl;
|
---|
| 122 |
|
---|
| 123 | // Ecriture de la sphere Healpix sur fits
|
---|
| 124 | {
|
---|
[1626] | 125 | dum = "rm -f "; dum += sphmsk; system(dum.c_str());
|
---|
[1522] | 126 | FitsOutFile swfits(sphmsk);
|
---|
| 127 | cout<<"Writing Mask Sphere Fits file"<<endl;
|
---|
| 128 | swfits<<sphm;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | exit(0);
|
---|
| 132 | }
|
---|