public double absorptionCorrectionCommon(boolean isSampleScatterer, boolean isSampleAttenuator) {
    // Make the two components as ComponentGeometries
    XPDFComponentGeometry sample = new XPDFComponentCylinder();
    XPDFComponentGeometry capillary = new XPDFComponentCylinder();

    sample.setDistances(0.0, 0.15);
    sample.setStreamality(true, true);

    capillary.setDistances(0.15, 0.16);
    capillary.setStreamality(true, true);

    XPDFComponentGeometry scatterer = (isSampleScatterer) ? sample : capillary;
    XPDFComponentGeometry attenuator = (isSampleAttenuator) ? sample : capillary;

    // These will be calculated by the Composition class
    double quartzAttenuationCoefficient = 0.0529783195963;
    double ceriaAttenuationCoefficient = 1.86349597825;
    double attenuationCoefficient =
        (isSampleAttenuator) ? ceriaAttenuationCoefficient : quartzAttenuationCoefficient;

    XPDFBeamData beamData = new XPDFBeamData();
    beamData.setBeamEnergy(76.6);
    beamData.setBeamHeight(0.07);
    beamData.setBeamWidth(0.07);

    // Read the target data, and also the angles (in radians) to run
    String dataPath = "/home/rkl37156/ceria_dean_data/";
    IDataHolder dh = null;
    String scattererName, attenuatorName;
    scattererName = (isSampleScatterer) ? "sample" : "container";
    attenuatorName = (isSampleAttenuator) ? "sample" : "container";
    try {
      dh = LoaderFactory.getData(dataPath + scattererName + "_" + attenuatorName + "_abs.xy");
    } catch (Exception e) {
    }
    Dataset delta1D = DatasetUtils.convertToDataset(dh.getLazyDataset("Column_1").getSlice());
    Dataset delta = new DoubleDataset(delta1D.getSize(), 1);
    for (int i = 0; i < delta1D.getSize(); i++) delta.set(delta1D.getDouble(i), i, 0);
    Dataset gamma = DoubleDataset.zeros(delta);
    Dataset expected = DatasetUtils.convertToDataset(dh.getLazyDataset("Column_2").getSlice());
    expected.setShape(expected.getSize(), 1);

    Dataset calculated =
        scatterer.calculateAbsorptionCorrections(
            gamma, delta, attenuator, attenuationCoefficient, beamData, true, true);

    // calculated.squeeze();

    Dataset difference = Maths.subtract(calculated, expected);
    return Math.sqrt((Double) Maths.square(difference).mean());
  }
Ejemplo n.º 2
0
  @BeforeClass
  public static void buildData() throws Exception {
    file = folder.newFile("file1.nxs");
    MapNexusFileBuilderUtils.makeGridScanWithSum(file.getAbsolutePath());
    IDataHolder data = LoaderFactory.getData(file.getAbsolutePath());
    ILazyDataset lazyDataset = data.getLazyDataset(MapNexusFileBuilderUtils.DETECTOR_PATH);

    MapScanDimensions msd = new MapScanDimensions(1, 0, 2);
    gridScanBlock =
        new MappedDataBlock(
            MapNexusFileBuilderUtils.DETECTOR_PATH, lazyDataset, file.getAbsolutePath(), msd);

    ILazyDataset sum = data.getLazyDataset(MapNexusFileBuilderUtils.SUM_PATH);

    gridScanMap =
        new MappedData(
            MapNexusFileBuilderUtils.SUM_PATH,
            sum.getSlice(),
            gridScanBlock,
            file.getAbsolutePath());

    fileRemap = folder.newFile("file2.nxs");
    MapNexusFileBuilderUtils.makeDiagLineScanWithSum(fileRemap.getAbsolutePath());
  }
Ejemplo n.º 3
0
  @Test
  public void lazyLoadLoaderFactory() throws Exception {

    IDataHolder dataHolder = LoaderFactory.getData(testFileFolder + file, true, true, true, null);

    ILazyDataset lazy = dataHolder.getLazyDataset("Portable Grey Map");
    assertArrayEquals(new int[] {1024, 1024}, lazy.getShape());

    IDataset data = lazy.getSlice();
    // Check the first data point
    assertEquals(data.getDouble(0, 0), 0.0, 0.0);
    // Check the middle data point
    assertEquals(data.getDouble(512, 511), 15104.0, 0.0);
    // Check the last data point
    assertEquals(data.getDouble(1023, 1023), 0.0, 0.0);
  }
Ejemplo n.º 4
0
  private void updateSliceWidget(String path) {
    try {
      IDataHolder dh = ServiceHolder.getLoaderService().getData(path, new IMonitor.Stub());
      ILazyDataset lazy = dh.getLazyDataset(fileManager.getContext().getDatasetNames().get(0));
      int[] shape = lazy.getShape();

      int[] dd = Slicer.getDataDimensions(shape, fileManager.getContext().getSliceDimensions());
      Slice[] slices =
          Slicer.getSliceArrayFromSliceDimensions(
              fileManager.getContext().getSliceDimensions(), shape);
      csw.setDatasetShapeInformation(shape, dd.clone(), slices);
      String ss = Slice.createString(csw.getCurrentSlice());
      currentSliceLabel.setText("Current slice of data: [" + ss + "]");
      currentSliceLabel.getParent().layout(true);
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }
Ejemplo n.º 5
0
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      output.setEnabled(false);
      EscapableSliceVisitor sliceVisitor = null;
      try {

        if (path == null) path = context.getFilePaths().get(0);

        final IDataHolder dh = ServiceHolder.getLoaderService().getData(path, new IMonitor.Stub());
        ILazyDataset lazyDataset = dh.getLazyDataset(context.getDatasetNames().get(0));

        if (lazyDataset == null) {
          logger.error("Selected dataset not in file!!!!");
          return Status.CANCEL_STATUS;
        }
        // take a local view
        lazyDataset = lazyDataset.getSliceView();

        Map<Integer, String> axesNames = context.getAxesNames();

        if (axesNames != null) {
          AxesMetadata am =
              ServiceHolder.getLoaderService().getAxesMetadata(lazyDataset, path, axesNames);
          lazyDataset.setMetadata(am);
          //					AxesMetadata axMeta = SlicedDataUtils.createAxisMetadata(path, lazyDataset,
          // axesNames);
          //					if (axMeta != null) lazyDataset.setMetadata(axMeta);
          //					else lazyDataset.clearMetadata(AxesMetadata.class);
        }

        int[] dataDims =
            Slicer.getDataDimensions(lazyDataset.getShape(), context.getSliceDimensions());
        Slice[] s = csw.getCurrentSlice();
        // Plot input, probably a bit wasteful to do each time
        IDataset firstSlice = null;
        if (lazyDataset instanceof IDataset) {
          firstSlice = ((IDataset) lazyDataset).getSliceView(s);
        } else {
          firstSlice = lazyDataset.getSlice(s);
        }
        eventManager.sendInitialDataUpdate(firstSlice.getSliceView().squeeze());
        MetadataPlotUtils.plotDataWithMetadata(firstSlice, input);

        IOperation<? extends IOperationModel, ? extends OperationData>[] ops = getOperations();
        if (ops == null) {
          output.clear();
          return Status.OK_STATUS;
        }
        // Only run what is necessary
        if (inputData != null) {

          if (inputData.getCurrentOperation() != end) {
            int pos = 0;
            for (int i = 0; i < ops.length; i++) {
              if (ops[i] == end) break;
              if (ops[i] == inputData.getCurrentOperation()) {
                pos = i;
                pos++;
                break;
              }
            }

            if (pos != 0) {
              firstSlice = inputData.getInputData();
              ops = Arrays.copyOfRange(ops, pos - 1, ops.length);
            }

          } else {
            firstSlice = inputData.getInputData();
            ops = new IOperation[] {inputData.getCurrentOperation()};
          }
        }

        SourceInformation si =
            new SourceInformation(path, context.getDatasetNames().get(0), lazyDataset);
        SliceInformation sli = csw.getCurrentSliceInformation();
        // TODO replace with check shape
        firstSlice.setMetadata(new SliceFromSeriesMetadata(si, sli));

        //				OriginMetadataImpl om = new OriginMetadataImpl(lazyDataset, viewSlice, dataDims, path,
        // context.getDatasetNames().get(0));
        //				om.setCurrentSlice(csw.getCurrentSlice());

        //				lazyDataset.setMetadata(om);

        sliceVisitor =
            getSliceVisitor(
                ops,
                lazyDataset,
                Slicer.getDataDimensions(lazyDataset.getShape(), context.getSliceDimensions()));
        sliceVisitor.setEndOperation(end);
        long start = System.currentTimeMillis();
        sliceVisitor.visit(firstSlice);
        inputData = sliceVisitor.getOperationInputData();
        eventManager.sendInputDataUpdate(inputData);
        logger.debug("Ran in: " + (System.currentTimeMillis() - start) / 1000. + " s");
        eventManager.sendErrorUpdate(null);

      } catch (OperationException e) {
        logger.error(e.getMessage(), e);
        eventManager.sendErrorUpdate(e);
        return Status.CANCEL_STATUS;
      } catch (Exception e) {
        logger.error(e.getMessage(), e);

        String message = e.getMessage();
        if (message == null) message = "Unexpected error!";
        eventManager.sendErrorUpdate(new OperationException(null, message));
        return Status.CANCEL_STATUS;
      } finally {
        if (sliceVisitor != null) {
          inputData = sliceVisitor.getOperationInputData();
          eventManager.sendInputDataUpdate(inputData);
        }
        output.setEnabled(true);
      }

      return Status.OK_STATUS;
    }
Ejemplo n.º 6
0
    /**
     * In order to implement a file watcher, we loop forever ensuring requesting to take the next
     * item from the file watchers queue.
     */
    @Override
    public void run() {

      final Path path = Paths.get(spath);
      try {
        // We wait until the file we are told to monitor exists.
        while (!Files.exists(path)) {
          Thread.sleep(200);
        }

        // get the first event before looping
        WatchKey key = null;
        while (session.isOpen() && connected && (key = watcher.take()) != null) {

          try {
            if (!Files.exists(path)) continue;

            for (WatchEvent<?> event : key.pollEvents()) {

              if (!Files.exists(path)) continue;

              Path epath = (Path) event.context();
              if (!Files.isDirectory(path) && !path.endsWith(epath)) continue;

              try {
                // Data has changed, read its shape and publish the event using a web socket.
                final IDataHolder holder =
                    ServiceHolder.getLoaderService().getData(spath, new IMonitor.Stub());
                if (holder == null) continue; // We do not stop if the loader got nothing.

                final ILazyDataset lz =
                    sdataset != null && !"".equals(sdataset)
                        ? holder.getLazyDataset(sdataset)
                        : holder.getLazyDataset(0);
                if (lz == null) continue; // We do not stop if the loader got nothing.

                if (lz instanceof IDynamicDataset) {
                  ((IDynamicDataset) lz).refreshShape();
                }

                if (writing) {
                  ServiceHolder.getLoaderService().clearSoftReferenceCache(spath);
                }
                final DataEvent evt = new DataEvent(lz.getName(), lz.getShape());
                evt.setFilePath(spath);

                // We manually JSON the object because we
                // do not want a dependency and object simple
                String json = evt.encode();
                session.getRemote().sendString(json);
                if (diagInfo != null) diagInfo.record("JSON Send", json);

              } catch (HDF5FunctionArgumentException h5error) {
                // This happens sometimes when the file is not ready to read.
                logger.trace("Path might not be ready to read " + path);
                continue;

              } catch (Exception ne) {
                logger.error("Exception getting data from " + path);
                continue;
              }
              break;
            }

          } finally {
            key.reset();
          }
        }

      } catch (Exception e) {
        logger.error("Exception monitoring " + path, e);
        if (session.isOpen()) session.close(403, e.getMessage());

      } finally {
        if (diagInfo != null) diagInfo.record("Close Thread", Thread.currentThread().getName());
        try {
          watcher.close();
        } catch (IOException e) {
          logger.error("Error closing watcher", e);
        }
      }
    }
 private void loadDataset() throws Exception {
   IDataHolder dh = LoaderFactory.getData("files/brain.h5");
   dataset = dh.getLazyDataset("/entry/edf/data").getSlice();
 }