fix(notebooks): update sensor data paths and improve plotting aesthetics

This commit is contained in:
nuluh
2025-06-10 17:20:13 +07:00
parent ebaa263781
commit ad6cda4270

View File

@@ -17,8 +17,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"sensor1 = pd.read_csv('D:/thesis/data/converted/raw/DAMAGE_1/DAMAGE_1_TEST1_01.csv',sep=',')\n", "sensor1 = pd.read_csv('D:/thesis/data/converted/raw/DAMAGE_1/DAMAGE_0_TEST1_01.csv',sep=',')\n",
"sensor2 = pd.read_csv('D:/thesis/data/converted/raw/DAMAGE_1/DAMAGE_1_TEST1_02.csv',sep=',')" "sensor2 = pd.read_csv('D:/thesis/data/converted/raw/DAMAGE_1/DAMAGE_0_TEST1_02.csv',sep=',')"
] ]
}, },
{ {
@@ -101,13 +101,16 @@
"source": [ "source": [
"# Combined Plot for sensor 1 and sensor 2 from data1 file in which motor is operated at 800 rpm\n", "# Combined Plot for sensor 1 and sensor 2 from data1 file in which motor is operated at 800 rpm\n",
"\n", "\n",
"plt.plot(df1['s2'], label='sensor 2')\n", "plt.plot(df1['s2'], label='Sensor 1', color='C1', alpha=0.6)\n",
"plt.plot(df1['s1'], label='sensor 1', alpha=0.5)\n", "plt.plot(df1['s1'], label='Sensor 2', color='C0', alpha=0.6)\n",
"plt.xlabel(\"Number of samples\")\n", "plt.xlabel(\"Number of samples\")\n",
"plt.ylabel(\"Amplitude\")\n", "plt.ylabel(\"Amplitude\")\n",
"plt.title(\"Raw vibration signal\")\n", "plt.title(\"Raw vibration signal\")\n",
"plt.ylim(-7.5, 5)\n", "plt.ylim(-7.5, 5)\n",
"plt.legend()\n", "plt.legend()\n",
"plt.locator_params(axis='x', nbins=8)\n",
"plt.ylim(-1, 1) # Adjust range as needed\n",
"plt.grid(True, linestyle='--', alpha=0.5)\n",
"plt.show()" "plt.show()"
] ]
}, },
@@ -334,9 +337,44 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# len(ready_data1a)\n", "import numpy as np\n",
"# plt.pcolormesh(ready_data1[0])\n", "import matplotlib.pyplot as plt\n",
"ready_data1a[0].max().max()" "from mpl_toolkits.mplot3d import Axes3D\n",
"\n",
"# Assuming ready_data1a[0] is a DataFrame or 2D array\n",
"spectrogram_data = ready_data1a[0].values # Convert to NumPy array if it's a DataFrame\n",
"\n",
"# Get the dimensions of the spectrogram\n",
"num_frequencies, num_time_frames = spectrogram_data.shape\n",
"\n",
"# Create frequency and time arrays\n",
"frequencies = np.arange(num_frequencies) # Replace with actual frequency values if available\n",
"time_frames = np.arange(num_time_frames) # Replace with actual time values if available\n",
"\n",
"# Create a meshgrid for plotting\n",
"T, F = np.meshgrid(time_frames, frequencies)\n",
"\n",
"# Create a 3D plot\n",
"fig = plt.figure(figsize=(12, 8))\n",
"ax = fig.add_subplot(111, projection='3d')\n",
"\n",
"# Plot the surface\n",
"surf = ax.plot_surface(T, F, spectrogram_data, cmap='bwr', edgecolor='none')\n",
"\n",
"# Add labels and a color bar\n",
"ax.set_xlabel('Time Frames')\n",
"ax.set_ylabel('Frequency [Hz]')\n",
"ax.set_zlabel('Magnitude')\n",
"ax.set_title('3D Spectrogram')\n",
"# Resize the z-axis (shrink it)\n",
"z_min, z_max = 0, 0.1 # Replace with your desired range\n",
"ax.set_zlim(z_min, z_max)\n",
"ax.get_proj = lambda: np.dot(Axes3D.get_proj(ax), np.diag([1, 1, 0.5, 1])) # Shrink z-axis by 50%\n",
"ax.set_facecolor('white')\n",
"fig.colorbar(surf, ax=ax, shrink=0.5, aspect=10)\n",
"\n",
"# Show the plot\n",
"plt.show()"
] ]
}, },
{ {
@@ -345,13 +383,32 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from cmcrameri import cm\n",
"# Create a figure and subplots\n",
"fig, axes = plt.subplots(2, 3, figsize=(15, 8), sharex=True, sharey=True)\n",
"\n",
"# Flatten the axes array for easier iteration\n",
"axes = axes.flatten()\n",
"\n",
"# Loop through each subplot and plot the data\n",
"for i in range(6):\n", "for i in range(6):\n",
" plt.pcolormesh(ready_data1a[i], cmap=\"jet\", vmax=0.03, vmin=0.0)\n", " pcm = axes[i].pcolormesh(ready_data1a[i].transpose(), cmap='bwr', vmax=0.03, vmin=0.0)\n",
" plt.colorbar() \n", " axes[i].set_title(f'Case {i} Sensor A', fontsize=12)\n",
" plt.title(f'STFT Magnitude for case {i} sensor 1')\n", "\n",
" plt.xlabel(f'Frequency [Hz]')\n", "# Add a single color bar for all subplots\n",
" plt.ylabel(f'Time [sec]')\n", "# Use the first `pcolormesh` object (or any valid one) for the color bar\n",
" plt.show()" "cbar = fig.colorbar(pcm, ax=axes, orientation='vertical')\n",
"# cbar.set_label('Magnitude')\n",
"\n",
"# Set shared labels\n",
"fig.text(0.5, 0.04, 'Time Frames', ha='center', fontsize=12)\n",
"fig.text(0.04, 0.5, 'Frequency [Hz]', va='center', rotation='vertical', fontsize=12)\n",
"\n",
"# Adjust layout\n",
"# plt.tight_layout(rect=[0.05, 0.05, 1, 1]) # Leave space for shared labels\n",
"plt.subplots_adjust(left=0.1, right=0.75, top=0.9, bottom=0.1, wspace=0.2, hspace=0.2)\n",
"\n",
"plt.show()"
] ]
}, },
{ {
@@ -576,6 +633,16 @@
"X2a, y = create_ready_data('D:/thesis/data/converted/raw/sensor2')" "X2a, y = create_ready_data('D:/thesis/data/converted/raw/sensor2')"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"X1a.iloc[-1,:]\n",
"# y[2565]"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@@ -646,7 +713,7 @@
" # \"KNN\": KNeighborsClassifier(),\n", " # \"KNN\": KNeighborsClassifier(),\n",
" # \"LDA\": LinearDiscriminantAnalysis(),\n", " # \"LDA\": LinearDiscriminantAnalysis(),\n",
" \"SVM\": SVC(),\n", " \"SVM\": SVC(),\n",
" \"XGBoost\": XGBClassifier()\n", " # \"XGBoost\": XGBClassifier()\n",
"}\n", "}\n",
"\n", "\n",
"results_sensor1 = []\n", "results_sensor1 = []\n",
@@ -669,7 +736,7 @@
" # \"KNN\": KNeighborsClassifier(),\n", " # \"KNN\": KNeighborsClassifier(),\n",
" # \"LDA\": LinearDiscriminantAnalysis(),\n", " # \"LDA\": LinearDiscriminantAnalysis(),\n",
" \"SVM\": SVC(),\n", " \"SVM\": SVC(),\n",
" \"XGBoost\": XGBClassifier()\n", " # \"XGBoost\": XGBClassifier()\n",
"}\n", "}\n",
"\n", "\n",
"results_sensor2 = []\n", "results_sensor2 = []\n",