Package cds.healpix
Class HealpixNested
java.lang.Object
cds.healpix.HealpixNested
- All Implemented Interfaces:
HashComputer
,HierarchyItem
,NeighbourSelector
,VerticesAndPathComputer
public final class HealpixNested
extends Object
implements HashComputer, VerticesAndPathComputer, NeighbourSelector
Implementation of the HEALPix tessellation using the NESTED scheme: the NESTED scheme consists
in the concatenation of 12 z-order curves, one by HEALPix base cell.
The hash value in the NESTED scheme is build as follow: 0...0bbbb112233...
With
The hash value in the NESTED scheme is build as follow: 0...0bbbb112233...
With
- 0...0: unused bits
- bbbb: the 4 bits coding the base cell, in [0, 11]
- 11: the 2 bits of the z-order curve coding depth 1
- 22: the 2 bits of the z-order curve coding depth 2
- 33: the 2 bits of the z-order curve coding depth 3
- ...
protected
. to get an instance, see the Healpix.getNested(int)
or Healpix.getNested(int, FillingCurve2DType)
.
WARNING: As pointed out by Mark Taylor, to use the methods of the HashComputer
and VerticesAndPathComputer
interfaces, you **MUST** be sure that no other code running on the same JVM can call those methods a the same time.
Else, you should use newHashComputer()
and newVerticesAndPathComputer()
.- Author:
- F.-X. Pineau
-
Field Summary
Fields inherited from interface cds.healpix.NeighbourSelector
ALL_MAIN_WINDS
Fields inherited from interface cds.healpix.VerticesAndPathComputer
ALL_CARDINAL_POINTS, LAT_INDEX, LON_INDEX
-
Method Summary
Modifier and TypeMethodDescriptiondouble[]
center
(long hash) Compute the position on the unit sphere of the center (in the Euclidean projection plane) of the cell associated to the given hash value.void
center
(long hash, double[] resultLonLat) SeeVerticesAndPathComputer.center(long)
, except that the result is stored in the given array.int
depth()
Returns the depth of the hash computed byHashComputer.hash(double, double)
method.long
dividedBy4Quotient
(long d) externalEdges
(long hash, int deltaDepth) void
externalEdges
(long hash, int deltaDepth, FlatHashList result) long
hash
(double lonRad, double latRad) This method is **not** thread safe.long
internalCorner
(long hash, int deltaDepth, CompassPoint.Cardinal direction) long
internalCornerE
(long hash, int deltaDepth) long
internalCornerN
(long hash, int deltaDepth) long
internalCornerS
(long hash, int deltaDepth) long
internalCornerW
(long hash, int deltaDepth) internalEdges
(long hash, int deltaDepth) void
internalEdges
(long hash, int deltaDepth, FlatHashList result) long
neighbour
(long hash, CompassPoint.MainWind direction) The hash value of the neighbour of the cell of given hash, in the given deirection.neighbours
(long hash) Returns the list of the hash of the cells surrounding the cell defined by the given hash.void
neighbours
(long hash, FlatHashList result) Idem asNeighbourSelector.neighbours(long, NeighbourList)
except that the result is put in a simpleFlatHashList
.void
neighbours
(long hash, NeighbourList result) Equivalent ofNeighbourSelector.neighbours(long)
but passing in argument the list object to be filled.neighbours
(long hash, EnumSet<CompassPoint.MainWind> directions) Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the wanted neighbours.void
neighbours
(long hash, EnumSet<CompassPoint.MainWind> directions, NeighbourList result) Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the wanted neighbours.newConeComputer
(double coneRadiusRad) Returns aHealpixNestedFixedRadiusConeComputer
, to be used in a distinct thread.newConeComputer4Xmatch
(double coneRadiusRad) We suppose here that the radius of the (cross-match) cone is smaller that the typical size of the cell by a factor at least 2 or 3.newConeComputerApprox
(double coneRadiusRad) Simpler version of the cone search, but at the cost of approximation (false positives).newEllipticalConeComputer
(double aRad, double bRad, double paRad) Simple ellipse search, but at the cost of approximations (leading to false positive).In multi-threaded environments, each thread must have its ownHashComputer
sinceHashComputer
is not thread safe.newHashComputerWithAux
(AuxiliaryAxis auxAxis) WARNING: the return object in not thread-safe!The internalNeighbourSelector
being thread-safe and unmutable, we return it instead of creating a new instance.Returns a new instance ofHealpixNestedPolygonComputer
at this object depth.Returns aVerticesAndPathComputer
, to be used in a distinct thread.double[][]
pathAlongCellEdge
(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide) void
pathAlongCellEdge
(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide, double[][] pathPoints) double[][]
pathAlongCellSide
(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments) Compute points on a given side of a given HEALPix cell on the unit sphere.void
pathAlongCellSide
(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments, double[][] pathPoints) long
regularRingEncode
(long baseCellHash, int iInBasePixel, int jInBasePixel) Encode the given data into the ring scheme hash.sortedExternalEdges
(long hash, int deltaDepth) void
sortedExternalEdges
(long hash, int deltaDepth, FlatHashList result) sortedInternalEdge
(long hash, int deltaDepth, CompassPoint.Ordinal direction) void
sortedInternalEdge
(long hash, int deltaDepth, CompassPoint.Ordinal direction, FlatHashList result) sortedInternalEdgeNE
(long hash, int deltaDepth) void
sortedInternalEdgeNE
(long hash, int deltaDepth, FlatHashList result) sortedInternalEdgeNW
(long hash, int deltaDepth) void
sortedInternalEdgeNW
(long hash, int deltaDepth, FlatHashList result) sortedInternalEdges
(long hash, int deltaDepth) void
sortedInternalEdges
(long hash, int deltaDepth, FlatHashList result) sortedInternalEdgeSE
(long hash, int deltaDepth) void
sortedInternalEdgeSE
(long hash, int deltaDepth, FlatHashList result) sortedInternalEdgeSW
(long hash, int deltaDepth) void
sortedInternalEdgeSW
(long hash, int deltaDepth, FlatHashList result) long
toNested
(long ringHash) Returns the nested representation if the given ring hash.long
toRing
(long nestedHash) Returns the ring representation if the given nested hash.double[]
vertex
(long hash, CompassPoint.Cardinal cardinalPoint) Compute the position of an HEALPix cell vertex on the unit sphere.void
vertex
(long hash, CompassPoint.Cardinal cardinalPoint, double[] resultLonLat) SeeVerticesAndPathComputer.vertex(long, Cardinal)
, except that the result is stored in the given array.void
vertices
(long hash, EnumMap<CompassPoint.Cardinal, double[]> cardinalPoints) EnumMap<CompassPoint.Cardinal,
double[]> vertices
(long hash, EnumSet<CompassPoint.Cardinal> cardinalPoints) Returns the vertices located at the given cardinal points.
-
Method Details
-
depth
public int depth()Description copied from interface:HashComputer
Returns the depth of the hash computed byHashComputer.hash(double, double)
method.- Specified by:
depth
in interfaceHashComputer
- Specified by:
depth
in interfaceHierarchyItem
- Returns:
- the depth of the hash computed by
HashComputer.hash(double, double)
method.
-
newHashComputer
In multi-threaded environments, each thread must have its ownHashComputer
sinceHashComputer
is not thread safe.- Returns:
- a new
HashComputer
, to be used in a distinct thread.
-
newHashComputerWithAux
WARNING: the return object in not thread-safe!- Parameters:
auxAxis
- object describing the auxiliary axis- Returns:
- a new
HashComputerWithAux
, to be used in a distinct thread.
-
hash
public long hash(double lonRad, double latRad) This method is **not** thread safe. For better performances, use oneHashComputer
created bynewHashComputer()
per thread. WARNING: this method IS NOT thread safe. In multi-threaded environments, use the method EXTRA WARNING: As pointed out by Mark Taylor, to use this method you **MUST** be sure that no other code running on the same JVM can call it a the same time. Else, usenewHashComputer()
.newHashComputer()
to create aHashComputer
for each thread.- Specified by:
hash
in interfaceHashComputer
- Parameters:
lonRad
- longitude (in radians) of the the coordinate we want the HEALPix hash value.latRad
- latitude (in radians) of the coordinate we want the HEALPix hash value.- Returns:
- the HEALPix hash value of the given coordinate.
-
newVerticesAndPathComputer
Returns aVerticesAndPathComputer
, to be used in a distinct thread.- Returns:
- a
VerticesAndPathComputer
, to be used in a distinct thread.
-
center
public double[] center(long hash) Description copied from interface:VerticesAndPathComputer
Compute the position on the unit sphere of the center (in the Euclidean projection plane) of the cell associated to the given hash value.- Specified by:
center
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the unprojected center- Returns:
- the unprojected position (on the unit sphere) of the center of the cell in the
Euclidean plane. The lon and lat coordinate are stored in the returned array at indices
VerticesAndPathComputer.LON_INDEX
andVerticesAndPathComputer.LAT_INDEX
respectively. Lat in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
center
public void center(long hash, double[] resultLonLat) Description copied from interface:VerticesAndPathComputer
SeeVerticesAndPathComputer.center(long)
, except that the result is stored in the given array.- Specified by:
center
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the unprojected center.resultLonLat
- array used to store the result. Must be of size >= 2.
-
vertex
Description copied from interface:VerticesAndPathComputer
Compute the position of an HEALPix cell vertex on the unit sphere.- Specified by:
vertex
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the given vertex.cardinalPoint
- location of the vertex with respect to the cell center- Returns:
- the position (on the unit sphere) of the vertex located at the given cardinal direction
from the center of the given cell.
The lon and lat coordinate are stored in the returned array at indices
VerticesAndPathComputer.LON_INDEX
andVerticesAndPathComputer.LAT_INDEX
respectively. Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
vertex
Description copied from interface:VerticesAndPathComputer
SeeVerticesAndPathComputer.vertex(long, Cardinal)
, except that the result is stored in the given array.- Specified by:
vertex
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the given vertex.cardinalPoint
- location of the vertex with respect to the cell centerresultLonLat
- array used to store the result. Must be of size >= 2.
-
vertices
public EnumMap<CompassPoint.Cardinal,double[]> vertices(long hash, EnumSet<CompassPoint.Cardinal> cardinalPoints) Description copied from interface:VerticesAndPathComputer
Returns the vertices located at the given cardinal points. If you want the full 4 vertices, simply useEnumSet.allOf(Cardinal)
. For West and East vertices, useEnumSet.of(Cardinal.W, Cardinal.E)
.- Specified by:
vertices
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the given vertices.cardinalPoints
- locations of the vertices we look for the positions- Returns:
- the positions (on the unit sphere) of the vertices located at the given cardinal
directions from the center of the given cell.
The lon and lat coordinates of each vertex are stored in the arrays at indices
VerticesAndPathComputer.LON_INDEX
andVerticesAndPathComputer.LAT_INDEX
respectively. Lat is in [-pi/2, pi/2] radians, lon is in [0, 2pi] radians.
-
vertices
Description copied from interface:VerticesAndPathComputer
SeeVerticesAndPathComputer.vertices(long, EnumSet)
. The difference is that the user provides a pre-set Map. The structure of the Map is not modified, but the coordinates of the values (array values) are overwritten. An error will be thrown if a value is null or contains less than two elements.- Specified by:
vertices
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the given vertices.cardinalPoints
- the map to be modified y
-
pathAlongCellSide
public double[][] pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments) Description copied from interface:VerticesAndPathComputer
Compute points on a given side of a given HEALPix cell on the unit sphere.- Specified by:
pathAlongCellSide
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for side path on the unit sphere.fromVertex
- direction (from the cell center) of the path starting vertextoVertex
- direction (from the cell center) of the path ending vertexisToVertexIncluded
- iffalse
, the result containsnSegments
points and do no include the result ending vertex. Else the result containsnSegments + 1
points.nSegments
- number of segments in the path from the starting vertex to the ending vertex- Returns:
- a list of points on the given side of the given HEALPix cell on the unit sphere.
-
pathAlongCellSide
public void pathAlongCellSide(long hash, CompassPoint.Cardinal fromVertex, CompassPoint.Cardinal toVertex, boolean isToVertexIncluded, int nSegments, double[][] pathPoints) Description copied from interface:VerticesAndPathComputer
SeeVerticesAndPathComputer.pathAlongCellSide(long, Cardinal, Cardinal, boolean, int)
. The difference is that the user provides a list of points whose coordinates are going to be overwritten. An error will be thrown if the array (of array) is not large enough (i.e. its is smaller than nSegments or nSegments + 1) or if one of the array is null or contains less than two elements.- Specified by:
pathAlongCellSide
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for side path on the unit sphere.fromVertex
- direction (from the cell center) of the path starting vertextoVertex
- direction (from the cell center) of the path ending vertexisToVertexIncluded
- iffalse
, the result containsnSegments
points and do no include the result ending vertex. Else the result containsnSegments + 1
points.nSegments
- number of segments in the path from the starting vertex to the ending vertexpathPoints
- object used to store the result.
-
pathAlongCellEdge
public double[][] pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide) - Specified by:
pathAlongCellEdge
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash value of the cell we look for the edge path on the unit sphere.startingVertex
- direction (from the cell center) of the path starting vertexclockwiseDirection
- iftrue
, result points are stored in a clockwise direction order, else they are stored in counter-clockwise direction order.nSegmentsBySide
- number of segments in each each side is divided. Hence, the total number of points in the result is4 x nSegmentsBySide
.- Returns:
- a list of points on the given edge of the given HEALPix cell on the unit sphere, clockwise or counter-clockwise ordered.
-
pathAlongCellEdge
public void pathAlongCellEdge(long hash, CompassPoint.Cardinal startingVertex, boolean clockwiseDirection, int nSegmentsBySide, double[][] pathPoints) Description copied from interface:VerticesAndPathComputer
SeeVerticesAndPathComputer.pathAlongCellEdge(long, Cardinal, boolean, int)
. The difference is that the user provides a list of points whose coordinates are going to be overwritten. An error will be thrown if the array (of array) is not large enough (i.e. its is smaller than 4 *nSegments) or if one of the array is null or contains less than two elements.- Specified by:
pathAlongCellEdge
in interfaceVerticesAndPathComputer
- Parameters:
hash
- hash hash value of the cell we look for the edge path on the unit sphere.startingVertex
- direction (from the cell center) of the path starting vertexclockwiseDirection
- iftrue
, result points are stored in a clockwise direction order, else they are stored in counter-clockwise direction order.nSegmentsBySide
- number of segments in each each side is divided. Hence, the total number of points in the result is4 x nSegmentsBySide
.pathPoints
- object used to store the result.
-
newNeighbourSelector
The internalNeighbourSelector
being thread-safe and unmutable, we return it instead of creating a new instance.- Returns:
- the internal neighbour selector.
-
neighbour
Description copied from interface:NeighbourSelector
The hash value of the neighbour of the cell of given hash, in the given deirection.- Specified by:
neighbour
in interfaceNeighbourSelector
- Parameters:
hash
- ash value of the cell we are looking for the neighbour.direction
- direction of the neighbour we are looking for.- Returns:
- -1 if there is no neighbour in the given direction (hashes located at corners of base hases).
-
neighbours
Description copied from interface:NeighbourSelector
Returns the list of the hash of the cells surrounding the cell defined by the given hash. The number of surrounding cells can be 8 (for all cells except the cells located at the corners of the 12 depth 0 cells), 7 (for the west and east corners of the polar caps, i.e. depth 0 cells number 0, 1, 2, 4, 8, 9, 10 and 11, or for the north and south corners of the equatorial regions, i.e. depth 0 cells number 4, 5, 6 and 7), or 6 for depth 0 pixels.- Specified by:
neighbours
in interfaceNeighbourSelector
- Parameters:
hash
- hash value of the cell we are looking for the neighbours.- Returns:
- the list of neighbours hashes
-
neighbours
Description copied from interface:NeighbourSelector
Equivalent ofNeighbourSelector.neighbours(long)
but passing in argument the list object to be filled. WARNING: the content of the provided list is overwritten, and be sure the list is large enough (at least of size 8). And the value -1 is returned if the given hash has no neighbour at the given main wind direction.- Specified by:
neighbours
in interfaceNeighbourSelector
- Parameters:
hash
- the hash code we want the neighboursresult
- which contains the list of neighbours from index 0 to the number of neighbours
-
neighbours
Description copied from interface:NeighbourSelector
Idem asNeighbourSelector.neighbours(long, NeighbourList)
except that the result is put in a simpleFlatHashList
. WARNING: the content of the provided list is overwritten, and be sure the list is large enough (at least of size 8).- Specified by:
neighbours
in interfaceNeighbourSelector
- Parameters:
hash
- the hash code we want the neighboursresult
- which contains the list of neighbours from index 0 to the number of neighbours
-
neighbours
Description copied from interface:NeighbourSelector
Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the wanted neighbours.- Specified by:
neighbours
in interfaceNeighbourSelector
- Parameters:
hash
- hash value of the cell we are looking for the neighbours.directions
- the directions of the neighbours we are looking for.- Returns:
- the list of the hash of the neighbours of the cell having the given hash.
-
neighbours
Description copied from interface:NeighbourSelector
Equivalent ofNeighbourSelector.neighbours(long, FlatHashList)
but with the list of direction of the wanted neighbours. And the value -1 is returned if the given hash has no neighbour at the given main wind direction.- Specified by:
neighbours
in interfaceNeighbourSelector
- Parameters:
hash
- hash value of the cell we are looking for the neighbours.directions
- the directions of the neighbours we are looking for.result
- the list holding the result.
-
internalEdges
- Specified by:
internalEdges
in interfaceNeighbourSelector
-
internalEdges
- Specified by:
internalEdges
in interfaceNeighbourSelector
-
sortedInternalEdges
- Specified by:
sortedInternalEdges
in interfaceNeighbourSelector
-
sortedInternalEdges
- Specified by:
sortedInternalEdges
in interfaceNeighbourSelector
-
sortedInternalEdge
- Specified by:
sortedInternalEdge
in interfaceNeighbourSelector
-
sortedInternalEdge
public void sortedInternalEdge(long hash, int deltaDepth, CompassPoint.Ordinal direction, FlatHashList result) - Specified by:
sortedInternalEdge
in interfaceNeighbourSelector
-
sortedInternalEdgeNE
- Specified by:
sortedInternalEdgeNE
in interfaceNeighbourSelector
-
sortedInternalEdgeNE
- Specified by:
sortedInternalEdgeNE
in interfaceNeighbourSelector
-
sortedInternalEdgeNW
- Specified by:
sortedInternalEdgeNW
in interfaceNeighbourSelector
-
sortedInternalEdgeNW
- Specified by:
sortedInternalEdgeNW
in interfaceNeighbourSelector
-
sortedInternalEdgeSE
- Specified by:
sortedInternalEdgeSE
in interfaceNeighbourSelector
-
sortedInternalEdgeSE
- Specified by:
sortedInternalEdgeSE
in interfaceNeighbourSelector
-
sortedInternalEdgeSW
- Specified by:
sortedInternalEdgeSW
in interfaceNeighbourSelector
-
sortedInternalEdgeSW
- Specified by:
sortedInternalEdgeSW
in interfaceNeighbourSelector
-
internalCorner
- Specified by:
internalCorner
in interfaceNeighbourSelector
-
internalCornerN
public long internalCornerN(long hash, int deltaDepth) - Specified by:
internalCornerN
in interfaceNeighbourSelector
-
internalCornerS
public long internalCornerS(long hash, int deltaDepth) - Specified by:
internalCornerS
in interfaceNeighbourSelector
-
internalCornerE
public long internalCornerE(long hash, int deltaDepth) - Specified by:
internalCornerE
in interfaceNeighbourSelector
-
internalCornerW
public long internalCornerW(long hash, int deltaDepth) - Specified by:
internalCornerW
in interfaceNeighbourSelector
-
externalEdges
- Specified by:
externalEdges
in interfaceNeighbourSelector
-
externalEdges
- Specified by:
externalEdges
in interfaceNeighbourSelector
-
sortedExternalEdges
- Specified by:
sortedExternalEdges
in interfaceNeighbourSelector
-
sortedExternalEdges
- Specified by:
sortedExternalEdges
in interfaceNeighbourSelector
-
newConeComputer
Returns aHealpixNestedFixedRadiusConeComputer
, to be used in a distinct thread.- Parameters:
coneRadiusRad
- radius of the cone.- Returns:
- a
HealpixNestedFixedRadiusConeComputer
, to be used in a distinct thread.
-
newConeComputerApprox
Simpler version of the cone search, but at the cost of approximation (false positives).- Parameters:
coneRadiusRad
- radius of the cone- Returns:
- an object allowing to perform fixed radius cone search queries.
-
newConeComputer4Xmatch
We suppose here that the radius of the (cross-match) cone is smaller that the typical size of the cell by a factor at least 2 or 3. The algorithm is design to be very fast, at the cost of very raw approxiations (false positives).- Parameters:
coneRadiusRad
- radius of the cone- Returns:
- an object allowing to perform fixed radius cone search queries.
-
newPolygonComputer
Returns a new instance ofHealpixNestedPolygonComputer
at this object depth.- Returns:
- a new instance of
HealpixNestedPolygonComputer
at this object depth.
-
newEllipticalConeComputer
public NestedEllipticalConeComputerApprox newEllipticalConeComputer(double aRad, double bRad, double paRad) Simple ellipse search, but at the cost of approximations (leading to false positive). The smallest the ratio between the HEALPix (deeper) cells area over the elliptical cone area , the more accurate the result is.- Parameters:
aRad
- semi-major axis of the elliptical cone, in radiansbRad
- semi-minor axis of the elliptical cone, in radianspaRad
- position angle (using as North the point lon=0, lat = pi/2)) of the elliptical cone, in radians- Returns:
- an object allowing to perform fixed elliptical cone search queries.
-
toRing
public long toRing(long nestedHash) Returns the ring representation if the given nested hash.- Parameters:
nestedHash
- an HEALPix cell nested hash.- Returns:
- the ring representation if the given nested hash.
-
regularRingEncode
public long regularRingEncode(long baseCellHash, int iInBasePixel, int jInBasePixel) Encode the given data into the ring scheme hash.- Parameters:
baseCellHash
- base cell number, in [0, 12[.iInBasePixel
- x-axis (i.e. South-East) z-curve coordinate in the base cell.jInBasePixel
- y-axis (i.e. South West) z-curve coordinate in the base cell.- Returns:
- the ring encoded hash of the given base cell and coordinates in the base cell.
-
toNested
public long toNested(long ringHash) Returns the nested representation if the given ring hash.- Parameters:
ringHash
- an HEALPix cell ring hash.- Returns:
- the nested representation if the given ring hash.
-
dividedBy4Quotient
public long dividedBy4Quotient(long d)
-