-
Hello all ! I am currently doing some speed tests with reading Sentinel 2 rasters located on a private S3 bucket. I have both standard and COG versions of them. After somes tests it turns out reading data from S3 using windowed reading takes me about 10x more time with rioxarray.open_rasterio() than with xarray.open_rasterio() .
Using a COG tif I get the following outputs:
So apparently xarray is 10x faster ? What am I missing here? Thanks in advance for any advice :) Best, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
rioxarray/xarray both use lazy loading to load data from the rasters. Calling rioxarray loads metadata from the files, so that is likely why it takes longer than xarray. Also, can you provide the output of EDIT: To avoid the cost of re-opening the files, I recommend modifying the tests to: for reader in readers:
if reader == "xarray":
xds = xr.open_rasterio(path)
if reader == "rioxarray":
xds = rioxr.open_rasterio(path)
# time elapsed for n_tries
time_tries = 0
for n in range(n_tries):
time_try = 0
start = time()
for col_off, row_off in zip(col_offs, row_offs):
if reader in ("xarray", "rioxarray"):
win = xds.isel(x=slice(row_off, h), y=slice(col_off, w)).load()
if reader == "rasterio":
with rasterio.open(path) as src:
win = src.read(window=Window(col_off=col_off, row_off=row_off, height=h, width=w))
end = time()
time_try = end - start
time_tries += time_try
total_time = time_tries / n_tries
print(f'reader {reader} - elapsed {mode}: {final_time} for {n_wins} windows with {n_tries} tries') |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I added a
And get the following:
xarray stills reads way faster apparently. Here is the output of
Any advice ? Again thank you ! |
Beta Was this translation helpful? Give feedback.
rioxarray/xarray both use lazy loading to load data from the rasters. Calling
win.load()
will likely get you performance closer torasterio
.rioxarray loads metadata from the files, so that is likely why it takes longer than xarray.
Also, can you provide the output of
rioxarray.show_versions
?EDIT: To avoid the cost of re-opening the files, I recommend modifying the tests to: