diff --git a/src/imcflibs/imagej/misc.py b/src/imcflibs/imagej/misc.py index 7b9d2630..5496e7e3 100644 --- a/src/imcflibs/imagej/misc.py +++ b/src/imcflibs/imagej/misc.py @@ -123,7 +123,7 @@ def calculate_mean_and_stdv(values_list, round_decimals=0): mean = round(sum(filtered_list) / len(filtered_list), round_decimals) variance = sum((x - mean) ** 2 for x in filtered_list) / len(filtered_list) - std_dev = round(variance ** 0.5, round_decimals) + std_dev = round(variance**0.5, round_decimals) return mean, std_dev @@ -627,31 +627,6 @@ def save_image_in_format(imp, format, out_dir, series, pad_number, split_channel current_imp.close() -def pad_number(index, pad_length=2): - """Pad a number with leading zeros to a specified length. - - Parameters - ---------- - index : int or str - The number to be padded - pad_length : int, optional - The total length of the resulting string after padding, by default 2 - - Returns - ------- - str - The padded number as a string - - Examples - -------- - >>> pad_number(7) - '07' - >>> pad_number(42, 4) - '0042' - """ - return str(index).zfill(pad_length) - - def locate_latest_imaris(paths_to_check=None): """Find paths to latest installed Imaris or ImarisFileConverter version. diff --git a/src/imcflibs/strtools.py b/src/imcflibs/strtools.py index 10e731a6..d522c460 100644 --- a/src/imcflibs/strtools.py +++ b/src/imcflibs/strtools.py @@ -150,3 +150,28 @@ def alphanum_key(key): return [convert(c) for c in re.split("([0-9]+)", key)] return sorted(data, key=alphanum_key) + + +def pad_number(index, pad_length=2): + """Pad a number with leading zeros to a specified length. + + Parameters + ---------- + index : int or str + The number to be padded + pad_length : int, optional + The total length of the resulting string after padding, by default 2 + + Returns + ------- + str + The padded number as a string + + Examples + -------- + >>> pad_number(7) + '07' + >>> pad_number(42, 4) + '0042' + """ + return str(index).zfill(pad_length)