From b7505557683c36c8a54e5bac567bb4e40204c14b Mon Sep 17 00:00:00 2001 From: ctena Date: Wed, 3 Mar 2021 15:41:49 +0100 Subject: [PATCH] Avoid to create static R-LINE files if the file already exist --- CHANGELOG | 5 +++++ environment.yml | 2 +- hermesv3_bu/sectors/traffic_sector.py | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 81ff954..682c708 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ +1.0.6 + 2021/XX/XX + + - Avoid to create static R-LINE files if the file already exist + 1.0.5 2020/12/09 diff --git a/environment.yml b/environment.yml index 584e815..a32aac5 100755 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,7 @@ channels: - anaconda dependencies: - - python = 2 + - python = 3 - numpy - netcdf4 >= 1.3.1 - python-cdo >= 1.3.6 diff --git a/hermesv3_bu/sectors/traffic_sector.py b/hermesv3_bu/sectors/traffic_sector.py index 35e1e30..306e145 100755 --- a/hermesv3_bu/sectors/traffic_sector.py +++ b/hermesv3_bu/sectors/traffic_sector.py @@ -1557,7 +1557,8 @@ class TrafficSector(Sector): df_in = df_in.to_crs({u'units': u'm', u'no_defs': True, u'ellps': u'intl', u'proj': u'utm', u'zone': 31}) if rline_shp: - df_in.to_file(os.path.join(self.output_dir, 'roads.shp')) + if not os.path.exists(os.path.join(self.output_dir, 'roads.shp')): + df_in.to_file(os.path.join(self.output_dir, 'roads.shp')) count = 0 for i, line in df_in.iterrows(): @@ -1604,7 +1605,8 @@ class TrafficSector(Sector): df_out.set_index('Link_ID', inplace=True) df_out.sort_index(inplace=True) - df_out.to_csv(os.path.join(self.output_dir, 'roads.txt'), index=False, sep=' ') + if not os.path.exists(os.path.join(self.output_dir, 'roads.txt')): + df_out.to_csv(os.path.join(self.output_dir, 'roads.txt'), index=False, sep=' ') self.comm.Barrier() self.logger.write_log('\t\tTraffic emissions calculated', message_level=2) self.logger.write_time_log('TrafficSector', 'write_rline_roadlinks', timeit.default_timer() - spent_time) -- GitLab