IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 31, 2019, 3:08:13 PM (7 years ago)
Author:
eugene
Message:

deimos updates to add psf trace

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20190329/src/opihi/mana/deimos_getobj.c

    r40659 r40663  
    33// temporary storage used in local functions:
    44
    5 float *tmpv = NULL;
    6 float *tmpx = NULL;
     5static float *tmpv = NULL;
     6static float *tmpx = NULL;
    77
    88// pass in a pointer to the row (&buffV[iy*Nx])
     
    3939  // input parameters:
    4040  // * 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
    4243  // * profile     : slit window profile (vector)
    4344  // * PSF         : point-spread function vector (flux normalized, x-dir)
     
    5152  int N;
    5253
    53   Spline *trace   = NULL;
     54  Spline *slit_trace = NULL;
     55  Spline *psf_trace  = NULL;
    5456  Vector *profile = NULL;
    5557
     
    7173
    7274  // 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);
    7683    remove_argument (N, &argc, argv);
    7784  } else { goto usage; }
     
    218225
    219226  // loop over the y positions
     227  // examine the slit window profile to measure background and slit sky
    220228  for (int iy = 0; iy < Ny; iy++) {
    221229
    222230    // 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);
    224232
    225233    // Xref is the reference coordinate of the profile on the image
     
    284292   
    285293    // 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);
    287296     
    288297    // Xref is the reference coordinate of the profile on the image
    289298    // Xpsf is the center of the PSF. 
    290299    // 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
    293303    // include the PSF trace and restrict the fit below to portions where the profile is > 0.95
    294304
    295305    // now I need to find the limits of the PSF in the buffer at this iy location
     306    int Ntmp = 0;
    296307    for (int ipsf = 0; ipsf < Npsf; ipsf ++) {
    297308
    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
    299312      float So = S_lf + (ix - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak
    300313
    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 ++;
    303326    }
    304327
     
    306329    // now fit the PSF to tmpv by calculating a normalization
    307330    float S1 = 0.0, S2 = 0.0;
    308     for (int ipsf = 0; ipsf < Npsf; ipsf++) {
     331    for (int ipsf = 0; ipsf < Ntmp; ipsf++) {
    309332      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]);
    311334      }
    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])
    314337    }
    315338
    316     int Xo = Xref - dXtrace; // center of PSF in image x-coordinates
     339    int Xo = Xref - dXtraceSLIT - dXtracePSF; // center of PSF in image x-coordinates
    317340    float So = S_lf + (Xo - X_lf)*(S_rt - S_lf)/(X_rt - X_lf); // interpolated sky under PSF peak
    318341    object->elements.Flt[iy] = S1 / S2;
Note: See TracChangeset for help on using the changeset viewer.