IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40622 for trunk


Ignore:
Timestamp:
Feb 8, 2019, 8:20:03 PM (7 years ago)
Author:
eugene
Message:

add deimos fitslit, mkobj, mkslit commands

Location:
trunk/Ohana/src/opihi/mana
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/mana/Makefile

    r12842 r40622  
    2121$(SRC)/init.$(ARCH).o \
    2222$(SRC)/mana.$(ARCH).o \
     23$(SRC)/deimos_mkobj.$(ARCH).o \
     24$(SRC)/deimos_mkslit.$(ARCH).o \
     25$(SRC)/deimos_fitslit.$(ARCH).o \
    2326$(SRC)/findrowpeaks.$(ARCH).o
    2427
    2528cmds = \
     29$(SRC)/deimos.$(ARCH).o \
    2630$(SRC)/rawstars.$(ARCH).o \
    2731$(SRC)/fitcontour.$(ARCH).o \
  • trunk/Ohana/src/opihi/mana/deimos.c

    r40617 r40622  
    11# include "data.h"
    22
    3 int deimos_list (int argc, char **argv);
     3int deimos_mkslit (int argc, char **argv);
     4int deimos_fitslit (int argc, char **argv);
     5int deimos_mkobj (int argc, char **argv);
    46
    5 static Command book_commands[] = {
    6   {1, "list",     book_list,     "list books"},
     7static Command deimos_commands[] = {
     8  {1, "mkobj", deimos_mkobj, "make a full object image"},
     9  {1, "mkslit", deimos_mkslit, "make a slit image"},
     10  {1, "fitslit", deimos_fitslit, "fit slit image to observed slit flux"},
    711};
    812
    9 int book_command (int argc, char **argv) {
     13int deimos (int argc, char **argv) {
    1014
    1115  int i, N, status;
    1216
    1317  if (argc < 2) {
    14     gprint (GP_ERR, "USAGE: book (command)\n");
    15     gprint (GP_ERR, "    book list                                  : list books\n");
     18    gprint (GP_ERR, "USAGE: deimos (command)\n");
     19    gprint (GP_ERR, "    deimos mkslit : make slit image\n");
    1620    return (FALSE);
    1721  }
    1822
    19   N = sizeof (book_commands) / sizeof (Command);
     23  N = sizeof (deimos_commands) / sizeof (Command);
    2024
    21   /* find the book sub-command which matches */
     25  /* find the deimos sub-command which matches */
    2226  for (i = 0; i < N; i++) {
    23     if (!strcmp (book_commands[i].name, argv[1])) {
    24       status = (*book_commands[i].func) (argc - 1, argv + 1);
     27    if (!strcmp (deimos_commands[i].name, argv[1])) {
     28      status = (*deimos_commands[i].func) (argc - 1, argv + 1);
    2529      return (status);
    2630    }
    2731  }
    2832
    29   gprint (GP_ERR, "unknown book command %s\n", argv[1]);
     33  gprint (GP_ERR, "unknown deimos command %s\n", argv[1]);
    3034  return (FALSE);
    3135}
  • trunk/Ohana/src/opihi/mana/deimos_commands.c

    r40617 r40622  
    22
    33int deimos_mkslit (int argc, char **argv) {
    4   OHANA_UNUSED_PARAM(argv);
    5   if (argc != 5) {
    6     gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace) (flux) (buffer)\n");
    7     return FALSE;
    8   }
    94
    105  // generate model observed flux given a uniformly illuminated slit
     
    1611
    1712  Vector *profile = NULL;
    18   Vector *flux = NULL;
    19   Spline *trace = NULL;
    20   Buffer *buff = NULL;
     13  Vector *flux    = NULL;
     14  Vector *sky     = NULL;
     15  Spline *trace   = NULL;
     16  Buffer *buff    = NULL;
     17
     18  // user-specified flux value (otherwise assumed to be 1)
     19  if ((N = get_argument (argc, argv, "-flux"))) {
     20    remove_argument (N, &argc, argv);
     21    if ((flux = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     22    remove_argument (N, &argc, argv);
     23  }
     24
     25  // user-specified sky value (otherwise assumed to be 0)
     26  if ((N = get_argument (argc, argv, "-sky"))) {
     27    remove_argument (N, &argc, argv);
     28    if ((sky = SelectVector (argv[N], OLDVECTOR, TRUE)) == NULL) return (FALSE);
     29    remove_argument (N, &argc, argv);
     30  }
     31
     32  // either flux or fluxbins must be specified to define output size
     33  int fluxbins = 0;
     34  if ((N = get_argument (argc, argv, "-fluxbins"))) {
     35    remove_argument (N, &argc, argv);
     36    Nrows = atoi (argv[N]);
     37    remove_argument (N, &argc, argv);
     38  }
     39
     40  if (argc != 4) {
     41    gprint (GP_ERR, "USAGE: deimos mkslit (profile) (trace) (buffer) [-flux vector] [-fluxbins N] [-sky vector]\n");
     42    return FALSE;
     43  }
     44
     45  if (!flux && !fluxbins) {
     46    gprint (GP_ERR, "either flux or fluxbins must be specified to define output size\n");
     47    return FALSE;
     48  }
    2149
    2250  // XXX I probably should rename FindSpline as SelectSpline and give it the same behavior
    2351  if ((profile = SelectVector (argv[1], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    2452  if ((trace   = FindSpline (argv[2])) == NULL) return (FALSE);
    25   if ((flux    = SelectVector (argv[3], OLDVECTOR, TRUE)) == NULL) return (FALSE);
    26   if ((buff    = SelectBuffer (argv[4], ANYBUFFER, TRUE)) == NULL) return (FALSE);
    27  
     53  if ((buff    = SelectBuffer (argv[3], ANYBUFFER, TRUE)) == NULL) return (FALSE);
     54
    2855  // define the output window
    2956  int Nx = 2*profile[0].Nelements;
    30   int Ny = flux[0].Nelements;
     57  int Ny = flux ? flux[0].Nelements : fluxbins;
    3158 
    3259  ResetBuffer (buff, Nx, Ny, -32, 0.0, 1.0);
    33  
     60
     61  // the profile is registered to the midpoint of the vector : (int) N / 2
     62  // the output window is registered to the midpoint of the window : (int) Nx / 2
     63
     64  int NxMidProfile = profile->Nelements / 2;
     65  int NxMidWindow  = Nx / 2;
     66
     67  float *out = (float *) buff[0].matrix.buffer;
    3468
    3569  // loop over the y positions
    36   for (iy = 0; iy < flux->Nelements; iy++) {
     70  for (int iy = 0; iy < Ny; iy++) {
    3771
    38     // evaluate the trace spline at this y-coord to find the x-coord of the profile center
    39     opihi_flt dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy);
     72    // evaluate the trace spline at this y-coord to find the x-coord offset of the profile center
     73    float dx = spline_apply_dbl (trace->xk, trace->yk, trace->y2, trace->Nknots, iy);
    4074   
    41     // interpolate the profile with offset of dx
    42     for (ix = 0; ix < profile->Nelements; ix++) {
    43       // interpolate from profile->elements.Flt[ix], interpolate from profile->elements.Flt[ix+1] to ix+dx
     75    // extract the integer pixel offset and the fractional offset
     76    int dxi = floor(dx); // -1.7 -> -2, -0.5 -> -1, +0.5 -> 0, +1.7 -> 1
     77    float dxf = dx - dxi;  // -1.7 -> +0.3, -0.5 -> +0.5, +0.5 ->+0.5, +1.7 -> +0.7
     78
     79    // starting point in output window is :
     80    // XXX handle case if profile is wider than window
     81    int Sx = (int)(NxMidWindow - NxMidProfile) + dxi;
     82
     83    // if fractional offset is small, do not interpolate
     84    int doInterp = fabs(dxf) < 1e-5 ? FALSE : TRUE;
     85
     86    // loop over the relevant pixels in the window:
     87    for (int ix = 0; ix < Nx; ix++) {
     88
     89      // equivalent coord in the profile:
     90      int px = ix - Sx;
     91      if (px < 0) continue;
     92      if (px >= profile->Nelements) continue;
     93
     94      float vout = NAN;
     95
     96      if (doInterp) {
     97        if ((px > 0) && (px < profile->Nelements - 1)) {
     98          // if ((px == 5) && (iy % 50 == 0)) {
     99          //   fprintf (stderr, "%d : %d %d : %d, %f\n", iy, Sx, px, dxi, dxf);
     100          // }
     101          // XXX something is not quite right in my math: I think (1-dx), dx are reversed
     102          // but if I use what I expect the interpolation is backwards...
     103          vout = profile->elements.Flt[px]*(1 - dxf) + profile->elements.Flt[px-1]*dxf;
     104        }
     105        if (px == 0) {
     106          vout = profile->elements.Flt[px]*dxf;
     107        }
     108        if (px == profile->Nelements - 1) {
     109          vout = profile->elements.Flt[profile->Nelements - 1]*(1.0 - dxf);
     110        }
     111      } else {
     112        vout = profile->elements.Flt[px];
     113      }
     114
     115      if (flux) vout *= flux->elements.Flt[iy];
     116      if (sky) vout += sky->elements.Flt[iy];
     117
     118      out[ix + iy*Nx] = vout;
    44119    }
    45 
    46120  }
    47121
  • trunk/Ohana/src/opihi/mana/init.c

    r16448 r40622  
    11# include "opihi.h"
    22
     3int deimos          PROTO((int, char **));
    34int findpeaks       PROTO((int, char **));
    45int fitcontour      PROTO((int, char **));
     
    89
    910static Command cmds[] = { 
     11  {1, "deimos",      deimos,       "deimos multislit spectrograph tools"},
    1012  {1, "findpeaks",   findpeaks,    "find image peaks"},
    1113  {1, "fitcontour",  fitcontour,   "fit ellipse contour"},
Note: See TracChangeset for help on using the changeset viewer.