storm-fsv-cvut / smoderp2d

SMODERP2D - Distributed event-based model for surface and subsurface runoff and erosion
https://storm-fsv-cvut.github.io/smoderp2d-manual/
GNU General Public License v3.0
9 stars 4 forks source link

infows error in nogis provider! #101

Closed jerabekjak closed 3 years ago

jerabekjak commented 3 years ago

The self.inflows used [1] is designes in the way that there is a boundary around the computation domain. In gis providers the loop [1] goes one cell above the uppermost cell in the computaitonal domain, where outflow is zero end use this zero as an inflow in the uppermost cell. WHich is the correct behaviour.

In no gis provider, where there is no empty cells sbove the compatatinal domain, it takes element with index -1 at the index of row from which should flow the first inflow into the compataional domain. In python (if i am corrent) index -1 in numpy arrays takes the last value in the array. wherefore the model took as on infow into the upslope cell an outflow from the last downslope cell.

Quick fix can be (not very systematic though):

--- a/smoderp2d/core/flow.py
+++ b/smoderp2d/core/flow.py
@@ -68,6 +68,7 @@ class D8(object):
             jbx = j + bx
             try:
                 insurfflow_from_cell = self.arr[iax][jbx].vol_runoff
+                if (iax < 0) : insurfflow_from_cell = 0
             except:
                 insurfflow_from_cell = 0.0
             try:

[1] https://github.com/storm-fsv-cvut/smoderp2d/blob/fb14b7040d675c27ba2cc9fc76a0fc3be6a811ad/smoderp2d/core/flow.py#L64

pesekon2 commented 3 years ago

What is the reason behind the try-except clause in your snippet? Maybe we can do an if-else clause (meaning that we can replace that try-except with the one you added?).

jerabekjak commented 3 years ago

The try-except is some relict, and i think it had some differnt meaning that the if statement suggested. I just spoke to @kavkapet, and devided to commit the sugested fix in the maste so we can test if it this was the cause of the error with nogis provider. It should be only a temporatl solution!

pesekon2 commented 3 years ago

Okay, in the case it's a relict, I would replace it with the if-else clause. Because the except branch used to do exactly what we want to do now. I am afraid that it's better than some workarounds on the nogis level as there we would need to change a lot and touch also other things.

jerabekjak commented 3 years ago

Yes, but the try-except was there in case of some error. I would rather raise some error in the except clause instead of puting there if-else, which I dont know how it should look like. The if (iax < 0) : insurfflow_from_cell = 0 is just workaround so @kubinro2 can test the nogis provider...