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.

Constructing a SphericalRepresentation object with a negative distance is impossible

See original GitHub issue

The explicit kwarg in the error dosen’t seem to work.

In [2]: from astropy.coordinates import Distance, SphericalRepresentation; import astropy.units as u                                                                                                                                 
In [3]: SphericalRepresentation(10*u.deg, 10*u.deg, Distance(-100*u.m, allow_negative=True))    
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/Git/astropy/astropy/coordinates/representation.py in __init__(self, lon, lat, distance, differentials, copy)
   1569             try:
-> 1570                 self._distance = Distance(self._distance, copy=False)
   1571             except ValueError as e:

~/Git/astropy/astropy/coordinates/distances.py in __new__(cls, value, unit, z, cosmology, distmod, parallax, dtype, copy, order, subok, ndmin, allow_negative)
    183         if not allow_negative and np.any(distance.value < 0):
--> 184             raise ValueError("Distance must be >= 0.  Use the argument "
    185                              "'allow_negative=True' to allow negative values.")

ValueError: Distance must be >= 0.  Use the argument 'allow_negative=True' to allow negative values.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-3-bc5d4ae3542b> in <module>
----> 1 SphericalRepresentation(10*u.deg, 10*u.deg, Distance(-100*u.m, allow_negative=True))

~/Git/astropy/astropy/coordinates/representation.py in __init__(self, lon, lat, distance, differentials, copy)
   1571             except ValueError as e:
   1572                 if e.args[0].startswith('Distance must be >= 0'):
-> 1573                     raise ValueError("Distance must be >= 0. To allow negative "
   1574                                      "distance values, you must explicitly pass"
   1575                                      " in a `Distance` object with the the "

ValueError: Distance must be >= 0. To allow negative distance values, you must explicitly pass in a `Distance` object with the the argument 'allow_negative=True'.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
astrojuanlucommented, Dec 20, 2020

This was fixed in #11113:

In [1]: from astropy.coordinates import Distance, SphericalRepresentation; import astropy.units as u

In [2]: SphericalRepresentation(10*u.deg, 10*u.deg, Distance(-100*u.m, allow_negative=True))
Out[2]: 
<SphericalRepresentation (lon, lat, distance) in (deg, deg, m)
    (10., 10., -100.)>
1reaction
mhvkcommented, Nov 9, 2018

p.s. Though frankly I’d prefer it if we moved this use of distance out of the representation class altogether, and instead did it inside frames.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merging multiple views using a spherical representation
To obtain the spherical representation, we ... building object models from observation. ... spherical surface such that the distance between vertices is.
Read more >
astropy.coordinates.baseframe — gala v1.3
If an item is set to `None`, it will be guessed from the base class. ... SphericalRepresentation) and 'distance' not in repr_kwargs): representation_cls ......
Read more >
Source code for astropy.coordinates.baseframe
SphericalRepresentation ) and "distance" not in repr_kwargs ... proceeds in a difficult-to-predict manner in the # case that one of the class objects...
Read more >
Spherical and Hyperbolic Embeddings of Data
positive and negative components which sum together to give the total distance. A pseudo-Euclidean space is however non- metric, which makes it difficult...
Read more >
Lines of Curvature as Pseudospherical Surfaces. - JSTOR
spherical surfaces-have been the object of study of the geometers since the days ... 114 EISENHART: Surfaces with the Same Spherical Representation.
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