コード例 #1
0
ファイル: ArrayMath.java プロジェクト: nhauser/cdma
 /**
  * Element wise divide the array1 value by value from given array2.
  *
  * @param array IArray object
  * @return this array1 after modification
  * @throws ShapeNotMatchException mismatching shape
  */
 public IArrayMath eltDivide(IArray newArray) throws ShapeNotMatchException {
   getArray().getArrayUtils().checkShape(newArray);
   if (getArray().getRank() == newArray.getRank()) {
     eltDivideWithEqualSize(newArray, getArray());
   } else {
     ISliceIterator sourceSliceIterator = null;
     try {
       sourceSliceIterator = getArray().getSliceIterator(newArray.getRank());
       while (sourceSliceIterator.hasNext()) {
         IArray sourceSlice = sourceSliceIterator.getArrayNext();
         sourceSlice.getArrayMath().eltDivideWithEqualSize(newArray, sourceSlice);
       }
     } catch (InvalidRangeException e) {
       throw new ShapeNotMatchException("shape is invalid");
     }
   }
   getArray().setDirty(true);
   return this;
 }
コード例 #2
0
ファイル: ArrayMath.java プロジェクト: nhauser/cdma
 /**
  * Element wise divide the value by value from a given array.
  *
  * @param array IArray object
  * @return new array
  * @throws ShapeNotMatchException mismatching shape
  */
 public IArrayMath toEltDivide(IArray newArray) throws ShapeNotMatchException {
   getArray().getArrayUtils().checkShape(newArray);
   IArray result = getFactory().createArray(Double.TYPE, getArray().getShape());
   if (getArray().getRank() == newArray.getRank()) {
     eltDivideWithEqualSize(newArray, result);
   } else {
     ISliceIterator sourceSliceIterator = null;
     ISliceIterator resultSliceIterator = null;
     try {
       sourceSliceIterator = getArray().getSliceIterator(newArray.getRank());
       resultSliceIterator = result.getSliceIterator(newArray.getRank());
       while (sourceSliceIterator.hasNext() && resultSliceIterator.hasNext()) {
         IArray sourceSlice = sourceSliceIterator.getArrayNext();
         IArray resultSlice = resultSliceIterator.getArrayNext();
         sourceSlice.getArrayMath().eltDivideWithEqualSize(newArray, resultSlice);
       }
     } catch (InvalidRangeException e) {
       throw new ShapeNotMatchException("shape is invalid");
     }
   }
   return result.getArrayMath();
 }
コード例 #3
0
ファイル: Normalise.java プロジェクト: Gumtree/gumtree
  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;
  }