minerva.data.readers.base_file_iterator

Classes

BaseFileIterator

A base class for iterating over files in a directory in a custom sorted

Module Contents

class minerva.data.readers.base_file_iterator.BaseFileIterator(files, sort_method=None, delimiter=None, key_index=0, reverse=False, filters=None)[source]

Bases: minerva.data.readers.reader._Reader

A base class for iterating over files in a directory in a custom sorted order.

Base class for iterating over files in a directory in a custom sorted order.

Parameters

filesPathLike

A list of file paths to iterate over.

sort_methodOptional[List[str]], optional

A list specifying how to sort each part of the filename. Each element can be either “text” (lexicographical) or “numeric” (numerically). By default, None, which will use “numeric” if numeric parts are detected.

delimiterOptional[str], optional

The delimiter to split filenames into components, by default None.

key_indexUnion[int, List[int]], optional

The index (or list of indices) of the part(s) of the filename to use for sorting. If a list is provided, files will be sorted based on multiple parts in sequence. Thus, first by the part at index 0, then by the part at index 1, and so on. By default 0.

reversebool, optional

Whether to sort in reverse order, by default False.

filters: Optional[Union[List[str], str]]

An optional string or list of strings containing regular expressions with which to filter files by their stems. Files that match at least one pattern are kept, and the others are excluded. Defaults to None, which means no files are excluded.

abstract __getitem__(index)[source]

Retrieve the image file at the specified index.

Parameters

indexint

Index of the image file to retrieve.

Returns

np.ndarray

The image file as a NumPy array.

Parameters:

index (int)

Return type:

numpy.ndarray

__len__()[source]

Return the number of image files in the directory.

Returns

int

The number of image files in the directory.

Return type:

int

__repr__()[source]
Return type:

str

__str__()[source]
Return type:

str

_filter_files()[source]

Filter files acording to provided regular expressions

_get_sort_values(value, method)[source]

Get the appropriate sorting value based on the method: ‘text’ or ‘numeric’.

Parameters:
  • value (str)

  • method (str)

_sort_files()[source]

Sort files based on the provided sorting options.

delimiter = None
files
filters: List[re.Pattern]
key_index
reverse = False
sort_method
Parameters:
  • files (List[minerva.utils.typing.PathLike])

  • sort_method (Optional[List[str]])

  • delimiter (Optional[str])

  • key_index (Union[int, List[int]])

  • reverse (bool)

  • filters (Optional[Union[List[str], str]])