Skip to content
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

Add some features that TreeCorr uses. #10

Merged
merged 8 commits into from
Mar 7, 2019
Merged

Add some features that TreeCorr uses. #10

merged 8 commits into from
Mar 7, 2019

Conversation

rmjarvis
Copy link
Collaborator

@rmjarvis rmjarvis commented Mar 5, 2019

I have had a similar set of classes in TreeCorr for various coordinate calculations I do there. I'd like to transition over to using Coord and remove the TreeCorr versions of these, but there are a few things I need that aren't in the current Coord package:

  • xyz_to_radec converts from 3D x,y,z coordinates to ra, dec in radians. Specifically, this needs to be able to handle numpy arrays. Other than that, it is equivalent to
coord = CelestialCoord.from_xyz(x, y, z)
ra, dec = coord.ra.rad, coord.dec.rad
  • radec_to_xyz converts from ra, dec coordinates in radians to x,y,z. Again, accepting numpy arrays. It is otherwise equivalent to
x,y,z = CelestialCoord(ra * radians, dec * radians).get_xyz()

I don't know if anyone will want to code review this. But I'll plan to merge this Friday unless someone speaks up.

Copy link
Member

@jmeyers314 jmeyers314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I listed a few small ideas for you to look at.

"""
import numpy
cosdec = numpy.cos(dec)
x = cosdec * numpy.cos(ra) * r
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a good opportunity to make a vectorized sincos?

"""
import numpy
ra = numpy.arctan2(y, x)
dec = numpy.arctan2(z, numpy.sqrt(x**2+y**2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line's about 10x faster for me as arctan(z/np.sqrt(x**2+y**2)), which I think is okay. (We already know the right quadrants.)

import numpy
ra = numpy.arctan2(y, x)
dec = numpy.arctan2(z, numpy.sqrt(x**2+y**2))
return ra,dec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about 10% more expensive here to also calculate r=np.sqrt(x**2+y**2+z**2). Maybe make that at least an optional output for symmetry?

@rmjarvis
Copy link
Collaborator Author

rmjarvis commented Mar 5, 2019

Thanks Josh. I didn't make a vectorized sincos. But I took your other two suggestions.

Some grist for the sincos mill:
https://stackoverflow.com/questions/32397347/is-there-a-fast-way-to-return-sin-and-cos-of-the-same-value-in-python
numpy/numpy#2626

I think the upshot is that to do this, we'd have to roll our own in C++ that can call MKL's vdSinCos if it's available. That's more work than I want to do right now. (Mostly in setup.py to find the MKL library if it's installed and have a backup plan if not.)

@rmjarvis rmjarvis merged commit 328e54c into master Mar 7, 2019
@rmjarvis rmjarvis deleted the treecorr branch March 7, 2019 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants