@Test
 public void testLazyAlignment() throws Exception {
   int[] shape = data.getShape();
   ILazyDataset alignedImages = null;
   // read from temp file
   alignedImages = transform.align(data, null);
   assertArrayEquals(shape, alignedImages.getShape());
   assertEquals(shape[2], alignedImages.getShape()[2]);
 }
 @Test
 public void testLazyRotation() throws Exception {
   int[] shape = data.getShape();
   // rotated shape
   int[] newShape = new int[] {data.getShape()[0], 724, 724};
   String name = "testLazyRotation.h5";
   ILazyWriteableDataset lazy = TestUtils.createTempLazyFile(newShape, name);
   for (int i = 0; i < shape[0]; i++) {
     IDataset slice = data.getSlice(new Slice(i, shape[0], shape[1])).squeeze();
     IDataset rotated = DatasetUtils.convertToDataset(transform.rotate(slice, 45, false));
     // add rotated image to temp file
     TestUtils.appendDataset(lazy, rotated, i, null);
   }
   assertArrayEquals(newShape, lazy.getShape());
   assertEquals(newShape[2], lazy.getShape()[2]);
   IDataset rotatedImage = lazy.getSlice(new Slice(10, shape[0], shape[1])).squeeze();
   assertEquals(newShape[2], rotatedImage.getShape()[1]);
 }
예제 #3
0
  public void removeLargeStacks(ISliceSystem slicingSystem, int maxStack) {

    for (DimsData dd : getDimsData()) {
      if (dd.getPlotAxis().isStack(slicingSystem)) {
        if (dd.getSliceRange(true) == null
            || "".equals(dd.getSliceRange(true))
            || "all".equals(dd.getSliceRange(true))) {
          final ILazyDataset lz = slicingSystem.getData().getLazySet();
          if (lz != null) {
            final int size = lz.getShape()[dd.getDimension()];
            if (size >= maxStack) { // We set a default slice
              dd.setSliceRange("0:25");
            }
          }
        }
      }
    }
  }
예제 #4
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());
  }
예제 #5
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);
        }
      }
    }