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