I am tring to resample Chirps data from 0.25 to 0.0025degrees resolution with the following code, I am still using 1 as an upscale factor to get the code to run:
import rasterio
from rasterio.enums import Resampling
import os
upscale_factor = 1
i = 0
for files in os.listdir(r'D:/CHIRPS RSDATA/CHIRPS(1981-1983)'):
if files [-4:] == '.tif':
i = i + 1
fp = r'D:\CHIRPS RSDATA\CHIRPS(1981-1983)'+'\\'+files
print(fp)
dataset = rasterio.open(fp)
data = dataset.read(out_shape=(dataset.count,
int(dataset.height*upscale_factor),
int(dataset.width*upscale_factor)),
resampling=Resampling.bilinear) #You can change the resamplng technique here
if data.shape[-1] != 0 and data.shape[-2] != 0:
transform=dataset.transform*dataset.transform.scale((dataset.width/data.shape[-1]),(dataset.height/data.shape[-2]))
height = int(dataset.height*upscale_factor)
width = int(dataset.width*upscale_factor)
with rasterio.Env():
profile = dataset.profile
profile.update(transform=transform,driver='GTiff',height=height,width=width)
with rasterio.open('D:\CHIRPS RSDATA\CHIRPS(1981-1983)\Rainfalls',"w",**profile) as output:
output.write(data)
print("Image resampled...")
and I am getting this error:
runfile('D:/CHIRPS RSDATA/CHIRPS(1981-1983)/Resampling_python.py', wdir='D:/CHIRPS RSDATA/CHIRPS(1981-1983)')
D:\CHIRPS RSDATA\CHIRPS(1981-1983)\chirps-v2.0.1981.01.01.tif
Traceback (most recent call last):
File "rasterio\_io.pyx", line 1139, in rasterio._io.DatasetWriterBase.__init__
File "rasterio\_err.pyx", line 215, in rasterio._err.exc_wrap_pointer
CPLE_OpenFailedError: Attempt to create new tiff file 'D:/CHIRPS RSDATA/CHIRPS(1981-1983)/Rainfalls' failed: Permission denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\CHIRPS RSDATA\CHIRPS(1981-1983)\Resampling_python.py", line 42, in <module>
with rasterio.open('D:\CHIRPS RSDATA\CHIRPS(1981-1983)\Rainfalls',"w",**profile) as output:
File "C:\Users\khoda\anaconda3\lib\site-packages\rasterio\env.py", line 435, in wrapper
return f(*args, **kwds)
File "C:\Users\khoda\anaconda3\lib\site-packages\rasterio\__init__.py", line 225, in open
s = writer(path, mode, driver=driver,
File "rasterio\_io.pyx", line 1143, in rasterio._io.DatasetWriterBase.__init__
RasterioIOError: Attempt to create new tiff file 'D:/CHIRPS RSDATA/CHIRPS(1981-1983)/Rainfalls' failed: Permission denied
I tried changing the permissions of the folder with no luck, I also double checked the synaxes as other people have suggested. Please help.