perrygeo/pyimpute

Floating point precision limit with Affine comparison in load_targets

Becheler opened this issue · 0 comments

I wonder if replacing the line 119 in https://github.com/perrygeo/pyimpute/blob/master/src/pyimpute/_main.py :
assert transform == src.transform
by
transform.almost_equals(src.transform)
would make some sense?
I'm having a bunch of rasters that trigger the assert exception, but they seem to actually be reasonably very close. I implemented the following function to make sure of it:

def check_transform(rasters):
    import rasterio
    transform = None
    previous = None
    for raster in rasters:
        with rasterio.open(raster) as src:
            if not transform:
                transform = src.transform
            else:
                if transform != src.transform:
                    print(raster + ' and ' + previous + 'have different transforms: ')
                    print(previous, ':', transform)
                    print(raster, ':', src.transform)
                    print(transform.almost_equals(src.transform))
        previous = raster

And the output is:

chelsa_20_dem.tif and chelsa_20_bio18.tif have different transforms: 
chelsa_20_bio18.tif : 
| 0.01, 0.00, 130.85|
| 0.00,-0.01,-11.03|
| 0.00, 0.00, 1.00|

chelsa_20_dem.tif : 
| 0.01, 0.00, 130.85|
| 0.00,-0.01,-11.03|
| 0.00, 0.00, 1.00|

True

What do you think?