@Override public IConversionContext init(String path) { IConversionContext context = ServiceHolder.getConversionService().open(path); return setupwizard(context); }
private int getAmountOfWork(IConversionContext context) { int c = 0; String name = context.getDatasetNames().get(0); int[] dd = null; Map<Integer, String> sliceDimensions = context.getSliceDimensions(); for (String path : context.getFilePaths()) { try { IMetadata metadata = ServiceHolder.getLoaderService().getMetadata(path, null); int[] s = metadata.getDataShapes().get(name); if (s == null) { try { s = ServiceHolder.getLoaderService() .getData(path, null) .getLazyDataset(name) .getShape(); } catch (Exception e) { logger.warn("Can't get shape to calculate work from"); } } Slice[] slices = Slicer.getSliceArrayFromSliceDimensions(sliceDimensions, s); SliceND slice = new SliceND(s, slices); int[] nShape = slice.getShape(); if (dd == null) { dd = Slicer.getDataDimensions(s, context.getSliceDimensions()); Arrays.sort(dd); } int n = 1; for (int i = 0; i < nShape.length; i++) { if (Arrays.binarySearch(dd, i) < 0) n *= nShape[i]; } c += n; } catch (Exception e) { logger.warn("cannot load metadata for {}, assuming one frame", path); c++; } } return c; }
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); } }
@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; }