protected OperationData process(IDataset input, IMonitor monitor) throws OperationException {

    double d = (2 * Math.PI) / model.getqValue();
    double p = (2 * Math.PI) / (model.getqValue() + model.getqDelta());
    double m = (2 * Math.PI) / (model.getqValue() - model.getqDelta());

    IDiffractionMetadata dm = getFirstDiffractionMetadata(input);
    if (dm == null) throw new OperationException(this, "No calibration information!");

    IParametricROI[] inOut = new IParametricROI[2];

    IParametricROI conic =
        (IParametricROI)
            DSpacing.conicFromDSpacing(
                dm.getDetector2DProperties(), dm.getDiffractionCrystalEnvironment(), d);
    inOut[0] =
        (IParametricROI)
            DSpacing.conicFromDSpacing(
                dm.getDetector2DProperties(), dm.getDiffractionCrystalEnvironment(), m);
    inOut[1] =
        (IParametricROI)
            DSpacing.conicFromDSpacing(
                dm.getDetector2DProperties(), dm.getDiffractionCrystalEnvironment(), p);

    PolylineROI points =
        PeakFittingEllipseFinder.findPointsOnConic(
            DatasetUtils.convertToDataset(input), null, conic, inOut, 256, null);

    double rms = -1;
    double[] semi = new double[2];
    double[] point = new double[2];
    double ang = 0;

    if (points != null && points.getNumberOfPoints() < 3) {

      EllipticalFitROI efroi = PowderRingsUtils.fitAndTrimOutliers(null, points, 2, false);
      rms = efroi.getRMS();
      semi = efroi.getSemiAxes();
      point = efroi.getPoint();
      ang = efroi.getAngleDegrees();
    }

    Dataset r = DatasetFactory.createFromObject(new double[] {rms});
    r.setName("rms");

    Dataset ax = DatasetFactory.createFromObject(semi);
    ax.setName("semi-axes");

    Dataset po = DatasetFactory.createFromObject(point);
    po.setName("centre");

    Dataset a = DatasetFactory.createFromObject(new double[] {ang});
    a.setName("angle");

    return new OperationData(input, new Serializable[] {r, ax, po, a});
  }
Esempio n. 2
0
  public static IROI runConicPeakFit(
      final IProgressMonitor monitor,
      Display display,
      final IPlottingSystem plotter,
      IImageTrace t,
      IParametricROI roi,
      IParametricROI[] innerOuter,
      int nPoints) {

    if (roi == null) return null;

    final ProgressMonitorWrapper mon = new ProgressMonitorWrapper(monitor);
    monitor.subTask("Find POIs near initial ellipse");
    Dataset image = (Dataset) t.getData();
    BooleanDataset mask = (BooleanDataset) t.getMask();
    PolylineROI points;
    monitor.subTask("Fit POIs");

    points = PeakFittingEllipseFinder.findPointsOnConic(image, mask, roi, innerOuter, nPoints, mon);

    if (monitor.isCanceled()) return null;

    if (points == null) return null;

    if (roi instanceof EllipticalROI) {
      if (points.getNumberOfPoints() < 3) {
        throw new IllegalArgumentException("Could not find enough points to trim");
      }

      monitor.subTask("Trim POIs");
      EllipticalFitROI efroi = PowderRingsUtils.fitAndTrimOutliers(mon, points, 5, false);
      logger.debug("Found {}...", efroi);
      monitor.subTask("");
      return efroi;
    }

    return points;
  }