IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 16, 2020, 2:04:27 PM (6 years ago)
Author:
tdeboer
Message:

quick undo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/mana/deimos_mkobj.c

    r41340 r41341  
    66
    77  // input parameters:
    8   // * trace       : spline fit of slit central x pos vs y-coord
    9   // * profile     : slit window profile (vector)
    10   // * object      : vector of object flux vs y-coord
    11   // * sky         : vector of local sky signal vs y-coord
    12   // * background  : vector of extra-slit background flux vs y-coord
    13   // * PSF         : point-spread function vector (flux normalized, x-dir)
    14   // * LSF         : sline-spread function vector (flux normalized, y-dir)
    15   // * stilt       : slit tilt response : 2D kernel?
     8  // * slit_trace_red : spline fit of slit central x pos vs y-coord for red chip
     9  // * slit_trace_blu : spline fit of slit central x pos vs y-coord for blu chip
     10  // * psf_trace      : spline fit of psf central x pos vs y-coord
     11  // * profile        : slit window profile (vector)
     12  // * object         : vector of object flux vs y-coord
     13  // * sky            : vector of local sky signal vs y-coord
     14  // * backgnd        : vector of extra-slit background flux vs y-coord
     15  // * PSF            : point-spread function vector (flux normalized, x-dir)
     16  // * LSF            : sline-spread function vector (flux normalized, y-dir)
     17  // * stilt          : slit tilt response : 2D kernel?
     18
     19  // * redlimit       : pixel break between red and blu chips
     20  // * Nwave          : number of wavelength pixels in output image
    1621
    1722  int N;
    1823
    1924  // if any of these are not defined, they will have assumed identity values
    20   Spline *trace   = NULL;
    21   Vector *profile = NULL;
    22   Vector *object  = NULL;
    23   Vector *sky     = NULL;
    24   Vector *backgnd = NULL;
    25 
    26   Vector *psf     = NULL;
    27   Vector *lsf     = NULL;
     25  Spline *slit_trace_red = NULL;
     26  Spline *slit_trace_blu = NULL;
     27  Spline *psf_trace  = NULL;
     28  Vector *profile    = NULL;
     29  Vector *object     = NULL;
     30  Vector *sky        = NULL;
     31  Vector *backgnd    = NULL;
     32                     
     33  Vector *psf        = NULL;
     34  Vector *lsf        = NULL;
    2835  // add tilt later
    2936
    30   Buffer *output  = NULL;
     37  Buffer *output     = NULL;
    3138
    3239  float stilt = 0.0; // angle of the slit
    3340
    34   if ((N = get_argument (argc, argv, "-trace"))) {
    35     remove_argument (N, &argc, argv);
    36     if ((trace = FindSpline (argv[N])) == NULL) return (FALSE);
     41  // for a red vs blu spline, we need to specify the split point
     42  // XXX this is REALLY ad-hoc for Deimos.  not sure how to make
     43  // this more generic (need to define the ranges somewhere)
     44  int redlimit = 4096;
     45  if ((N = get_argument (argc, argv, "-redlimit"))) {
     46    remove_argument (N, &argc, argv);
     47    redlimit = atoi (argv[N]);
     48    remove_argument (N, &argc, argv);
     49  }
     50
     51  if ((N = get_argument (argc, argv, "-slit-trace-red"))) {
     52    remove_argument (N, &argc, argv);
     53    if ((slit_trace_red = FindSpline (argv[N])) == NULL) return (FALSE);
     54    remove_argument (N, &argc, argv);
     55  }
     56  if ((N = get_argument (argc, argv, "-slit-trace-blu"))) {
     57    remove_argument (N, &argc, argv);
     58    if ((slit_trace_blu = FindSpline (argv[N])) == NULL) return (FALSE);
     59    remove_argument (N, &argc, argv);
     60  }
     61  if ((N = get_argument (argc, argv, "-psf-trace"))) {
     62    remove_argument (N, &argc, argv);
     63    if ((psf_trace = FindSpline (argv[N])) == NULL) return (FALSE);
    3764    remove_argument (N, &argc, argv);
    3865  }
     
    81108  }
    82109
     110  int VERBOSE = FALSE;
     111  if ((N = get_argument (argc, argv, "-v"))) {
     112    remove_argument (N, &argc, argv);
     113    VERBOSE = TRUE;
     114  }
     115
    83116  if (argc != 3) {
    84     gprint (GP_ERR, "USAGE: deimos mkobj (buffer) (Ncross) [-Nwave N] [-object vector] [-sky vector] [-backgnd vector] [-trace spline] [-profile vector]\n");
     117    gprint (GP_ERR, "USAGE: deimos mkobj (buffer) (Ncross) [-object vector] [-sky vector] [-backgnd vector] [-slit-trace-red spline] [-slit-trace-blu spline] [-psf-trace spline] [-profile vector] [-psf vector] [-lsf vector] [-stilt angle] [-Nwave Npixel] [-redlimit pixel]\n");
     118    gprint (GP_ERR, "  slit_trace_red : spline fit of slit central x pos vs y-coord for red chip\n");
     119    gprint (GP_ERR, "  slit_trace_blu : spline fit of slit central x pos vs y-coord for blu chip\n");
     120    gprint (GP_ERR, "  psf_trace      : spline fit of psf central x pos vs y-coord\n");
     121    gprint (GP_ERR, "  profile        : slit window profile (vector)\n");
     122    gprint (GP_ERR, "  object         : vector of object flux vs y-coord \n");
     123    gprint (GP_ERR, "  sky            : vector of local sky signal vs y-coord\n");
     124    gprint (GP_ERR, "  backgnd        : vector of extra-slit background flux vs y-coord\n");
     125    gprint (GP_ERR, "  PSF            : point-spread function vector (flux normalized, x-dir)\n");
     126    gprint (GP_ERR, "  LSF            : sline-spread function vector (flux normalized, y-dir)\n");
     127    gprint (GP_ERR, "  stilt          : slit tilt response : 2D kernel? \n");
     128    gprint (GP_ERR, "  redlimit       : pixel break between red and blu chips\n");
     129    gprint (GP_ERR, "  Nwave          : number of wavelength pixels in output image\n");
    85130    return FALSE;
    86131  }
     
    123168  // if we are appying a trace offset spline, we need to generate an output window which
    124169  // is Nx + the full swing of the trace, then window back down
    125   if (trace) {
     170  if (slit_trace_red && slit_trace_blu) {
    126171    float dXmin = +1000;
    127172    float dXmax = -1000;
    128173    for (int iy = 0; iy < Ny; iy++) {
    129174      // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center
    130       float dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy);
     175      Spline *slit_trace = (iy < redlimit) ? slit_trace_red : slit_trace_blu;
     176      float dx = spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy);
    131177      dXmin = MIN (dx, dXmin);
    132178      dXmax = MAX (dx, dXmax);
     
    181227    if (psf) Npof -= Npsf;
    182228
     229    // integral and fractional pixel offsets of PSF (none, by default)
     230    int dxi = 0;
     231    float dxf = 0.0, dxr = 1.0;
     232   
     233    if (psf_trace) {
     234      float dx = spline_apply_dbl (psf_trace->xk, psf_trace->yk, psf_trace->y2, psf_trace->Nknots, iy);
     235      dxi = floor(dx);
     236      dxf = dx - dxi;  // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7
     237      dxr = 1 - dxf;
     238      Npof += dxi;
     239      // fprintf (stderr, "%d: %f : %d\n", iy, dx, Npof);
     240      if (VERBOSE && (iy % 200 == 0)) { gprint (GP_ERR, "%d : %f : %d : %f %f\n", iy, dx, dxi, dxf, dxr); }
     241    }
     242
     243    // if fractional offset is small, do not interpolate
     244    int doInterp = fabs(dxf) < 1e-5 ? FALSE : TRUE;
     245
    183246    // flux = obj * PSF + sky
    184247    for (int ix = 0; ix < Nx; ix++) {
     
    191254        // only add in the flux if we are in range of the PSF
    192255        if ((n >= 0) && (n < NpsfFull)) {
    193           value += objVy * psfV[n];
     256          if (doInterp) {
     257            if ((n > 0) && (n < NpsfFull)) {
     258              if (isfinite(psfV[n]) && isfinite(psfV[n-1])) {
     259                value += objVy*psfV[n]*dxr + objVy*psfV[n-1]*dxf;
     260              }
     261            }
     262            if (n == 0) {
     263              if (isfinite(psfV[n])) {
     264                value += objVy*psfV[n]*dxr;
     265              }
     266            }
     267          } else {
     268            if (isfinite(psfV[n])) {
     269              value += objVy*psfV[n];
     270            }
     271          }
    194272        }
    195273      } else {
     
    329407
    330408  // shift pixels in x based on the trace
    331   if (trace) {
     409  if (slit_trace_red && slit_trace_blu) {
    332410    ALLOCATE_PTR (outTraceBuffer, char, NxBase*Ny*sizeof(float));
    333411    float *outTrace = (float *) outTraceBuffer;
     
    337415
    338416      // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center
    339       float dx = -spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy);
     417      Spline *slit_trace = (iy < redlimit) ? slit_trace_red : slit_trace_blu;
     418      float dx = -spline_apply_dbl (slit_trace->xk, slit_trace->yk, slit_trace->y2, slit_trace->Nknots, iy);
    340419     
    341420      // extract the integer pixel offset and the fractional offset
Note: See TracChangeset for help on using the changeset viewer.