99"""
1010
1111import numpy as np
12- from numpy .testing import assert_almost_equal
12+ from numpy .testing import assert_allclose
1313import pytest
1414
1515import 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
3030def 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
4040def 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
5555def 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
7171def 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
9392def 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
127124def 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 ])
0 commit comments