Greater than 2-D data throws error on histogram
When trying to histogram data with more than two dimensions, yori raises an error:
Traceback (most recent call last):
File "monitor.py", line 71, in yori_aggregate
callYori('%s-settings.yaml' % product, new_f, new_grid_f)
File "/home/enelson/venv/lib/python3.6/site-packages/yori-1.3.11.dev0+g7e044fb.d20190927-py3.6.egg/yori/run_yori.py", line 187, in callYori
Yori.runYori(debug, compression)
File "/home/enelson/venv/lib/python3.6/site-packages/yori-1.3.11.dev0+g7e044fb.d20190927-py3.6.egg/yori/run_yori.py", line 149, in runYori
tmp_gridvar = myGrid.compute_stats(masked_data_in, var_name_out)
File "/home/enelson/venv/lib/python3.6/site-packages/yori-1.3.11.dev0+g7e044fb.d20190927-py3.6.egg/yori/gridtools.py", line 100, in compute_stats
var = reformat_vector(var)
File "/home/enelson/venv/lib/python3.6/site-packages/yori-1.3.11.dev0+g7e044fb.d20190927-py3.6.egg/yori/gridtools.py", line 251, in reformat_vector
vec = np.reshape(vec, np.shape(vec)[0]*np.shape(vec)[1])
File "<__array_function__ internals>", line 6, in reshape
File "/home/enelson/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 301, in reshape
return _wrapfunc(a, 'reshape', newshape, order=order)
File "/home/enelson/venv/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 61, in _wrapfunc
return bound(*args, **kwds)
ValueError: cannot reshape array of size 1131200 into shape (2828,)
This error stems from a hard-coded assumption of data shape as 2-D in the reformat_vector
function. (It would have actually been raised sooner in execution, https://gitlab.ssec.wisc.edu/pveglio/yori/blob/master/yori/gridtools.py#L23, except I formatted my input lat/lon arrays incorrectly to be 2-D instead of 3-D.)
One path forward may be to change this line in the reformat_vector
function to numpy.flatten
to handle arrays of higher dimension. The program will then make sure that lat/lon and data variables are of the same length after flattening (https://gitlab.ssec.wisc.edu/pveglio/yori/blob/master/yori/gridtools.py#L103).
Another may be to enforce a dimension limit in the program by checking if all inputs are 2-D early in the execution. I don't know how that aligns with the program philosophy--I can see a case of someone wanting to grid data with shape (time, lat, lon)
.