コード例 #1
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);
  }
コード例 #2
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);
    }
  }
コード例 #3
0
  @Test
  public void testStackedFile() throws ScanFileHolderException {
    ILazyDataset image =
        new TIFFImageLoader(TestFileFolder + "untitled1020.TIF").loadFile().getLazyDataset(0);
    Assert.assertArrayEquals("Shape not equal", new int[] {3, 2048, 2048}, image.getShape());

    IDataset d = image.getSlice(new Slice(1));
    Assert.assertArrayEquals("Shape not equal", new int[] {1, 2048, 2048}, d.getShape());
    Assert.assertEquals("Type is int32", Integer.class, d.elementClass());

    d = image.getSlice(new Slice(1, 3), new Slice(1));
    Assert.assertArrayEquals("Shape not equal", new int[] {2, 1, 2048}, d.getShape());
    Assert.assertEquals("Type is int32", Integer.class, d.elementClass());

    d = image.getSlice(new Slice(1, 3), new Slice(null, null, 4), new Slice(2, 25));
    Assert.assertArrayEquals("Shape not equal", new int[] {2, 512, 23}, d.getShape());
    Assert.assertEquals("Type is int32", Integer.class, d.elementClass());
  }
コード例 #4
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;
    }