-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-30024: Implement matching in DRP DiaAssociation task #526
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import healpy as hp | ||
import numpy as np | ||
|
||
"""Utilities for interfacing with healpy. Originally implemented in | ||
http://github.com/LSSTDESC/dia_pipe | ||
""" | ||
|
||
# Will update docs and the like in DM-30673 | ||
|
||
|
||
def toIndex(nside, ra, dec): | ||
"""Return healpix index given ra,dec in degrees""" | ||
return hp.pixelfunc.ang2pix(nside, np.radians(-dec+90.), np.radians(ra)) | ||
|
||
|
||
def toRaDec(nside, index): | ||
"""Convert from healpix index to ra,dec in degrees""" | ||
vec = hp.pix2ang(nside, index) | ||
dec = np.rad2deg(-vec[0])+90 | ||
ra = np.rad2deg(vec[1]) | ||
return np.dstack((ra, dec))[0] | ||
|
||
|
||
def eq2xyz(ra, dec): | ||
"""Convert from equatorial ra,dec in degrees to x,y,z on unit sphere""" | ||
phi = np.deg2rad(ra) | ||
theta = np.pi/2 - np.deg2rad(dec) | ||
sintheta = np.sin(theta) | ||
x = sintheta * np.cos(phi) | ||
y = sintheta * np.sin(phi) | ||
z = np.cos(theta) | ||
return np.array([x, y, z]) | ||
|
||
|
||
def eq2vec(ra, dec): | ||
"""Convert equatorial ra,dec in degrees to x,y,z on the unit sphere parameters""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't have been able to guess just by the name that this is the vectorized version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. |
||
ra = np.array(ra, dtype='f8', ndmin=1, copy=False) | ||
dec = np.array(dec, dtype='f8', ndmin=1, copy=False) | ||
if ra.size != dec.size: | ||
raise ValueError("ra,dec not same size: %s,%s" % (ra.size, dec.size)) | ||
|
||
vec = eq2xyz(ra, dec) | ||
|
||
return vec | ||
|
||
|
||
def convert_spherical(ra, dec): | ||
"""Convert from ra,dec to spherical""" | ||
|
||
return np.dstack([np.cos(dec*np.pi/180.)*np.cos(ra*np.pi/180.), | ||
np.cos(dec*np.pi/180.)*np.sin(ra*np.pi/180.), | ||
np.sin(dec*np.pi/180.)])[0] | ||
|
||
|
||
def convert_spherical_array(array): | ||
"""Convert from ra,dec to spherical from array""" | ||
ra = array[:, 0] | ||
dec = array[:, 1] | ||
return convert_spherical(ra, dec) | ||
|
||
|
||
def query_disc(nside, ra, dec, max_rad, min_rad=0): | ||
""" | ||
Get the list of healpix indices within max_rad,min_rad given in radians | ||
around ra,dec given in degrees | ||
""" | ||
if np.isscalar(ra): | ||
ra = np.array([ra]) | ||
dec = np.array([dec]) | ||
|
||
pixels = np.unique([hp.query_disc(nside, eq2vec(a, b), max_rad) for (a, b) in zip(ra, dec)]) | ||
|
||
if min_rad > 0 and len(pixels) > 0: | ||
vec0 = convert_spherical(ra, dec) | ||
min_rad2 = min_rad**2 | ||
vecs = convert_spherical_array(toRaDec(nside, pixels)) | ||
dsq = np.sum((vecs-vec0)**2, axis=1) | ||
match = dsq > min_rad2 | ||
pixels = pixels[match] | ||
|
||
return pixels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.lsst.io/python/style.html?highlight=order#standard-code-order-should-be-followed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This set functions was copied over from the LSSTDESC/dia_pipe directory. Didn't want worry about getting this up to spec for now. I can make a ticket to document it up to standards.