[AstroPy] astropy.cosmology

Erik Tollerud erik.tollerud at gmail.com
Fri Dec 13 13:52:04 EST 2013

(Passing on a message from Alex Conley here about a complication in
the inverse function scheme, same as Rick White pointed out.)

But I disagree that this is "bloat" - the fact that three people on
this list have already said they need it for science shows that it's a
useful thing to include.  Inverting it with scipy functions is not
necessarily trivial, and having an informative warning that
specifically states the non-monotonicity is in the cosmology module is
a reason to make it specific to astropy.cosmology .

Anyway, we'll see what Neil comes up with and see then whether it
seems like it will be difficult to maintain (the main disavantage of

On Wed, Dec 11, 2013 at 11:58 AM, Alex Conley <alexanderconley at gmail.com> wrote:
> That seems pretty contrived, honestly.  It doesn’t sound like you were up
> to much good when you did this.
> Maybe a more serious issue: luminosity distance is not monotonic in closed Universes.
> And the angular diameter distance is not monotonic in most, including the
> one we live in.  Age, at least, is always monotonic, at least in Universes with a Big Bang.
> So most of the inverses you want are ill-defined.
>>>> from astropy.cosmology import LambdaCDM
>>>> cos = LambdaCDM(70, 0.2, 1.4)
>>>> cos.luminosity_distance([1.3044, 3.0, 5.5])
> <Quantity [ 11800.64030641, 17066.4066551 , 11800.83252956] Mpc>
>>>> from astropy.cosmology import WMAP9
>>>> WMAP9.angular_diameter_distance([0.668, 3, 4.0])
> <Quantity [ 1468.8531073 , 1625.97548513, 1468.88895528] Mpc>
> Even assuming you overcame this problem — what about the function
> inverter says: should be specific to astropy.cosmology?  This screams
> code bloat to me.
> PS: I’m not subscribed to astropy at scipy.org, so it will not let me
> post.
> On 11-Dec-2013, at 9:41 AM, Erik Tollerud <erik.tollerud at gmail.com> wrote:
>>> I don’t see much point in implementing reverse functions of -everything- —
>>> it’s hard to imagine scenarios where most of them would be interesting.
>>> When will somebody want to know what redshift corresponds to a given
>>> luminosity distance?   Age is really the only one I can imagine having
>>> wide interest, so I would just start with that in the interest of avoiding
>>> bloat.
>> Suppose you have a galaxy where you think you know what its absolute
>> magnitude should be (say its a standard candle) and have an apparent
>> magnitude, and you want to use it to know what redshift it's at.  Then
>> you need this, because the distance modulus is tied to the luminosity
>> distance (this example came to mind because I've actually needed this
>> for actual science in the past).  My point here is mainly that just
>> because we don't want all of them, doesn't mean some other users don't
>> have a need.
>> That said, I see your point in that others are probably generally less
>> useful (e.g. AD distance), and duplicating every function/method does
>> make everything harder to deal with. Perhaps the solution is to add an
>> `inverse` function to `astropy.cosmology`?  You could then do
>> something like ``z = cosmology.inverse(WMAP.age, 1 * u.Gyr)``.  That
>> would keep the API cleaner, and it would be fairly trivial to
>> implement it that way using the method Juande and Alex are talking
>> about.  Then if we decide to optimize some of them later, we can add
>> those in and have the `inverse` function use those if they are
>> present.


More information about the AstroPy mailing list