def _list_file_stack(fname, ind, digit=None): """ Return a stack of file names in a folder as a list. Parameters ---------- fname : str String defining the path of file or file name. ind : list of int Indices of the files to read. digit : int Deprecated input for the number of digits in all indexes of the stacked files. """ if digit is not None: warnings.warn(("The 'digit' argument is deprecated and no longer used." " It may be removed completely in a later version."), FutureWarning) body = writer.get_body(fname) body, digits = writer.remove_trailing_digits(body) ext = writer.get_extension(fname) list_fname = [] for m in ind: counter_string = str(m).zfill(digits) list_fname.append(body + counter_string + ext) return list_fname
def _list_file_stack(fname, ind, digit=None): """ Return a stack of file names in a folder as a list. Parameters ---------- fname : str String defining the path of file or file name. ind : list of int Indices of the files to read. digit : int Deprecated input for the number of digits in all indexes of the stacked files. """ if digit is not None: warnings.warn(("The 'digit' argument is deprecated and no longer used." " It may be removed completely in a later version."), FutureWarning) body = writer.get_body(fname) body, digits = writer.remove_trailing_digits(body) ext = writer.get_extension(fname) list_fname = [] for m in ind: counter_string = str(m).zfill(digits) list_fname.append(body + counter_string + ext) return list_fname
def read_hdf5_stack(h5group, dname, ind, digit=4, slc=None, out_ind=None): """ Read data from stacked datasets in a hdf5 file Parameters ---------- fname : str One of the dataset names in the dataset stack ind : list of int Indices of the datasets to be read digit : int (Deprecated) Number of digits indexing the stacked datasets slc : {sequence, int} Range of values for slicing data. ((start_1, end_1, step_1), ... , (start_N, end_N, step_N)) defines slicing parameters for each axis of the data matrix out_ind : list of int, optional Outer level indices for files with two levels of indexing. i.e. [name_000_000.tif, name_000_001.tif, ..., name_000_lmn.tif, name_001_lmn.tif, ..., ..., name_fgh_lmn.tif] """ list_fname = _list_file_stack(dname, ind, digit) if out_ind is not None: list_fname_ = [] for name in list_fname: fname = (writer.get_body(name).split('/')[-1] + '_' + digit * '0' + writer.get_extension(name)) list_fname_.extend(_list_file_stack(fname, out_ind, digit)) list_fname = sorted(list_fname_, key=lambda x: str(x).split('_')[-1]) for m, image in enumerate(list_fname): _arr = h5group[image] _arr = _slice_array(_arr, slc) if m == 0: dx, dy, dz = _arr.shape dx = len(list_fname) arr = np.empty((dx, dy, dz), dtype=_arr.dtype) arr[m] = _arr return arr
def read_hdf5_stack(h5group, dname, ind, digit=4, slc=None, out_ind=None): """ Read data from stacked datasets in a hdf5 file Parameters ---------- fname : str One of the dataset names in the dataset stack ind : list of int Indices of the datasets to be read digit : int (Deprecated) Number of digits indexing the stacked datasets slc : {sequence, int} Range of values for slicing data. ((start_1, end_1, step_1), ... , (start_N, end_N, step_N)) defines slicing parameters for each axis of the data matrix out_ind : list of int, optional Outer level indices for files with two levels of indexing. i.e. [name_000_000.tif, name_000_001.tif, ..., name_000_lmn.tif, name_001_lmn.tif, ..., ..., name_fgh_lmn.tif] """ list_fname = _list_file_stack(dname, ind, digit) if out_ind is not None: list_fname_ = [] for name in list_fname: fname = (writer.get_body(name).split('/')[-1] + '_' + digit * '0' + writer.get_extension(name)) list_fname_.extend(_list_file_stack(fname, out_ind, digit)) list_fname = sorted(list_fname_, key=lambda x: str(x).split('_')[-1]) for m, image in enumerate(list_fname): _arr = h5group[image] _arr = _slice_array(_arr, slc) if m == 0: dx, dy, dz = _arr.shape dx = len(list_fname) arr = np.empty((dx, dy, dz), dtype=_arr.dtype) arr[m] = _arr return arr
def _list_file_stack(fname, ind, digit): """ Return a stack of file names in a folder as a list. Parameters ---------- fname : str String defining the path of file or file name. ind : list of int Indices of the files to read. digit : int Number of digits in indexing stacked files. """ body = writer.get_body(fname, digit) ext = writer.get_extension(fname) list_fname = [] for m in ind: list_fname.append(str(body + '{0:0={1}d}'.format(m, digit) + ext)) return list_fname
def _list_file_stack(fname, ind, digit): """ Return a stack of file names in a folder as a list. Parameters ---------- fname : str String defining the path of file or file name. ind : list of int Indices of the files to read. digit : int Number of digits in indexing stacked files. """ body = writer.get_body(fname, digit) ext = writer.get_extension(fname) list_fname = [] for m in ind: list_fname.append(str(body + '{0:0={1}d}'.format(m, digit) + ext)) return list_fname