JGCRI / xanthos

An extensible global hydrologic framework
Other
34 stars 16 forks source link

Ensure drought statistics are written into their output array. #39

Closed rplzzz closed 5 years ago

rplzzz commented 5 years ago

The problem here was that we were setting a variable equal to an array slice, and then assigning it with the results of the time step's drought calculation. However, in order for that to work as intended, we have to do it in a way that doesn't rebind the reference. This fix should do the trick, based on some simple tests:

>>> z = np.zeros((5,5))
>>> z
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> z1 = z[1,:]
>>> z1
array([ 0.,  0.,  0.,  0.,  0.])
>>> z1 = np.array([1,2,3,4,5])
>>> z
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
>>> z1 = z[1,:]
>>> z1[:] = np.array([1,2,3,4,5])
>>> z
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 1.,  2.,  3.,  4.,  5.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

That said, I haven't been able to test this, since I don't have Xanthos set up to run anywhere. If one of you guys could do a short run to verify that this does the trick, I'd be much obliged.