From fb4aad510fd35e8dedc3a2574d8868d509c3106d Mon Sep 17 00:00:00 2001 From: Wouter Knoben Date: Wed, 19 May 2021 15:34:01 -0600 Subject: [PATCH 1/3] added flag to overwrite or skip existing remapped nc files --- easymore/easymore.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easymore/easymore.py b/easymore/easymore.py index 0bdb348..90fbe46 100644 --- a/easymore/easymore.py +++ b/easymore/easymore.py @@ -35,6 +35,7 @@ def __init__(self): self.remapped_var_lat = 'latitude' # name of the latitude variable in the new nc file; default 'latitude' self.remapped_var_lon = 'longitude' # name of the longitude variable in the new nc file; default 'longitude' self.remapped_dim_id = 'ID' # name of the ID dimension in the new nc file; default 'ID' + self.overwrite_existing_remap = True # Flag to automatically overwrite existing remapping files. If 'False', aborts the remapping procedure if a file is detected self.temp_dir = './temp/' # temp_dir self.output_dir = './output/' # output directory self.format_list = ['f8'] # float for the remapped values @@ -992,8 +993,12 @@ def __target_nc_creation(self): self.length_of_time = len(time_var) target_date_times = nc4.num2date(time_var,units = time_unit,calendar = time_cal) target_name = self.output_dir + self.case_name + '_remapped_' + target_date_times[0].strftime("%Y-%m-%d-%H-%M-%S")+'.nc' - if os.path.exists(target_name): # remove file if exists + if os.path.exists(target_name) and self.overwrite_existing_remap: # remove file if exists + print('Removing existing remapped .nc file.') os.remove(target_name) + elif os.path.exists(target_name) and not self.overwrite_existing_remap: # do not overwrite existing file + print('Remapped .nc file already exists. Going to next file.') + continue # skip to next file for var in ncids.variables.values(): if var.name == self.var_time: time_dtype = str(var.dtype) From f3a13007a59d9b028c1470e465e3db3290405a59 Mon Sep 17 00:00:00 2001 From: Wouter Knoben Date: Wed, 19 May 2021 16:11:38 -0600 Subject: [PATCH 2/3] rewritten changes to be easier to read; functionality is the same --- easymore/easymore.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/easymore/easymore.py b/easymore/easymore.py index 90fbe46..14084c4 100644 --- a/easymore/easymore.py +++ b/easymore/easymore.py @@ -993,12 +993,13 @@ def __target_nc_creation(self): self.length_of_time = len(time_var) target_date_times = nc4.num2date(time_var,units = time_unit,calendar = time_cal) target_name = self.output_dir + self.case_name + '_remapped_' + target_date_times[0].strftime("%Y-%m-%d-%H-%M-%S")+'.nc' - if os.path.exists(target_name) and self.overwrite_existing_remap: # remove file if exists - print('Removing existing remapped .nc file.') - os.remove(target_name) - elif os.path.exists(target_name) and not self.overwrite_existing_remap: # do not overwrite existing file - print('Remapped .nc file already exists. Going to next file.') - continue # skip to next file + if os.path.exists(target_name): + if self.overwrite_existing_remap: + print('Removing existing remapped .nc file.') + os.remove(target_name) + else: + print('Remapped .nc file already exists. Going to next file.') + continue # skip to next file for var in ncids.variables.values(): if var.name == self.var_time: time_dtype = str(var.dtype) From f927afca1b6fa156ab1eb1ff4c85e1ca121f28c4 Mon Sep 17 00:00:00 2001 From: wknoben Date: Mon, 31 May 2021 09:30:09 -0600 Subject: [PATCH 3/3] changed setup dependency `osgeo` to `gdal` --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 12b4ce1..207e89b 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ 'shapely', 'pyshp', 'pysheds', - 'osgeo', + 'gdal', 'geovoronoi', 'json5', 'rasterio']