IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40792


Ignore:
Timestamp:
Jun 12, 2019, 3:49:40 PM (7 years ago)
Author:
eugene
Message:

ignore inf/nan values in cut

File:
1 edited

Legend:

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

    r33662 r40792  
    5959      /* accumulate values */
    6060      Vin = (float *)(buf[0].matrix.buffer) + sy*Nx + sx + i;
     61      int Npix = 0;
    6162      for (j = 0; j < ny; j++, Vin += Nx) {
     63        if (!isfinite(*Vin)) continue;
    6264        Vbuf[j] = *Vin;
     65        Npix ++;
     66      }
     67      if (Npix == 0) {
     68        value = NAN;
     69        goto set_yvalue;
    6370      }
    6471      /* apply stat of choice */
    6572      if (Mode == MEDIAN) {
    66         fsort (Vbuf, ny);
    67         value = Vbuf[(int)(0.5*ny)];
     73        fsort (Vbuf, Npix);
     74        value = Vbuf[(int)(0.5*Npix)];
    6875      } else {
    6976        value = 0;
    70         for (j = 0; j < ny; j++) {
     77        for (j = 0; j < Npix; j++) {
    7178          value += Vbuf[j];
    7279        }
    73         if (Mode == MEAN) { value /= ny; }
     80        if (Mode == MEAN) { value /= Npix; }
    7481      }
     82    set_yvalue:
    7583      yvec[0].elements.Flt[i] = value;
    7684    }
     
    9199      /* accumulate values */
    92100      Vin = (float *)(buf[0].matrix.buffer) + (sy + i)*Nx + sx;
     101      int Npix = 0;
    93102      for (j = 0; j < nx; j++, Vin ++) {
     103        if (!isfinite(*Vin)) continue;
    94104        Vbuf[j] = *Vin;
     105        Npix ++;
     106      }
     107      if (Npix == 0) {
     108        value = NAN;
     109        goto set_xvalue;
    95110      }
    96111      /* apply stat of choice */
    97112      if (Mode == MEDIAN) {
    98         fsort (Vbuf, nx);
    99         value = Vbuf[(int)(0.5*nx)];
     113        fsort (Vbuf, Npix);
     114        value = Vbuf[(int)(0.5*Npix)];
    100115      } else {
    101116        value = 0;
    102         for (j = 0; j < nx; j++) {
     117        for (j = 0; j < Npix; j++) {
    103118          value += Vbuf[j];
    104119        }
    105         if (Mode == MEAN) { value /= nx; }
     120        if (Mode == MEAN) { value /= Npix; }
    106121      }
     122    set_xvalue:
    107123      yvec[0].elements.Flt[i] = value;
    108124    }
Note: See TracChangeset for help on using the changeset viewer.