def convert_files(files, output_dir, opt, mask_file):
comm = MPI.COMM_WORLD
rank = comm.rank
size = comm.size
if mask_file:
# temporary cropped mask file
cropped_mask_file = tempfile.mktemp(suffix='.tif', dir=TMPDIR)
# crop/reproject/resample the mask
crop_reproject_resample(opt.mask_file,
cropped_mask_file,
sampling='near',
extents=opt.extents,
reproject=opt.reproject)
else:
cropped_mask_file = opt.mask_file
for i in range(rank, len(files), size):
in_file = files[i]
print('============file no: {} of {}==========='.format(i, len(files)))
log.info("operating on {file} in process {rank}".format(file=in_file,
rank=rank))
out_file = join(output_dir, basename(in_file))
log.info('Output file: {}'.format(out_file))
do_work(input_file=in_file,
mask_file=cropped_mask_file,
output_file=out_file,
options=options)
if mask_file:
os.remove(cropped_mask_file)
log.info('removed intermediate cropped '
'mask file {}'.format(cropped_mask_file))
comm.Barrier()
# TODO: use click here
评论列表
文章目录