IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 19, 2019, 5:33:23 PM (7 years ago)
Author:
eugene
Message:

avoid NANs; testing fitalt

File:
1 edited

Legend:

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

    r40663 r40838  
    8686// generate a subimage of the full model for the range row - row + Ny
    8787// obj,sky,bck are subset vectors corresponding to the range row to row+Ny
    88 float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *slit_trace, Spline *psf_trace, int Nx, int Ny, int row) {
     88// the slit_trace_* and psf_trace refer to the full image starting at row
     89float *deimos_make_model (opihi_flt *obj, opihi_flt *sky, opihi_flt *bck, Vector *psf, Vector *profile, Spline *slit_trace_red, Spline *slit_trace_blu, float redlimit, Spline *psf_trace, int Nx, int Ny, int row) {
    8990
    9091  float *raw = deimos_make_straight_image (obj, sky, psf, psf_trace, Nx, Ny, row);
     
    9293  deimos_apply_profile (profile, new, Nx, Ny);
    9394  deimos_add_background (bck, new, Nx, Ny, row);
    94   float *out = deimos_apply_trace (slit_trace, new, Nx, Ny, row);
     95  float *out = deimos_apply_trace (slit_trace_red, slit_trace_blu, redlimit, new, Nx, Ny, row);
    9596
    9697  free (raw);
     
    113114
    114115  // Xref is a global supplied by the user (defaults to Nx/2 if < 0)
    115   int Xoff = (int)(Xref - Npsf);
     116  int XoffRef = (int)(Xref - Npsf);
    116117
    117118  // Nx : width of output window
     
    123124   
    124125    // we are generating the image for just the row range row to row+Ny
     126    // note that obj & sky are subset vectors for just this range of pixels
    125127    opihi_flt objVy = obj[iy]; // if we shift to using the row offset: obj[iy + row]
    126128    opihi_flt skyVy = sky[iy]; // if we shift to using the row offset: sky[iy + row]
     
    129131    int dxi = 0;
    130132    float dxf = 0.0, dxr = 1.0;
     133    int Xoff = XoffRef;
    131134   
    132135    if (psf_trace) {
    133       float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy);
     136      // the psf_trace is referenced against the full image, so we need to add row to iy:
     137      float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy + row);
    134138      dxi = floor(dx);
    135139      dxf = dx - dxi;  // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7
    136140      dxr = 1 - dxf;
    137       Xref += dxi;
     141      Xoff += dxi;
     142      // fprintf (stderr, "%d: %f : %d\n", iy + row, dx, Xoff);
    138143    }
    139144
     
    153158        if (doInterp) {
    154159          if ((n > 0) && (n < NpsfFull)) {
    155             value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf;
     160            if (isfinite(psfV[n]) && isfinite(psfV[n-1])) {
     161              value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf;
     162            }
    156163          }
    157164          if (n == 0) {
    158             value += objVy*psfV[n]*dxr;
     165            if (isfinite(psfV[n])) {
     166              value += objVy*psfV[n]*dxr;
     167            }
    159168          }
    160169        } else {
    161           value += objVy * psfV[n];
     170          if (isfinite(psfV[n])) {
     171            value += objVy * psfV[n];
     172          }
    162173        }
    163174      }
     
    243254
    244255// shift pixels in x based on the trace
    245 float *deimos_apply_trace (Spline *slit_trace, float *input, int Nx, int Ny, int row) {
     256float *deimos_apply_trace (Spline *slit_trace_red, Spline *slit_trace_blu, float redlimit, float *input, int Nx, int Ny, int row) {
    246257
    247258  ALLOCATE_PTR (output, float, Nx*Ny);
     
    251262    // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center
    252263    // NOTE: spline is evaluated at full dispersion coordinate
    253     float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy + row);
     264    int iy_full = iy + row;
     265    Spline *slit_trace = (iy_full < redlimit) ? slit_trace_red : slit_trace_blu;
     266    float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy_full);
    254267     
    255268    // extract the integer pixel offset and the fractional offset
Note: See TracChangeset for help on using the changeset viewer.