Skip to content

Commit 3fd85aa

Browse files
authored
Merge pull request #2059 from dopplershift/backport-2057
Backports for 0.20.x
2 parents 96f77d9 + 50b7399 commit 3fd85aa

File tree

13 files changed

+59
-53
lines changed

13 files changed

+59
-53
lines changed

.appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ install:
1616
- conda config --add channels conda-forge/label/testing
1717
- set ENV_NAME=test-environment
1818
- set PACKAGES=%PACKAGES% flufl.lock owslib pep8 pillow pyshp pytest
19-
- set PACKAGES=%PACKAGES% requests setuptools_scm setuptools_scm_git_archive
20-
- set PACKAGES=%PACKAGES% shapely
19+
- set PACKAGES=%PACKAGES% requests setuptools_scm shapely
2120
- conda create -n %ENV_NAME% python=%PYTHON_VERSION% %PACKAGES%
2221
- activate %ENV_NAME%
2322
- set INCLUDE=%CONDA_PREFIX%\Library\include;%INCLUDE%

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ deps-run: &deps-install
4646
requests \
4747
scipy \
4848
setuptools_scm \
49-
setuptools_scm_git_archive \
5049
shapely \
5150
$EXTRA_PACKAGES \
5251
--file docs/doc-requirements.txt

.git_archival.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/ci-testing.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ jobs:
4848
- name: Install dependencies
4949
run: |
5050
PACKAGES="$PACKAGES flufl.lock owslib pep8 pillow pyshp pytest"
51-
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm"
52-
PACKAGES="$PACKAGES setuptools_scm_git_archive shapely"
51+
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm shapely"
5352
# openssl 3.0 updated the legacy renegotiation default, which causes
5453
# failures in NASA's WMTS server. They will need to update their
5554
# server before we can use a newer openssl.

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ jobs:
2626
run: |
2727
PACKAGES="cython fiona matplotlib-base numpy pyproj pykdtree scipy"
2828
PACKAGES="$PACKAGES flufl.lock owslib pep8 pillow pyshp pytest"
29-
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm"
30-
PACKAGES="$PACKAGES setuptools_scm_git_archive shapely"
29+
PACKAGES="$PACKAGES pytest-xdist requests setuptools_scm shapely"
3130
conda install $PACKAGES
3231
3332
- name: Create sdist

lib/cartopy/feature/nightshade.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ def __init__(self, date=None, delta=0.1, refraction=-0.83,
7777

7878
# Solve the generalized equation for omega0, which is the
7979
# angle of sunrise/sunset from solar noon
80-
omega0 = np.rad2deg(np.arccos(np.sin(np.deg2rad(refraction)) /
81-
np.cos(np.deg2rad(y))))
80+
# We need to clip the input to arccos to [-1, 1] due to floating
81+
# point precision and arccos creating nans for values outside
82+
# of the domain
83+
arccos_tmp = np.clip(np.sin(np.deg2rad(refraction)) /
84+
np.cos(np.deg2rad(y)), -1, 1)
85+
omega0 = np.rad2deg(np.arccos(arccos_tmp))
8286

8387
# Fill the longitude values from the offset for midnight.
8488
# This needs to be a closed loop to fill the polygon.

lib/cartopy/tests/crs/test_interrupted_goode_homolosine.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
import numpy as np
12-
from numpy.testing import assert_almost_equal
12+
from numpy.testing import assert_allclose
1313
import pytest
1414

1515
import cartopy.crs as ccrs
@@ -24,10 +24,10 @@ def test_default(emphasis):
2424
check_proj_params("igh", igh, other_args)
2525
elif emphasis == "ocean":
2626
check_proj_params("igh_o", igh, other_args)
27-
assert_almost_equal(
27+
assert_allclose(
2828
np.array(igh.x_limits), [-20037508.3427892, 20037508.3427892]
2929
)
30-
assert_almost_equal(
30+
assert_allclose(
3131
np.array(igh.y_limits), [-8683259.7164347, 8683259.7164347]
3232
)
3333

@@ -42,8 +42,8 @@ def test_eccentric_globe(emphasis):
4242
elif emphasis == "ocean":
4343
check_proj_params("igh_o", igh, other_args)
4444

45-
assert_almost_equal(np.array(igh.x_limits), [-3141.5926536, 3141.5926536])
46-
assert_almost_equal(np.array(igh.y_limits), [-1361.410035, 1361.410035])
45+
assert_allclose(np.array(igh.x_limits), [-3141.5926536, 3141.5926536])
46+
assert_allclose(np.array(igh.y_limits), [-1361.410035, 1361.410035])
4747

4848

4949
@pytest.mark.parametrize(
@@ -60,11 +60,10 @@ def test_central_longitude(emphasis, lon):
6060
elif emphasis == "ocean":
6161
check_proj_params("igh_o", igh, other_args)
6262

63-
assert_almost_equal(
63+
assert_allclose(
6464
np.array(igh.x_limits),
6565
[-20037508.3427892, 20037508.3427892],
66-
decimal=5,
6766
)
68-
assert_almost_equal(
67+
assert_allclose(
6968
np.array(igh.y_limits), [-8683259.7164347, 8683259.7164347]
7069
)

lib/cartopy/tests/crs/test_mollweide.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
import numpy as np
12-
from numpy.testing import assert_almost_equal
12+
from numpy.testing import assert_allclose
1313
import pytest
1414

1515
import cartopy.crs as ccrs
@@ -21,10 +21,10 @@ def test_default():
2121
other_args = {'a=6378137.0', 'lon_0=0'}
2222
check_proj_params('moll', moll, other_args)
2323

24-
assert_almost_equal(np.array(moll.x_limits),
25-
[-18040095.6961473, 18040095.6961473])
26-
assert_almost_equal(np.array(moll.y_limits),
27-
[-9020047.8480736, 9020047.8480736])
24+
assert_allclose(np.array(moll.x_limits),
25+
[-18040095.6961473, 18040095.6961473])
26+
assert_allclose(np.array(moll.y_limits),
27+
[-9020047.8480736, 9020047.8480736])
2828

2929

3030
def test_sphere_globe():
@@ -33,8 +33,8 @@ def test_sphere_globe():
3333
other_args = {'a=1000', 'lon_0=0'}
3434
check_proj_params('moll', moll, other_args)
3535

36-
assert_almost_equal(moll.x_limits, [-2828.4271247, 2828.4271247])
37-
assert_almost_equal(moll.y_limits, [-1414.2135624, 1414.2135624])
36+
assert_allclose(moll.x_limits, [-2828.4271247, 2828.4271247])
37+
assert_allclose(moll.y_limits, [-1414.2135624, 1414.2135624])
3838

3939

4040
def test_ellipse_globe():
@@ -48,8 +48,8 @@ def test_ellipse_globe():
4848
check_proj_params('moll', moll, other_args)
4949

5050
# Limits are the same as default since ellipses are not supported.
51-
assert_almost_equal(moll.x_limits, [-18040095.6961473, 18040095.6961473])
52-
assert_almost_equal(moll.y_limits, [-9020047.8480736, 9020047.8480736])
51+
assert_allclose(moll.x_limits, [-18040095.6961473, 18040095.6961473])
52+
assert_allclose(moll.y_limits, [-9020047.8480736, 9020047.8480736])
5353

5454

5555
def test_eccentric_globe():
@@ -64,8 +64,8 @@ def test_eccentric_globe():
6464
check_proj_params('moll', moll, other_args)
6565

6666
# Limits are the same as spheres since ellipses are not supported.
67-
assert_almost_equal(moll.x_limits, [-2828.4271247, 2828.4271247])
68-
assert_almost_equal(moll.y_limits, [-1414.2135624, 1414.2135624])
67+
assert_allclose(moll.x_limits, [-2828.4271247, 2828.4271247])
68+
assert_allclose(moll.y_limits, [-1414.2135624, 1414.2135624])
6969

7070

7171
def test_offset():
@@ -83,11 +83,10 @@ def test_central_longitude(lon):
8383
other_args = {'a=6378137.0', f'lon_0={lon}'}
8484
check_proj_params('moll', moll, other_args)
8585

86-
assert_almost_equal(np.array(moll.x_limits),
87-
[-18040095.6961473, 18040095.6961473],
88-
decimal=5)
89-
assert_almost_equal(np.array(moll.y_limits),
90-
[-9020047.8480736, 9020047.8480736])
86+
assert_allclose(np.array(moll.x_limits),
87+
[-18040095.6961473, 18040095.6961473])
88+
assert_allclose(np.array(moll.y_limits),
89+
[-9020047.8480736, 9020047.8480736])
9190

9291

9392
def test_grid():
@@ -100,10 +99,8 @@ def test_grid():
10099
other_args = {'a=0.7071067811865476', 'b=0.7071067811865476', 'lon_0=0'}
101100
check_proj_params('moll', moll, other_args)
102101

103-
assert_almost_equal(np.array(moll.x_limits),
104-
[-2, 2])
105-
assert_almost_equal(np.array(moll.y_limits),
106-
[-1, 1])
102+
assert_allclose(np.array(moll.x_limits), [-2, 2])
103+
assert_allclose(np.array(moll.y_limits), [-1, 1])
107104

108105
lats = np.arange(0, 91, 5)[::-1]
109106
lons = np.full_like(lats, 90)
@@ -114,14 +111,14 @@ def test_grid():
114111
0.75894, 0.80591, 0.84739, 0.88362, 0.91477, 0.94096, 0.96229, 0.97882,
115112
0.99060, 0.99765, 1.00000,
116113
])
117-
assert_almost_equal(result[:, 0], expected_x, decimal=5)
114+
assert_allclose(result[:, 0], expected_x, atol=1e-5)
118115

119116
expected_y = np.array([
120117
1.00000, 0.97837, 0.94539, 0.90606, 0.86191, 0.81382, 0.76239, 0.70804,
121118
0.65116, 0.59204, 0.53097, 0.46820, 0.40397, 0.33850, 0.27201, 0.20472,
122119
0.13681, 0.06851, 0.00000,
123120
])
124-
assert_almost_equal(result[:, 1], expected_y, decimal=5)
121+
assert_allclose(result[:, 1], expected_y, atol=1e-5)
125122

126123

127124
def test_sphere_transform():
@@ -135,14 +132,13 @@ def test_sphere_transform():
135132
other_args = {'a=1.0', 'b=1.0', 'lon_0=-90.0'}
136133
check_proj_params('moll', moll, other_args)
137134

138-
assert_almost_equal(np.array(moll.x_limits),
139-
[-2.8284271247461903, 2.8284271247461903],
140-
decimal=2)
141-
assert_almost_equal(np.array(moll.y_limits),
142-
[-1.4142135623730951, 1.4142135623730951])
135+
assert_allclose(np.array(moll.x_limits),
136+
[-2.8284271247461903, 2.8284271247461903])
137+
assert_allclose(np.array(moll.y_limits),
138+
[-1.4142135623730951, 1.4142135623730951])
143139

144140
result = moll.transform_point(-75.0, -50.0, geodetic)
145-
assert_almost_equal(result, [0.1788845, -0.9208758])
141+
assert_allclose(result, [0.1788845, -0.9208758])
146142

147143
inverse_result = geodetic.transform_point(result[0], result[1], moll)
148-
assert_almost_equal(inverse_result, [-75.0, -50.0])
144+
assert_allclose(inverse_result, [-75.0, -50.0])

lib/cartopy/tests/feature/test_nightshade.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from cartopy.feature.nightshade import _julian_day, _solar_position
11+
from cartopy.feature.nightshade import _julian_day, _solar_position, Nightshade
1212

1313

1414
def test_julian_day():
@@ -44,3 +44,12 @@ def test_solar_position(dt, true_lat, true_lon):
4444
lat, lon = _solar_position(dt)
4545
assert pytest.approx(true_lat, 0.1) == lat
4646
assert pytest.approx(true_lon, 0.1) == lon
47+
48+
49+
def test_nightshade_floating_point():
50+
# Smoke test for clipping nightshade floating point values
51+
date = datetime(1999, 12, 31, 12)
52+
53+
# This can cause an error with floating point precision if it is
54+
# set to exactly -6 and arccos input is not clipped to [-1, 1]
55+
Nightshade(date, refraction=-6.0, color='none')
209 Bytes
Loading

0 commit comments

Comments
 (0)