Repository navigation
Angular diameter distance for positive curvature - #4723
joergdietrich wants to merge 11 commits into
Conversation
…her numerical accuracy in very closed universes
…n checking for now supported cases in angular_diameter_distance_z1z2
…for comoving_transverse_distance_z1z2 and comoving_distance_z1z2
| return self.comoving_transverse_distance_z1z2(0, z) | ||
|
|
||
| def comoving_transverse_distance_z1z2(self, z1, z2): | ||
| """Comoving transverse distance in Mpc between to redshifts. |
|
I left some inline comments pointing out docstring typos. Otherwise this looks excellent to me. I much prefer having this generalised comoving distance method (and the new related methods) allowing two input redshifts, instead of the previous approximation used for angular_diameter_distance_z1z2. @aconley should take a look at this too, though, as he's more of a cosmology guru than me. |
|
Fixed the typos. Thanks! The previous expression wasn't an approximation. It's analytically exact but numerically unstable. |
|
The functionality looks good to me. But it does seem a little strange to me that we now have _z1z2 versions of some functions but For example: we'd have to keep angular_diameter_distance_z1z2 for backwards compatibility, I'd be happy to make that change by making a pull against @joergdietrich -s branch |
|
Unfortunately, that's a syntax error in Python. Non-default arguments can't follow default arguments. Doing things this way would also allow us to keep the old behavior of raising ValueError for angular_diameter_distance_z1z2 if any z2 < z1 and going ahead with the new, more sensible approach to return negative distances if z2 < z1 in angular_diameter_distance(z1, z2) calls. |
|
Oh, right, nuts. At that point I think you call them distance(self, zmax, zmin=0). |
|
Will anybody actually use any of the z1z2s except the angular diameter one? With that in mind, a simpler, fix it now, solution would be to remove (or make private |
|
@joergdietrich Thanks for clarifying (i.e. it's an exact analytic expression, but numerically unstable). I don't think the API is a problem here. We can always just replace the existing positional argument with a z1 keyword argument: luminosity_distance(self, z1=None, z2=None) But I agree with @aconley's concern about method bloat, and I like his idea to just make the new z1z2 functions private by adding a leading underscore for now. |
|
I like @nhmc's suggestion to make both arguments keyword arguments, although in the end very few methods actually benefit from having both z1 and z2 in practice. Occasionally lookback_time(z1, z2) may be interesting. So I'm okay with making the new methods private for now. |
|
age(z1, z2) would be convenient to have, although easy enough to calculate But not a suggestion for now. On Wed, Mar 30, 2016 at 9:58 AM, Jörg Dietrich [email protected]
|
|
New commit to make them private for now. |
| if isiterable(x): | ||
| return np.vectorize(func)(x) | ||
| if any(map(isiterable, x)): | ||
| return np.vectorize(func)(*x) |
There was a problem hiding this comment.
I don't think this is lazy in python 2. any is, but map isn't.
So this isn't quite as efficient as it may seem. I'm not sure we care though.
There was a problem hiding this comment.
For Python 2 there is itertools.imap, and six provides a wrapper : six.map
There was a problem hiding this comment.
Thanks! Already in the morning I can answer the question "what have I learned today?".
|
Looks good to me. |
|
@nhmc - are we waiting on something to accept this? |
|
No, it looks ready to merge to me. Sorry for not commenting sooner. Thanks again @joergdietrich. |
|
Yes, thanks for adding this capability. I know lensing folk will find this quite helpful. |
|
One last request before merge -- squash all commits into one. Thanks! |
|
Use the squash button when merging? I know it will take me too much time to figure out how to squash commits already pushed upstream. |
|
Haha... Funny you brought it up. There was a lengthy discussion about that button, resulting in it being disabled. (See #4423 for part of that discussion and |
|
Well, your choice. I don't have the time for another fight with git. |
|
Yeah... I was thinking about whether or not to ask for that, but given
the battles Jorg had with git earlier, I was hesitant to ask. And I'm
not sure I could cleanly do it for somebody elses branch.
Jorg, if you are willing to try -once-, it would be helpful. But if
you have any problems at all, I would say don't worry about it.
And if you simply have too much git fatigue to even consider it,
I, at least, am okay with forgetting about it.
Like many things about git, it's awesome when it works, but when
it goes wrong...
git rebase -i
change the first part of each line -except the first- to s from pick
edit the message to be something sensible
git push -f <upstream> <branch>
|
|
@aconley , I was going to do it for him but turns out it is quite painful because halfway through the commits, he merged master into his PR. So |
|
I am closing this one now. See #4769 for the squashed version. I eyeballed the changes and made sure I didn't introduce anything new, and added @joergdietrich as the author, so everything should be okay... |
Angular diameter distance for positive curvature (#4723)
Angular diameter distance for positive curvature (astropy/astropy#4723)
Angular diameter distance for positive curvature (astropy/astropy#4723)
This is the PR promised in #4661 to make
angular_diameter_distance_z1z2work reliably in positive curvature models. Along the way it creates the new methodscomoving_distance_z1z2andcomoving_transverse_distance_z1z2on whichangular_diameter_distance_z1z2is now based instead of Peebles' (1993) eq. 13.70.comoving_distanceandcomoving_transverse_distanceare now special cases of the corresponding_z1z2methods. The performance impact is one additional function call for these methods and amounts to 2-4 µs on my laptop for a total execution time of 78 µs for a scalar input. For array like input, the perfomance difference is negligible because the code spends most of the time in the for loop of the vectorized function call.vectorize_if_needednow deals with functions with more than one input argument (arbitrary combinations of scalar and array like)angular_diameter_distance_z1z2is 50% faster on scalar input because the integral over 1/E(z) is computed only once instead of twice. Again, the performance difference vanishes if the function needs to be vectorized.