fix(notebook): correct execution counts and update file naming conventions for STFT processing

Closes #27
This commit is contained in:
nuluh
2025-03-11 19:08:56 +07:00
parent fa6e1ff72b
commit b890e556cf

View File

@@ -23,7 +23,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -32,7 +32,7 @@
"Index(['Time', 'Real'], dtype='object')" "Index(['Time', 'Real'], dtype='object')"
] ]
}, },
"execution_count": 4, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -271,7 +271,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -363,7 +363,7 @@
" [262144 rows x 2 columns]]" " [262144 rows x 2 columns]]"
] ]
}, },
"execution_count": 6, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -375,7 +375,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -404,7 +404,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -457,7 +457,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 19,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -483,7 +483,7 @@
" sensor_num = sensor_suffix[-1] # '1' or '2'\n", " sensor_num = sensor_suffix[-1] # '1' or '2'\n",
" \n", " \n",
" # Construct the file path\n", " # Construct the file path\n",
" file_name = f'D{damage_num}_TEST{test_num:02d}_{sensor_suffix}.csv'\n", " file_name = f'DAMAGE_{damage_num}_TEST{test_num}_{sensor_suffix}.csv'\n",
" file_path = os.path.join(damage_base_path, f'DAMAGE_{damage_num}', file_name)\n", " file_path = os.path.join(damage_base_path, f'DAMAGE_{damage_num}', file_name)\n",
" \n", " \n",
" # Check if the file exists\n", " # Check if the file exists\n",
@@ -517,7 +517,7 @@
" sensor_output_dir = os.path.join(damage_base_path, sensor_name.lower())\n", " sensor_output_dir = os.path.join(damage_base_path, sensor_name.lower())\n",
" os.makedirs(sensor_output_dir, exist_ok=True)\n", " os.makedirs(sensor_output_dir, exist_ok=True)\n",
" stft_file_path = os.path.join(sensor_output_dir, stft_file_name)\n", " stft_file_path = os.path.join(sensor_output_dir, stft_file_name)\n",
" \n", " print(stft_file_path)\n",
" # Append the flattened STFT to the CSV\n", " # Append the flattened STFT to the CSV\n",
" try:\n", " try:\n",
" flattened_stft_df = pd.DataFrame([flattened_stft])\n", " flattened_stft_df = pd.DataFrame([flattened_stft])\n",
@@ -534,7 +534,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 20,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -609,19 +609,19 @@
" (6, 5, '02')]" " (6, 5, '02')]"
] ]
}, },
"execution_count": 2, "execution_count": 20,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"# Define the base path where DAMAGE_X folders are located\n", "# Define the base path where DAMAGE_X folders are located\n",
"damage_base_path = 'D:/thesis/data/working/'\n", "damage_base_path = 'D:/thesis/data/converted/raw/'\n",
"\n", "\n",
"# Define active sensors\n", "# Define active sensors\n",
"active_sensors = {\n", "active_sensors = {\n",
" '01': 'Sensor1', # Beginning map sensor\n", " '01': 'sensor1', # Beginning map sensor\n",
" '02': 'Sensor2' # End map sensor\n", " '02': 'sensor2' # End map sensor\n",
"}\n", "}\n",
"\n", "\n",
"# Define damage cases and test runs\n", "# Define damage cases and test runs\n",
@@ -648,23 +648,33 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"Starting STFT processing with 8 CPU cores...\n" "Starting sequential STFT processing...\n",
"D:/thesis/data/converted/raw/sensor1\\stft_data1_1.csv\n",
"Appended STFT data to D:/thesis/data/converted/raw/sensor1\\stft_data1_1.csv\n",
"Processed 1/60 files\n",
"D:/thesis/data/converted/raw/sensor2\\stft_data2_1.csv\n",
"Appended STFT data to D:/thesis/data/converted/raw/sensor2\\stft_data2_1.csv\n",
"Processed 2/60 files\n",
"D:/thesis/data/converted/raw/sensor1\\stft_data1_1.csv\n",
"Appended STFT data to D:/thesis/data/converted/raw/sensor1\\stft_data1_1.csv\n",
"Processed 3/60 files\n",
"D:/thesis/data/converted/raw/sensor2\\stft_data2_1.csv\n"
] ]
} }
], ],
"source": [ "source": [
"# Use multiprocessing Pool to process STFTs in parallel\n", "# Process STFTs sequentially instead of in parallel\n",
"if __name__ == \"__main__\":\n", "if __name__ == \"__main__\":\n",
" print(f\"Starting STFT processing with {os.cpu_count()} CPU cores...\")\n", " print(f\"Starting sequential STFT processing...\")\n",
" with Pool(processes=os.cpu_count()) as pool:\n", " for i, arg in enumerate(args_list, 1):\n",
" for i, _ in enumerate(pool.imap_unordered(process_stft, args_list), 1):\n", " process_stft(arg)\n",
" print(f\"Processed {i}/{len(args_list)} files\")\n", " print(f\"Processed {i}/{len(args_list)} files\")\n",
" print(\"STFT processing completed.\")" " print(\"STFT processing completed.\")"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {