23
23
from datetime import datetime , timedelta
24
24
import numpy as np
25
25
from collections import OrderedDict
26
- import sys
27
- import io
28
26
import argparse
29
27
try :
30
28
from netCDF4 import Dataset
36
34
from .version import __version__
37
35
38
36
39
- def open_csv_rb (my_file ):
40
- if sys .version_info [0 ] < 3 :
41
- return io .open (my_file , 'rb' )
42
- else :
43
- return io .open (my_file , 'r' , encoding = 'utf8' )
44
-
45
-
46
- def open_csv_wb (my_file ):
47
- if sys .version_info [0 ] < 3 :
48
- return io .open (my_file , 'wb' )
49
- else :
50
- return io .open (my_file , 'w' , newline = '' , encoding = 'utf8' )
51
-
52
-
53
- def open_csv_ab (my_file ):
54
- if sys .version_info [0 ] < 3 :
55
- return io .open (my_file , 'ab' )
56
- else :
57
- return io .open (my_file , 'a' , newline = '' , encoding = 'utf8' )
58
-
59
-
60
37
def get_dict_rain_series_simu (file_location , file_format , start_simu , end_simu , time_delta_simu ):
61
38
dict_rain , start_data , end_data , time_delta_data = read_rain_file (file_location , file_format )
62
39
@@ -202,7 +179,7 @@ def read_flow_file(file_location, file_format):
202
179
def read_simulation_settings_file (file_location ):
203
180
my_dict_args = dict ()
204
181
try :
205
- with open_csv_rb (file_location ) as my_file :
182
+ with open (file_location , 'r' , encoding = 'utf8' ) as my_file :
206
183
my_reader = DictReader (my_file )
207
184
for row in my_reader :
208
185
my_dict_args [row ['ARGUMENT' ]] = row ['VALUE' ]
@@ -216,7 +193,7 @@ def read_simulation_settings_file(file_location):
216
193
217
194
def read_csv_time_series_with_delta_check (csv_file , key_header , val_header ):
218
195
try :
219
- with open_csv_rb (csv_file ) as my_file :
196
+ with open (csv_file , 'r' , encoding = 'utf8' ) as my_file :
220
197
my_dict_data = dict ()
221
198
my_list_dt = list ()
222
199
my_reader = DictReader (my_file )
@@ -258,7 +235,7 @@ def read_netcdf_time_series_with_delta_check(netcdf_file, key_variable, val_vari
258
235
259
236
def read_csv_time_series_with_missing_check (csv_file , key_header , val_header ):
260
237
try :
261
- with open_csv_rb (csv_file ) as my_file :
238
+ with open (csv_file , 'r' , encoding = 'utf8' ) as my_file :
262
239
my_dict_data = OrderedDict ()
263
240
my_reader = DictReader (my_file )
264
241
try :
@@ -314,7 +291,7 @@ def write_flow_file_from_nds(series_report, discharge, the_file, out_file_format
314
291
315
292
316
293
def write_flow_csv_file_from_nds (series_report , discharge , csv_file ):
317
- with open_csv_wb (csv_file ) as my_file :
294
+ with open (csv_file , 'w' , newline = '' , encoding = 'utf8' ) as my_file :
318
295
my_writer = writer (my_file , delimiter = ',' )
319
296
my_writer .writerow (['DateTime' , 'flow' ])
320
297
for dt , val in zip (series_report , discharge ):
0 commit comments