Class Dataset2D

java.lang.Object
nz.org.riskscape.engine.data.coverage.Dataset2D

public abstract class Dataset2D extends Object

Wrapper that maps a two-dimensional (x, y) grid to an underlying set of data. This allows us to: - easily vary the underlying data we're storing (via subclassing), e.g. in DatasetCoverage we need to support both doubles and lists of doubles. - actually use a one-dimensional array underneath (for memory efficiency). - potentially calculate the underlying data on demand, e.g. for huge HDF5 datasets that we can't fit in memory in a single array.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Dataset2D(long width, long height)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Dataset2D
    combine(List<Dataset2D> datasets, nz.org.riskscape.engine.types.Struct combinedType)
    Combines multiple datasets together and returns a combined struct each time they are sampled.
    static Dataset2D
    fromDoubles(int width, int height, double[] data)
    Maps a simple one-dimensional array of doubles to a two-dimensional grid, with the dataset yielding the double at each grid position.
    long
     
    protected int
    getIndex(long x, long y)
     
    abstract nz.org.riskscape.engine.types.Type
     
    abstract Object
    getValue(long x, long y)
     
    long
     
    boolean
    isInBounds(long x, long y)
     

    Methods inherited from class java.lang.Object

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

    • Dataset2D

      public Dataset2D(long width, long height)
  • Method Details

    • fromDoubles

      public static Dataset2D fromDoubles(int width, int height, double[] data)

      Maps a simple one-dimensional array of doubles to a two-dimensional grid, with the dataset yielding the double at each grid position.

      Data should be organized in the data array to be x, y, that is the first width number of values are for y = 0

    • combine

      public static Dataset2D combine(List<Dataset2D> datasets, nz.org.riskscape.engine.types.Struct combinedType)

      Combines multiple datasets together and returns a combined struct each time they are sampled.

    • getIndex

      protected int getIndex(long x, long y)
    • isInBounds

      public boolean isInBounds(long x, long y)
      Returns:
      whether the x, y co-ordinates fall within this dataset grid
    • getValue

      public abstract Object getValue(long x, long y)
      Returns:
      the data stored at the given x, y co-ordinates. Warning: you should verify the co-ordinates via isInBounds() first
    • getType

      public abstract nz.org.riskscape.engine.types.Type getType()
      Returns:
      the type of data stored by the dataset. Similar to TypedCoverage.getType()
    • getWidth

      public long getWidth()
    • getHeight

      public long getHeight()