added some draft plots

This commit is contained in:
2025-07-15 17:28:04 +02:00
parent 91ee876066
commit 7fac00c5c1
34 changed files with 288 additions and 45 deletions

View File

@@ -1,5 +1,5 @@
{
"Number_of_cycles": 5,
"Number_of_cycles": 2,
"Amplitude_mm": 10,
"Time_in_beam_s": 5,
"Time_out_of_beam_s": 10

View File

@@ -1,4 +1,4 @@
{"std_test_mov": [10, -10],
"std_test_wait": [1],
{"std_test_mov": [1, -1],
"std_test_wait": [1, 2],
"backlsh_meas_mov": [10, -10, -10, 10],
"backlash_meas_wait": [1]}

View File

@@ -31,7 +31,7 @@ import ad
import myutility as myu
workdir = \
os.path.expanduser(rf'C:\Users\berti_r\Python_Projects\StagePerformaceDocu\data{get_datestr()}_alignment_tests')
os.path.expanduser(rf'C:\Users\berti_r\Python_Projects\StagePerformaceDocu\data\data{get_datestr()}_alignment_tests')
if not os.path.exists(workdir):
os.makedirs(workdir)
@@ -74,15 +74,17 @@ def run_repeatability_series(
#--------------------------------------load coordinates from file-----------------------
x_coordinates_json = myu.load_object(measurement_mov_path)
x_coordinates = x_coordinates_json.get('std_test_mov')
wait_x_json = myu.load_object(measurement_mov_path)
wait_x = wait_x_json.get('std_test_wait')
print(wait_x)
for i in range(ntries):
#---------------------------------------------move------------------------------------------
#add multithreading for simultanious movement of y and x axis
for mov in x_coordinates:
for mov,wait in x_coordinates,wait_x:
axis1.moveRelativeAndWait(mov)
sleep(0.1)
sleep(1)
sleep(wait)
start_pos_rbv = 4 #????
meas_pos_rbv = 5 #????
#---------------------------------------------capture------------------------------------------
@@ -188,10 +190,11 @@ def analyze_repeatability(input_file, pixel_size, units='um'):
'Y-neg', p2v_y_neg, rms_y_neg, sigma_y_neg, 3*sigma_y_neg))
print(result_str)
"""
result_file = os.path.splitext(input_file)[0] + "_results.dat"
with open(result_file, 'w') as fh:
fh.write(result_str)
print(f"Results saved in: {result_file:s}")
print(f"Results saved in: {result_file:s}")"""
def plot_repeatability(
ax, index, com, mean, p2v, rms, pos_mask, neg_mask):

View File

@@ -1,4 +1,8 @@
import json
import glob
from datetime import datetime
import os
import numpy as np
# Load config from JSON file
def load_object(path):
with open(path, 'r') as f:
@@ -7,4 +11,30 @@ def load_object(path):
# Save updated config to JSON file
def save_config(path, updated_config):
with open(path, 'w') as f:
json.dump(updated_config, f, indent=4)
json.dump(updated_config, f, indent=4)
def find_newest_dat_file(folder):
dat_files = glob.glob(os.path.join(folder, '*.dat'))
if not dat_files:
raise FileNotFoundError("No .dat files found in the specified directory.")
return max(dat_files, key=os.path.getmtime)
def load_data(filepath):
times = []
temps = [[] for _ in range(5)]
with open(filepath, 'r') as file:
for line in file:
parts = line.strip().split()
if len(parts) == 6:
try:
*temp_values, timestamp = map(float, parts)
dt = datetime.fromtimestamp(timestamp)
times.append(dt)
for i in range(5):
temps[i].append(temp_values[i])
except ValueError:
continue # skip lines with invalid data
return np.array(times), [np.array(t) for t in temps]

View File

@@ -0,0 +1,2 @@
0 4.000000 5.000000 37.588 32.706 1752579103.475
1 4.000000 5.000000 26.667 34.583 1752579113.614

View File

@@ -0,0 +1,5 @@
0 4.000000 5.000000 35.724 30.828 1752579166.933
1 4.000000 5.000000 11.538 18.154 1752579176.988
2 4.000000 5.000000 31.867 18.267 1752579187.062
3 4.000000 5.000000 26.045 8.455 1752579197.156
4 4.000000 5.000000 39.571 21.000 1752579207.221

View File

@@ -0,0 +1,99 @@
26.0 25.3 23.861 25.588 24.964 1752586824.1837282
25.9 25.2 23.866 25.585 24.964 1752586826.183605
25.9 25.2 23.886 25.602 24.982 1752586828.184603
25.8 25.1 23.882 25.594 24.972 1752586830.199268
25.8 25.1 23.897 25.604 24.982 1752586832.1972249
25.6 24.9 23.915 25.619 24.994 1752586834.212561
25.4 24.7 23.938 25.638 25.008 1752586836.212204
25.2 24.6 23.957 25.657 25.034 1752586838.211518
25.3 24.6 23.944 25.648 25.019 1752586840.2269042
25.5 24.8 23.932 25.632 25.01 1752586842.228628
25.6 24.9 23.91 25.613 24.99 1752586844.22601
25.7 25.0 23.906 25.613 24.992 1752586846.225013
25.7 25.1 23.905 25.606 24.98 1752586848.2242439
25.9 25.2 23.891 25.594 24.968 1752586850.223988
26.1 25.4 23.87 25.578 24.954 1752586852.239352
26.3 25.6 23.838 25.546 24.928 1752586854.238882
26.4 25.7 23.853 25.556 24.941 1752586856.238347
26.3 25.6 23.853 25.554 24.942 1752586858.2537038
26.2 25.5 23.865 25.562 24.949 1752586860.253046
26.1 25.4 23.874 25.576 24.958 1752586862.252479
26.0 25.3 23.887 25.588 24.971 1752586864.2676952
26.0 25.2 23.884 25.587 24.965 1752586866.2670798
25.9 25.2 23.887 25.592 24.974 1752586868.266782
25.9 25.2 23.888 25.59 24.973 1752586870.266042
25.9 25.2 23.89 25.595 24.974 1752586872.2813718
25.8 25.1 23.894 25.596 24.977 1752586874.280805
25.8 25.1 23.9 25.606 24.989 1752586876.280521
25.7 25.0 23.911 25.611 24.995 1752586878.279445
25.5 24.9 23.923 25.626 25.005 1752586880.279273
25.4 24.7 23.936 25.64 25.018 1752586882.293673
25.2 24.6 23.944 25.644 25.025 1752586884.293417
25.2 24.5 23.962 25.663 25.044 1752586886.308494
25.2 24.6 23.953 25.656 25.033 1752586888.308178
25.3 24.7 23.944 25.644 25.031 1752586890.3074229
25.4 24.8 23.924 25.628 25.011 1752586892.3069818
25.6 24.9 23.919 25.62 25.003 1752586894.322195
25.7 25.0 23.911 25.613 24.992 1752586896.32154
25.7 25.0 23.907 25.611 24.995 1752586898.3210409
25.8 25.1 23.899 25.602 24.985 1752586900.336499
25.9 25.2 23.891 25.595 24.976 1752586902.3356748
26.1 25.3 23.878 25.578 24.958 1752586904.3352919
26.1 25.4 23.868 25.57 24.949 1752586906.33491
26.3 25.6 23.862 25.556 24.946 1752586908.34994
26.4 25.6 23.848 25.548 24.933 1752586910.349826
26.4 25.7 23.852 25.553 24.943 1752586912.3488698
26.3 25.6 23.844 25.54 24.936 1752586914.363883
26.2 25.5 23.869 25.571 24.958 1752586916.363335
26.0 25.3 23.884 25.582 24.967 1752586918.3628879
25.9 25.2 23.89 25.587 24.971 1752586920.362539
25.9 25.1 23.899 25.597 24.986 1752586922.377503
25.7 25.1 23.906 25.607 24.989 1752586924.377158
25.5 24.9 23.915 25.622 24.999 1752586926.376668
25.3 24.6 23.943 25.646 25.019 1752586928.376014
25.2 24.6 23.948 25.656 25.027 1752586930.3755782
25.3 24.7 23.941 25.648 25.026 1752586932.390708
25.5 24.8 23.921 25.624 25.006 1752586934.3903801
25.6 24.9 23.903 25.611 24.994 1752586936.389437
25.7 25.0 23.911 25.615 24.994 1752586938.388937
25.8 25.1 23.899 25.603 24.985 1752586940.404243
26.0 25.3 23.876 25.585 24.964 1752586942.40373
26.2 25.5 23.853 25.56 24.945 1752586944.4029598
26.4 25.6 23.841 25.547 24.935 1752586946.4026492
26.4 25.6 23.838 25.548 24.935 1752586948.417901
26.3 25.5 23.852 25.564 24.949 1752586950.417684
26.1 25.4 23.865 25.578 24.961 1752586952.415821
26.0 25.2 23.877 25.587 24.972 1752586954.43089
25.9 25.2 23.879 25.59 24.973 1752586956.4302561
25.8 25.1 23.884 25.594 24.977 1752586958.4298198
25.6 24.9 23.909 25.618 24.995 1752586960.429197
25.3 24.6 23.935 25.643 25.018 1752586962.428664
25.2 24.6 23.937 25.646 25.028 1752586964.428184
25.2 24.6 23.941 25.651 25.031 1752586966.443626
25.4 24.8 23.914 25.624 25.008 1752586968.44347
25.6 24.9 23.906 25.614 25.001 1752586970.442456
25.7 24.9 23.899 25.614 24.99 1752586972.457783
25.7 25.0 23.892 25.604 24.986 1752586974.4575202
25.7 25.0 23.895 25.607 24.986 1752586976.456855
25.8 25.1 23.879 25.599 24.978 1752586978.47243
25.9 25.2 23.871 25.587 24.965 1752586980.4713678
26.1 25.3 23.858 25.582 24.966 1752586982.470873
26.2 25.5 23.841 25.566 24.949 1752586984.486071
26.3 25.6 23.827 25.555 24.943 1752586986.485833
26.4 25.7 23.822 25.55 24.937 1752586988.484992
26.4 25.6 23.824 25.549 24.934 1752586990.484446
26.3 25.6 23.825 25.553 24.941 1752586992.4995918
26.2 25.5 23.829 25.562 24.949 1752586994.4993951
26.1 25.3 23.845 25.578 24.962 1752586996.498636
26.0 25.2 23.857 25.587 24.975 1752586998.49827
25.9 25.2 23.857 25.591 24.969 1752587000.4974
25.8 25.1 23.855 25.592 24.98 1752587002.5129511
25.8 25.1 23.865 25.596 24.986 1752587004.512277
25.6 25.0 23.874 25.607 24.991 1752587006.511234
25.5 24.9 23.882 25.615 24.996 1752587008.52704
25.4 24.8 23.896 25.628 25.011 1752587010.5261939
25.3 24.6 23.907 25.637 25.022 1752587012.526295
25.2 24.6 23.905 25.645 25.023 1752587014.525428
25.2 24.5 23.911 25.653 25.034 1752587016.525544
25.2 24.5 23.919 25.655 25.035 1752587018.539364
25.2 24.5 23.913 25.653 25.035 1752587020.5387409

Binary file not shown.

View File

@@ -0,0 +1,2 @@
0 4.000000 5.000000 24.706 23.529 1752579920.330
1 4.000000 5.000000 22.412 31.176 1752579924.312

View File

@@ -0,0 +1,10 @@
0 4.000000 5.000000 30.925 28.393 1752591829.817
1 4.000000 5.000000 30.665 29.303 1752591833.783
2 4.000000 5.000000 31.665 28.431 1752591837.661
3 4.000000 5.000000 30.946 28.660 1752591841.628
4 4.000000 5.000000 30.976 28.804 1752591845.609
5 4.000000 5.000000 31.347 27.971 1752591849.563
6 4.000000 5.000000 30.715 29.699 1752591853.508
7 4.000000 5.000000 30.736 28.887 1752591857.439
8 4.000000 5.000000 31.110 28.342 1752591861.341
9 4.000000 5.000000 30.990 27.982 1752591865.240

View File

@@ -38,6 +38,11 @@
"- Motor properties\n",
"- Humidity\n",
"- enc resolution\n",
"## Measurement tests\n",
"### unidirectional repetabillity\n",
"### bidirectional repetability\n",
"### thermal expansion\n",
"### relative distance accuracy\n",
"\n"
],
"id": "ac98fcd46a8e41f9",
@@ -53,8 +58,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-07-15T07:13:05.822677Z",
"start_time": "2025-07-15T07:13:05.801198Z"
"end_time": "2025-07-15T15:21:34.553058Z",
"start_time": "2025-07-15T15:21:34.403724Z"
}
},
"cell_type": "code",
@@ -178,18 +183,27 @@
"output_type": "stream",
"text": [
"Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Scripts\n",
"Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n"
"Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\config.json\n",
"Path exists: C:\\Users\\berti_r\\Python_Projects\\templates\\motion_libs\n",
"Path exists: C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\measurement.json\n",
"Constructor for PLC\n",
"Connect to PLC\n",
"is_open()=True\n",
"get_local_address()=None\n",
"read_device_info()=('Plc30 App', <pyads.structs.AdsVersion object at 0x0000023C8668CC20>)\n",
"GVL_APP.nAXIS_NUM=3\n",
"Constructor for axis\n"
]
},
{
"data": {
"text/plain": [
"BoundedIntText(value=5, description='Nr of cycles:', max=1000, min=1)"
"BoundedIntText(value=2, description='Nr of cycles:', max=1000, min=1)"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "931ffe1c6a4c4fe1af39442aafcd5a6d"
"model_id": "3b0d5b4ffb8e49818c298b9f4aa88c9a"
}
},
"metadata": {},
@@ -203,7 +217,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "49d711d81ca94028bd6c60a4ab0d22fa"
"model_id": "e6a7e81d76c54669996f666432736c9a"
}
},
"metadata": {},
@@ -217,7 +231,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "39198dfeeaa243cba9d410027dffe994"
"model_id": "e984d8a357044a279564d1bf46272beb"
}
},
"metadata": {},
@@ -231,14 +245,21 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "24e25cd7cc814f898ca4503bca9184f1"
"model_id": "841448ed4ad34367b522a923213d4d23"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"BIG TODO: ADD dropdown menue for choosing which test to run\n"
]
}
],
"execution_count": 5
"execution_count": 1
},
{
"metadata": {},
@@ -249,16 +270,100 @@
{
"metadata": {},
"cell_type": "code",
"source": [
"axis_path = r\"C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\data\\data20250715_alignment_tests\\20250715_170343_repeatibility_0\"\n",
"axis_data_file_path = myu.find_newest_dat_file(axis_path)\n",
"print(axis_data_file_path)\n",
"mf.analyze_repeatability(axis_data_file_path,1.1)\n"
],
"id": "35424a827215f084",
"outputs": [],
"execution_count": null,
"source": "",
"id": "35424a827215f084"
"execution_count": null
},
{
"metadata": {},
"cell_type": "markdown",
"source": "## Temperature time plot\n",
"id": "ffd60bd1525f3b15"
},
{
"metadata": {},
"cell_type": "code",
"source": [
"# Live update function\n",
"data_folder = r'C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\data\\Temp'\n",
"%matplotlib widget\n",
"from matplotlib.widgets import Cursor\n",
"import matplotlib.dates as mdates\n",
"# Load the newest file\n",
"\n",
"# Load file\n",
"file_path = myu.find_newest_dat_file(data_folder)\n",
"times, temps = myu.load_data(file_path)\n",
"\n",
"# Initial plot range setup\n",
"initial_xlim = (mdates.date2num(times[0]), mdates.date2num(times[-1]))\n",
"colors = ['red', 'green', 'blue', 'orange', 'purple']\n",
"labels = [f\"Temp {i+1}\" for i in range(5)]\n",
"\n",
"# Setup plot\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = []\n",
"\n",
"# Plot initial downsampled data\n",
"def plot_initial():\n",
" ind_min, ind_max = 0, len(times)\n",
" step = max((ind_max - ind_min) // 1000, 1)\n",
"\n",
" for i in range(5):\n",
" line, = ax.plot(times[ind_min:ind_max:step],\n",
" temps[i][ind_min:ind_max:step],\n",
" label=labels[i], color=colors[i])\n",
" lines.append(line)\n",
"\n",
" ax.set_title(\"Temperature Over Time\")\n",
" ax.set_xlabel(\"Time\")\n",
" ax.set_ylabel(\"Temperature (°C)\")\n",
" ax.legend()\n",
" ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))\n",
" ax.set_xlim(initial_xlim)\n",
" ax.relim()\n",
" ax.autoscale_view()\n",
"\n",
"# Update on zoom/pan\n",
"def update_plot(event=None):\n",
" xlim = ax.get_xlim()\n",
" t_nums = mdates.date2num(times)\n",
" ind_min, ind_max = np.searchsorted(t_nums, xlim)\n",
" ind_max = min(len(times), ind_max)\n",
" step = max((ind_max - ind_min) // 1000, 1)\n",
"\n",
" for line, temp_data in zip(lines, temps):\n",
" line.set_data(times[ind_min:ind_max:step], temp_data[ind_min:ind_max:step])\n",
"\n",
" ax.relim()\n",
" ax.autoscale_view()\n",
" fig.canvas.draw_idle()\n",
"\n",
"# Hook zoom & pan events\n",
"fig.canvas.mpl_connect('button_release_event', update_plot)\n",
"fig.canvas.mpl_connect('scroll_event', update_plot)\n",
"fig.canvas.mpl_connect('motion_notify_event', update_plot)\n",
"\n",
"# Run\n",
"plot_initial()\n",
"update_plot()\n",
"plt.tight_layout()\n",
"fig.canvas.draw_idle()"
],
"id": "6b1735e5aee89bc6",
"outputs": [],
"execution_count": null
},
{
"metadata": {},
"cell_type": "code",
"source": [
"~~~~# Live update function\n",
"def load_recent_data():\n",
"\n",
" return 0\n",
@@ -337,35 +442,22 @@
"execution_count": null
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-07-15T07:22:40.123332Z",
"start_time": "2025-07-15T07:22:40.118923Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"x_coordinates_json = myu.load_object(r\"C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\measurement.json\")\n",
"x_coordinates = x_coordinates_json.get('backlsh_meas_mov')\n",
"x_coordinates = x_coordinates_json.get('std_test_mov')\n",
"wait_x_json = myu.load_object(r\"C:\\Users\\berti_r\\Python_Projects\\StagePerformaceDocu\\Config\\measurement.json\")\n",
"wait_x = wait_x_json.get('std_test_wait')\n",
"print(x_coordinates)\n",
"for mov in x_coordinates:\n",
" print(mov)"
"print(wait_x)\n",
"for mov,wait in x_coordinates, wait_x:\n",
" print(mov)\n",
" print(wait)"
],
"id": "9813d493bd439789",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[10, -10, -10, 10]\n",
"10\n",
"-10\n",
"-10\n",
"10\n"
]
}
],
"execution_count": 9
"outputs": [],
"execution_count": null
}
],
"metadata": {