From 28cfaac663bcb9116ed5923a656e6ef1fa3e53a0 Mon Sep 17 00:00:00 2001 From: Travis Thurber Date: Thu, 4 Jan 2024 11:22:44 -0800 Subject: [PATCH] prevent infinite loop stemming from divide by zero --- mosartwmpy/grid/grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mosartwmpy/grid/grid.py b/mosartwmpy/grid/grid.py index bf61515..a31261c 100644 --- a/mosartwmpy/grid/grid.py +++ b/mosartwmpy/grid/grid.py @@ -273,7 +273,7 @@ def __init__(self, config: Benedict = None, parameters: Parameters = None, empty # parameter for calculating number of main channel iterations needed # phi_r phi_main = np.where( - (self.mosart_mask > 0) & (self.channel_length > 0), + (self.mosart_mask > 0) & (self.channel_length > 0) & (self.channel_width > 0), self.total_drainage_area_single * np.sqrt(self.channel_slope) / (self.channel_length * self.channel_width), 0 ) @@ -352,7 +352,7 @@ def __init__(self, config: Benedict = None, parameters: Parameters = None, empty # parameter for calculating number of subnetwork iterations needed # phi_t phi_sub = np.where( - self.subnetwork_length > 0, + (self.mosart_mask > 0) & (self.subnetwork_length > 0) & (self.subnetwork_width > 0), (self.area * np.sqrt(self.subnetwork_slope)) / (self.subnetwork_length * self.subnetwork_width), 0, )