Skip to content

Database Integration

src.material_database

get_database_material(idx)

Retrieves the material name and absorption coefficients from a CSV file based on the given index. The CSV file is expected to be in the current working directory and named "materials.csv".

Parameters:

Name Type Description Default
idx int

The index of the material in the CSV file.

required

Returns:

Type Description
tuple

A tuple containing the material name material_name (str) and an array of absorption coefficients abs_coeff (np.ndarray). The absorption coefficients are expected to be in the columns 1 to 8 of the CSV file.

Source code in src/material_database.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def get_database_material(idx):
    """
    Retrieves the material name and absorption coefficients from a CSV file based on the given index.
    The CSV file is expected to be in the current working directory and named "materials.csv".

    Parameters
    ----------
    idx : int
        The index of the material in the CSV file.

    Returns
    -------
    tuple
        A tuple containing the material name material_name (str) and an array of absorption coefficients abs_coeff (np.ndarray).
        The absorption coefficients are expected to be in the columns 1 to 8 of the CSV file.
    """

    path = os.getcwd()
    df = pd.read_csv(os.path.join(path, "materials.csv"))
    material_name = df.iloc[idx, 0]
    abs_coeff = df.iloc[idx, [1, 2, 3, 4, 5, 6, 7, 8]].to_numpy(dtype=float)

    return material_name,abs_coeff