Changeset 877 in Sophya for trunk/SophyaProg/PMixer/extractRS.cc
- Timestamp:
- Apr 11, 2000, 3:24:27 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/PMixer/extractRS.cc
r817 r877 12 12 #include "tvector.h" 13 13 #include "vector3d.h" 14 14 #include "nbrandom.h" 15 15 #include "timing.h" 16 16 #include "sambainit.h" … … 34 34 SpectralResponse * getSpectralResponse(DataCards & dc); 35 35 template <class T> 36 void addComponent(SpectralResponse& sr, PixelMap<T>& finalMap,37 PixelMap<T>& mapToAdd, RadSpectra& rs, double K=1.);38 template <class T>39 36 void MeanSig(NDataBlock<T> const & dbl, double& gmoy, double& gsig); 40 37 float ComputeFrequency(DataCards &,string&); … … 45 42 static bool rdmap = false; // true -> Read map first 46 43 static char mapPath[256]; // Path for input maps 44 static int hp_nside = 32; // HealPix NSide 47 45 static int nskycomp = 0; // Number of sky components 48 46 static int debuglev = 0; // Debug Level … … 55 53 int main(int narg, char * arg[]) 56 54 { 57 if ((narg < 4) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) {58 cout << " Usage: extractRS parameterFile outputfitsnameformaps outputfitsnameforsource[outppfname]" << endl;55 if ((narg < 3) || ((narg > 1) && (strcmp(arg[1], "-h") == 0) )) { 56 cout << " Usage: extractRS parameterFile outputfitsnameformaps [outppfname]" << endl; 59 57 exit(0); 60 58 } … … 90 88 91 89 92 cout << " extractRS/Info : NComp = " << nskycomp << endl;90 cout << " extractRS/Info : NComp = " << nskycomp << " SphereGorski_NSide= " << hp_nside << endl; 93 91 cout << " ... MapPath = " << (string)mapPath << " DebugLev= " << debuglev 94 92 << " PrintLev= " << printlev << endl; … … 97 95 // We create an output persist file for writing debug objects 98 96 if (debuglev > 0) so = new POutPersist("extrRSdbg.ppf"); 99 100 101 TMatrix<float> outgs; 102 bool okout = false; 97 SphereGorski<float> SourceMap(hp_nside); 98 SphereGorski<float> OutputMap(hp_nside); 99 bool okout = true; 103 100 104 101 try { … … 120 117 int nb_source; 121 118 TMatrix<float> rareSource; //par freq et par numero de source 122 119 123 120 for(sk = 0; sk<maxOfSkyComp; sk++) 124 121 { 125 126 122 TMatrix<float> ings; 127 123 // Opening the file containing the map … … 137 133 if (printlev > 2) 138 134 { 139 MeanSig(ings.DataBlock(), moy, sig ); 140 cout << " MeanSig for input map - Mean= " << moy << " Sigma= " << sig << endl; 141 } 142 135 double min = 1000000000; 136 double max = -10000000000; 137 for(int x=0;x<ings.NRows(); x++) 138 { 139 for(int y=0;y<ings.NCols(); y++) 140 { 141 if(min>ings(x,y)) min = ings(x,y); 142 if(max<ings(x,y)) max = ings(x,y); 143 } 144 } 145 cout << "min and max values for input map" << min << " " << max << endl; 146 } 143 147 // Computing the frequency according to the name of the file 144 148 freq(sk) = ComputeFrequency(dc,key); 145 149 if (printlev > 2) cout << "filling spectrum for freq = " << freq(sk) << endl; 150 146 151 // Opening the file containing the point source 147 152 sprintf(buff, "%d", sk+1); … … 169 174 for(int x=0;x<ings.NRows(); x++) 170 175 { 171 for(int y=0; x<ings.NCols(); x++)176 for(int y=0;y<ings.NCols(); y++) 172 177 { 173 178 spectrum(x,y) = ings(x,y)*1.e-26; //for Jansky->W … … 185 190 K = dc.DParam(key, 1, 1.); 186 191 if (debuglev > 4) { // Writing the input map to the outppf 187 so->PutObject(ings, key); // $CHECK$ Reza 05/04/2000 192 FIO_TMatrix<float> fiog; 193 fiog.Write(*so, key); 188 194 } 189 195 … … 205 211 TVector<float> outCoeff(nbOfPix); 206 212 207 for(int pix= 1;pix<nbOfPix;pix++)213 for(int pix=0;pix<nbOfPix;pix++) 208 214 { 209 215 Vector smallFDeNu(maxOfSkyComp); … … 216 222 if (printlev > 10) cout << "RadiationSpectra" << radSV << endl; 217 223 218 TVector<float> smallFDeNuT(maxOfSkyComp);219 for(sk = 0; sk<maxOfSkyComp; sk++)220 {221 smallFDeNuT(sk) = smallFDeNu(sk);222 }223 224 outCoeff(pix) = radSV.filteredIntegratedFlux(*sr); 224 225 } 225 226 FitsIoServer fiosrs; 227 fiosrs.save(outCoeff,arg[2]); 228 cout << "Output Map (TMatrix<float>) written to FITS file " 229 << arg[2]<< endl; 230 cout << endl; 231 226 227 for(int i=0;i<OutputMap.NbPixels();i++) 228 { 229 float random = frand01(); 230 if(random == 1) random = frand01(); 231 int randomPix = random*OutputMap.NbPixels(); 232 int outpix = random*nbOfPix; 233 OutputMap(i) = outCoeff(outpix)*1.e18; 234 } 235 236 232 237 // --------------------------------------------------------------------- 233 238 // Integration in the detector band of the sources … … 244 249 sourceCoeff(nsource) = radSV_Source.filteredIntegratedFlux(*sr); 245 250 } 246 FitsIoServer fiosrs_source; 247 fiosrs_source.save(sourceCoeff,arg[3]); 248 cout << "Output Map (TMatrix<float>) written to FITS file " 249 << arg[3]<< endl; 250 cout << endl; 251 252 // --------------------------------------------------------------------- 253 // Check of write/read on FITS file 254 // --------------------------------------------------------------------- 255 if (printlev > 2) 256 { 257 cout << " Check of write/read on FITS file for skymap!" << endl; 258 TVector<float> outout; 259 FitsIoServer fiotest; 260 fiotest.load(outout, arg[2]); 261 cout << "Coeff(2)" << outout(2) << " ? " << outCoeff(2) << endl; 262 cout << endl; 263 } 264 if (printlev > 2) 265 { 266 cout << " Check of write/read on FITS file for sources!" << endl; 267 FitsIoServer fiotest; 268 TVector<float> outout2; 269 fiotest.load(outout2, arg[3]); 270 cout << "sourceCoeff(2)" << outout2(2) << " ? " << sourceCoeff(2) << endl; 271 } 272 273 274 } // End of try block 275 276 251 252 for(int i=0;i<nb_source;i++) 253 { 254 float random = frand01(); 255 int outPix = random*OutputMap.NbPixels(); 256 SourceMap(outPix) = sourceCoeff(i); 257 OutputMap(outPix) = OutputMap(i)+ SourceMap(outPix)*1.E18; 258 } 259 } 277 260 catch (PException exc) { 278 261 msg = exc.Msg(); … … 291 274 292 275 // Saving the output map in FITS format 293 if (okout) { 294 FitsIoServer fios; 295 fios.save(outgs, arg[2]); 296 cout << "Output Map (TMatrix<float>) written to FITS file " 297 << (string)(arg[2]) << endl; 298 if(printlev>2) PrtTim("End of WriteFITS "); 299 // Saving the output map in PPF format 300 if (narg > 3) { 301 POutPersist s(arg[3]); 302 s.PutObject(outgs); // $CHECK$ Reza 05/04/2000 303 cout << "Output Map (TMatrix<float>) written to POutPersist file " 304 << (string)(arg[3]) << endl; 305 if(printlev>2) PrtTim("End of WritePPF "); 276 if (okout) 277 { 278 // { 279 // FitsIoServer fios; 280 // fios.save(SourceMap, arg[3]); 281 // double moy,sig; 282 // MeanSig(SourceMap.DataBlock(),moy,sig); 283 // cout << " MeanSig for Source Map - Mean= " << moy << " Sigma= " << sig << endl; 284 // cout << "Source Map (SphereGorski<float>) written to FITS file " 285 // << (string)(arg[3]) << endl; 286 // } 287 { 288 FitsIoServer fios; 289 fios.save(OutputMap, arg[2]); 290 double moy,sig; 291 MeanSig(OutputMap.DataBlock(),moy,sig); 292 cout << " MeanSig for Output Map - Mean= " << moy << " Sigma= " << sig << endl; 293 cout << "Output Map (SphereGorski<float>) written to FITS file " 294 << (string)(arg[2]) << endl; 295 } 296 if(printlev>2) PrtTim("End of WriteFITS "); 297 // Saving the output map in PPF format 298 if (narg > 2) { 299 POutPersist s(arg[3]); 300 FIO_SphereGorski<float> fiog(OutputMap); 301 fiog.Write(s); 302 cout << "Output Map (SphereGorski<float>) written to POutPersist file " 303 << (string)(arg[3]) << endl; 304 if(printlev>2) PrtTim("End of WritePPF "); 305 } 306 306 } 307 }308 307 if (so) delete so; // Closing the debug ppf file 309 308 return(rc); … … 326 325 327 326 // Checking datacards 328 if (dc.NbParam("EXT_RS") < 1) {327 if (dc.NbParam("EXT_RS") < 2) { 329 328 rc = 71; 330 329 msg = "Invalid parameters - Check @EXT_RS card "; … … 337 336 int ncomp = 0; 338 337 ncomp = dc.IParam("EXT_RS", 0); 338 int nside = 32; 339 nside = dc.IParam("EXT_RS", 1); 339 340 340 341 for(kc=0; kc<ncomp; kc++) … … 371 372 msg = "OK"; 372 373 nskycomp = ncomp; 373 374 hp_nside = nside; 374 375 // Checking for PATH definition card 375 376 key = "RS_EXT_PATH"; … … 409 410 if (gsig >= 0.) gsig = sqrt(gsig); 410 411 } 411 /* Nouvelle-Fonction */412 template <class T>413 void addComponent(SpectralResponse& sr, PixelMap<T>& finalMap,414 PixelMap<T>& mapToAdd, RadSpectra& rs, double K)415 {416 // finalMap = finalMap + coeff* mapToAdd417 // coeff = convolution of sr and rs418 // compute the coefficient corresponding to mapToAdd419 if (finalMap.NbPixels() != mapToAdd.NbPixels())420 throw SzMismatchError("addComponent()/Error: Unequal number of Input/Output map pixels");421 double coeff = rs.filteredIntegratedFlux(sr) * K;422 if (printlev > 1)423 cout << " addComponent - Coeff= " << coeff << " (K= " << K << ")" << endl;424 for(int i=0; i<finalMap.NbPixels(); i++)425 {426 finalMap(i) += coeff * mapToAdd(i);427 }428 }429 430 412 431 413 /* Nouvelle-Fonction */
Note:
See TracChangeset
for help on using the changeset viewer.