-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject5.html
More file actions
257 lines (227 loc) · 9.95 KB
/
project5.html
File metadata and controls
257 lines (227 loc) · 9.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Laser Delay Control Code</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism-tomorrow.min.css" rel="stylesheet" />
<style>
.back-button {
position: fixed;
top: 20px;
left: 20px;
padding: 10px 20px;
background-color: #666;
color: white;
text-decoration: none;
border-radius: 4px;
font-size: 0.9em;
z-index: 1000;
transition: background-color 0.2s;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.6;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.code-container {
background: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 20px;
margin: 20px 0;
}
pre[class*="language-"] {
border-radius: 4px;
margin: 0;
padding: 15px;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
.description {
background: #fff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<a href="/research.html" class="back-button">Back</a>
<h1>Laser Delay Control Program</h1>
<div class="description">
<p>This program controls laser delay lines using PyVISA to interface with SDG2000x and DG535 delay generators.
It provides functionality for setting parameters, saving/loading profiles, and automated/manual data collection.</p>
</div>
<div class="code-container">
<pre><code class="language-python">import numpy as np
import json
import os
import pyvisa
rm = pyvisa.ResourceManager()
class LaserDelayControl:
def __init__(self):
self.max_delay_SDG = None
self.min_delay = None
self.num_photos_per_cycle = None
self.delay_increment = None
def push_SDG2000x_delay(self,channel,delay):
sdg = rm.open_resource('USB0::0xF4EC::0xEE38::SDG2XCAC1R0015::INSTR')
sdg.write(f"C{channel}:BSWV DLY,{delay}")
print(f'successfully pushed delay of {delay} to SDG2000x.')
print()
return
def push_DG535_delay(target_channel,reference_channel,delay):
dg535 = rm.open_resource("GPIB0::GPIB_ADDRESS::INSTR")
dg535.write(f'DT {target_channel},{reference_channel},{delay}')
print(f'successfully pushed delay of {delay} to DG535.')
print()
return
def set_parameters(self):
self.num_photos_per_cycle = self.get_int_input("Enter desired number of photos per cycle:")
self.delay_increment = self.get_int_input("Enter desired delay increment:")
self.min_delay = self.get_int_input("Enter desired minimum delay:")
self.max_delay_SDG = self.get_int_input("Enter desired starting delay for SDG2000x:")
print('-'*50, "PARAMETERS SUCCESSFULLY INITIALIZED", '-'*50)
self.print_current_parameters()
return self.max_delay_SDG, self.min_delay, self.num_photos_per_cycle, self.delay_increment
def get_int_input(self, prompt):
while True:
try:
return int(input(prompt))
except ValueError:
print(self.error_msg)
print()
def begin_data_collection(self):
sdg = rm.open_resource('USB0::0xF4EC::0xEE38::SDG2XCAC1R0015::INSTR')
dg535 = rm.open_resource("GPIB0::GPIB_ADDRESS::INSTR")
rm = pyvisa.ResourceManager()
if not all([self.max_delay_SDG, self.min_delay, self.num_photos_per_cycle, self.delay_increment]):
print("Error: Try again after you've set the parameters or loaded one of the profiles.")
return
delay_array = np.linspace(self.min_delay, self.max_delay_SDG, self.delay_increment)
delay_difference = 10
total_photos = int(len(delay_array))
current_delay = self.max_delay_SDG
is_automatic = input("automatic data collection? (y/n):")
if is_automatic == 'y':
while current_delay > self.min_delay:
current_delay = current_delay - self.delay_increment
self.push_SDG2000x_delay(1, current_delay)
self.push_DG535_delay(2,3,current_delay + delay_difference)
else:
while current_delay > self.min_delay:
go_next = input("input anything to continue to next shot. Type 'exit' to terminate program.")
if go_next == "exit":
return
else:
current_delay = current_delay - self.delay_increment
self.push_SDG2000x_delay(1, current_delay)
self.push_DG535_delay(2,3,current_delay + np.abs(delay_difference))
sdg.close()
dg535.close()
print("Data Collection Complete!")
return
def save_profile(self):
if not all([self.max_delay_SDG, self.min_delay, self.num_photos_per_cycle, self.delay_increment]):
print("Error: Try again after you've set the parameters or loaded one of the profiles.")
return
self.print_current_parameters()
while True:
yn = input("Save This Profile? (y/n): ").lower()
if yn in ['y', 'yes', 'n', 'no']:
break
print("Invalid Input. Please enter 'y' or 'n'.")
if yn in ['y', 'yes']:
profile_name = input("Enter desired profile name: ")
profile_data = {
"name": profile_name,
"data": [self.max_delay_SDG, self.min_delay, self.num_photos_per_cycle, self.delay_increment]
}
with open('profiles.txt', 'a') as file:
file.write(json.dumps(profile_data) + '\n')
print('-'*50)
print(f'PROFILE "{profile_name}" SUCCESSFULLY SAVED')
print('-'*50)
else:
print('-'*50)
print("SAVE PROFILE OPERATION CANCELLED")
print('-'*50)
def load_profile(self):
try:
with open('profiles.txt', 'r') as file:
lines = file.readlines()
print("PROFILES:")
for index, line in enumerate(lines):
profile = json.loads(line.strip())
print(f"{index}: {profile['name']} - {profile['data']}")
while True:
try:
which_profile = int(input("Select Profile to Load (enter index): "))
if 0 <= which_profile < len(lines):
break
else:
print("Invalid index. Please try again.")
except ValueError:
print("Please enter a valid number.")
selected_profile = json.loads(lines[which_profile].strip())
self.max_delay_SDG, self.min_delay, self.num_photos_per_cycle, self.delay_increment = selected_profile['data']
print(f"Loaded profile: {selected_profile['name']}")
self.print_current_parameters()
except FileNotFoundError:
print("profiles.txt file not found.")
except json.JSONDecodeError:
print("Error decoding JSON from the file. Make sure the file is properly formatted.")
def print_current_parameters(self):
print("Current Parameters:")
print(f"Initial Delay of SDG2000x: {self.max_delay_SDG}")
print(f"Minimum Delay of SDG2000x: {self.min_delay}")
print(f"Number of Photos Per Cycle: {self.num_photos_per_cycle}")
print(f"Delay Increment: {self.delay_increment}")
print()
def run(self):
self.error_msg = "Error: Please Try Again"
print("Welcome to the laser delay-line control program!")
print("Please follow the directions below.")
print()
while True:
print('-'*50, "MAIN MENU", '-'*50)
print("(1) SET PARAMETERS")
print("(2) BEGIN DATA COLLECTION")
print("(3) SAVE PROFILE")
print("(4) LOAD PROFILE")
print("(5) PRINT CURRENT PARAMETERS")
print("(6) EXIT")
token = self.get_int_input("Enter Token:")
if token == 1:
self.set_parameters()
elif token == 2:
self.begin_data_collection()
elif token == 3:
self.save_profile()
elif token == 4:
self.load_profile()
elif token == 5:
self.print_current_parameters()
elif token == 6:
print("Exiting program")
break
else:
print("Invalid token. Please try again.")
begin_script = LaserDelayControl()
begin_script.run()</code></pre>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js"></script>
</body>
<div style="margin-top: 60px; padding-top: 20px; border-top: 1px solid #eee; font-size: 0.8em; color: #666;">
<p>Documentation (HTML) formatted with assistance from Anthropic's <i>Claude</i>, an LLM</p>
</div>
</html>