question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUGs: Inconsistencies with `Distance`

See original GitHub issue

Signed-off-by: Nathaniel Starkman (@nstarman) nstarkman@protonmail.com

Round-tripping

  1. The redshift is not actually stored, even if passed to the Distance constructor. This means the distance is recomputed every time and only to the accuracy of z_at_value. While this accuracy is high enough for actual astronomy purposes, the following fails:
>>> from astropy.coordinates import Distance
>>> from astropy.cosmology import Planck18
>>> d = Distance(z=100, cosmology=Planck18)
>>> d.z == 100
False
  1. For large redshifts the default values of zmin and zmax mean the redshift cannot even be computed.
>>> from astropy.coordinates import Distance
>>> from astropy.cosmology import Planck18
>>> d = Distance(z=4e3, cosmology=Planck18)
>>> d.z
CosmologyError: Best guess z=999.9999999676769 is very close to the upper z limit 1000.
Try re-running with a different zmax.

Inconsistent cosmology

Distance doesn’t store the cosmology when initialized with a redshift, even if that cosmology is explicitly passed as an argument.

Consider the following:

>>> import astropy.coordinates as coord
>>> import astropy.cosmology as cosmology
>>> d = coord.Distance(z=100, cosmology=cosmology.Planck18)
>>> cosmology.default_cosmology.set("WMAP7")
>>> d.z
98.78242384189551

I think that if Distance is initialized with a redshift, that it should be tied to the cosmology, especially if the cosmology is also passed as an argument. This can be solved by storing the cosmology used at initialization (if initialized by z).

Conceptual

I think there might be a deeper conceptual problem. Calculating cosmological redshifts on distances smaller than 0.01 are pretty much meaningless because we are locally disconnected from the Hubble flow. Conversely, parallax measures on scales larger than 0.01 have and probably will never be observed. 1 AU is just too small a baseline. While it’s nice to have 1 class that does all distance measures, it doesn’t make much as much sense physically given the difference in applicable scales.

Possible Solution

My thought is that there should be a new class: CosmologicalDistance, with .value as the redshift. The physical distance would be accessible by some attribute, kind of the opposite of Distance. Now Distance.z would return a CosmologicalDistance. When Distance is initialized with a redshift it internally stores a CosmologicalDistance that also keeps the cosmology. Keeping the CosmologicalDistance synced to the retaining Distance would be a bit tricky, but not insurmountable. The CosmologicalDistance can have other nice attributes, like comoving_distance, since it stores the cosmology. Additionally, like SpectralQuantity (#10263), CosmologicalDistance can have (and provide) equivalencies like with_H0 and from https://github.com/astropy/astropy/pull/10143 (when merged)

System Details

macOS-10.16-x86_64-i386-64bit Python 3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:56:27) [Clang 9.0.1 ] Numpy 1.18.4 astropy 4.3.dev1549+g7fa7ed275.d20210519 Scipy 1.4.1 Matplotlib 3.4.1

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mhvkcommented, Sep 23, 2022

Distance is used only if the unit is a length, so it would be safe from that perspective.

0reactions
mhvkcommented, Sep 23, 2022

I guess in the initializer one can raise an exception on redshifts that are out of range? And otherwise just document that the code always converts to length units? I’m not sure going beyond that is worth the effort for Distance (I can see the point in a new cosmology-specific class).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Distance Perception in Insects - jstor
The bee seems to possess such a mechanism, which is the kind of system that would enable an insect to fly through the...
Read more >
Measuring Travel Distance across Ground and through Air
Travel through air and on the ground pose different problems. A major difficulty for a flying insect needing to know its travel distance...
Read more >
Ruler bug: wrong distance and travel time between carrier and ...
I notice a bug where the ruler reports incorrect travel time for some of my carriers that departed a star the previous turn....
Read more >
Inconsistent behaviour with static route using same interface ...
Cisco Bug: CSCve37330 - Inconsistent behaviour with static route using same interface and distinct AD (admin distance)
Read more >
PGF and TikZ -- Graphic systems for TeX Bugs - matrix
#432 Inconsistent distance between matrix columns when the first row is missing cells and the `between origins` matrix option is specified.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found