IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 9, 2019, 4:40:10 PM (7 years ago)
Author:
eugene
Message:

allow the extraction and the cut to extend beyond the valid image pixels (and fill with nan values)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20190329/src/opihi/cmd.data/cut.c

    r40812 r40830  
    11# include "data.h"
    22
    3 enum {SUM, MEAN, MEDIAN, INNER};
     3enum {SUM, MEAN, MEDIAN, INNER, NGOOD};
    44
    55double cutstat (float *value, int Nvalue, int mode) {
     
    5050    return output;
    5151  }
     52  if (mode == NGOOD) {
     53    return Nvalue;
     54  }
    5255  if ((mode == MEAN) || (mode == SUM)) {
    5356    for (int i = 0; i < Nvalue; i++) {
     
    7073
    7174  Mode = SUM;
     75  if ((N = get_argument (argc, argv, "-sum"))) {
     76    remove_argument (N, &argc, argv);
     77    Mode = SUM;
     78  }
    7279  if ((N = get_argument (argc, argv, "-median"))) {
    7380    remove_argument (N, &argc, argv);
     
    8188    remove_argument (N, &argc, argv);
    8289    Mode = INNER;
     90  }
     91  if ((N = get_argument (argc, argv, "-ngood"))) {
     92    remove_argument (N, &argc, argv);
     93    Mode = NGOOD;
    8394  }
    8495
     
    98109  Ny = buf[0].matrix.Naxis[1];
    99110
    100   if ((sx < 0) || (sy < 0) || (sx+nx > Nx) || (sy+ny > Ny)) {
    101     gprint (GP_ERR, "region out of range\n");
     111  // ny & nx do not need to be constrained by the buffer, but they do need to be sensible
     112  if ((nx < 0) || (ny < 0) || (nx > 1e8) || (ny > 1e8)) {
     113    gprint (GP_ERR, "warning : extraction size is crazy: %d,%d\n", nx, ny);
    102114    return (FALSE);
    103115  }
     
    119131
    120132    for (i = 0; i < nx; i++) {
     133      // for out-of-range areas, set the output pixels to NAN
     134      if (i + sx < 0) {
     135        yvec[0].elements.Flt[i] = NAN;
     136        continue;
     137      }
     138      if (i + sx >= Nx) {
     139        yvec[0].elements.Flt[i] = NAN;
     140        continue;
     141      }
     142
    121143      /* accumulate values */
     144      // skip out-of-range areas in y
     145      if (sy < 0) {
     146        ny += sy;
     147        sy = 0;
     148      }
     149      if (sy > Ny) sy = Ny;
     150      if (sy + ny >= Ny) ny = Ny - sy;
     151
    122152      Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i;
    123153      int Npix = 0;
    124154      for (j = 0; j < ny; j++, Vin += Nx) {
    125155        if (!isfinite(*Vin)) continue;
    126         Vbuf[j] = *Vin;
     156        Vbuf[Npix] = *Vin;
    127157        Npix ++;
    128158      }
     
    143173
    144174    for (i = 0; i < ny; i++) {
     175      // for out-of-range areas, set the output pixels to NAN
     176      if (i + sy < 0) {
     177        yvec[0].elements.Flt[i] = NAN;
     178        continue;
     179      }
     180      if (i + sy >= Ny) {
     181        yvec[0].elements.Flt[i] = NAN;
     182        continue;
     183      }
     184
    145185      /* accumulate values */
     186      // skip out-of-range areas in x
     187      if (sx < 0) {
     188        nx += sx;
     189        sx = 0;
     190      }
     191      if (sx > Nx) sx = Nx;
     192      if (sx + nx >= Nx) nx = Nx - sx;
     193
    146194      Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx;
    147195      int Npix = 0;
    148196      for (j = 0; j < nx; j++, Vin ++) {
    149197        if (!isfinite(*Vin)) continue;
    150         Vbuf[j] = *Vin;
     198        Vbuf[Npix] = *Vin;
    151199        Npix ++;
    152200      }
Note: See TracChangeset for help on using the changeset viewer.