Skip to content

Commit

Permalink
ENH: Add check for weight file presence before overwriting in chunked…
Browse files Browse the repository at this point in the history
…-rwg #510
  • Loading branch information
bekozi committed Jan 3, 2020
1 parent 0fa9f6f commit 4bfc44d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ocgis/ocli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
CRWG_LOG = "chunked-rwg"


def handle_weight_file_check(path):
if os.path.exists(path):
exc = IOError("Weight file must be removed before writing a new new one: {}".format(path))
try:
raise exc
finally:
ocgis.vm.abort(exc=exc)


@click.group()
def ocli():
pass
Expand Down Expand Up @@ -174,6 +183,7 @@ def chunked_rwg(source, destination, weight, nchunks_dst, merge, esmf_src_type,
if genweights:
msg = "Writing ESMF weights..."
ocgis_lh(msg=msg, level=logging.INFO, logger=CRWG_LOG)
handle_weight_file_check(weight)
gs.write_esmf_weights(source, destination, weight)

# Create the global weight file. This does not apply to spatial subsets because there will always be one weight
Expand All @@ -185,6 +195,7 @@ def chunked_rwg(source, destination, weight, nchunks_dst, merge, esmf_src_type,
if not ocgis.vm.is_null:
msg = "Merging chunked weight files to global file. Output global weight file is: {}".format(weight)
ocgis_lh(msg=msg, level=logging.INFO, logger=CRWG_LOG)
handle_weight_file_check(weight)
gs.create_merged_weight_file(weight)
excs = ocgis.vm.gather(exc)
excs = ocgis.vm.bcast(excs)
Expand Down

0 comments on commit 4bfc44d

Please sign in to comment.