Skip to content

Commit 4857715

Browse files
committed
Small fix for debug_paddyrice output debug file
1 parent 96b7fc0 commit 4857715

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/lisflood/hydrological_modules/waterabstraction.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@ def initial(self):
255255
#### Prepare output file to store info on potential issue for Paddy Rice Water Abstraction
256256
if option.get('repPaddyRiceDebug') is True:
257257
self.debug_paddyrice_filename = os.path.join(settings.output_dir,f"debug_paddyrice.csv")
258-
if os.path.exists(self.debug_paddyrice_filename):
259-
os.remove(self.debug_paddyrice_filename)
260-
261-
262-
258+
try:
259+
if os.path.exists(self.debug_paddyrice_filename):
260+
os.remove(self.debug_paddyrice_filename)
261+
except IOError:
262+
print("Error accessing file {0}".format(self.debug_paddyrice_filename))
263+
263264

264265
def dynamic(self):
265266
""" dynamic part of the water use module
@@ -708,12 +709,15 @@ def dynamic(self):
708709
f"{self.var.areatotal_withdrawal_LakRes_actual_M3[idx]}, {self.var.AreaTotalAvailableWaterFromChannelsM3[idx]}, " \
709710
f"{areatotal_withdrawal_SW_required[idx]}, {areatotal_withdrawal_SW_required[idx]-areatotal_PaddyRiceWaterAbstractionFromSurfaceWaterM3[idx]}\n"
710711
#print(message)
711-
# Open the file in write mode
712-
with open(self.debug_paddyrice_filename, 'a') as file:
713-
if header is not None:
714-
file.write(header)
715-
# Write the message to the file
716-
file.write(message)
712+
try:
713+
# Open the file in write mode
714+
with open(self.debug_paddyrice_filename, 'a') as file:
715+
if header is not None:
716+
file.write(header)
717+
# Write the message to the file
718+
file.write(message)
719+
except IOError:
720+
print("Error accessing file {0} (2)".format(self.debug_paddyrice_filename))
717721

718722
#from numba import njit
719723
#from builtins import max, min

0 commit comments

Comments
 (0)