-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 new module for generating random or gridded spherical points #11628
Conversation
Oh, and needs tests! Next push... |
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.
Overall I like it, but some inline comments. Also might be good to mention in the narrative docs, although I think @adrn was already planning on that. Particularly important there I think is a "copy-and-pastable" example of how to get a SkyCoord out (I know it's just "wrap in SkyCoord()
", but the poor user might not)
Also, I think this belongs in astropy.coordinates
, so probably should get an __all__
and an ... import *
in the coordinates/__init__.py
?
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.
How about calling the module angle_sampling
instead of angle_generators
, in order to avoid confusing the terminology with Python generators?
I am a little hesitant about adding uniform_spherical_random_volume
because this function is not directly useful for sampling uniformly in significant spatial distributions like comoving volume, etc.
I think it would be worthwhile stepping back for a moment and thinking about the use cases for this new module and prior art. Some ideas:
- Designing survey grids: look at LSST pipelines. In addition to the golden angle spiral, we probably would also want geodesic grids and simple grids consisting of constant-declination rings.
- Sampling for Monte Carlo simulations: in this case I think that you would also want to be able to draw in different distributions like uniform in comoving volume, comoving rate density, etc.
- Sample data for unit tests: I'm not sure that this is a good application for this module; wouldn't you rather use hypothesis?
- Concisely generate a coordinate for example code: not sure that we need a random generator, as one can always do things like
SkyCoord.from_name('M31')
(replace with your favorite Messier object).
Hm, in that case maybe just put this in
Not sure I understand this comment...that seems like a problem for
Use cases are different for the functions here:
|
👍 |
good point!
I'm not sure this is in scope for
I think that's still useful here following the above: I've actually used this case for my own science, and generally I do exactly what
I think a mix of both is useful - I'd add a few other:
|
True... but then the problem would be that Astropy coordinates' distances are always luminosity distances, right? |
How about |
My 2¢: I think there is little doubt about randomly sampling the sphere and the case for the golden spiral seems OK too. I think combining them in a module with That subset still could go in 4.3, though I think it is also fine to leave it for 5.0, so there is time to write some nice documentation about it. |
My proposal then: move everything except |
Won't have time to finish this by end of today, but also not critical for 4.3 - moving milestone to 5.0! |
Hello @adrn 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2021-05-03 14:43:39 UTC |
Alright, I pushed up a set of changes that I think addresses @adrn's suggestions in #11628 (comment) . Honestly, I think we could sneak this in just under 🥶 if you're happy with it @adrn... we can always fill in the documentation more fully later. (I think 4.3 is slightly better because it lets us get rid of the deprecated names in 5.0...) |
return UnitSphericalRepresentation(lon, lat) | ||
|
||
|
||
def uniform_spherical_random_surface(size=1, rng=None): |
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.
I wonder if it is truly desirable to take the random number generator as an option? Other methods throughout Astropy that use an RNG do not take such an argument (e.g. LombScargle.false_alarm_probability
). Various examples throughout the docs already suggest using astropy.utils.NumpyRNGContext
to control the random state.
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.
I personally like this idiom in my own code but I don't feel too strongly here
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.
I don't feel strongly about this idiom either, my only concern is consistency with other modules.
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.
You raise a good point there @lpsinger about consistency with NumpyRNGContext
! I'm going to just make a command decision to remove it for now - we can always put it in in a future version.
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.
Ohh, I also just realized np.random.default_rng
does not respect np.random.seed
, which is what everything else assumes, so definitely important to do this for consistency.
Hm, @eteq I personally would have kept the |
Ha ha, we're all being doggedly noncommittal on this point! I can readily be convinced of including an |
Implicit in Numpy because the random number generation is all handled by the new |
Oh, duh 🙄 ... it's present in every I'm convinced about having such an argument now, but should it be called |
However: |
👍 for |
Co-authored-by: Leo Singer <leo.singer@ligo.org>
682a024
to
6821cb4
Compare
The only thing this file does is it defines the `randomly_sample_sphere()` function, which is deprecated since astropy#11628.
…enerators (re-implementing bits of astropy#11628 that were removed before merge)
…enerators (re-implementing bits of astropy#11628 that were removed before merge)
…enerators (re-implementing bits of astropy#11628 that were removed before merge)
…enerators (re-implementing bits of astropy#11628 that were removed before merge)
This adds a few functions for generating points on or in a sphere:
golden_spiral_grid()
produces a grid of points on the unit sphere using the Fibonacci or Golden Spiral methoduniform_spherical_random_surface()
produces randomly sampled points on the unit sphereuniform_spherical_random_volume()
produces randomly sampled points that fill the volume of a sphere, with an optional distance scale (that on second thought maybe shouldn't have units unless the user wants it to...)Fixes #11612