- Timestamp:
- Mar 31, 2019, 3:08:13 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_getobj.c
r40659 r40663 3 3 // temporary storage used in local functions: 4 4 5 float *tmpv = NULL;6 float *tmpx = NULL;5 static float *tmpv = NULL; 6 static float *tmpx = NULL; 7 7 8 8 // pass in a pointer to the row (&buffV[iy*Nx]) … … 39 39 // input parameters: 40 40 // * buffer : 2D image of slit (full frame or cutout?) 41 // * trace : spline fit of slit central x pos vs y-coord 41 // * slit_trace : spline fit of slit central x pos vs y-coord 42 // * psf_trace : spline fit of psf central x pos vs y-coord 42 43 // * profile : slit window profile (vector) 43 44 // * PSF : point-spread function vector (flux normalized, x-dir) … … 51 52 int N; 52 53 53 Spline *trace = NULL; 54 Spline *slit_trace = NULL; 55 Spline *psf_trace = NULL; 54 56 Vector *profile = NULL; 55 57 … … 71 73 72 74 // Input parameters: 73 if ((N = get_argument (argc, argv, "-trace"))) { 74 remove_argument (N, &argc, argv); 75 if ((trace = FindSpline (argv[N])) == NULL) return (FALSE); 75 if ((N = get_argument (argc, argv, "-slit-trace"))) { 76 remove_argument (N, &argc, argv); 77 if ((slit_trace = FindSpline (argv[N])) == NULL) return (FALSE); 78 remove_argument (N, &argc, argv); 79 } else { goto usage; } 80 if ((N = get_argument (argc, argv, "-psf-trace"))) { 81 remove_argument (N, &argc, argv); 82 if ((psf_trace = FindSpline (argv[N])) == NULL) return (FALSE); 76 83 remove_argument (N, &argc, argv); 77 84 } else { goto usage; } … … 218 225 219 226 // loop over the y positions 227 // examine the slit window profile to measure background and slit sky 220 228 for (int iy = 0; iy < Ny; iy++) { 221 229 222 230 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 223 float dXtrace = spline_apply_dbl ( trace->xk, trace->yk, trace->y2,trace->Nknots, iy);231 float dXtrace = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 224 232 225 233 // Xref is the reference coordinate of the profile on the image … … 284 292 285 293 // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center 286 float dXtrace = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy); 294 float dXtraceSLIT = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy); 295 float dXtracePSF = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy); 287 296 288 297 // Xref is the reference coordinate of the profile on the image 289 298 // Xpsf is the center of the PSF. 290 299 // dXtrace follows the x-dir variations of the slit profile (or PSF?) 291 float Xtrace = Xref - Xpsf + dXtrace; 292 300 float XtracePSF = Xref - Xpsf + dXtraceSLIT + dXtracePSF; 301 float XtraceSLIT = Xref - Xprofile + dXtraceSLIT; 302 293 303 // include the PSF trace and restrict the fit below to portions where the profile is > 0.95 294 304 295 305 // now I need to find the limits of the PSF in the buffer at this iy location 306 int Ntmp = 0; 296 307 for (int ipsf = 0; ipsf < Npsf; ipsf ++) { 297 308 298 int ix = ipsf + Xtrace + 0.5; // image coordinate (nearest pixel center) 309 int ix = ipsf + XtracePSF + 0.5; // image coordinate (nearest pixel center) 310 int islit = ix - XtraceSLIT - 0.5; // image coordinate (nearest pixel center) 311 299 312 float So = S_lf + (ix - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak 300 313 301 tmpv[ipsf] = buffV[ix + iy*Nx] - So; 302 tmpx[ipsf] = ipsf; 314 if (islit < 0) continue; 315 if (islit >= profile->Nelements) continue; 316 317 if (iy == 6000) { 318 fprintf (stderr, "%d : %f %f : %f : %f\n", ipsf, buffV[ix + iy*Nx] - So, psfV[ipsf], (buffV[ix + iy*Nx] - So)*psfV[ipsf], profile->elements.Flt[islit]); 319 } 320 321 if (profile->elements.Flt[islit] < 0.95) continue; 322 323 tmpv[Ntmp] = buffV[ix + iy*Nx] - So; 324 tmpx[Ntmp] = psfV[ipsf]; 325 Ntmp ++; 303 326 } 304 327 … … 306 329 // now fit the PSF to tmpv by calculating a normalization 307 330 float S1 = 0.0, S2 = 0.0; 308 for (int ipsf = 0; ipsf < N psf; ipsf++) {331 for (int ipsf = 0; ipsf < Ntmp; ipsf++) { 309 332 if (iy == 6000) { 310 fprintf (stderr, "%d : %f %f : %f\n", ipsf, tmpv[ipsf], psfV[ipsf], tmpv[ipsf]*psfV[ipsf]);333 fprintf (stderr, "%d : %f %f : %f\n", ipsf, tmpv[ipsf], tmpx[ipsf], tmpv[ipsf]*tmpx[ipsf]); 311 334 } 312 S1 += tmpv[ipsf]* psfV[ipsf]; // if we have an errorbar, include / SQ(sigv[i])313 S2 += psfV[ipsf]*psfV[ipsf]; // if we have an errorbar, include / SQ(sigv[i])335 S1 += tmpv[ipsf]*tmpx[ipsf]; // if we have an errorbar, include / SQ(sigv[i]) 336 S2 += tmpx[ipsf]*tmpx[ipsf]; // if we have an errorbar, include / SQ(sigv[i]) 314 337 } 315 338 316 int Xo = Xref - dXtrace ; // center of PSF in image x-coordinates339 int Xo = Xref - dXtraceSLIT - dXtracePSF; // center of PSF in image x-coordinates 317 340 float So = S_lf + (Xo - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak 318 341 object->elements.Flt[iy] = S1 / S2;
Note:
See TracChangeset
for help on using the changeset viewer.
