Skip to content

Extracting valid values from large raster #501

Answered by snowman2
samfav asked this question in Q&A
Discussion options

You must be logged in to vote

rioxarray.open_rasterio lazily loads the data by default. You can take advantage of this in your process and read the data in windows (or you could just select subsets of the array by slicing).
To prevent your memory from loading up, I recommend using the cache=False kwarg when opening the file.

da = rioxarray.open_rasterio(f"{BASE_PATH}large_tiff.tif", cache=False, mask_and_scale=True)

windows = [...]
out_data = []
for window in windows:
    subset = da.rio.isel_window(window)
    out_data.append(
        subset
            .to_dataframe()
            .reset_index()
            .drop_vars("spatial_ref")
            .dropna(how="all", subset=list(subset.data_vars))
   )

pandas.concat(ou…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@samfav
Comment options

Answer selected by samfav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants