Exemplo n.º 1
0
  @Test
  public void loadLoaderFactoryMetaData() throws Exception {

    IMetadata meta = LoaderFactory.getMetadata(testFileFolder + file, null);
    assertEquals(meta.getMetaValue("MagicNumber"), "P5");
    assertEquals(meta.getMetaValue("Width"), "1024");
    assertEquals(meta.getMetaValue("Height"), "1024");
    assertEquals(meta.getMetaValue("Maxval"), "65535");
  }
Exemplo n.º 2
0
  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;
  }
Exemplo n.º 3
0
  /**
   * Fetch diffraction metadata, doesn't add it to the IDataset
   *
   * @param image
   * @param altPath alternative for file path if metadata is null or does not hold it
   * @param service
   * @param statusText returned message (can be null)
   * @return diffraction metadata
   */
  public static IDiffractionMetadata getDiffractionMetadata(
      IDataset image, String altPath, ILoaderService service, String[] statusText) {
    // Now always returns IDiffractionMetadata to prevent creation of a new
    // metadata object after listeners have been added to the old metadata
    // TODO improve this section- it's pretty horrible
    IDiffractionMetadata lockedMeta = service.getLockedDiffractionMetaData();

    if (image == null) return lockedMeta;

    int[] shape = image.getShape();
    IMetadata mdImage = null;
    try {
      mdImage = image.getMetadata();
    } catch (Exception e1) {
      // do nothing
    }
    if (lockedMeta != null) {
      if (mdImage instanceof IDiffractionMetadata) {
        IDiffractionMetadata dmd = (IDiffractionMetadata) mdImage;
        if (!dmd.getDiffractionCrystalEnvironment()
                .equals(lockedMeta.getDiffractionCrystalEnvironment())
            || !dmd.getDetector2DProperties().equals(lockedMeta.getDetector2DProperties())) {
          try {
            DiffractionMetadataUtils.copyNewOverOld(lockedMeta, (IDiffractionMetadata) mdImage);
          } catch (IllegalArgumentException e) {
            if (statusText != null)
              statusText[0] = "Locked metadata does not match image dimensions!";
          }
        }
      } else {
        // TODO what if the image is rotated?

        if (shape[0] == lockedMeta.getDetector2DProperties().getPx()
            && shape[1] == lockedMeta.getDetector2DProperties().getPy()) {
        } else {
          IDiffractionMetadata clone = lockedMeta.clone();
          clone.getDetector2DProperties().setPx(shape[0]);
          clone.getDetector2DProperties().setPy(shape[1]);
          if (statusText != null)
            statusText[0] = "Locked metadata does not match image dimensions!";
        }
      }
      if (statusText != null && statusText[0] == null) {
        statusText[0] = "Metadata loaded from locked version";
      }
      return lockedMeta;
    }

    // If not see if the trace has diffraction meta data
    if (mdImage instanceof IDiffractionMetadata) {
      if (statusText != null && statusText[0] == null) {
        statusText[0] = "Metadata loaded from image";
      }
      return (IDiffractionMetadata) mdImage;
    }

    // Try and get the filename here, it will help later on
    String filePath = mdImage == null ? null : mdImage.getFilePath();

    if (filePath == null) {
      filePath = altPath;
    }

    if (filePath != null) {
      // see if we can read diffraction info from nexus files
      NexusDiffractionMetaCreator ndmc = new NexusDiffractionMetaCreator(filePath);
      IDiffractionMetadata difMet = ndmc.getDiffractionMetadataFromNexus(shape);
      if (difMet != null) {
        // TODO comment out
        // image.setMetadata(difMet);
        if (statusText != null && statusText[0] == null) {
          if (ndmc.isCompleteRead()) {
            statusText[0] = "Metadata completely loaded from nexus tree";
            return difMet;
          } else if (ndmc.isPartialRead()) {
            statusText[0] = "Required metadata loaded from nexus tree";
            return difMet;
          } else if (ndmc.anyValuesRead())
            statusText[0] = "Incomplete metadata in nexus tree, loading from preferences";
          else statusText[0] = "No metadata in nexus tree, metadata loaded from preferences";
        }
      }
    }

    // if it is null try and get it from the loader service
    if (mdImage == null && filePath != null) {
      IMetadata md = null;
      try {
        md = service.getMetadata(filePath, null);
      } catch (Exception e) {
        logger.error("Cannot read meta data from part", e);
      }

      // If it is there and diffraction data return it
      if (md instanceof IDiffractionMetadata) {
        if (statusText != null && statusText[0] == null) {
          statusText[0] = "Metadata loaded from file";
        }
        return (IDiffractionMetadata) md;
      }
    }

    // if there is no meta or is not nexus or IDiff create default IDiff and put it in the dataset
    mdImage = DiffractionDefaultMetadata.getDiffractionMetadata(filePath, shape);
    // image.setMetadata(mdImage);
    if (statusText != null && statusText[0] == null) {
      statusText[0] = "No metadata found. Values loaded from preferences:";
    }
    return (IDiffractionMetadata) mdImage;
  }