@@ -26,7 +26,9 @@ def test_bounds2raster():
26
26
- 93.50721740722656 ,
27
27
36.49387741088867 ,
28
28
)
29
- _ = cx .bounds2raster (w , s , e , n , "test.tif" , zoom = 4 , ll = True )
29
+ _ = cx .bounds2raster (
30
+ w , s , e , n , "test.tif" , zoom = 4 , ll = True , source = cx .providers .CartoDB .Positron
31
+ )
30
32
rtr = rio .open ("test.tif" )
31
33
img = np .array ([band for band in rtr .read ()]).transpose (1 , 2 , 0 )
32
34
solu = (
@@ -37,13 +39,13 @@ def test_bounds2raster():
37
39
)
38
40
for i , j in zip (rtr .bounds , solu ):
39
41
assert round (i - j , TOL ) == 0
40
- assert img [0 , 100 , :].tolist () == [220 , 217 , 214 , 255 ]
41
- assert img [20 , 120 , :].tolist () == [246 , 245 , 238 , 255 ]
42
- assert img [200 , 100 , :].tolist () == [247 , 246 , 241 , 255 ]
43
- assert img [:, :, :3 ].sum () == pytest .approx (44440377 , rel = 0.1 )
44
- assert img .sum () == pytest .approx (61152057 , rel = 0.1 )
45
- assert_array_almost_equal (img [:, :, :3 ].mean (), 226.0354461669922 , decimal = 0 )
46
- assert_array_almost_equal (img .mean (), 233.27658462524414 , decimal = 0 )
42
+ assert img [0 , 100 , :].tolist () == [250 , 250 , 248 , 255 ]
43
+ assert img [20 , 120 , :].tolist () == [139 , 153 , 164 , 255 ]
44
+ assert img [200 , 100 , :].tolist () == [250 , 250 , 248 , 255 ]
45
+ assert img [:, :, :3 ].sum () == pytest .approx (47622796 , rel = 0.1 )
46
+ assert img .sum () == pytest .approx (64334476 , rel = 0.1 )
47
+ assert_array_almost_equal (img [:, :, :3 ].mean (), 242.2220662434896 , decimal = 0 )
48
+ assert_array_almost_equal (img .mean (), 245.4165496826172 , decimal = 0 )
47
49
48
50
# multiple tiles for which result is not square
49
51
w , s , e , n = (
@@ -52,7 +54,9 @@ def test_bounds2raster():
52
54
6.15665815595878 ,
53
55
51.47502370869813 ,
54
56
)
55
- img , ext = cx .bounds2raster (w , s , e , n , "test2.tif" , zoom = 7 , ll = True )
57
+ img , ext = cx .bounds2raster (
58
+ w , s , e , n , "test2.tif" , zoom = 7 , ll = True , source = cx .providers .CartoDB .Positron
59
+ )
56
60
rtr = rio .open ("test2.tif" )
57
61
rimg = np .array ([band for band in rtr .read ()]).transpose (1 , 2 , 0 )
58
62
assert rimg .shape == img .shape
@@ -84,7 +88,14 @@ def test_bounds2img(n_connections):
84
88
16 ,
85
89
]: # valid number of connections (test single and multiple connections)
86
90
img , ext = cx .bounds2img (
87
- w , s , e , n , zoom = 4 , ll = True , n_connections = n_connections
91
+ w ,
92
+ s ,
93
+ e ,
94
+ n ,
95
+ zoom = 4 ,
96
+ ll = True ,
97
+ n_connections = n_connections ,
98
+ source = cx .providers .CartoDB .Positron ,
88
99
)
89
100
solu = (
90
101
- 12523442.714243276 ,
@@ -94,9 +105,9 @@ def test_bounds2img(n_connections):
94
105
)
95
106
for i , j in zip (ext , solu ):
96
107
assert round (i - j , TOL ) == 0
97
- assert img [0 , 100 , :].tolist () == [220 , 217 , 214 , 255 ]
98
- assert img [20 , 120 , :].tolist () == [246 , 245 , 238 , 255 ]
99
- assert img [200 , 100 , :].tolist () == [247 , 246 , 241 , 255 ]
108
+ assert img [0 , 100 , :].tolist () == [250 , 250 , 248 , 255 ]
109
+ assert img [20 , 120 , :].tolist () == [139 , 153 , 164 , 255 ]
110
+ assert img [200 , 100 , :].tolist () == [250 , 250 , 248 , 255 ]
100
111
elif n_connections == 0 : # no connections should raise an error
101
112
with pytest .raises (ValueError ):
102
113
img , ext = cx .bounds2img (
@@ -112,7 +123,9 @@ def test_warp_tiles():
112
123
- 93.50721740722656 ,
113
124
36.49387741088867 ,
114
125
)
115
- img , ext = cx .bounds2img (w , s , e , n , zoom = 4 , ll = True )
126
+ img , ext = cx .bounds2img (
127
+ w , s , e , n , zoom = 4 , ll = True , source = cx .providers .CartoDB .Positron
128
+ )
116
129
wimg , wext = cx .warp_tiles (img , ext )
117
130
assert_array_almost_equal (
118
131
np .array (wext ),
@@ -125,9 +138,9 @@ def test_warp_tiles():
125
138
]
126
139
),
127
140
)
128
- assert wimg [100 , 100 , :].tolist () == [247 , 246 , 241 , 255 ]
129
- assert wimg [100 , 200 , :].tolist () == [246 , 246 , 241 , 255 ]
130
- assert wimg [20 , 120 , :].tolist () == [139 , 128 , 149 , 255 ]
141
+ assert wimg [100 , 100 , :].tolist () == [249 , 249 , 247 , 255 ]
142
+ assert wimg [100 , 200 , :].tolist () == [250 , 250 , 248 , 255 ]
143
+ assert wimg [20 , 120 , :].tolist () == [250 , 250 , 248 , 255 ]
131
144
132
145
133
146
@pytest .mark .network
@@ -138,13 +151,15 @@ def test_warp_img_transform():
138
151
- 93.50721740722656 ,
139
152
36.49387741088867 ,
140
153
)
141
- _ = cx .bounds2raster (w , s , e , n , "test.tif" , zoom = 4 , ll = True )
154
+ _ = cx .bounds2raster (
155
+ w , s , e , n , "test.tif" , zoom = 4 , ll = True , source = cx .providers .CartoDB .Positron
156
+ )
142
157
rtr = rio .open ("test.tif" )
143
158
img = np .array ([band for band in rtr .read ()])
144
159
wimg , _ = cx .warp_img_transform (img , rtr .transform , rtr .crs , "epsg:4326" )
145
- assert wimg [:, 100 , 100 ].tolist () == [247 , 246 , 241 , 255 ]
146
- assert wimg [:, 100 , 200 ].tolist () == [246 , 246 , 241 , 255 ]
147
- assert wimg [:, 20 , 120 ].tolist () == [139 , 128 , 149 , 255 ]
160
+ assert wimg [:, 100 , 100 ].tolist () == [249 , 249 , 247 , 255 ]
161
+ assert wimg [:, 100 , 200 ].tolist () == [250 , 250 , 248 , 255 ]
162
+ assert wimg [:, 20 , 120 ].tolist () == [250 , 250 , 248 , 255 ]
148
163
149
164
150
165
def test_howmany ():
@@ -227,7 +242,7 @@ def test_validate_zoom():
227
242
228
243
@pytest .mark .network
229
244
def test_place ():
230
- expected_bbox = [- 105.3014509 , 39.9643513 , - 105.1780988 , 40.094409 ]
245
+ expected_bbox = [- 105.3014509 , 39.9569362 , - 105.1780988 , 40.0944658 ]
231
246
expected_bbox_map = [
232
247
- 11740727.544603072 ,
233
248
- 11701591.786121061 ,
@@ -356,7 +371,9 @@ def test_add_basemap_query():
356
371
357
372
assert ax .images [0 ].get_array ().sum () == 64685390
358
373
assert ax .images [0 ].get_array ().shape == (256 , 256 , 4 )
359
- assert_array_almost_equal (ax .images [0 ].get_array ()[:, :, :3 ].mean (), 244.03656 , decimal = 0 )
374
+ assert_array_almost_equal (
375
+ ax .images [0 ].get_array ()[:, :, :3 ].mean (), 244.03656 , decimal = 0
376
+ )
360
377
assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 246.77742 , decimal = 0 )
361
378
362
379
@@ -420,42 +437,68 @@ def test_add_basemap_auto_zoom():
420
437
)
421
438
assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 217.2718038 , decimal = 0 )
422
439
423
- @pytest .mark .network
424
- @pytest .mark .parametrize ("zoom_adjust, expected_extent, expected_sum_1, expected_sum_2, expected_shape" , [
425
- # zoom_adjust and expected values where zoom_adjust == 1
426
- (1 , (
427
- - 11740727.544603072 ,
428
- - 11701591.786121061 ,
429
- 4852834.051769271 ,
430
- 4891969.810251278 ,
431
- ), 648244877 , 915631757 , (1024 , 1024 , 4 )),
432
440
433
- # zoom_adjust and expected values where zoom_adjust == -1
434
- (- 1 , (
441
+ @pytest .mark .network
442
+ @pytest .mark .parametrize (
443
+ "zoom_adjust, expected_extent, expected_sum_1, expected_sum_2, expected_shape" ,
444
+ [
445
+ # zoom_adjust and expected values where zoom_adjust == 1
446
+ (
447
+ 1 ,
448
+ (
449
+ - 11740727.544603072 ,
450
+ - 11701591.786121061 ,
451
+ 4852834.0517692715 ,
452
+ 4891969.810251278 ,
453
+ ),
454
+ 763769618 ,
455
+ 1031156498 ,
456
+ (1024 , 1024 , 4 ),
457
+ ),
458
+ # zoom_adjust and expected values where zoom_adjust == -1
459
+ (
460
+ - 1 ,
461
+ (
462
+ - 11740727.544603072 ,
463
+ - 11701591.786121061 ,
464
+ 4852834.0517692715 ,
465
+ 4891969.810251278 ,
466
+ ),
467
+ 47973710 ,
468
+ 64685390 ,
469
+ (256 , 256 , 4 ),
470
+ ),
471
+ ],
472
+ )
473
+ def test_add_basemap_zoom_adjust (
474
+ zoom_adjust , expected_extent , expected_sum_1 , expected_sum_2 , expected_shape
475
+ ):
476
+ x1 , x2 , y1 , y2 = [
435
477
- 11740727.544603072 ,
436
478
- 11701591.786121061 ,
437
- 4852834.051769271 ,
479
+ 4852834.0517692715 ,
438
480
4891969.810251278 ,
439
- ), 40396582 , 57108262 , (256 , 256 , 4 )),
440
- ])
441
- def test_add_basemap_zoom_adjust (zoom_adjust , expected_extent , expected_sum_1 , expected_sum_2 , expected_shape ):
442
- x1 , x2 , y1 , y2 = [- 11740727.544603072 , - 11701591.786121061 , 4852834.0517692715 , 4891969.810251278 ]
481
+ ]
443
482
444
483
f , ax = matplotlib .pyplot .subplots (1 )
445
484
ax .set_xlim (x1 , x2 )
446
485
ax .set_ylim (y1 , y2 )
447
- cx .add_basemap (ax , zoom = "auto" , zoom_adjust = zoom_adjust )
486
+ cx .add_basemap (
487
+ ax , zoom = "auto" , zoom_adjust = zoom_adjust , source = cx .providers .CartoDB .Positron
488
+ )
448
489
449
490
ax_extent = expected_extent
450
491
assert_array_almost_equal (ax_extent , ax .images [0 ].get_extent ())
451
492
452
- assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (expected_sum_1 , rel = 0.1 )
493
+ assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (
494
+ expected_sum_1 , rel = 0.1
495
+ )
453
496
assert ax .images [0 ].get_array ().sum () == pytest .approx (expected_sum_2 , rel = 0.1 )
454
497
assert ax .images [0 ].get_array ().shape == expected_shape
455
498
assert_array_almost_equal (
456
- ax .images [0 ].get_array ()[:, :, :3 ].mean (), 204.695738 , decimal = 0
499
+ ax .images [0 ].get_array ()[:, :, :3 ].mean (), 242.79582 , decimal = 0
457
500
)
458
- assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 217.2718038 , decimal = 0 )
501
+ assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 245.8468 , decimal = 0 )
459
502
460
503
461
504
@pytest .mark .network
@@ -466,38 +509,42 @@ def test_add_basemap_warping():
466
509
f , ax = matplotlib .pyplot .subplots (1 )
467
510
ax .set_xlim (x1 , x2 )
468
511
ax .set_ylim (y1 , y2 )
469
- cx .add_basemap (ax , crs = "epsg:4326" , attribution = None )
512
+ cx .add_basemap (
513
+ ax , crs = "epsg:4326" , attribution = None , source = cx .providers .CartoDB .Positron
514
+ )
470
515
assert ax .get_xlim () == (x1 , x2 )
471
516
assert ax .get_ylim () == (y1 , y2 )
472
- assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (811443707 , rel = 0.1 )
517
+ assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (978096737 , rel = 0.1 )
473
518
assert ax .images [0 ].get_array ().shape == (1135 , 1183 , 4 )
474
519
assert_array_almost_equal (
475
- ax .images [0 ].get_array ()[:, :, :3 ].mean (), 201.445020 , decimal = 0
520
+ ax .images [0 ].get_array ()[:, :, :3 ].mean (), 242.8174808 , decimal = 0
476
521
)
477
- assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 214.8337650 , decimal = 0 )
522
+ assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 245.8631 , decimal = 0 )
478
523
479
524
480
525
@pytest .mark .network
481
526
def test_add_basemap_warping_local ():
482
527
# Test local source warping
483
528
x1 , x2 = - 105.5 , - 105.00
484
529
y1 , y2 = 39.56 , 40.13
485
- _ = cx .bounds2raster (x1 , y1 , x2 , y2 , "./test2.tif" , ll = True )
530
+ _ = cx .bounds2raster (
531
+ x1 , y1 , x2 , y2 , "./test2.tif" , ll = True , source = cx .providers .CartoDB .Positron
532
+ )
486
533
f , ax = matplotlib .pyplot .subplots (1 )
487
534
ax .set_xlim (x1 , x2 )
488
535
ax .set_ylim (y1 , y2 )
489
536
cx .add_basemap (ax , source = "./test2.tif" , crs = "epsg:4326" , attribution = None )
490
537
assert ax .get_xlim () == (x1 , x2 )
491
538
assert ax .get_ylim () == (y1 , y2 )
492
539
493
- assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (515569833 , rel = 0.1 )
540
+ assert ax .images [0 ].get_array ()[:, :, :3 ].sum () == pytest .approx (613344449 , rel = 0.1 )
494
541
assert ax .images [0 ].get_array ().shape == (980 , 862 , 4 )
495
542
assert_array_almost_equal (
496
- ax .images [0 ].get_array ()[:, :, :3 ].mean (), 203.4383860 , decimal = 0
543
+ ax .images [0 ].get_array ()[:, :, :3 ].mean (), 242.0192121 , decimal = 0
497
544
)
498
545
499
- assert ax .images [0 ].get_array ().sum () == pytest .approx (730014888 , rel = 0.1 )
500
- assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 216.0420971 , decimal = 0 )
546
+ assert ax .images [0 ].get_array ().sum () == pytest .approx (827789504 , rel = 0.1 )
547
+ assert_array_almost_equal (ax .images [0 ].get_array ().mean (), 244.9777167 , decimal = 0 )
501
548
502
549
503
550
@pytest .mark .network
0 commit comments