HMpTy.htm.htm module ∞
Tools for working with Hierarchical Triangular Meshes, including coordinate crossmatching
- Author
David Young (originally forked from Erin Sheldon’s esutil - esheldon)
-
class
HTM
(depth=16, log=False)[source] ∞ Bases:
HMpTy.htm._htmcCode.HTMC
A Hierarchical Triangular Mesh object
Key Arguments
depth
– the depth of the mesh you wish to create. Default 16
Usage
To generate a mesh object:
from HMpTy import HTM mesh16 = HTM( depth=16 )
-
property
area
[source] ∞ The mean area of triangles in this mesh in units of square degrees.
Usage
mesh.area
-
lookup_id
(ra, dec)[source] ∞ Lookup the ID of HTM trixel that a coordinate or lists of coordinates lie on
Key Arguments
ra
– list, numpy array or single ra value (first coordinate set)dec
– list, numpy array or single dec value (first coordinate set - must match ra1 array length)
Return
htmIds
– a list of HTM trixel ids the coordinates lie on
Usage
To find the trixel IDs that a set of coordinate lie on:
raList1 = ["13:20:00.00", 200.0, "13:20:00.00", 175.23, 21.36] decList1 = ["+24:18:00.00", 24.3, "+24:18:00.00", -28.25, -15.32] htmids = mesh.lookup_id(raList1, decList1) for h, r, d in zip(htmids, raList1, decList1): print(r, d, " --> ", h)
-
intersect
(ra, dec, radius, inclusive=True, convertCoordinates=True)[source] ∞ return IDs of all triangles contained within and/or intersecting a circle centered on a given ra and dec
Key Arguments
ra
– RA of central point in decimal degrees or sexagesimaldec
– DEC of central point in decimal degrees or sexagesimalradius
– radius of circle in degreesinclusive
– include IDs of triangles that intersect the circle as well as those completely inclosed by the circle. Default True
Return
trixelArray
– a numpy array of the match trixel IDs
Usage
To return the trixels overlapping a circle with a 10 arcsec radius centred at 23:25:53.56, +26:54:23.9
overlappingTrixels = mesh16.intersect( ra="23:25:53.56", dec="+26:54:23.9", radius=10 / (60 * 60), inclusive=True )
Or to return the trixels completing enclosed by a circle with a 1 degree radius centred at 23:25:53.56, +26:54:23.9
overlappingTrixels = mesh16.intersect( ra="23:25:53.56", dec="+26:54:23.9", radius=1, inclusive=False )
-
match
(ra1, dec1, ra2, dec2, radius, maxmatch=1, convertToArray=True)[source] ∞ Crossmatch two lists of ra/dec points
This is very efficient for large search angles and large lists. Note, if you need to match against the same points many times, you should use a
Matcher
objectKey Arguments
ra1
– list, numpy array or single ra value (first coordinate set)dec1
– list, numpy array or single dec value (first coordinate set - must match ra1 array length)ra2
– list, numpy array or single ra value (second coordinate set)dec2
– list, numpy array or single dec value (second coordinate set - must match ra2 array length)radius
– search radius in degrees. Can be list, numpy array or single value. If list or numpy array must be same length as ra1 array length)maxmatch
– maximum number of matches to return. Set to0
to match all points. Default 1 (i.e. closest match)convertToArray
– convert the coordinates into an array. Default True. Can bypass the conversion check if you are sure coordinates in numpy array
Return
matchIndices1
– match indices for list1 (ra1, dec1)matchIndices2
– match indices for list2 (ra2, dec2)sepDeg
– separations between matched corrdinates in degrees. All returned arrays are the same size
Usage
To match 2 lists of corrdinates try something like this:
twoArcsec = 2.0 / 3600. raList1 = [200.0, 200.0, 200.0, 175.23, 21.36] decList1 = [24.3, 24.3, 24.3, -28.25, -15.32] raList2 = [200.0, 200.0, 200.0, 175.23, 55.25] decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec, 24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22] matchIndices1, matchIndices2, seps = mesh.match( ra1=raList1, dec1=decList1, ra2=raList2, dec2=decList2, radius=twoArcsec, maxmatch=0 ) for m1, m2, s in zip(matchIndices1, matchIndices2, seps): print(raList1[m1], decList1[m1], " -> ", s * 3600., " arcsec -> ", raList2[m2], decList2[m2])
Note from the print statement, you can index the arrays
raList1
,decList1
with thematchIndices1
array values andraList2
,decList2
with thematchIndices2
values.
-
class
Matcher
(ra, dec, depth=16, log=False, convertToArray=True)[source] ∞ Bases:
HMpTy.htm._htmcCode.Matcher
A matcher-array object to match other arrays of ra,dec against
The Matcher object is initialized with a set of ra,dec coordinates and can then be used and reused to match against other sets of coordinates
Key Arguments
log
– loggerdepth
– the depth of the mesh generate the Matcher object at. Default 16ra
– list, numpy array or single ra valuedec
– –list, numpy array or single dec value (must match ra array length)convertToArray
– convert the coordinates into an array. Default True. Can bypass the conversion check if you are sure coordinates in numpy array
Return
None
Usage
If we have a set of coordinates such that:
raList1 = [200.0, 200.0, 200.0, 175.23, 21.36] decList1 = [24.3, 24.3, 24.3, -28.25, -15.32]
We can initialise a matcher object like so:
from HMpTy import Matcher coordinateSet = Matcher( log=log, ra=raList1, dec=decList1, depth=16 )
-
match
(ra, dec, radius, maxmatch=1)[source] ∞ match a corrdinate set against this Matcher object’s coordinate set
Key Arguments
ra
– list, numpy array or single ra valuedec
– –list, numpy array or single dec value (must match ra array length)radius
– radius of circle in degreesmaxmatch
– maximum number of matches to return. Set to0
to match all points. Default 1 (i.e. closest match)
Return
None
Usage
Once we have initialised a Matcher coordinateSet object we can match other coordinate sets against it:
twoArcsec = 2.0 / 3600. raList2 = [200.0, 200.0, 200.0, 175.23, 55.25] decList2 = [24.3 + 0.75 * twoArcsec, 24.3 + 0.25 * twoArcsec, 24.3 - 0.33 * twoArcsec, -28.25 + 0.58 * twoArcsec, 75.22] matchIndices1, matchIndices2, seps = coordinateSet.match( ra=raList2, dec=decList2, radius=twoArcsec, maxmatch=0 ) for m1, m2, s in zip(matchIndices1, matchIndices2, seps): print(raList1[m1], decList1[m1], " -> ", s * 3600., " arcsec -> ", raList2[m2], decList2[m2])
Or to return just the nearest matches:
matchIndices1, matchIndices2, seps = coordinateSet.match( ra=raList2, dec=decList2, radius=twoArcsec, maxmatch=1 )
Note from the print statement, you can index the arrays
raList1
,decList1
with thematchIndices1
array values andraList2
,decList2
with thematchIndices2
values.