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.

float32 representation of pi/2 is rejected by `Latitude`

See original GitHub issue

Description

The closest float32 value to pi/2 is by accident slightly larger than pi/2:

In [5]: np.pi/2
Out[5]: 1.5707963267948966

In [6]: np.float32(np.pi/2)
Out[6]: 1.5707964

Astropy checks using float64 precision, rejecting “valid” alt values (e.g. float32 values read from files):


In [1]: from astropy.coordinates import Latitude

In [2]: import numpy as np

In [3]: lat = np.float32(np.pi/2)

In [4]: Latitude(lat, 'rad')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In [4], line 1
----> 1 Latitude(lat, 'rad')

File ~/.local/lib/python3.10/site-packages/astropy/coordinates/angles.py:564, in Latitude.__new__(cls, angle, unit, **kwargs)
    562     raise TypeError("A Latitude angle cannot be created from a Longitude angle")
    563 self = super().__new__(cls, angle, unit=unit, **kwargs)
--> 564 self._validate_angles()
    565 return self

File ~/.local/lib/python3.10/site-packages/astropy/coordinates/angles.py:585, in Latitude._validate_angles(self, angles)
    582     invalid_angles = (np.any(angles.value < lower) or
    583                       np.any(angles.value > upper))
    584 if invalid_angles:
--> 585     raise ValueError('Latitude angle(s) must be within -90 deg <= angle <= 90 deg, '
    586                      'got {}'.format(angles.to(u.degree)))

ValueError: Latitude angle(s) must be within -90 deg <= angle <= 90 deg, got 90.00000250447816 deg

Expected behavior

Be lenient? E.g. only make the comparison up to float 32 precision?

Actual behavior

See error above

Steps to Reproduce

See snippet above.

System Details

Linux-5.15.65-1-MANJARO-x86_64-with-glibc2.36
Python 3.10.7 (main, Sep  6 2022, 21:22:27) [GCC 12.2.0]
Numpy 1.23.3
pyerfa 2.0.0.1
astropy 5.0.1
Scipy 1.9.1
Matplotlib 3.5.2

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
maxnoecommented, Sep 22, 2022

I’ll open a PR with unit test cases and then we can decide about the wanted behaviour for each of them

1reaction
maxnoecommented, Sep 19, 2022

That wouldn’t solve the case where the value is read from a float32 into a float64, which can happen pretty fast due to the places where casting can happen. Better than nothing, but…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Format Definition Document
Latitude : Pi/2 to –Pi/2 (90 north to 90 South) ... “Invalid data values” are used to indicate data rejected because of quality...
Read more >
ShapeGISMap - AnyLogic Help
GIS map projection manager and map renderer (persistent GIS Map shape whichdisplays and map projection)GIS map is a Shape and it can be...
Read more >
How to find distance from the latitude and longitude of two ...
The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes....
Read more >
Sensor rejection for reliable state estimation of ... - UPCommons
from different sensors, however the sensor rejection problem has barely ... Figure 1.2: Schematic representation of this project's inputs, ...
Read more >
Untitled
Y: An n-element vector of type integer, float or double. ... and therefore we do not reject the hypothesis that X and Y...
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