Skip to content
Snippets Groups Projects
Commit e27c46fb authored by Rahil Doshi's avatar Rahil Doshi
Browse files

Fix bugs, final working implementation for data_handler with test cases

parent 224e5f8b
Branches
No related merge requests found
Pipeline #68340 failed with stages
in 1 minute and 3 seconds
...@@ -58,7 +58,7 @@ class Alloy: ...@@ -58,7 +58,7 @@ class Alloy:
self.temperature_boil = interpolate_temperature_boil(self.elements, self.composition) self.temperature_boil = interpolate_temperature_boil(self.elements, self.composition)
def interpolate_property(self, T: VariableTypes, temp_array: ValueTypes, prop_array: ValueTypes, prop_name: str, def interpolate_property(self, T: VariableTypes, temp_array: ValueTypes, prop_array: ValueTypes, prop_name: str,
temp_array_limit=5, force_lookup=False): temp_array_limit=6, force_lookup=False):
""" """
Perform interpolation based on the type of temperature array (equidistant or not). Perform interpolation based on the type of temperature array (equidistant or not).
......
import os import os
def create_test_files() -> None: def create_test_files() -> None:
""" """
Creates a folder named 'test_files' and generates test files with predefined contents. Creates a folder named 'test_files' and generates test files with predefined contents.
...@@ -24,7 +25,7 @@ def create_test_files() -> None: ...@@ -24,7 +25,7 @@ def create_test_files() -> None:
3050 54.5 3050 54.5
3000 54.0 3000 54.0
2900 53.0 2900 53.0
2800 52.1 2800 52.0
""", """,
"test_files/test_data_variable_spacing.txt": """Temp Density "test_files/test_data_variable_spacing.txt": """Temp Density
3400 58.0 3400 58.0
......
...@@ -81,6 +81,9 @@ def clean_temperature_data(temp: np.ndarray, prop: np.ndarray) -> Tuple[np.ndarr ...@@ -81,6 +81,9 @@ def clean_temperature_data(temp: np.ndarray, prop: np.ndarray) -> Tuple[np.ndarr
# common_diff = bin_edges[np.argmax(hist)] # Most frequent temperature difference # common_diff = bin_edges[np.argmax(hist)] # Most frequent temperature difference
unique_diffs, counts = np.unique(diffs, return_counts=True) unique_diffs, counts = np.unique(diffs, return_counts=True)
common_diff = unique_diffs[np.argmax(counts)] common_diff = unique_diffs[np.argmax(counts)]
if np.max(counts) < 2:
print("No repeated temperature differences found. Returning original data.")
return temp, prop
print(f"Most common temperature difference: {common_diff}") print(f"Most common temperature difference: {common_diff}")
except Exception as e: except Exception as e:
print(f"Error calculating most common difference: {e}") print(f"Error calculating most common difference: {e}")
...@@ -249,7 +252,7 @@ def run_tests() -> None: ...@@ -249,7 +252,7 @@ def run_tests() -> None:
Runs predefined tests to validate data reading and processing functions. Runs predefined tests to validate data reading and processing functions.
""" """
test_cases = [ test_cases = [
# {"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"}, {"name": "Normal Case", "file_path": "test_files/test_data_normal.txt"},
# {"name": "Normal Case 1", "file_path": "test_files/test_data_normal1.txt"}, # {"name": "Normal Case 1", "file_path": "test_files/test_data_normal1.txt"},
# {"name": "Case with Variable Spacing", "file_path": "test_files/test_data_variable_spacing.txt"}, # {"name": "Case with Variable Spacing", "file_path": "test_files/test_data_variable_spacing.txt"},
# {"name": "Case with Sparse Data", "file_path": "test_files/test_data_sparse.txt"}, # {"name": "Case with Sparse Data", "file_path": "test_files/test_data_sparse.txt"},
...@@ -262,7 +265,7 @@ def run_tests() -> None: ...@@ -262,7 +265,7 @@ def run_tests() -> None:
# {"name": "Mismatched Columns", "file_path": "test_files/test_data_mismatched_columns.txt"}, # {"name": "Mismatched Columns", "file_path": "test_files/test_data_mismatched_columns.txt"},
# {"name": "Missing Data Entries", "file_path": "test_files/test_data_missing_data.txt"}, # {"name": "Missing Data Entries", "file_path": "test_files/test_data_missing_data.txt"},
# {"name": "Ascending density_temperature values", "file_path": "test_files/test_data_density_temperature_ascending.txt"}, # {"name": "Ascending density_temperature values", "file_path": "test_files/test_data_density_temperature_ascending.txt"},
{"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"} # {"name": "Descending density_temperature values", "file_path": "test_files/test_data_density_temperature_descending.txt"}
] ]
for case in test_cases: for case in test_cases:
......
...@@ -6,4 +6,4 @@ Temp Density ...@@ -6,4 +6,4 @@ Temp Density
3050 54.5 3050 54.5
3000 54.0 3000 54.0
2900 53.0 2900 53.0
2800 52.1 2800 52.0
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment