Package gov.fnal.eag.healpix
Class PixTools
java.lang.Object
gov.fnal.eag.healpix.PixTools
contains methods translated from HEALPix Fortran90
with increased map resolution in comparison to original Fortran code.
- Author:
- N Kuropatkin
Created on Mar 10, 2005
Modified on December 18 2007
Corrected arithmetic and mistyping April 20 2008, Mark Taylor made modifications to make the class thread safe 11-Jan-2012
All methods are thread safe. This class can be used as a singleton, the singleton instance being available from the
getInstance()
method. For compatibility with previous versions however it is possible to construct new instances using the default constructor.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlong
ang2pix_nest
(long nside, double theta, double phi) renders the pixel number pix (NESTED scheme) for a pixel which contains a point on a sphere at coordinates theta and phi, given map resolution parameter nside.long
ang2pix_ring
(long nside, double theta, double phi) renders the pixel number ipix (RING scheme) for a pixel which contains a point with coordinates theta and phi, given the map resolution parameter nside.javax.vecmath.Vector3d
Ang2Vec
(double theta, double phi) calculates vector corresponding to angles theta (co-latitude measured from North pole, in [0,pi] radians) phi (longitude measured eastward in [0,2pi] radians) North pole is (x,y,z) = (0, 0, 1)double
AngDist
(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2) calculates angular distance (in radians) between 2 Vectors v1 and v2 In general dist = acos(v1.v2) except if the vectors are almost alignedObject[]
convert_inplace_long
(String subcall, Object[] map) converts a 8 byte Object map from RING to NESTED and vice versa in place, ie without allocation a temporary map (Has no reason for Java).Object[]
convert_nest2ring
(long nside, Object[] map) make the conversion NEST to RINGObject[]
convert_ring2nest
(long nside, Object[] map) makes the conversion RING to NESTjavax.vecmath.Vector3d
crossProduct
(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2) calculate cross product of two vectorsdouble
dotProduct
(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2) calculates a dot product (inner product) of two 3D vectors the result is doublegetDisc_ring
(long nside, javax.vecmath.Vector3d vector0, double radius) an obsolete method.static PixTools
Returns singleton instance.long
GetNSide
(double pixsize) calculate requared nside given pixel size in arcsecInRing
(long nside, long iz, double phi0, double dphi, boolean nest) returns the list of pixels in RING or NEST scheme with latitude in [phi0 - dpi, phi0 + dphi] on the ring iz in [1, 4*nside -1 ] The pixel id numbers are in [0, 12*nside^2 - 1] the indexing is in RING, unless nest is set to 1double[]
intrs_intrv
(double[] d1, double[] d2) computes the intersection di of 2 intervals d1 (= [a1,b1]) and d2 (= [a2,b2]) on the periodic domain (=[A,B] where A and B arbitrary) ni is the resulting number of intervals (0,1, or 2) if a1 <b1 then d1 = {x |a1 <= x <= b1} if a1>b1 then d1 = {x | a1 <=x <= B U A <=x <=b1}neighbours_nest
(long nside, long ipix) returns 7 or 8 neighbours of any pixel in the nested scheme The neighbours are ordered in the following way: First pixel is the one to the south ( the one west of the south direction is taken for pixels that don't have a southern neighbour).long
nest2ring
(long nside, long ipnest) converts from NESTED to RING pixel numberinglong
next_in_line_nest
(long nside, long ipix) calculates the pixel that lies on the East side (and the same latitude) as the given NESTED pixel number - ipixlong
Npix2Nside
(long npix) returns nside such that npix = 12*nside^2, nside should be power of 2 and smaller than ns_max if not return -1long
Nside2Npix
(long nside) calculates npix such that npix = 12*nside^2 ,nside should be a power of 2, and smaller than ns_max otherwise return -1double[]
pix2ang_nest
(long nside, long ipix) Renders theta and phi coordinates of the normal pixel center for the pixel number ipix (NESTED scheme) given the map resolution parameter nside.double[]
pix2ang_ring
(long nside, long ipix) renders theta and phi coordinates of the nominal pixel center for the pixel number ipix (RING scheme) given the map resolution parameter nsidejavax.vecmath.Vector3d
pix2vect_nest
(long nside, long ipix) renders vector (x,y,z) coordinates of the nominal pixel center for the pixel ipix (NESTED scheme ) given the map resolution parameter nside.javax.vecmath.Vector3d
pix2vect_ring
(long nside, long ipix) returns the vector pointing in the center of the pixel ipix.double[][]
pix2vertex_nest
(long nside, long ipix) renders vector (x,y,z) coordinates of the nominal pixel center for the pixel ipix (NESTED scheme ) given the map resolution parameter nside.double[][]
pix2vertex_ring
(long nside, long ipix) returns double [][] with coordinates of the pixel corners.double
PixRes
(long nside) calculates angular resolution of the pixel map in arc seconds.double[]
PolarToRaDec
(double[] polar) returns ra, dec in degrees given polar coordinates in radiansquery_disc
(long nside, javax.vecmath.Vector3d vector, double radius, int nest, int inclusive) generates in the RING or NESTED scheme all pixels that lays within an angular distance Radius of the center.query_polygon
(long nside, ArrayList vlist, long nest, long inclusive) finds pixels that lay within a CONVEX polygon defined by its vertex on spherequery_ring
(long nside, javax.vecmath.Vector3d vector, double radius, int nest, int inclusive) generates in the RING or NESTED scheme all pixels that lays at an angular distance Radius of the center.query_strip
(long nside, double theta1, double theta2, long nest) finds pixels having a colatitude (measured from North pole) : theta1 < colatitude < theta2 with 0 <= theta1 < theta2 <= Pi if theta2 < theta1 then pixels with 0 <= colatitude < theta2 or theta1 < colatitude < Pi are returnedquery_triangle
(long nside, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2, javax.vecmath.Vector3d v3, long nest, long inclusive) generates a list of pixels that lay inside a triangle defined by the three vertex vectorsdouble[]
RaDecToPolar
(double[] radec) returns polar coordinates in radians given ra, dec in degreeslong
ring2nest
(long nside, long ipring) converts pixel number from ring numbering schema to the nested onelong
RingNum
(long nside, double z) returns the ring number in {1, 4*nside - 1} calculated from z coordinatedouble
SurfaceTriangle
(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2, javax.vecmath.Vector3d v3) calculates the surface of spherical triangle defined by vertices v1,v2,v3 Algorithm: finds triangle sides and uses l'Huilier formula to compute "spherical excess" = surface area of triangle on a sphere of radius one see, eg Bronshtein, Semendyayev Eq 2.86 half perimeter hp = 0.5*(side1+side2+side3) l'Huilier formula x0 = tan( hp/2.) x1 = tan((hp - side1)/2.) x2 = tan((hp - side2)/2.) x3 = tan((hp - side3)/2.)double[]
Vect2Ang
(javax.vecmath.Vector3d v) converts a Vector3d in a tuple of angles tup[0] = theta co-latitude measured from North pole, in [0,PI] radians, tup[1] = phi longitude measured eastward, in [0,2PI] radianslong
vect2pix_nest
(long nside, javax.vecmath.Vector3d vector) renders the pixel number pix (NESTED scheme) for a pixel which contains a point on a sphere at coordinate vector (x,y,z), given the map resolution parameter nside.long
vect2pix_ring
(long nside, javax.vecmath.Vector3d vector) renders the pixel number ipix (RING scheme) for a pixel which contains a point on a sphere at coordinate vector (x,y,z), given the map resolution parameter nsidecalculates a vector production of two vectors.double[]
xyzToPolar
(double x, double y, double z) returns polar coordinates of a point on unit sphere given Cartesian coordinates
-
Constructor Details
-
PixTools
public PixTools()default constructor
-
-
Method Details
-
query_strip
finds pixels having a colatitude (measured from North pole) : theta1 < colatitude < theta2 with 0 <= theta1 < theta2 <= Pi if theta2 < theta1 then pixels with 0 <= colatitude < theta2 or theta1 < colatitude < Pi are returned- Parameters:
nside
- long the map resolution parametertheta1
- lower edge of the colatitudetheta2
- upper edge of the colatitudenest
- long if = 1 result is in NESTED scheme- Returns:
- ArrayList of pixel numbers (long)
- Throws:
Exception
IllegalArgumentException
-
query_polygon
public ArrayList query_polygon(long nside, ArrayList vlist, long nest, long inclusive) throws Exception finds pixels that lay within a CONVEX polygon defined by its vertex on sphere- Parameters:
nside
- the map resolutionvlist
- ArrayList of vectors defining the polygon verticesnest
- if set to 1 use NESTED schemeinclusive
- if set 1 returns all pixels crossed by polygon boundaries- Returns:
- ArrayList of pixels algorithm: the polygon is divided into triangles vertex 0 belongs to all triangles
- Throws:
Exception
IllegalArgumentException
-
query_triangle
public ArrayList query_triangle(long nside, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2, javax.vecmath.Vector3d v3, long nest, long inclusive) throws Exception generates a list of pixels that lay inside a triangle defined by the three vertex vectors- Parameters:
nside
- long map resolution parameterv1
- Vector3d defines one vertex of the trianglev2
- Vector3d another vertexv3
- Vector3d yet another onenest
- long 0 (default) RING numbering scheme, if set to 1 the NESTED scheme will be used.inclusive
- long 0 (default) only pixels whose centers are inside the triangle will be listed, if set to 1 all pixels overlaping the triangle will be listed- Returns:
- ArrayList with pixel numbers
- Throws:
Exception
IllegalArgumentException
-
intrs_intrv
public double[] intrs_intrv(double[] d1, double[] d2) computes the intersection di of 2 intervals d1 (= [a1,b1]) and d2 (= [a2,b2]) on the periodic domain (=[A,B] where A and B arbitrary) ni is the resulting number of intervals (0,1, or 2) if a1 <b1 then d1 = {x |a1 <= x <= b1} if a1>b1 then d1 = {x | a1 <=x <= B U A <=x <=b1}- Parameters:
d1
- double[] first intervald2
- double[] second interval- Returns:
- double[] one or two intervals intersections
-
getDisc_ring
an obsolete method. Use query_disc instead.- Parameters:
nside
-vector0
-radius
-- Returns:
- - ArrayList of long
-
query_disc
public ArrayList query_disc(long nside, javax.vecmath.Vector3d vector, double radius, int nest, int inclusive) generates in the RING or NESTED scheme all pixels that lays within an angular distance Radius of the center.- Parameters:
nside
- long map resolutionvector
- Vector3d pointing to the disc centerradius
- double angular radius of the disc (in RADIAN )nest
- int 0 (default) if output is in RING scheme, if set to 1 output is in NESTEDinclusive
- int 0 (default) only pixels whose centers lay in the disc are listed, if set to 1, all pixels overlapping the disc are listed. In the inclusive mode the radius is increased by half the pixel size. In this case most probably all neighbor pixels will be listed even with very small radius. In case of exclusive search and very small radius when the disc lays completely inside a pixel the pixel number is returned using vector2pix method.- Returns:
- ArrayList of pixel numbers calls: RingNum(nside, ir) InRing(nside, iz, phi0, dphi,nest) vector2pix(nside,ipix)
-
query_ring
public ArrayList query_ring(long nside, javax.vecmath.Vector3d vector, double radius, int nest, int inclusive) generates in the RING or NESTED scheme all pixels that lays at an angular distance Radius of the center.- Parameters:
nside
- long map resolutionvector
- Vector3d pointing to the ring centerradius
- double angular radius of the ring (in RADIAN )nest
- int 0 (default) if output is in RING scheme, if set to 1 output is in NESTEDinclusive
- int 0 (default) only pixels whose centers are crossed by the ring are listed, if set to 1, all pixels crossed or touched by the ring are listed. In the inclusive mode the radius is increased by half the pixel size. In this case most probably all neighbor pixels will be listed even with very small radius. In case of exclusive search and very small radius when the ring lays completely inside a pixel the pixel number is returned using vector2pix method.- Returns:
- ArrayList of pixel numbers calls: RingNum(nside, ir) InRing(nside, iz, phi0, dphi,nest) vector2pix(nside,ipix)
-
pix2ang_ring
public double[] pix2ang_ring(long nside, long ipix) renders theta and phi coordinates of the nominal pixel center for the pixel number ipix (RING scheme) given the map resolution parameter nside- Parameters:
nside
- long map resolutionipix
- long pixel number- Returns:
- double[] theta,phi
-
pix2vect_ring
public javax.vecmath.Vector3d pix2vect_ring(long nside, long ipix) returns the vector pointing in the center of the pixel ipix. The vector is calculated by makePix2Vect_ring method- Parameters:
nside
- map resolutionipix
- pixel number- Returns:
- Vector3d
-
pix2vertex_ring
public double[][] pix2vertex_ring(long nside, long ipix) returns double [][] with coordinates of the pixel corners. The array is calculated by makePix2Vect_ring method- Parameters:
nside
- map resolutionipix
- pixel number- Returns:
- double[][] list of vertex coordinates
-
ang2pix_ring
public long ang2pix_ring(long nside, double theta, double phi) renders the pixel number ipix (RING scheme) for a pixel which contains a point with coordinates theta and phi, given the map resolution parameter nside.- Parameters:
nside
- long map resolution parametertheta
- double thetaphi
- - double phi- Returns:
- long ipix
-
vect2pix_ring
public long vect2pix_ring(long nside, javax.vecmath.Vector3d vector) renders the pixel number ipix (RING scheme) for a pixel which contains a point on a sphere at coordinate vector (x,y,z), given the map resolution parameter nside- Parameters:
nside
- long map resolutionvector
- Vector3d of the point coordinates- Returns:
- long pixel number
- Throws:
IllegalArgumentException
-
pix2ang_nest
public double[] pix2ang_nest(long nside, long ipix) Renders theta and phi coordinates of the normal pixel center for the pixel number ipix (NESTED scheme) given the map resolution parameter nside.- Parameters:
nside
- map resolution parameter - longipix
- long pixel number- Returns:
- double[] (theta, phi)
- Throws:
IllegalArgumentException
-
pix2vect_nest
public javax.vecmath.Vector3d pix2vect_nest(long nside, long ipix) renders vector (x,y,z) coordinates of the nominal pixel center for the pixel ipix (NESTED scheme ) given the map resolution parameter nside. Also calculates the (x,y,z) positions of 4 pixel vertices (corners) in the order N,W,S,E. These can be get using method pix2vertex_nest.- Parameters:
nside
- the map resolutionipix
- long pixel number- Returns:
- Vector3d
- Throws:
IllegalArgumentException
-
pix2vertex_nest
public double[][] pix2vertex_nest(long nside, long ipix) renders vector (x,y,z) coordinates of the nominal pixel center for the pixel ipix (NESTED scheme ) given the map resolution parameter nside. Also calculates the (x,y,z) positions of 4 pixel vertices (corners) in the order N,W,S,E.- Parameters:
nside
- the map resolutionipix
- long pixel number- Returns:
- double[3][4] 4 sets of vector components
- Throws:
IllegalArgumentException
-
ang2pix_nest
public long ang2pix_nest(long nside, double theta, double phi) renders the pixel number pix (NESTED scheme) for a pixel which contains a point on a sphere at coordinates theta and phi, given map resolution parameter nside. The computation is made to the highest resolution available and then degraded to required resolution by integer division. It makes sure that the treatment of round-off will be consistent for every resolution.- Parameters:
nside
- the map resolution parametertheta
- double theta coordinate in radiansphi
- double phi coordinate in radians- Returns:
- pixel number long
- Throws:
IllegalArgumentException
-
convert_nest2ring
make the conversion NEST to RING- Parameters:
nside
- the map resolution parametermap
- Object[] the map in NESTED scheme- Returns:
- - Object[] a map in RING scheme
- Throws:
IllegalArgumentException
-
convert_ring2nest
makes the conversion RING to NEST- Parameters:
nside
- long resolutionmap
- map in RING- Returns:
- map in NEST
- Throws:
IllegalArgumentException
-
convert_inplace_long
converts a 8 byte Object map from RING to NESTED and vice versa in place, ie without allocation a temporary map (Has no reason for Java). This method is more general but slower than convert_nest2ring. This method is a wrapper for functions ring2nest and nest2ring. Their names are supplied in the subcall argument.- Parameters:
subcall
- String name of the method to use.map
- Object[] map- Returns:
- resulting Object[] map.
- Throws:
IllegalArgumentException
-
neighbours_nest
returns 7 or 8 neighbours of any pixel in the nested scheme The neighbours are ordered in the following way: First pixel is the one to the south ( the one west of the south direction is taken for pixels that don't have a southern neighbour). From then on the neighbors are ordered in the clockwise direction.- Parameters:
nside
- the map resolutionipix
- long pixel number- Returns:
- ArrayList
- Throws:
IllegalArgumentException
-
InRing
returns the list of pixels in RING or NEST scheme with latitude in [phi0 - dpi, phi0 + dphi] on the ring iz in [1, 4*nside -1 ] The pixel id numbers are in [0, 12*nside^2 - 1] the indexing is in RING, unless nest is set to 1- Parameters:
nside
- long the map resolutioniz
- long ring numberphi0
- doubledphi
- doublenest
- boolean format flag- Returns:
- ArrayList of pixels
- Throws:
IllegalArgumentException
- Modified by N. Kuropatkin 07/09/2008 Corrected several bugs and make test of all cases.
-
next_in_line_nest
public long next_in_line_nest(long nside, long ipix) calculates the pixel that lies on the East side (and the same latitude) as the given NESTED pixel number - ipix- Parameters:
nside
- long resolutionipix
- long pixel number- Returns:
- long next pixel in line
- Throws:
IllegalArgumentException
-
vect2pix_nest
public long vect2pix_nest(long nside, javax.vecmath.Vector3d vector) renders the pixel number pix (NESTED scheme) for a pixel which contains a point on a sphere at coordinate vector (x,y,z), given the map resolution parameter nside. The computation is made to the highest resolution available (nside=ns_max) and then degraded to that requared (by Integer division) this doesn't cost much, and it makes sure that the treatment of round-off will be consistent for every resolution- Parameters:
nside
- long the map resolutionvector
- Vewctor3d the input vector- Returns:
- pixel long
- Throws:
IllegalArgumentException
-
ring2nest
public long ring2nest(long nside, long ipring) converts pixel number from ring numbering schema to the nested one- Parameters:
nside
- long resolutionipring
- long pixel number in ring schema- Returns:
- long pixel number in nest schema
- Throws:
IllegalArgumentException
-
nest2ring
public long nest2ring(long nside, long ipnest) converts from NESTED to RING pixel numbering- Parameters:
nside
- long resolutionipnest
- long NEST pixel number- Returns:
- ipring long RING pixel number
- Throws:
IllegalArgumentException
-
RingNum
public long RingNum(long nside, double z) returns the ring number in {1, 4*nside - 1} calculated from z coordinate- Parameters:
nside
- long resolutionz
- double z coordinate- Returns:
- long ring number
-
Ang2Vec
public javax.vecmath.Vector3d Ang2Vec(double theta, double phi) calculates vector corresponding to angles theta (co-latitude measured from North pole, in [0,pi] radians) phi (longitude measured eastward in [0,2pi] radians) North pole is (x,y,z) = (0, 0, 1)- Parameters:
theta
- doublephi
- double- Returns:
- Vector3d
- Throws:
IllegalArgumentException
-
Vect2Ang
public double[] Vect2Ang(javax.vecmath.Vector3d v) converts a Vector3d in a tuple of angles tup[0] = theta co-latitude measured from North pole, in [0,PI] radians, tup[1] = phi longitude measured eastward, in [0,2PI] radians- Parameters:
v
- Vector3d- Returns:
- double[] out_tup out_tup[0] = theta out_tup[1] = phi
-
Npix2Nside
public long Npix2Nside(long npix) returns nside such that npix = 12*nside^2, nside should be power of 2 and smaller than ns_max if not return -1- Parameters:
npix
- long the number of pixels in the map- Returns:
- long nside the map resolution parameter
-
Nside2Npix
public long Nside2Npix(long nside) calculates npix such that npix = 12*nside^2 ,nside should be a power of 2, and smaller than ns_max otherwise return -1- Parameters:
nside
- long the map resolution- Returns:
- npix long the number of pixels in the map
-
SurfaceTriangle
public double SurfaceTriangle(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2, javax.vecmath.Vector3d v3) throws Exception calculates the surface of spherical triangle defined by vertices v1,v2,v3 Algorithm: finds triangle sides and uses l'Huilier formula to compute "spherical excess" = surface area of triangle on a sphere of radius one see, eg Bronshtein, Semendyayev Eq 2.86 half perimeter hp = 0.5*(side1+side2+side3) l'Huilier formula x0 = tan( hp/2.) x1 = tan((hp - side1)/2.) x2 = tan((hp - side2)/2.) x3 = tan((hp - side3)/2.)- Parameters:
v1
- Vector3dv2
- Vector3dv3
- Vector3d vertices of the triangle- Returns:
- double the triangle surface
- Throws:
Exception
-
AngDist
calculates angular distance (in radians) between 2 Vectors v1 and v2 In general dist = acos(v1.v2) except if the vectors are almost aligned- Parameters:
v1
- Vector3dv2
- Vector3d- Returns:
- double dist in radians
- Throws:
Exception
-
VectProd
calculates a vector production of two vectors.- Parameters:
v1
- Vectror containing 3 elements of Number typev2
- Vector containing 3 elements of Number type- Returns:
- Vector of 3 Objects of Double type
- Throws:
Exception
-
dotProduct
calculates a dot product (inner product) of two 3D vectors the result is double- Parameters:
v1
- 3d Vector of Number Objects (Double, long .. )v2
- 3d Vector- Returns:
- double
- Throws:
Exception
-
crossProduct
public javax.vecmath.Vector3d crossProduct(javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2) calculate cross product of two vectors- Parameters:
v1
- Vector3dv2
- Vector3d- Returns:
- Vector3d result of the product
-
PixRes
public double PixRes(long nside) calculates angular resolution of the pixel map in arc seconds.- Parameters:
nside
-- Returns:
- double resolution in arcsec
-
GetNSide
public long GetNSide(double pixsize) calculate requared nside given pixel size in arcsec- Parameters:
pixsize
- in arcsec- Returns:
- long nside parameter
-
RaDecToPolar
public double[] RaDecToPolar(double[] radec) returns polar coordinates in radians given ra, dec in degrees- Parameters:
radec
- double array containing ra,dec in degrees- Returns:
- res double array containing theta and phi in radians res[0] = theta res[1] = phi
-
PolarToRaDec
public double[] PolarToRaDec(double[] polar) returns ra, dec in degrees given polar coordinates in radians- Parameters:
polar
- double array polar[0] = phi in radians polar[1] = theta in radians- Returns:
- double array radec radec[0] = ra in degrees radec[1] = dec in degrees
-
xyzToPolar
public double[] xyzToPolar(double x, double y, double z) returns polar coordinates of a point on unit sphere given Cartesian coordinates- Parameters:
x
- - Cartesian coordinate x of a point on unit spherey
- - y coordinatez
- - z coordinate- Returns:
- double [] theta,phi
-
getInstance
Returns singleton instance.
-