0

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.

mmachenry
  • 1,773
  • 3
  • 22
  • 38

1 Answers1

0

What's so mysterious about?

In [142]: np.zeros((10,-2))
Traceback (most recent call last):
  File "<ipython-input-142-c7db7030b12c>", line 1, in <module>
    np.zeros((10,-2))
ValueError: negative dimensions are not allowed

One or more of

(output_count, output_height, output_width)

But not knowing anything about merge or rasterio I don't know where those dimensions come from.

Can you tell us anything about test1, test2 when this error occurs.

As writen this question is not reproducible - it involves files that we don't have access to (and probably don't want either).

hpaulj
  • 221,503
  • 14
  • 230
  • 353