<commit_before>"""
:mod:`dic.dic_io` provides IO operations for DIC and associated files.
This includes loading (and possibly modifying) DIC data from ``.MAT`` files and MTS data from ``.CSV`` files.
In addition, the ability to find and sort image (or general) filenames is provided.

"""
from __future__ import absolute_import, division, print_function
import itertools
import multiprocessing as mp
import numpy as np
import os
import pandas as pd
import scipy.io as spio
import sys
from tqdm import tqdm
import warnings

__all__ = ["load_dic_data", "load_csv_data", "get_filenames", "get_image_filenames", "update_dic_data"]


def get_filenames(directory, extension, prepend_directory=False):
    """
    Retrieves a sorted list of file names in the specified directory with the given extension.

    Parameters
    ----------
    directory : str
        Directory to search.
    extension : str
        Extension to search for (including the period, if applicable).
    prepend_directory : bool, optional
        Whether to prepend the directory to the filenames. Default = ``False``.

    Returns
    -------
    List[str]
        Sorted list of file names that match the given extension
    """
    output = []
    for f in os.listdir(directory):
        fbase, fext = os.path.splitext(f)
        if fext == extension:
            output.append(f)
    output.sort()

    if prepend_directory:
        for i, f in enumerate(output):
            output[i] = os.path.join(directory, f)

    return output


def get_image_filenames(directory, extension=".tif", prepend_directory=False):
    """
    Sorts and retrieves the camera images in the specified directory. This function assumes that the left camera images
    end in ``_0.ext``, where ``.ext`` is the provided extension. Similarly, the right camera images are assumed to
    end in ``_1.ext``.

    Parameters<commit_msg>Function to retrieve filenames now prepends the directory using a list comprehension instead of a for loop.<commit_after>"""
:mod:`dic.dic_io` provides IO operations for DIC and associated files.
This includes loading (and possibly modifying) DIC data from ``.MAT`` files and MTS data from ``.CSV`` files.
In addition, the ability to find and sort image (or general) filenames is provided.

"""
from __future__ import absolute_import, division, print_function
import itertools
import multiprocessing as mp
import numpy as np
import os
import pandas as pd
import scipy.io as spio
import sys
from tqdm import tqdm
import warnings

__all__ = ["load_dic_data", "load_csv_data", "get_filenames", "get_image_filenames", "update_dic_data"]


def get_filenames(directory, extension, prepend_directory=False):
    """
    Retrieves a sorted list of file names in the specified directory with the given extension.

    Parameters
    ----------
    directory : str
        Directory to search.
    extension : str
        Extension to search for (including the period, if applicable).
    prepend_directory : bool, optional
        Whether to prepend the directory to the filenames. Default = ``False``.

    Returns
    -------
    List[str]
        Sorted list of file names that match the given extension
    """
    output = []
    for f in os.listdir(directory):
        fbase, fext = os.path.splitext(f)
        if fext == extension:
            output.append(f)
    output.sort()

    if prepend_directory:
        output = [os.path.join(directory, f) for f in output]

    return output


def get_image_filenames(directory, extension=".tif", prepend_directory=False):
    """
    Sorts and retrieves the camera images in the specified directory. This function assumes that the left camera images
    end in ``_0.ext``, where ``.ext`` is the provided extension. Similarly, the right camera images are assumed to
    end in ``_1.ext``.

    Parameters
{'fraction_non_alphanumeric': 0.08699059561128526, 'fraction_numerical': 0.0010449320794148381, 'mean_word_length': 3.297418630751964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3458574', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1059, 'n_words': 434}