Changeset 37642
- Timestamp:
- Nov 19, 2014, 7:56:39 PM (12 years ago)
- Location:
- branches/eam_branches/ipp-20140904/Ohana/src/relastro/src
- Files:
-
- 2 edited
-
FrameCorrection.c (modified) (3 diffs)
-
UpdateObjects.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/FrameCorrection.c
r37623 r37642 176 176 } 177 177 178 // I need to generate a collection of values dR,dD(R,D), where dR = average.R - ICRF.R, etc. 179 // I will then fit the set of dR,dD values to a set of spherical harmonics (up to Lmax). 180 // I will then generate correction images dR,dD(R,D) 181 // I will then correct all values average.R,D by the interpolated values from the images 182 // average.R' = average.R - dR(R,d), average.D' = average.D - dD(R,d) 183 184 int SHfitWithMask (double *R, double *D, double *value, int *mask, int Npts, SHterms *fit); 185 178 186 int FrameCorrectionFitSH (Catalog *catalog, int Ncatalog, SHterms *dRc, SHterms *dDc) { 179 187 188 int i; 189 180 190 myAssert (dRc->lmax == dDc->lmax, "dR and dD must match\n"); 181 182 // allocate an SHterms structure to hold the Ylm values183 SHterms *SH = SHtermsInit (dRc->lmax);184 191 185 192 int Nicrf = ICRFmax(); 186 193 fprintf (stderr, "start Fit %d SH l-modes for %d QSOs\n", dRc->lmax, Nicrf); 187 194 188 FILE *f = fopen ("sh.dat", "w"); 189 myAssert (f, "oops"); 190 191 int i, j; 195 double *Rave, *Dave, *dRoff, *dDoff; 196 197 int Npts = 0; 198 ALLOCATE (Rave, double, Nicrf); 199 ALLOCATE (Dave, double, Nicrf); 200 ALLOCATE (dRoff, double, Nicrf); 201 ALLOCATE (dDoff, double, Nicrf); 202 203 int *mask = NULL; 204 ALLOCATE (mask, int, Nicrf); 205 memset (mask, 0, Nicrf*sizeof(int)); 206 207 // select the ICRF QSOS and save the necessary data 192 208 for (i = 0; i < Nicrf; i++) { 193 209 194 210 int cat, meas, ave; 195 211 ICRFdata (i, &cat, &ave, &meas); 196 197 // I need to generate a collection of values dR,dD(R,D), where dR = average.R - ICRF.R, etc.198 // I will then fit the set of dR,dD values to a set of spherical harmonics (up to Lmax).199 // I will then generate correction images dR,dD(R,D)200 // I will then correct all values average.R,D by the interpolated values from the images201 // average.R' = average.R - dR(R,d), average.D' = average.D - dD(R,d)202 212 203 213 Average *average = &catalog[cat].average[ave]; … … 209 219 double dD = 3600.0*(average->D - measure->D); 210 220 211 fprintf (f, "%12.8f %12.8f %7.3f %7.3f\n", average->R, average->D, dR, dD);212 221 if (isnan(dR)) continue; 213 222 if (isnan(dD)) continue; 214 223 215 // get the value of Ylm at this coordinate 216 SHtermsForRD (SH, average->R, average->D); 224 225 Rave[Npts] = average->R; 226 Dave[Npts] = average->D; 227 dRoff[Npts] = dR; 228 dDoff[Npts] = dD; 229 Npts ++; 230 } 231 232 SHfitWithMask (Rave, Dave, dRoff, mask, Npts, dRc); 233 SHfitWithMask (Rave, Dave, dDoff, mask, Npts, dDc); 234 235 // allocate an SHterms structure to hold the Ylm values 236 SHterms *Ylm = SHtermsInit (dRc->lmax); 237 238 FILE *f = fopen ("sh.dat", "w"); 239 myAssert (f, "oops"); 240 241 for (i = 0; i < Nicrf; i++) { 217 242 218 // accumulate the dot products 219 for (j = 0; j < SH->Nterms; j++) { 220 dRc->Fr[j] += dR * SH->Fr[j]; 221 dRc->Fi[j] += dR * SH->Fi[j]; 222 dDc->Fr[j] += dD * SH->Fr[j]; 223 dDc->Fi[j] += dD * SH->Fi[j]; 224 } 243 SHtermsForRD (Ylm, Rave[i], Dave[i]); 244 245 double dRfit = 0.0; 246 double dDfit = 0.0; 247 248 int j; 249 for (j = 0; j < Ylm->Nterms; j++) { 250 dRfit += dRc->Fr[j]*Ylm->Fr[j] + dRc->Fi[j]*Ylm->Fi[j]; 251 dDfit += dDc->Fr[j]*Ylm->Fr[j] + dDc->Fi[j]*Ylm->Fi[j]; 252 } 253 fprintf (f, "%12.8f %12.8f %7.3f %7.3f : %7.3f %7.3f\n", Rave[i], Dave[i], dRoff[i], dDoff[i], dRfit, dDfit); 225 254 } 226 255 fclose (f); 227 256 228 for (j = 0; j < SH->Nterms; j++) { 229 dRc->Fr[j] *= 4.0*M_PI/(float)Nicrf; 230 dRc->Fi[j] *= 4.0*M_PI/(float)Nicrf; 231 dDc->Fr[j] *= 4.0*M_PI/(float)Nicrf; 232 dDc->Fi[j] *= 4.0*M_PI/(float)Nicrf; 233 } 234 SHtermsFree (SH); 257 free (Rave); 258 free (Dave); 259 free (dRoff); 260 free (dDoff); 261 free (mask); 262 263 return TRUE; 264 } 265 266 int SHfitWithMask (double *R, double *D, double *value, int *mask, int Npts, SHterms *fit) { 267 268 int i, j, k; 269 270 // allocate an SHterms structure to hold the Ylm values 271 SHterms *Ylm = SHtermsInit (fit->lmax); 272 273 // we only fit the linearly independent terms: Re(m >= 0), Im(m > 0) 274 int NtermRE = 0; 275 int NtermIM = 0; 276 for (i = 0; i < Ylm->Nterms; i++) { 277 if (Ylm->m[i] >= 0) NtermRE ++; 278 if (Ylm->m[i] > 0) NtermIM ++; 279 } 280 int *Nre = NULL; 281 int *Nim = NULL; 282 ALLOCATE (Nre, int, NtermRE); 283 ALLOCATE (Nim, int, NtermIM); 284 285 NtermRE = NtermIM = 0; 286 for (i = 0; i < Ylm->Nterms; i++) { 287 if (Ylm->m[i] >= 0) { 288 Nre[NtermRE] = i; 289 NtermRE ++; 290 } 291 if (Ylm->m[i] > 0) { 292 Nim[NtermIM] = i; 293 NtermIM ++; 294 } 295 } 296 297 double **Are, **bre, **Aim, **bim; 298 ALLOCATE (Are, double *, NtermRE); 299 ALLOCATE (bre, double *, NtermRE); 300 ALLOCATE (Aim, double *, NtermIM); 301 ALLOCATE (bim, double *, NtermIM); 302 for (i = 0; i < NtermRE; i++) { 303 ALLOCATE_ZERO (Are[i], double, NtermRE); 304 ALLOCATE_ZERO (bre[i], double, 1); 305 } 306 for (i = 0; i < NtermIM; i++) { 307 ALLOCATE_ZERO (Aim[i], double, NtermIM); 308 ALLOCATE_ZERO (bim[i], double, 1); 309 } 310 311 // measure the dot product \sum(F_i * Ylm_i) and the cross terms (\sum(Y_lm * Y_jk)) 312 int Nfit = 0; 313 for (i = 0; i < Npts; i++) { 314 if (mask[i]) continue; 315 Nfit ++; 316 317 // set the values of Ylm(R[i],D[i]) 318 SHtermsForRD (Ylm, R[i], D[i]); 319 320 double Fv = value[i]; 321 322 for (j = 0; j < NtermRE; j++) { 323 int jre = Nre[j]; 324 bre[j][0] += Fv * Ylm->Fr[jre]; 325 } 326 for (j = 0; j < NtermIM; j++) { 327 int jim = Nim[j]; 328 bim[j][0] += Fv * Ylm->Fi[jim]; 329 } 330 331 for (j = 0; j < NtermRE; j++) { 332 int jre = Nre[j]; 333 for (k = j; k < NtermRE; k++) { 334 int kre = Nre[k]; 335 Are[j][k] += Ylm->Fr[jre] * Ylm->Fr[kre]; 336 } 337 } 338 339 for (j = 0; j < NtermIM; j++) { 340 int jim = Nim[j]; 341 for (k = j; k < NtermIM; k++) { 342 int kim = Nim[k]; 343 Aim[j][k] += Ylm->Fi[jim] * Ylm->Fi[kim]; 344 } 345 } 346 } 347 348 for (j = 1; j < NtermRE; j++) { 349 for (k = 0; k < j; k++) { 350 Are[j][k] = Are[k][j]; 351 } 352 } 353 for (j = 1; j < NtermIM; j++) { 354 for (k = 0; k < j; k++) { 355 Aim[j][k] = Aim[k][j]; 356 } 357 } 358 359 if (!dgaussjordan (Are, bre, NtermRE, 1)) { 360 gprint (GP_ERR, "failed to fit data : ill-conditioned matrix\n"); 361 return FALSE; 362 } 363 if (!dgaussjordan (Aim, bim, NtermIM, 1)) { 364 gprint (GP_ERR, "failed to fit data : ill-conditioned matrix\n"); 365 return FALSE; 366 } 367 368 for (j = 0; j < fit->Nterms; j++) { 369 fit->Fr[j] = 0.0; 370 fit->Fi[i] = 0.0; 371 } 372 for (j = 0; j < NtermRE; j++) { 373 int jre = Nre[j]; 374 // fit->Fr[jre] = bre[j][0] * fit->Nterms / (float) Nfit; // XXX EAM : why is this factor needed? 375 fit->Fr[jre] = bre[j][0]; 376 } 377 for (j = 0; j < NtermIM; j++) { 378 int jim = Nim[j]; 379 // fit->Fi[jim] = bim[j][0] * fit->Nterms / (float) Nfit; // XXX EAM : why is this factor needed? 380 fit->Fi[jim] = bim[j][0]; 381 } 382 383 SHtermsFree (Ylm); 384 385 for (i = 0; i < NtermRE; i++) { 386 free (Are[i]); 387 free (bre[i]); 388 } 389 for (i = 0; i < NtermIM; i++) { 390 free (Aim[i]); 391 free (bim[i]); 392 } 393 free (Are); 394 free (bre); 395 free (Aim); 396 free (bim); 397 235 398 return TRUE; 236 399 } … … 542 705 double dR = frame->Roff[iD][iR]; 543 706 double dD = frame->Doff[iD][iR]; 707 708 // do not apply if the fabs(offset) is > 8 arcsec) 709 if ((fabs(dR) > 8.0) || (fabs(dD) > 8.0)) { 710 fprintf (stderr, "skip: %10.6f %10.6f : %7.3f %7.3f\n", average->R, average->D, dR, dD); 711 continue; 712 } 713 544 714 average->R -= dR / 3600.0; 545 715 average->D -= dD / 3600.0; -
branches/eam_branches/ipp-20140904/Ohana/src/relastro/src/UpdateObjects.c
r37631 r37642 2 2 # define PAR_TOOFEW 5 3 3 4 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int Nloop);4 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int applyGalaxyOffset); 5 5 int UpdateObjects_Stack (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats); 6 6 … … 146 146 // This function operates on both Measure and MeasureTiny. In the big stages, this should 147 147 // be called with just MeasureTiny set and Measure == NULL 148 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int Nloop) {148 int UpdateObjects_Chips (Average *average, SecFilt *secfilt, MeasureTiny *measure, Measure *measureBig, int Nsecfilt, FitStats *fitStats, int i, off_t m, int applyGalaxyOffset) { 149 149 150 150 int setRefColor = areImagesMatched();
Note:
See TracChangeset
for help on using the changeset viewer.
