Skip to content

Commit

Permalink
fix(pad_dict): should also update ppd, visual_size, if it can
Browse files Browse the repository at this point in the history
  • Loading branch information
JorisVincent committed Jul 15, 2023
1 parent 5ad8cb3 commit dab5bf5
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions stimupy/utils/pad.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy

import numpy as np

from .utils import resolution
Expand Down Expand Up @@ -268,7 +269,7 @@ def pad_dict_by_visual_size(dct, padding, ppd, pad_value=0.0, keys=("img", "*mas
img = pad_by_visual_size(img, padding, ppd, pad_value)
new_dict[key] = img

# Update visual_size and shape-keys
# Update resolution
new_dict["visual_size"] = resolution.visual_size_from_shape_ppd(img.shape, ppd)
new_dict["shape"] = resolution.validate_shape(img.shape)
return new_dict
Expand Down Expand Up @@ -301,7 +302,13 @@ def pad_dict_to_visual_size(dct, visual_size, ppd, pad_value=0, keys=("img", "*m
shape = resolution.shape_from_visual_size_ppd(visual_size=visual_size, ppd=ppd)

# pad
return pad_dict_to_shape(dct=dct, shape=shape, pad_value=pad_value, keys=keys)
padded_dict = pad_dict_to_shape(dct=dct, shape=shape, pad_value=pad_value, keys=keys)

# update resolution
padded_dict["ppd"] = ppd
padded_dict["visual_size"] = visual_size

return padded_dict


def pad_dict_by_shape(dct, padding, pad_value=0, keys=("img", "*mask")):
Expand Down Expand Up @@ -430,7 +437,7 @@ def pad_dict_to_shape(dct, shape, pad_value=0, keys=("img", "*mask")):
img = pad_by_shape(img, padding=padding, pad_value=pad_value)
new_dict[key] = img

# Update visual_size and shape-keys
# Update resolution
new_dict["shape"] = resolution.validate_shape(shape)
if "ppd" in dct.keys():
new_dict["visual_size"] = resolution.visual_size_from_shape_ppd(shape, dct["ppd"])
Expand Down

0 comments on commit dab5bf5

Please sign in to comment.