Skip to content

Commit

Permalink
[ENH] Add overwrite option to transform_images (#509)
Browse files Browse the repository at this point in the history
* Add overwrite option to transform_images.

* Apply suggestions from code review
  • Loading branch information
tsalo authored May 26, 2021
1 parent ed4abc4 commit bffd5e9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nimare/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
LGR = logging.getLogger(__name__)


def transform_images(images_df, target, masker, metadata_df=None, out_dir=None):
def transform_images(images_df, target, masker, metadata_df=None, out_dir=None, overwrite=False):
"""Generate images of a given type from other image types and write out to files.
Parameters
Expand All @@ -37,6 +37,8 @@ def transform_images(images_df, target, masker, metadata_df=None, out_dir=None):
out_dir : :obj:`str` or :obj:`None`, optional
Path to output directory. If None, use folder containing first image
for each study in ``images_df``.
overwrite : :obj:`bool`, optional
Whether to overwrite existing files or not. Default is False.
Returns
-------
Expand Down Expand Up @@ -84,7 +86,11 @@ def transform_images(images_df, target, masker, metadata_df=None, out_dir=None):
# Get converted data
img = resolve_transforms(target, available_data, new_masker)
if img is not None:
img.to_filename(new_file)
if overwrite or not op.isfile(new_file):
img.to_filename(new_file)
else:
LGR.debug("Image already exists. Not overwriting.")

images_df.loc[images_df["id"] == id_, target] = new_file
else:
images_df.loc[images_df["id"] == id_, target] = None
Expand Down

0 comments on commit bffd5e9

Please sign in to comment.