I am trying to use Python's rasterio library to analyze GIS wind data available here. I've written this reduced program:
import numpy as np
import rasterio as rio
from rasterio.merge import merge
file1 = 'us-wind-data/wtk_conus_120m_mean_masked.tif'
file2 = 'us-wind-data/wtk_conus_140m_mean_masked.tif'
def f(old_data, new_data, old_nodata, new_nodata, index=None, roff=None, coff=None):
old_data[:] = np.maximum(old_data, new_data)
with rio.open(file1, dtype=np.float64) as test1, rio.open(file2, dtype=np.float64) as test2:
mosaic, out_trans = merge([test1, test2], method=f)
print(mosaic)
and when running this I see:
Traceback (most recent call last):
File "merge5.py", line 16, in <module>
mosaic, out_trans = merge([test1, test2], method=f)
File "/home/mmachenry/.local/lib/python3.8/site-packages/rasterio/merge.py", line 261, in merge
dest = np.zeros((output_count, output_height, output_width), dtype=dt)
ValueError: negative dimensions are not allowed
There are a lot of examples of this error on Stackoverflow. None that I've found seem to be what I'm doing. It is, after all, a low level numpy error. In my research I've found people experiencing issues with reading the data as default float16 and then getting math overflow errors producing negatives. So I bumped up my dtype to float64 and it did not improve the situation.
I'm attempting to write a simple function that will take several of these tif files with a wind speed at each data point and create a new tif file with my data point that is a function of all of the wind speeds.