@@ -13,7 +13,7 @@ def make_array(self):
13
13
u = np .ones ((len (lat ), len (lon )))
14
14
v = np .zeros ((len (lat ), len (lon )))
15
15
return u ,v ,lat ,lon
16
-
16
+
17
17
def test_cylindrical (self ):
18
18
# Cylindrical case
19
19
B = Basemap ()
@@ -22,7 +22,7 @@ def test_cylindrical(self):
22
22
# Check that the vectors are identical.
23
23
assert_almost_equal (ru , u )
24
24
assert_almost_equal (rv , v )
25
-
25
+
26
26
def test_nan (self ):
27
27
B = Basemap ()
28
28
u ,v ,lat ,lon = self .make_array ()
@@ -32,12 +32,12 @@ def test_nan(self):
32
32
assert not np .isnan (ru ).any ()
33
33
assert_almost_equal (u , ru )
34
34
assert_almost_equal (v , rv )
35
-
35
+
36
36
def test_npstere (self ):
37
37
# NP Stereographic case
38
38
B = Basemap (projection = 'npstere' , boundinglat = 50. , lon_0 = 0. )
39
39
u ,v ,lat ,lon = self .make_array ()
40
- v = np .ones ((len (lat ), len (lon )))
40
+ v = np .ones ((len (lat ), len (lon )))
41
41
ru , rv = B .rotate_vector (u ,v , lon , lat )
42
42
assert_almost_equal (ru [2 , :],[1 ,- 1 ,- 1 ,1 ], 6 )
43
43
assert_almost_equal (rv [2 , :],[1 ,1 ,- 1 ,- 1 ], 6 )
@@ -96,6 +96,59 @@ def test_no_cyc2(self):
96
96
assert (grid == gridout ).all ()
97
97
98
98
99
+ class TestShiftdata (TestCase ):
100
+
101
+ def _get_2d_lons (self , lons1d ):
102
+ """
103
+ Generate a 2d grid
104
+ """
105
+ lats = [10 , ] * len (lons1d )
106
+ return np .meshgrid (lons1d , lats )[0 ]
107
+
108
+ def test_2_points_should_work (self ):
109
+ """
110
+ Shiftdata should work with 2 points
111
+ """
112
+ bm = Basemap (llcrnrlon = 0 , llcrnrlat = - 80 , urcrnrlon = 360 , urcrnrlat = 80 , projection = 'mill' )
113
+
114
+ lons_expected = [10 , 15 , 20 ]
115
+ lonsout = bm .shiftdata (lons_expected [:])
116
+ assert_almost_equal (lons_expected , lonsout )
117
+
118
+ lonsout_expected = bm .shiftdata ([10 , 361 , 362 ])
119
+ lonsout = bm .shiftdata ([10 , 361 ])
120
+ assert_almost_equal (lonsout_expected [:len (lonsout )], lonsout )
121
+
122
+ def test_1_point_should_work (self ):
123
+ bm = Basemap (llcrnrlon = 0 , llcrnrlat = - 80 , urcrnrlon = 360 , urcrnrlat = 80 , projection = 'mill' )
124
+
125
+ # should not fail
126
+ lonsout = bm .shiftdata ([361 ])
127
+ assert_almost_equal (lonsout , [1.0 ,])
128
+
129
+ lonsout = bm .shiftdata ([10 ])
130
+ assert_almost_equal (lonsout , [10.0 ,])
131
+
132
+ lonsin = np .array ([361.0 ])
133
+ lonsin .shape = (1 , 1 )
134
+ lonsout = bm .shiftdata (lonsin [:])
135
+ assert_almost_equal (lonsout .squeeze (), [1.0 ,])
136
+
137
+ def test_less_than_n_by_3_points_should_work (self ):
138
+ bm = Basemap (llcrnrlon = 0 , llcrnrlat = - 80 , urcrnrlon = 360 , urcrnrlat = 80 , projection = 'mill' )
139
+ lons_expected = self ._get_2d_lons ([10 , 15 , 20 ])
140
+
141
+ # nothing should change
142
+ lonsout = bm .shiftdata (lons_expected )
143
+ assert_almost_equal (lons_expected , lonsout )
144
+
145
+ # shift n x 3 and n x 2 grids and compare results over overlapping region
146
+ lonsin = self ._get_2d_lons ([10 , 361 , 362 ])
147
+ lonsout_expected = bm .shiftdata (lonsin [:])[:, :2 ]
148
+ lonsout = bm .shiftdata (lonsin [:, :2 ])
149
+ assert_almost_equal (lonsout_expected , lonsout )
150
+
151
+
99
152
class TestProjectCoords (TestCase ):
100
153
def get_data (self ):
101
154
lons , lats = np .arange (- 180 , 180 , 20 ), np .arange (- 90 , 90 , 10 )
@@ -130,7 +183,6 @@ def test_results_should_be_same_for_c_and_f_order_arrays(self):
130
183
131
184
132
185
133
-
134
186
def test ():
135
187
"""
136
188
Run some tests.
0 commit comments