@@ -1443,7 +1443,6 @@ class TestPyNioAutocloseTrue(TestPyNio):
1443
1443
class TestRasterio (TestCase ):
1444
1444
1445
1445
def test_serialization_utm (self ):
1446
-
1447
1446
import rasterio
1448
1447
from rasterio .transform import from_origin
1449
1448
@@ -1462,13 +1461,15 @@ def test_serialization_utm(self):
1462
1461
transform = transform ,
1463
1462
dtype = rasterio .float32 ) as s :
1464
1463
s .write (data )
1464
+ dx , dy = s .res [0 ], - s .res [1 ]
1465
1465
1466
1466
# Tests
1467
1467
expected = DataArray (data , dims = ('band' , 'y' , 'x' ),
1468
- coords = {'band' : [1 , 2 , 3 ],
1469
- 'y' : - np .arange (ny ) * 2000 + 80000 ,
1470
- 'x' : np .arange (nx ) * 1000 + 5000 ,
1471
- })
1468
+ coords = {
1469
+ 'band' : [1 , 2 , 3 ],
1470
+ 'y' : - np .arange (ny ) * 2000 + 80000 + dy / 2 ,
1471
+ 'x' : np .arange (nx ) * 1000 + 5000 + dx / 2 ,
1472
+ })
1472
1473
with xr .open_rasterio (tmp_file ) as rioda :
1473
1474
assert_allclose (rioda , expected )
1474
1475
assert 'crs' in rioda .attrs
@@ -1504,13 +1505,14 @@ def test_serialization_platecarree(self):
1504
1505
transform = transform ,
1505
1506
dtype = rasterio .float32 ) as s :
1506
1507
s .write (data , indexes = 1 )
1508
+ dx , dy = s .res [0 ], - s .res [1 ]
1507
1509
1508
1510
# Tests
1509
1511
expected = DataArray (data [np .newaxis , ...],
1510
1512
dims = ('band' , 'y' , 'x' ),
1511
1513
coords = {'band' : [1 ],
1512
- 'y' : - np .arange (ny )* 2 + 2 ,
1513
- 'x' : np .arange (nx )* 0.5 + 1 ,
1514
+ 'y' : - np .arange (ny )* 2 + 2 + dy / 2 ,
1515
+ 'x' : np .arange (nx )* 0.5 + 1 + dx / 2 ,
1514
1516
})
1515
1517
with xr .open_rasterio (tmp_file ) as rioda :
1516
1518
assert_allclose (rioda , expected )
@@ -1548,11 +1550,12 @@ def test_indexing(self):
1548
1550
transform = transform ,
1549
1551
dtype = rasterio .float32 ) as s :
1550
1552
s .write (data )
1553
+ dx , dy = s .res [0 ], - s .res [1 ]
1551
1554
1552
1555
# ref
1553
1556
expected = DataArray (data , dims = ('band' , 'y' , 'x' ),
1554
- coords = {'x' : np .arange (nx )* 0.5 + 1 ,
1555
- 'y' : - np .arange (ny )* 2 + 2 ,
1557
+ coords = {'x' : ( np .arange (nx )* 0.5 + 1 ) + dx / 2 ,
1558
+ 'y' : ( - np .arange (ny )* 2 + 2 ) + dy / 2 ,
1556
1559
'band' : [1 , 2 , 3 ]})
1557
1560
1558
1561
with xr .open_rasterio (tmp_file , cache = False ) as actual :
@@ -1640,11 +1643,12 @@ def test_caching(self):
1640
1643
transform = transform ,
1641
1644
dtype = rasterio .float32 ) as s :
1642
1645
s .write (data )
1646
+ dx , dy = s .res [0 ], - s .res [1 ]
1643
1647
1644
1648
# ref
1645
1649
expected = DataArray (data , dims = ('band' , 'y' , 'x' ),
1646
- coords = {'x' : np .arange (nx )* 0.5 + 1 ,
1647
- 'y' : - np .arange (ny )* 2 + 2 ,
1650
+ coords = {'x' : ( np .arange (nx )* 0.5 + 1 ) + dx / 2 ,
1651
+ 'y' : ( - np .arange (ny )* 2 + 2 ) + dy / 2 ,
1648
1652
'band' : [1 , 2 , 3 ]})
1649
1653
1650
1654
# Cache is the default
@@ -1683,6 +1687,7 @@ def test_chunks(self):
1683
1687
transform = transform ,
1684
1688
dtype = rasterio .float32 ) as s :
1685
1689
s .write (data )
1690
+ dx , dy = s .res [0 ], - s .res [1 ]
1686
1691
1687
1692
# Chunk at open time
1688
1693
with xr .open_rasterio (tmp_file , chunks = (1 , 2 , 2 )) as actual :
@@ -1693,8 +1698,8 @@ def test_chunks(self):
1693
1698
1694
1699
# ref
1695
1700
expected = DataArray (data , dims = ('band' , 'y' , 'x' ),
1696
- coords = {'x' : np .arange (nx )* 0.5 + 1 ,
1697
- 'y' : - np .arange (ny )* 2 + 2 ,
1701
+ coords = {'x' : np .arange (nx )* 0.5 + 1 + dx / 2 ,
1702
+ 'y' : - np .arange (ny )* 2 + 2 + dy / 2 ,
1698
1703
'band' : [1 , 2 , 3 ]})
1699
1704
1700
1705
# do some arithmetic
0 commit comments