Skip to content

Commit 7cc70a6

Browse files
authored
Merge pull request #64 from lguerard/issues/58
Move `pad_number()` to `strtools`
2 parents 7b79ffc + ef64219 commit 7cc70a6

2 files changed

Lines changed: 26 additions & 26 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def calculate_mean_and_stdv(values_list, round_decimals=0):
123123

124124
mean = round(sum(filtered_list) / len(filtered_list), round_decimals)
125125
variance = sum((x - mean) ** 2 for x in filtered_list) / len(filtered_list)
126-
std_dev = round(variance ** 0.5, round_decimals)
126+
std_dev = round(variance**0.5, round_decimals)
127127

128128
return mean, std_dev
129129

@@ -627,31 +627,6 @@ def save_image_in_format(imp, format, out_dir, series, pad_number, split_channel
627627
current_imp.close()
628628

629629

630-
def pad_number(index, pad_length=2):
631-
"""Pad a number with leading zeros to a specified length.
632-
633-
Parameters
634-
----------
635-
index : int or str
636-
The number to be padded
637-
pad_length : int, optional
638-
The total length of the resulting string after padding, by default 2
639-
640-
Returns
641-
-------
642-
str
643-
The padded number as a string
644-
645-
Examples
646-
--------
647-
>>> pad_number(7)
648-
'07'
649-
>>> pad_number(42, 4)
650-
'0042'
651-
"""
652-
return str(index).zfill(pad_length)
653-
654-
655630
def locate_latest_imaris(paths_to_check=None):
656631
"""Find paths to latest installed Imaris or ImarisFileConverter version.
657632

src/imcflibs/strtools.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,28 @@ def alphanum_key(key):
150150
return [convert(c) for c in re.split("([0-9]+)", key)]
151151

152152
return sorted(data, key=alphanum_key)
153+
154+
155+
def pad_number(index, pad_length=2):
156+
"""Pad a number with leading zeros to a specified length.
157+
158+
Parameters
159+
----------
160+
index : int or str
161+
The number to be padded
162+
pad_length : int, optional
163+
The total length of the resulting string after padding, by default 2
164+
165+
Returns
166+
-------
167+
str
168+
The padded number as a string
169+
170+
Examples
171+
--------
172+
>>> pad_number(7)
173+
'07'
174+
>>> pad_number(42, 4)
175+
'0042'
176+
"""
177+
return str(index).zfill(pad_length)

0 commit comments

Comments
 (0)