IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37869


Ignore:
Timestamp:
Jan 19, 2015, 11:27:34 AM (12 years ago)
Author:
eugene
Message:

various updates to handle 3D cubes better

Location:
branches/eam_branches/ipp-20150112/Ohana/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150112/Ohana/src/kapa2/src/InterpretKeys.c

    r37807 r37869  
    9898      Screen_to_Image (&X, &Y, (double)(event[0].x + 0.5), (double)(event[0].y + 0.5), &image[0].picture); \
    9999      UpdateStatusBox (graphic, image, X, Y, 0.0, 1); \
     100      Remap (graphic, image); \
    100101      break;
    101 
    102 //    Remap (graphic, image);
    103102
    104103    // the number of entries here must match the value of NCHANNELS in contants.h
  • branches/eam_branches/ipp-20150112/Ohana/src/libfits/include/gfitsio.h

    r37807 r37869  
    147147
    148148int     gfits_init_matrix              PROTO((Matrix *matrix));
     149off_t   gfits_npix_matrix              PROTO((Matrix *matrix));
    149150void    gfits_add_matrix_value         PROTO((Matrix *matrix, off_t x, off_t y, double value));
    150151int     gfits_convert_format           PROTO((Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign));
  • branches/eam_branches/ipp-20150112/Ohana/src/libfits/matrix/F_convert_format.c

    r27435 r37869  
    9090
    9191/*********************** fits convert format ***********************************/
     92/* this function is safe in the number of axes (can even be 0) */
    9293int gfits_convert_format (Header *header, Matrix *matrix, int outBitpix, double outScale, double outZero, int inBlank, int outUnsign) {
    9394
    94   unsigned long i, nbytes, Npixels;
     95  off_t i, nbytes;
    9596  int    inBitpix, inUnsign;
    9697  double inScale, inZero;
     
    116117  gfits_modify_alt (header, "UNSIGN", "%t", 1, outUnsign);
    117118
    118   Npixels          = header[0].Naxis[0]*header[0].Naxis[1];
    119   nbytes           = Npixels * (abs(outBitpix) / 8);
     119  off_t Npixels = gfits_npix_matrix (matrix);
     120  nbytes                = Npixels * (abs(outBitpix) / 8);
    120121
    121122  A = inScale / outScale;
  • branches/eam_branches/ipp-20150112/Ohana/src/libfits/matrix/F_create_M.c

    r35756 r37869  
    4343}
    4444
    45 // XXX free buffer if non-null: need to double check for existing frees
     45/*********************** return number of valid pixels *******************************/
     46off_t gfits_npix_matrix (Matrix *matrix) {
     47
     48  if (!matrix->Naxes) return 0;
     49
     50  int i;
     51  int Npix = 1;
     52  for (i = 0; i < matrix->Naxes; i++) {
     53    if (matrix->Naxis[i] == 0) break;
     54    Npix *= matrix->Naxis[i];
     55  }
     56  return Npix;
     57}
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/mcreate.c

    r9275 r37869  
    33int mcreate (int argc, char **argv) {
    44 
    5   int Nx, Ny;
     5  int N;
    66  Buffer *buf;
    77
     8  int Nz = 0;
     9  if ((N = get_argument (argc, argv, "-nz"))) {
     10    remove_argument (N, &argc, argv);
     11    Nz = atoi (argv[N]);
     12    remove_argument (N, &argc, argv);
     13  }
     14
    815  if (argc != 4) {
    9     gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny\n");
     16    gprint (GP_ERR, "USAGE: mcreate <buffer> Nx Ny [-nz Nz]\n");
    1017    return (FALSE);
    1118  }
    1219
    1320  if ((buf = SelectBuffer (argv[1], ANYBUFFER, TRUE)) == NULL) return (FALSE);
    14   Nx = atof (argv[2]);
    15   Ny = atof (argv[3]);
     21  int Nx = atof (argv[2]);
     22  int Ny = atof (argv[3]);
    1623
    1724  /* I should encapsulate this in a create_default_buffer */
    1825  gfits_free_matrix (&buf[0].matrix);
    1926  gfits_free_header (&buf[0].header);
    20   CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0);
     27
     28  if (Nz) {
     29    CreateBuffer3D (buf, Nx, Ny, Nz, -32, 1.0, 0.0);
     30  } else {
     31    CreateBuffer (buf, Nx, Ny, -32, 1.0, 0.0);
     32  }
    2133  return (TRUE);
    2234}
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/rd.c

    r29938 r37869  
    44int rd (int argc, char **argv) {
    55 
    6   int i, N, status, plane, Nplane, extend, Nextend, Nskip, JustHead, blank;
    7   int ccdsel, done, Nword, IsCompressed;
    8   char region[512], *ccdid, *filename;
    9   FILE *f;
     6  int i, N, Nskip, blank;
     7  int done, Nword;
     8  char region[512];
    109  Buffer *buf;
    1110
    12   JustHead = FALSE;
     11  int JustHead = FALSE;
    1312  if ((N = get_argument (argc, argv, "-head"))) {
    1413    remove_argument (N, &argc, argv);
     
    1615  }
    1716
    18   plane = 1;
     17  int plane = -1;
    1918  if ((N = get_argument (argc, argv, "-plane"))) {
    2019    remove_argument (N, &argc, argv);
     
    2322  }
    2423
    25   extend = FALSE;
    26   Nextend = -1;
     24  int extend = FALSE;
     25  int Nextend = -1;
    2726  if ((N = get_argument (argc, argv, "-x"))) {
    2827    remove_argument (N, &argc, argv);
     
    3231  }
    3332
    34   ccdsel = FALSE;
    35   ccdid = (char *) NULL;
     33  int ccdsel = FALSE;
     34  char *ccdid = NULL;
    3635  if ((N = get_argument (argc, argv, "-n"))) {
    3736    remove_argument (N, &argc, argv);
     
    5251
    5352  /* test if file exists */
    54   f = fopen (argv[2], "r");
     53  FILE *f = fopen (argv[2], "r");
    5554  if (f == (FILE *) NULL) {
    5655    gprint (GP_ERR, "file %s not found\n", argv[2]);
     
    6766
    6867  /* save file name */
    69   filename = filebasename (argv[2]);
     68  char *filename = filebasename (argv[2]);
    7069  strcpy (buf[0].file, filename);
    7170  free (filename);
    7271
    73   status = FALSE;
    74   IsCompressed = FALSE;
     72  int status = FALSE;
     73  int IsCompressed = FALSE;
    7574
    7675  /*** advance to the correct FITS extension ***/
     
    168167
    169168  /* check for valid plane */
    170   Nplane = buf[0].header.Naxis[2];
    171   if (Nplane == 0) Nplane = 1;
    172   if (plane > Nplane) {
    173     gprint (GP_ERR, "-plane is too large: %d total planes\n", Nplane);
    174     DeleteBuffer (buf);
    175     fclose (f);
    176     return (FALSE);
     169  int Nz = buf[0].header.Naxis[2];
     170  if (plane >= 0) {
     171    // we are requesting a specific plane (-1 : all data)
     172    int tooFar = Nz ? (plane >= Nz) : (plane > Nz);
     173    if (tooFar) {
     174      gprint (GP_ERR, "-plane is too large: %d total planes\n", Nz);
     175      DeleteBuffer (buf);
     176      fclose (f);
     177      return (FALSE);
     178    }
    177179  }
    178180
    179181  /* load matrix data */
    180182  if (IsCompressed) {
     183    if (plane > -1) {
     184      gprint (GP_ERR, "-plane incompatible with compressed image\n");
     185      DeleteBuffer (buf);
     186      fclose (f);
     187      return (FALSE);
     188    }
    181189    FTable ftable;
    182190    Header theader;
     
    191199    // XXX this currently does not work for a cube (we get a cube back, not a specific plane)
    192200  } else {
    193     sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
    194     status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     201    if (plane > -1) {
     202      // read a single plane into a 2D image
     203      sprintf (region, "-1 -1 -1 -1 %d %d", (plane - 1), plane);
     204      status = gfits_fread_matrix_segment (f, &buf[0].matrix, &buf[0].header, region);
     205      buf[0].header.Naxis[2] = 0;
     206      buf[0].header.Naxes = 2;
     207      gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
     208      gfits_modify (&buf[0].header, "NAXIS3", "%d", 1, 0);
     209    } else {
     210      status = gfits_fread_matrix (f, &buf[0].matrix, &buf[0].header);
     211    }
    195212  }
    196213  fclose (f);
     
    200217    DeleteBuffer (buf);
    201218    return (FALSE);
    202   }
    203 
    204   /* adjust buffer to represent 2D data */
    205   if (Nplane > 1) {
    206     buf[0].header.Naxis[2] = 0;
    207     buf[0].header.Naxes = 2;
    208     gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
    209     gfits_delete (&buf[0].header, "NAXIS3", 1);
    210219  }
    211220
     
    215224    buf[0].header.Naxis[1] = 1;
    216225    buf[0].matrix.Naxis[1] = 1;
     226    gfits_modify (&buf[0].header, "NAXIS", "%d", 1, 2);
     227    gfits_modify (&buf[0].header, "NAXIS2", "%d", 1, 1);
    217228  }   
    218229
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/tv.c

    r37807 r37869  
    2828  }
    2929
     30  int plane = 0;
     31  if ((N = get_argument (argc, argv, "-plane"))) {
     32    remove_argument (N, &argc, argv);
     33    plane = atoi (argv[N]);
     34    remove_argument (N, &argc, argv);
     35  }
     36  if (plane < 0) {
     37    gprint (GP_ERR, " ERROR: -plane (plane) : cannot be negative\n");
     38    return (FALSE);
     39  }
     40
    3041  /* shell exits on pipe close, FIX */
    3142  if ((N = get_argument (argc, argv, "-kill"))) {
     
    5566  GetCoords (&coords, &buf[0].header);
    5667 
    57   image.data1d = (float *) buf[0].matrix.buffer;
    5868  image.Nx = buf[0].matrix.Naxis[0];
    5969  image.Ny = buf[0].matrix.Naxis[1];
     70
     71  int tooBig = buf[0].matrix.Naxis[2] ? (plane >= buf[0].matrix.Naxis[2]) : plane > 0;
     72  if (tooBig) {
     73    gprint (GP_ERR, " ERROR: -plane (plane) : out of bounds (%d vs %d)\n", plane, buf[0].matrix.Naxis[2]);
     74    return (FALSE);
     75  }
     76  int Npix2D = image.Nx * image.Ny;
     77
     78  float *imdata = (float *) buf[0].matrix.buffer;
     79  image.data1d = &imdata[plane*Npix2D];
    6080
    6181  // send only the root of the file, not the full path
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/cmd.data/wd.c

    r27435 r37869  
    8181  memcpy (temp_header.buffer, buf[0].header.buffer, temp_header.datasize);
    8282
    83   if (temp_header.Naxes) {
    84     // the inBlank value probably does not matter: temp_matrix is float, so nan is used
    85     gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign);
    86   } else {
    87     gfits_modify (&temp_header, "BITPIX", "%d", 1, outBitpix);
    88     gfits_modify (&temp_header, "BSCALE", "%lf", 1, outScale);
    89     gfits_modify (&temp_header, "BZERO",  "%lf", 1, outZero);
    90     gfits_modify_alt (&temp_header, "UNSIGN", "%t", 1, outUnsign);
    91   }
     83  gfits_convert_format (&temp_header, &temp_matrix, outBitpix, outScale, outZero, 0xffff, outUnsign);
    9284
     85  // Extend puts the output matrix in the first available non-PHU slot (ie, the last one)
     86  // it updates NEXTEND and set EXTEND to TRUE, and modifies the PHU header (neither should happen)
     87  // if those keywords do not exist...
    9388  if (Extend) {
    9489    Header Xhead;
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/BufferOps.c

    r37855 r37869  
    120120}
    121121 
     122// buffer is 1D array referenced in the order:
     123// buffer[x + Nx*y + Nx*Ny*z + ...]
    122124int CreateBuffer3D (Buffer *buf, int Nx, int Ny, int Nz, int bitpix, float bzero, float bscale) {
    123125
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r36679 r37869  
    6060    if (!strcmp (argv[i], "xramp"))  { type = ST_UNARY; goto gotit; }
    6161    if (!strcmp (argv[i], "yramp"))  { type = ST_UNARY; goto gotit; }
     62    if (!strcmp (argv[i], "zramp"))  { type = ST_UNARY; goto gotit; }
    6263    if (!strcmp (argv[i], "ramp"))   { type = ST_UNARY; goto gotit; }
    6364    if (!strcmp (argv[i], "zero"))   { type = ST_UNARY; goto gotit; }
  • branches/eam_branches/ipp-20150112/Ohana/src/opihi/lib.shell/stack_math.c

    r37857 r37869  
    127127int MMM_trinary (StackVar *OUT, StackVar *V1, StackVar *V2, StackVar *V3, char *op) {
    128128
    129   int i, Npix;
     129  int i;
    130130  float *out, *M1, *M2, *M3;
    131131  char line[512]; // this is only used to report an error
    132132 
    133   Npix = 1;
    134   for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) {
    135     if (V1[0].buffer[0].matrix.Naxis[i] == 0) break;
    136     Npix *= V1[0].buffer[0].matrix.Naxis[i];
    137   }
     133  int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix);
    138134 
    139135  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
     
    725721int MM_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
    726722
    727   int i, Npix;
     723  int i;
    728724  float *out, *M1, *M2;
    729725  char line[512]; // this is only used to report an error
    730726 
    731   Npix = 1;
    732   for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) {
    733     if (V1[0].buffer[0].matrix.Naxis[i] == 0) break;
    734     Npix *= V1[0].buffer[0].matrix.Naxis[i];
    735   }
     727  int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix);
    736728 
    737729  if (V1[0].type == ST_MATRIX_TMP) {  /** use V1 as temp buffer **/
     
    809801int MS_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
    810802
    811   int i, Npix;
     803  int i;
    812804  char line[512]; // this is only used to report an error
    813805 
    814   Npix = 1;
    815   for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) {
    816     if (V1[0].buffer[0].matrix.Naxis[i] == 0) break;
    817     Npix *= V1[0].buffer[0].matrix.Naxis[i];
    818   }
     806  int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix);
    819807
    820808  /* if possible, use V1 as temp buffer, otherwise create new one */
     
    890878int SM_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
    891879
    892   int i, Npix;
     880  int i;
    893881  char line[512]; // this is only used to report an error
    894882 
    895   Npix = 1;
    896   for (i = 0; i < V2[0].buffer[0].matrix.Naxes; i++) {
    897     if (V2[0].buffer[0].matrix.Naxis[i] == 0) break;
    898     Npix *= V2[0].buffer[0].matrix.Naxis[i];
    899   }
     883  int Npix = gfits_npix_matrix (&V2[0].buffer[0].matrix);
    900884 
    901885  if (V2[0].type == ST_MATRIX_TMP) {  /* V2[0] is NOT temporary, we can't use it for storage */
     
    12521236  if (!strcmp (op, "xramp"))  V_FUNC(i, ST_SCALAR_INT);
    12531237  if (!strcmp (op, "yramp"))  V_FUNC(0, ST_SCALAR_INT);
    1254   /* xramp and yramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */
     1238  if (!strcmp (op, "zramp"))  V_FUNC(0, ST_SCALAR_INT);
     1239  /* xramp, yramp, zramp above only make sense for matrices. for vectors, xramp = ramp, yramp = zero */
    12551240
    12561241# undef V_FUNC
     
    12711256int M_unary (StackVar *OUT, StackVar *V1, char *op) {
    12721257
    1273   int i, j, Npix;
     1258  int i, j, k;
    12741259  float *out, *M1;
    12751260 
    1276   Npix = 1;
    1277   for (i = 0; i < V1[0].buffer[0].matrix.Naxes; i++) {
    1278     if (V1[0].buffer[0].matrix.Naxis[i] == 0) break;
    1279     Npix *= V1[0].buffer[0].matrix.Naxis[i];
    1280   }
     1261  int Npix = gfits_npix_matrix (&V1[0].buffer[0].matrix);
    12811262 
    12821263  if (V1[0].type == ST_MATRIX_TMP) {
     
    13361317    int Nx = V1[0].buffer[0].matrix.Naxis[0];
    13371318    int Ny = V1[0].buffer[0].matrix.Naxis[1];
    1338     for (j = 0; j < Ny; j++) {
    1339       for (i = 0; i < Nx; i++, out++, M1++) {
    1340         *out = i;
     1319    int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]);
     1320    for (k = 0; k < Nz; k++) {
     1321      for (j = 0; j < Ny; j++) {
     1322        for (i = 0; i < Nx; i++, out++, M1++) {
     1323          *out = i;
     1324        }
    13411325      }
    13421326    }
     
    13451329    int Nx = V1[0].buffer[0].matrix.Naxis[0];
    13461330    int Ny = V1[0].buffer[0].matrix.Naxis[1];
    1347     for (j = 0; j < Ny; j++) {
    1348       for (i = 0; i < Nx; i++, out++, M1++) {
    1349         *out = j;
     1331    int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]);
     1332    for (k = 0; k < Nz; k++) {
     1333      for (j = 0; j < Ny; j++) {
     1334        for (i = 0; i < Nx; i++, out++, M1++) {
     1335          *out = j;
     1336        }
     1337      }
     1338    }
     1339  }
     1340  if (!strcmp (op, "zramp")) {
     1341    int Nx = V1[0].buffer[0].matrix.Naxis[0];
     1342    int Ny = V1[0].buffer[0].matrix.Naxis[1];
     1343    int Nz = MAX (1, V1[0].buffer[0].matrix.Naxis[2]);
     1344    for (k = 0; k < Nz; k++) {
     1345      for (j = 0; j < Ny; j++) {
     1346        for (i = 0; i < Nx; i++, out++, M1++) {
     1347          *out = k;
     1348        }
    13501349      }
    13511350    }
Note: See TracChangeset for help on using the changeset viewer.