Exemplo n.º 1
0
 /**
  * Treat the array as a variance. Normalise the sum against the number of elements in the array.
  *
  * @return double value
  */
 public double varianceSumNormalise() {
   double sum = Double.NaN;
   int countNaN = 0;
   IArrayIterator iterator = getArray().getIterator();
   while (iterator.hasNext()) {
     Double value = iterator.getDoubleNext();
     if (value.isNaN()) {
       countNaN++;
     } else {
       sum = value;
       break;
     }
   }
   while (iterator.hasNext()) {
     Double value = iterator.getDoubleNext();
     if (value.isNaN()) {
       countNaN++;
     } else {
       sum += value;
     }
   }
   if (Double.isNaN(sum)) {
     return sum;
   }
   double normaliseFactor = getArray().getSize() / Double.valueOf(getArray().getSize() - countNaN);
   return Double.valueOf(sum) * normaliseFactor * normaliseFactor;
 }
Exemplo n.º 2
0
 /**
  * Update the array with arc trigonometric of its values.
  *
  * @return Array itself Created on 11/12/2008
  */
 public IArrayMath atan() {
   IArrayIterator oldIterator = getArray().getIterator();
   while (oldIterator.hasNext()) {
     oldIterator.setDoubleCurrent(Math.atan(oldIterator.getDoubleNext()));
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 3
0
 /**
  * Update the array with arc cosine of its values.
  *
  * @return Array itself Created on 11/12/2008
  */
 public IArrayMath acos() {
   IArrayIterator iterator = getArray().getIterator();
   while (iterator.hasNext()) {
     iterator.setDoubleCurrent(Math.acos(iterator.getDoubleNext()));
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 4
0
 /**
  * Update the array with to a constant power of its values.
  *
  * @param power double value
  * @return Array itself Created on 11/12/2008
  */
 public IArrayMath power(double value) {
   IArrayIterator oldIterator = getArray().getIterator();
   while (oldIterator.hasNext()) {
     oldIterator.setDoubleCurrent(Math.pow(oldIterator.getDoubleNext(), value));
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 5
0
 /**
  * Update the array with adding a constant to its values.
  *
  * @param value double type
  * @return Array itself Created on 14/07/2008
  */
 public IArrayMath add(double val) {
   IArrayIterator iter = getArray().getIterator();
   while (iter.hasNext()) {
     iter.setDoubleCurrent(iter.getDoubleNext() + val);
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 6
0
 /**
  * Calculate the arc trigonometric value of each elements in the Array.
  *
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toAtan() {
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     newIterator.setDoubleNext(Math.atan(oldIterator.getDoubleNext()));
   }
   return result.getArrayMath();
 }
Exemplo n.º 7
0
 /**
  * Do an element-wise power calculation of the array. Yij = Xij ^ power.
  *
  * @param power double value
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toPower(double value) {
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     newIterator.setDoubleNext(Math.pow(oldIterator.getDoubleNext(), value));
   }
   return result.getArrayMath();
 }
Exemplo n.º 8
0
 /**
  * Modulo the array with a double value.
  *
  * @param value double type
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toMod(double value) {
   IArray result = getFactory().createArray(getArray().getElementType(), getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     newIterator.setDoubleNext(oldIterator.getDoubleNext() % value);
   }
   return result.getArrayMath();
 }
Exemplo n.º 9
0
 /**
  * Update the array with element-wise inverse of its values, skip zero values.
  *
  * @return Array itself Created on 11/12/2008
  */
 public IArrayMath eltInverseSkipZero() {
   IArrayIterator oldIterator = getArray().getIterator();
   while (oldIterator.hasNext()) {
     double det = oldIterator.getDoubleNext();
     oldIterator.setDoubleCurrent(det == 0 ? 0 : 1 / det);
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 10
0
 public double getMinimum() {
   IArrayIterator iter = getArray().getIterator();
   double min = Double.MAX_VALUE;
   while (iter.hasNext()) {
     double val = iter.getDoubleNext();
     if (Double.isNaN(val)) continue;
     if (val < min) min = val;
   }
   return min;
 }
Exemplo n.º 11
0
 public double getMaximum() {
   IArrayIterator iter = getArray().getIterator();
   double max = -Double.MAX_VALUE;
   while (iter.hasNext()) {
     double val = iter.getDoubleNext();
     if (Double.isNaN(val)) continue;
     if (val > max) max = val;
   }
   return max;
 }
Exemplo n.º 12
0
 /**
  * Do a element-wise inverse calculation that skip zero values. Yij = 1 / Xij.
  *
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toEltInverseSkipZero() {
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     double det = oldIterator.getDoubleNext();
     newIterator.setDoubleNext(det == 0 ? 0 : 1 / det);
   }
   return result.getArrayMath();
 }
Exemplo n.º 13
0
 /**
  * Add a value to the Array element-wisely.
  *
  * @param value double type
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toAdd(double value) {
   // [ANSTO][Tony][2011-08-30] Resulting array should be typed as double
   IArray result = getFactory().createArray(double.class, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     newIterator.setDoubleNext(oldIterator.getDoubleNext() + value);
   }
   return result.getArrayMath();
 }
Exemplo n.º 14
0
 /**
  * Update the array with element-wise inverse of its values.
  *
  * @return Array itself
  * @throws DivideByZeroException divided by zero Created on 11/12/2008
  */
 public IArrayMath eltInverse() throws DivideByZeroException {
   IArrayIterator oldIterator = getArray().getIterator();
   while (oldIterator.hasNext()) {
     try {
       oldIterator.setDoubleCurrent(1 / oldIterator.getDoubleNext());
     } catch (Exception e) {
       throw new DivideByZeroException(e);
     }
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 15
0
 /**
  * Update the array with element-wise logarithm (base 10) of its values.
  *
  * @return Array itself Created on 11/12/2008
  */
 public IArrayMath log10() {
   IArrayIterator oldIterator = getArray().getIterator();
   while (oldIterator.hasNext()) {
     double value = oldIterator.getDoubleNext();
     if (value == 0) {
       oldIterator.setDoubleCurrent(Double.NaN);
     } else {
       oldIterator.setDoubleCurrent(Math.log10(value));
     }
   }
   getArray().setDirty(true);
   return this;
 }
Exemplo n.º 16
0
 /**
  * Inverse every element of the array into a new storage.
  *
  * @return Array with new storage
  * @throws DivideByZeroException Created on 14/07/2008
  */
 public IArrayMath toEltInverse() throws DivideByZeroException {
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     try {
       newIterator.setDoubleNext(1 / oldIterator.getDoubleNext());
     } catch (Exception e) {
       throw new DivideByZeroException(e);
     }
   }
   return result.getArrayMath();
 }
Exemplo n.º 17
0
 /**
  * Calculate the sum value of the array. If an element is NaN, skip it.
  *
  * @return a double value Created on 14/07/2008
  */
 public double sum() {
   double sum = Double.NaN;
   IArrayIterator iterator = getArray().getIterator();
   while (iterator.hasNext()) {
     Double value = iterator.getDoubleNext();
     if (!value.isNaN()) {
       sum = value;
       break;
     }
   }
   while (iterator.hasNext()) {
     Double value = iterator.getDoubleNext();
     if (!value.isNaN()) {
       sum += value;
     }
   }
   return sum;
 }
Exemplo n.º 18
0
 /**
  * Element-wise divided by another array, and put the result in a given array.
  *
  * @param array GDM Array object
  * @param result GDM Array object
  * @throws ShapeNotMatchException Created on 01/10/2008
  */
 public void eltDivideWithEqualSize(IArray newArray, IArray result) throws ShapeNotMatchException {
   if (getArray().getSize() != newArray.getSize()) {
     throw new ShapeNotMatchException("the size of the arrays not match");
   }
   IArrayIterator iterator1 = getArray().getIterator();
   IArrayIterator iterator2 = newArray.getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (iterator1.hasNext()) {
     double newValue = iterator2.getDoubleNext();
     if (newValue != 0) {
       newIterator.setDoubleNext(iterator1.getDoubleNext() / newValue);
     } else {
       newIterator.setDoubleNext(iterator1.getDoubleNext());
     }
   }
   getArray().setDirty(true);
 }
Exemplo n.º 19
0
 public void eltRemainderEqualSize(IArray newArray, IArray result) throws ShapeNotMatchException {
   if (getArray().getSize() != newArray.getSize()) {
     throw new ShapeNotMatchException("the size of the arrays not match");
   }
   IArrayIterator iterator1 = getArray().getIterator();
   IArrayIterator iterator2 = newArray.getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (iterator1.hasNext()) {
     newIterator.setDoubleNext(iterator1.getDoubleNext() % iterator2.getDoubleNext());
   }
   getArray().setDirty(true);
 }
Exemplo n.º 20
0
 /**
  * Calculate an element-wise logarithm (base 10) of values of an Array.
  *
  * @return Array with new storage Created on 14/07/2008
  */
 public IArrayMath toLog10() {
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   IArrayIterator oldIterator = getArray().getIterator();
   IArrayIterator newIterator = result.getIterator();
   while (oldIterator.hasNext()) {
     double value = oldIterator.getDoubleNext();
     if (value == 0) {
       newIterator.setDoubleNext(Double.NaN);
     } else {
       newIterator.setDoubleNext(Math.log10(value));
     }
   }
   return result.getArrayMath();
 }
Exemplo n.º 21
0
  public Boolean process() throws Exception {
    if (skip_norm) {
      normalised_data = normalise_groupdata;
      return false;
    }
    // Read in needed data and prepare output arrays
    IArray dataArray = ((Plot) normalise_groupdata).findSignalArray();
    IArray variance_array = ((Plot) normalise_groupdata).getVariance().getData();
    /* If we have a 3D array, this means a series of monitor counts is available to
     * allow normalisation at each scan step.  If the array is 2D, then no such
     * normalisation is necessary.
     */
    double monmax = 1.0; // Value to which we normalise; usually maximum monitor counts
    if (dataArray.getRank() > 2) {
      int[] data_dims = dataArray.getShape();
      int dlength = dataArray.getRank();
      IArray monitor_array =
          normalise_groupdata.getRootGroup().getDataItem("monitor_data").getData();
      // We should have a monitor array rather than a single value
      monmax = monitor_array.getArrayMath().getMaximum();
      System.out.printf("Normalising to %f monitor counts\n", monmax);
      IArray outarray = Factory.createArray(double.class, data_dims);
      IArray out_variance = Factory.createArray(double.class, data_dims);
      int[] origin_list = new int[dlength];
      int[] range_list = new int[dlength];
      int[] target_shape = new int[dlength]; // shape to make a 2D array from multi-dim array
      for (int i = 0; i < dlength; i++) origin_list[i] = 0; // take in all elements
      for (int i = 0; i < dlength - 2; i++) {
        range_list[i] = data_dims[i]; // last two are rank reduced
        target_shape[i] = 1;
      }
      range_list[dlength - 2] = 1;
      range_list[dlength - 1] = 1;
      target_shape[dlength - 2] = data_dims[dlength - 2];
      target_shape[dlength - 1] = data_dims[dlength - 1];
      // Create an iterator over the higher dimensions.  We leave in the final two dimensions so
      // that we can
      // use the getCurrentCounter method to create an origin.
      // Iterate over two-dimensional slices
      // Array loop_array = dataArray.sectionNoReduce(origin_list, range_list, null);
      ISliceIterator higher_dim_iter = dataArray.getSliceIterator(2);
      IArrayIterator mon_iter = monitor_array.getIterator();
      ISliceIterator high_dim_out_it = outarray.getSliceIterator(2);
      ISliceIterator var_out_it = out_variance.getSliceIterator(2);
      ISliceIterator invar_iter = variance_array.getSliceIterator(2);
      // Now loop over higher dimensional frames
      while (higher_dim_iter.hasNext()) {
        double monval = mon_iter.getDoubleNext();
        if (monval == 0) {
          String errorstring = "Normalisation error: zero monitor counts found";
          throw new Exception(errorstring);
        }
        double monerr = monmax * monmax / (monval * monval * monval);
        monval = monmax / monval; // Actual value to multiply by
        IArray[] out_with_var = {high_dim_out_it.getArrayNext(), var_out_it.getArrayNext()};
        IArray[] in_with_var = {higher_dim_iter.getArrayNext(), invar_iter.getArrayNext()};
        // First create a scalar for normalisation of each frame
        double[] norm_with_err = {monval, monerr};
        ArrayOperations.multiplyByScalar(in_with_var, norm_with_err, out_with_var);
      }
      // Now build the output databag
      String resultName = "normalisation_result";
      normalised_data = PlotFactory.createPlot(normalise_groupdata, resultName, dataDimensionType);
      ((NcGroup) normalised_data).addLog("Apply normalisation to get " + resultName);
      PlotFactory.addDataToPlot(
          normalised_data,
          resultName,
          outarray,
          "Normalised data",
          "Normalised counts",
          out_variance);
      // Copy axes across from previous data
      List<Axis> data_axes = ((Plot) normalise_groupdata).getAxisList();
      for (Axis oneaxis : data_axes) {
        PlotFactory.addAxisToPlot(normalised_data, oneaxis, oneaxis.getDimensionName());
      }

      // We need the value to which everything has been normalised to be available to
      // subsequent processing steps
      IAttribute norm_val = Factory.createAttribute("normalised_to_val", monmax);
      // normalised_data.buildResultGroup(signal, stthVector, channelVector, twoThetaVector);
      normalised_data.addOneAttribute(norm_val);

    } else {
      normalised_data = normalise_groupdata;
    }
    return false;
  }