diff --git a/city_metrix/layers/cams.py b/city_metrix/layers/cams.py index 34c8892..729d37b 100644 --- a/city_metrix/layers/cams.py +++ b/city_metrix/layers/cams.py @@ -48,8 +48,8 @@ def get_data(self, bbox): # load netcdf files dataarray_list = [] for nc_file in os.listdir(fname): - dataarray = xr.open_dataset(f'{fname}/{nc_file}') - dataarray_list.append(dataarray) + with xr.open_dataset(f'{fname}/{nc_file}') as dataarray: + dataarray_list.append(dataarray) # not all variables have 'model_level', concatenate without 'model_level' dimension dataarray_list = [