All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generated.docs.javadoc.org.eclipse.dawnsci.nexus.NexusUtils.html Maven / Gradle / Ivy






NexusUtils (h5jan API)












org.eclipse.dawnsci.nexus

Class NexusUtils

  • java.lang.Object
    • org.eclipse.dawnsci.nexus.NexusUtils


  • public class NexusUtils
    extends java.lang.Object
    Utility methods for dealing with NeXus files.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  NexusUtils.ChunkingStrategy
      Possible strategies for estimating chunking
    • Constructor Summary

      Constructors 
      Constructor and Description
      NexusUtils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static java.lang.StringBuilder addToAugmentPath(java.lang.StringBuilder path, java.lang.String name, java.lang.String nxClass)
      Add to a NeXus augmented path
      static java.lang.String addToAugmentPath(java.lang.String path, java.lang.String name, java.lang.String nxClass)
      Add to a NeXus augmented path
      static DataNode appendData(NexusFile f, GroupNode g, Dataset a)
      Append data to a dataset in group node.
      static int compareScalars(java.lang.Object a, java.lang.Object b)
      Compares the two scalar objects if they are the same type and Comparable using their compareTo method, else compares the toString value.
      static int compareScalarToString(java.lang.Object a, java.lang.String b)
      Compare object a as a scalar to String b by first converting b to a type that matches a.
      static java.lang.String createAugmentPath(java.lang.String name, java.lang.String nxClass)
      Create a (top-level) NeXus augmented path
      static ILazyWriteableDataset createLazyWriteableDataset(java.lang.String name, int dtype, int[] shape, int[] maxShape, int[] chunks)
      Create a lazy writeable dataset
      static int[] estimateChunking(int[] expectedMaxShape, int dataByteSize)
      Estimate suitable chunk parameters based on the expected final size of a dataset
      static int[] estimateChunking(int[] expectedMaxShape, int dataByteSize, int[] fixedChunkDimensions)
      Estimate suitable chunk parameters based on the expected final size of a dataset
      static int[] estimateChunking(int[] expectedMaxShape, int dataByteSize, int[] fixedChunkDimensions, NexusUtils.ChunkingStrategy strategy)
      Estimate suitable chunk parameters based on the expected final size of a dataset
      static int[] estimateChunking(int[] expectedMaxShape, int dataByteSize, NexusUtils.ChunkingStrategy strategy)
      Estimate suitable chunk parameters based on the expected final size of a dataset
      static java.lang.Object extractScalarFromDataset(java.lang.Object value)
      Convert the size == 1 array to a scalar.
      static java.util.List<java.lang.String> getAxisNames(java.lang.String filePath, java.lang.String nexusPath, int dimension)
      Returns names of axes in group at same level as name passed in.
      static java.lang.String getName(java.lang.String path)
      Get name of last part
      static GroupNode loadGroupFully(NexusFile file, java.lang.String path, int maxDepth)
      Load group and its subgroups to given maximum depth
      static TreeFile loadNexusTree(NexusFile nexusFile)
      Loads the entire nexus tree structure into memory.
      static java.lang.String stripAugmentedPath(java.lang.String augmentedPath)
      Create a plain path by stripping out NXclasses
      static DataNode write(NexusFile file, GroupNode group, java.lang.String name, java.lang.Object value)
      Write the object into a field called 'name' at the group in the NeXus file.
      static void writeAttribute(NexusFile file, Node node, java.lang.String name, java.lang.Object value) 
      static DataNode writeDouble(NexusFile file, GroupNode group, java.lang.String name, double value)
      Write the double into a field called 'name' at the group in the NeXus file.
      static DataNode writeDouble(NexusFile file, GroupNode group, java.lang.String name, double value, java.lang.String units)
      Write the double into a field called 'name' at the group in the NeXus file.
      static DataNode writeDoubleArray(NexusFile file, GroupNode group, java.lang.String name, double[] value)
      Write the double into a field called 'name' at the group in the NeXus file.
      static DataNode writeDoubleArray(NexusFile file, GroupNode group, java.lang.String name, java.lang.Double[] value)
      Write the double into a field called 'name' at the group in the NeXus file.
      static void writeDoubleAttribute(NexusFile file, Node node, java.lang.String name, double... value) 
      static void writeDoubleAttribute(NexusFile file, Node node, java.lang.String name, java.lang.Double... value) 
      static DataNode writeInteger(NexusFile file, GroupNode group, java.lang.String name, int value)
      Write the integer into a field called 'name' at the group in the NeXus file.
      static DataNode writeIntegerArray(NexusFile file, GroupNode group, java.lang.String name, int[] value)
      Write the integer array into a field called 'name' at the group in the NeXus file.
      static void writeIntegerAttribute(NexusFile file, Node node, java.lang.String name, int... value) 
      static DataNode writeString(NexusFile file, GroupNode group, java.lang.String name, java.lang.String value)
      Write the string into a field called 'name' at the group in the NeXus file.
      static void writeStringAttribute(NexusFile file, Node node, java.lang.String name, java.lang.String value) 
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NexusUtils

        public NexusUtils()
    • Method Detail

      • createAugmentPath

        public static java.lang.String createAugmentPath(java.lang.String name,
                                                         java.lang.String nxClass)
        Create a (top-level) NeXus augmented path
        Parameters:
        name -
        nxClass -
        Returns:
        augmented path
      • addToAugmentPath

        public static java.lang.String addToAugmentPath(java.lang.String path,
                                                        java.lang.String name,
                                                        java.lang.String nxClass)
        Add to a NeXus augmented path
        Parameters:
        path -
        name -
        nxClass -
        Returns:
        augmented path
      • addToAugmentPath

        public static java.lang.StringBuilder addToAugmentPath(java.lang.StringBuilder path,
                                                               java.lang.String name,
                                                               java.lang.String nxClass)
        Add to a NeXus augmented path
        Parameters:
        path -
        name -
        nxClass -
        Returns:
        augmented path
      • stripAugmentedPath

        public static java.lang.String stripAugmentedPath(java.lang.String augmentedPath)
        Create a plain path by stripping out NXclasses
        Parameters:
        augmentedPath -
        Returns:
        plain path
      • getName

        public static java.lang.String getName(java.lang.String path)
        Get name of last part
        Parameters:
        path -
        Returns:
        name or null if path does not contain any or ends in that
      • createLazyWriteableDataset

        public static ILazyWriteableDataset createLazyWriteableDataset(java.lang.String name,
                                                                       int dtype,
                                                                       int[] shape,
                                                                       int[] maxShape,
                                                                       int[] chunks)
        Create a lazy writeable dataset
        Parameters:
        name -
        dtype -
        shape -
        maxShape -
        chunks -
        Returns:
        lazy writeable dataset
      • writeString

        public static DataNode writeString(NexusFile file,
                                           GroupNode group,
                                           java.lang.String name,
                                           java.lang.String value)
                                    throws NexusException
        Write the string into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeInteger

        public static DataNode writeInteger(NexusFile file,
                                            GroupNode group,
                                            java.lang.String name,
                                            int value)
                                     throws NexusException
        Write the integer into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeIntegerArray

        public static DataNode writeIntegerArray(NexusFile file,
                                                 GroupNode group,
                                                 java.lang.String name,
                                                 int[] value)
                                          throws NexusException
        Write the integer array into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeDouble

        public static DataNode writeDouble(NexusFile file,
                                           GroupNode group,
                                           java.lang.String name,
                                           double value)
                                    throws NexusException
        Write the double into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeDoubleArray

        public static DataNode writeDoubleArray(NexusFile file,
                                                GroupNode group,
                                                java.lang.String name,
                                                double[] value)
                                         throws NexusException
        Write the double into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeDoubleArray

        public static DataNode writeDoubleArray(NexusFile file,
                                                GroupNode group,
                                                java.lang.String name,
                                                java.lang.Double[] value)
                                         throws NexusException
        Write the double into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Throws:
        NexusException
      • writeDouble

        public static DataNode writeDouble(NexusFile file,
                                           GroupNode group,
                                           java.lang.String name,
                                           double value,
                                           java.lang.String units)
                                    throws NexusException
        Write the double into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        units -
        Throws:
        NexusException
      • write

        public static DataNode write(NexusFile file,
                                     GroupNode group,
                                     java.lang.String name,
                                     java.lang.Object value)
                              throws NexusException
        Write the object into a field called 'name' at the group in the NeXus file.
        Parameters:
        file -
        group -
        name -
        value -
        Returns:
        data node
        Throws:
        NexusException
      • writeStringAttribute

        public static void writeStringAttribute(NexusFile file,
                                                Node node,
                                                java.lang.String name,
                                                java.lang.String value)
                                         throws NexusException
        Parameters:
        file -
        node -
        name -
        value -
        Throws:
        NexusException
      • writeIntegerAttribute

        public static void writeIntegerAttribute(NexusFile file,
                                                 Node node,
                                                 java.lang.String name,
                                                 int... value)
                                          throws NexusException
        Parameters:
        file -
        node -
        name -
        value -
        Throws:
        NexusException
      • writeDoubleAttribute

        public static void writeDoubleAttribute(NexusFile file,
                                                Node node,
                                                java.lang.String name,
                                                double... value)
                                         throws NexusException
        Parameters:
        file -
        node -
        name -
        value -
        Throws:
        NexusException
      • writeDoubleAttribute

        public static void writeDoubleAttribute(NexusFile file,
                                                Node node,
                                                java.lang.String name,
                                                java.lang.Double... value)
                                         throws NexusException
        Parameters:
        file -
        node -
        name -
        value -
        Throws:
        NexusException
      • writeAttribute

        public static void writeAttribute(NexusFile file,
                                          Node node,
                                          java.lang.String name,
                                          java.lang.Object value)
                                   throws NexusException
        Parameters:
        file -
        node -
        name -
        value -
        Throws:
        NexusException
      • loadNexusTree

        public static TreeFile loadNexusTree(NexusFile nexusFile)
                                      throws NexusException
        Loads the entire nexus tree structure into memory. Note that this does not necessarily load the contents of every dataset within the nexus file into memory, as some may be ILazyDatasets.
        Parameters:
        filePath - file path
        Returns:
        TreeFile tree file representing nexus tree
        Throws:
        NexusException
      • estimateChunking

        public static int[] estimateChunking(int[] expectedMaxShape,
                                             int dataByteSize,
                                             int[] fixedChunkDimensions,
                                             NexusUtils.ChunkingStrategy strategy)
        Estimate suitable chunk parameters based on the expected final size of a dataset
        Parameters:
        expectedMaxShape - expected final size of the dataset
        dataByteSize - size of each element in bytes
        fixedChunkDimensions - provided dimensions in a chunk to be kept constant (-1 for no provided chunk)
        strategy - strategy to use for estimating
        Returns:
        chunk estimate
      • estimateChunking

        public static int[] estimateChunking(int[] expectedMaxShape,
                                             int dataByteSize,
                                             NexusUtils.ChunkingStrategy strategy)
        Estimate suitable chunk parameters based on the expected final size of a dataset
        Parameters:
        expectedMaxShape - expected final size of the dataset
        dataByteSize - size of each element in bytes
        strategy - strategy to use for estimating
        Returns:
        chunk estimate
      • estimateChunking

        public static int[] estimateChunking(int[] expectedMaxShape,
                                             int dataByteSize,
                                             int[] fixedChunkDimensions)
        Estimate suitable chunk parameters based on the expected final size of a dataset
        Parameters:
        expectedMaxShape - expected final size of the dataset
        dataByteSize - size of each element in bytes
        fixedChunkDimensions - provided dimensions in a chunk to be kept constant (-1 for no provided chunk)
        Returns:
        chunk estimate
      • estimateChunking

        public static int[] estimateChunking(int[] expectedMaxShape,
                                             int dataByteSize)
        Estimate suitable chunk parameters based on the expected final size of a dataset
        Parameters:
        expectedMaxShape - expected final size of the dataset
        dataByteSize - size of each element in bytes
        Returns:
        chunk estimate
      • getAxisNames

        public static java.util.List<java.lang.String> getAxisNames(java.lang.String filePath,
                                                                    java.lang.String nexusPath,
                                                                    int dimension)
                                                             throws java.lang.Exception
        Returns names of axes in group at same level as name passed in. This opens and safely closes a nexus file if one is not already open for this location.
        Parameters:
        filePath -
        nexusPath - - path to signal dataset
        dimension, - the dimension we want the axis for starting with 1
        Returns:
        Throws:
        java.lang.Exception
      • compareScalarToString

        public static int compareScalarToString(java.lang.Object a,
                                                java.lang.String b)
                                         throws java.lang.NumberFormatException
        Compare object a as a scalar to String b by first converting b to a type that matches a.
        Throws:
        java.lang.NumberFormatException - if b can not be converted to the same type as a
        See Also:
        Comparable.compareTo(Object)
      • compareScalars

        public static int compareScalars(java.lang.Object a,
                                         java.lang.Object b)
        Compares the two scalar objects if they are the same type and Comparable using their compareTo method, else compares the toString value.
        See Also:
        Comparable.compareTo(Object)
      • extractScalarFromDataset

        public static java.lang.Object extractScalarFromDataset(java.lang.Object value)
        Convert the size == 1 array to a scalar. Works on January data types Dataset
        Parameters:
        value - a January Dataset is expected
        Returns:
        the scalar value, or null if no scalar can be extracted
      • appendData

        public static DataNode appendData(NexusFile f,
                                          GroupNode g,
                                          Dataset a)
                                   throws NexusException,
                                          DatasetException
        Append data to a dataset in group node. If data node does not exist then create one. This assumes that data is of a consistent rank R and will be appended to a shape with rank R+1 along the first dimension
        Parameters:
        f - Nexus file
        g - group node
        a - dataset
        Returns:
        data node
        Throws:
        NexusException
        DatasetException
      • loadGroupFully

        public static GroupNode loadGroupFully(NexusFile file,
                                               java.lang.String path,
                                               int maxDepth)
                                        throws NexusException
        Load group and its subgroups to given maximum depth
        Parameters:
        file -
        path -
        maxDepth -
        Returns:
        group
        Throws:
        NexusException




© 2015 - 2024 Weber Informatics LLC | Privacy Policy