Streamlit app aborts when attempting to execute map reprojection for the second time

A simple streamlit app was made for matching the resolution and projection of two raster layers. The app could be executed by clicking on the Run button for the first time, but it would be aborted when clicking on the second time.

Any suggestion? Thank you very much!

Sample TIFF files:

Here’s the code:

import os
import sys
import gc
import rioxarray as rxr
import streamlit as st
from import MemoryFile

def read_memory(memoryfile):
    with MemoryFile(memoryfile) as mf:
        with as ds:
            data_array = rxr.open_rasterio(ds)
    return data_array.squeeze()

uploaded_files = st.file_uploader("TIF files", type=['tif'], accept_multiple_files=True)

if len(uploaded_files) > 0:

    filenames = [ for file in uploaded_files]

    img1_filename = st.selectbox("img1: ", options=filenames)
    img2_filename = st.selectbox("img2: ", options=filenames)

    img1_ind = filenames.index(img1_filename)
    img2_ind = filenames.index(img2_filename)

    img1 = read_memory(uploaded_files[img1_ind])
    img2 = read_memory(uploaded_files[img2_ind])
    collected_img = [i for i in ['img1', 'img2'] if i in globals()]

    if img1 is not None and img2 is not None:

        if st.button("Run"):
            img3 =

            st.code(f"img1: {img1.shape}, {}")
            st.code(f"img2: {img2.shape}, {}")
            st.code(f"img3: {img3.shape}, {}")


# streamlit run pycode\

Here’s the error messages:

RasterioIOError: No such file or directory
File "D:\pyenv\lib\site-packages\streamlit\runtime\scriptrunner\", line 552, in _run_script
    exec(code, module.__dict__)
File "D:\pycode\", line 36, in <module>
    img3 =
File "D:\pyenv\lib\site-packages\rioxarray\", line 546, in reproject_match
    reprojected_data_array = self.reproject(
File "D:\pyenv\lib\site-packages\rioxarray\", line 451, in reproject
File "D:\pyenv\lib\site-packages\xarray\core\", line 733, in values
    return self.variable.values
File "D:\pyenv\lib\site-packages\xarray\core\", line 614, in values
    return _as_array_or_item(self._data)
File "D:\pyenv\lib\site-packages\xarray\core\", line 314, in _as_array_or_item
    data = np.asarray(data)
File "D:\pyenv\lib\site-packages\xarray\core\", line 693, in __array__
    return np.asarray(self.get_duck_array(), dtype=dtype)
File "D:\pyenv\lib\site-packages\xarray\core\", line 696, in get_duck_array
File "D:\pyenv\lib\site-packages\xarray\core\", line 690, in _ensure_cached
    self.array = as_indexable(self.array.get_duck_array())
File "D:\pyenv\lib\site-packages\xarray\core\", line 664, in get_duck_array
    return self.array.get_duck_array()
File "D:\pyenv\lib\site-packages\xarray\core\", line 551, in get_duck_array
    array = self.array[self.key]
File "D:\pyenv\lib\site-packages\rioxarray\", line 453, in __getitem__
    return indexing.explicit_indexing_adapter(
File "D:\pyenv\lib\site-packages\xarray\core\", line 858, in explicit_indexing_adapter
    result = raw_indexing_method(raw_key.tuple)
File "D:\pyenv\lib\site-packages\rioxarray\", line 428, in _getitem
    self.manager.acquire(needs_lock=False), self.vrt_params
File "D:\pyenv\lib\site-packages\xarray\backends\", line 193, in acquire
    file, _ = self._acquire_with_cache_info(needs_lock)
File "D:\pyenv\lib\site-packages\xarray\backends\", line 217, in _acquire_with_cache_info
    file = self._opener(*self._args, **kwargs)
File "D:\pyenv\lib\site-packages\rasterio\", line 451, in wrapper
    return f(*args, **kwds)
File "D:\pyenv\lib\site-packages\rasterio\", line 320, in open
    dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
File "rasterio\_base.pyx", line 312, in rasterio._base.DatasetBase.__init__

Hey @p10911004,

Thanks for sharing this question. Just to confirm, you’re running this app on your local machine – it’s not deployed on Community Cloud?

Dear @Caroline ,

Thanks for your attention. Yes, the app was designed to run on local. I’ve tried to mount it on the cloud, but it seems to have the same problems.

* Sample images (img1, img2) are provided on top of the post.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.