Class DomainMapper<T>
- java.lang.Object
-
- uk.ac.rdg.resc.edal.dataset.DomainMapper<T>
-
- All Implemented Interfaces:
Iterable<DomainMapper.DomainMapperEntry<T>>
- Direct Known Subclasses:
Domain1DMapper
,Domain2DMapper
public abstract class DomainMapper<T> extends Object implements Iterable<DomainMapper.DomainMapperEntry<T>>
Maps real-world points to i and j indices of corresponding points within the source data. A DomainMapper is constructed using the following general algorithm:
For each point in the given targetDomain: 1. Find the grid cell in the source grid that contains this point 2. Let i and j be the coordinates of this grid cell 3. Let p be the index of this point in the target domain 4. Add the mapping (p to i,j) to the pixel map
The resulting DomainMapper is then used by
DataReadingStrategy
s to work out what data to read from the source data files. A variety of strategies are possible for reading these data points, each of which may be optimal in a certain situation.- Author:
- Jon Blower, Guy
- See Also:
DataReadingStrategy
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DomainMapper.DomainMapperEntry<P>
Maps a point in the source grid to corresponding points in the target grid.static interface
DomainMapper.Scanline<P>
Holds all the DomainMapperEntries corresponding with a certain j index
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Logger
log
-
Constructor Summary
Constructors Modifier Constructor Description protected
DomainMapper(HorizontalGrid sourceGrid, long targetDomainSize)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract T
convertIndexToCoordType(int index)
This performs the conversion from a single long index into whatever coordinate type is required.boolean
equals(Object obj)
long
getBoundingBoxSize()
Gets the size of the i-j bounding box that encompasses all data.int
getMaxIIndex()
Gets the maximum i index in the whole domain mapperint
getMaxJIndex()
Gets the maximum j index in the whole domain mapperint
getMinIIndex()
Gets the minimum i index in the whole domain mapperint
getMinJIndex()
Gets the minimum j index in the whole domain mapperint
getNumUniqueIJPairs()
Gets the number of unique i-j pairs in this pixel map.int
getTargetDomainSize()
Returns the size of the target domainint
hashCode()
boolean
isEmpty()
Returns true if this DomainMapper does not contain any data: this will happen if there is no intersection between the requested data and the data on disk.Iterator<DomainMapper.DomainMapperEntry<T>>
iterator()
Returns an unmodifiable iterator over all theDomainMapper.DomainMapperEntry
s in this PixelMap.protected void
put(int i, int j, int targetGridIndex)
Adds a new pixel index to this map.Iterator<DomainMapper.Scanline<T>>
scanlineIterator()
Returns an unmodifiable iterator over all the Scanlines in this pixel mapprotected void
sortIndices()
Sorts the arrays of source and target indices so that the arrays are in order of increasing source grid index, then increasing target grid index.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
DomainMapper
protected DomainMapper(HorizontalGrid sourceGrid, long targetDomainSize)
-
-
Method Detail
-
sortIndices
protected void sortIndices()
Sorts the arrays of source and target indices so that the arrays are in order of increasing source grid index, then increasing target grid index. Uses an in-place quicksort algorithm adapted from http://www.vogella.de/articles/JavaAlgorithmsQuicksort/article.html.
-
put
protected void put(int i, int j, int targetGridIndex)
Adds a new pixel index to this map. Does nothing if either i or j is negative.- Parameters:
i
- The i index of the point in the source dataj
- The j index of the point in the source datatargetGridIndex
- The index of the corresponding point in the target domain
-
isEmpty
public boolean isEmpty()
Returns true if this DomainMapper does not contain any data: this will happen if there is no intersection between the requested data and the data on disk.
-
getTargetDomainSize
public int getTargetDomainSize()
Returns the size of the target domain
-
getMinIIndex
public int getMinIIndex()
Gets the minimum i index in the whole domain mapper
-
getMinJIndex
public int getMinJIndex()
Gets the minimum j index in the whole domain mapper
-
getMaxIIndex
public int getMaxIIndex()
Gets the maximum i index in the whole domain mapper
-
getMaxJIndex
public int getMaxJIndex()
Gets the maximum j index in the whole domain mapper
-
getNumUniqueIJPairs
public int getNumUniqueIJPairs()
Gets the number of unique i-j pairs in this pixel map. When combined with the size of the resulting image we can quantify the under- or over-sampling. This is the number of data points that will be extracted by the
DataReadingStrategy.PIXEL_BY_PIXEL
data reading strategy.This implementation counts the number of unique pairs by cycling through the
iterator()
and so is not a cheap operation. Use sparingly, e.g. for debugging.- Returns:
- the number of unique i-j pairs in this pixel map.
-
getBoundingBoxSize
public long getBoundingBoxSize()
Gets the size of the i-j bounding box that encompasses all data. This is the number of data points that will be extracted using theBOUNDING_BOX
data reading strategy.- Returns:
- the size of the i-j bounding box that encompasses all data.
-
iterator
public Iterator<DomainMapper.DomainMapperEntry<T>> iterator()
Returns an unmodifiable iterator over all theDomainMapper.DomainMapperEntry
s in this PixelMap.
-
convertIndexToCoordType
protected abstract T convertIndexToCoordType(int index)
This performs the conversion from a single long index into whatever coordinate type is required. The simplest example would be to simply return the index for a 1D array (seeDomain1DMapper
for this). TODO This currently takes an int. Do we want to support target domains which are bigger than Integer.MAX_VALUE?- Parameters:
index
- The index to convert to a co-ordinate- Returns:
- The co-ordinate represented by the index
-
scanlineIterator
public Iterator<DomainMapper.Scanline<T>> scanlineIterator()
Returns an unmodifiable iterator over all the Scanlines in this pixel map
-
-