-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathData_Run_0D.py
226 lines (189 loc) · 8.21 KB
/
Data_Run_0D.py
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
# -*- coding: utf-8 -*-
"""
Multi-scope data acquisition program.
Run this program to acquire data from multiple scopes and save it in an HDF5 file.
Result is plotted in real time.
The user should edit this file to:
1) Set scope IP addresses
2) Set number of shots and external delays
3) Set the HDF5 filename and experiment description
4) Set descriptions for scopes and channels
5) Configure any other experiment-specific parameters
Created on Dec.13.2024
@author: Jia Han
"""
import datetime
import os
from multi_scope_acquisition import MultiScopeAcquisition
import time
import sys
############################################################################################################################
'''
User: Set experiment name and path
'''
exp_name = 'exp_00_test' # experiment name
date = datetime.date.today()
path = f"E:\\Shadow data\\Energetic_Electron_Ring\\{exp_name}_{date}"
save_path = f"{path}\\{exp_name}.hdf5"
#-------------------------------------------------------------------------------------------------------------
'''
User: Set scope IP addresses and parameters
'''
scope_ips = {
'magnetron': '192.168.7.64', # RF source measurements
'x-ray_dipole': '192.168.7.66', # X-ray dipole measurements
'Bdot': '192.168.7.63' # Magnetic field measurements
}
external_delays = { # unit: milliseconds
'magnetron': 15,
'x-ray_dipole': 15,
'Bdot': 25
}
num_shots = 2 # Number of acquisitions to make
#-------------------------------------------------------------------------------------------------------------
def get_experiment_description(): # USER EDITED
"""Return overall experiment description"""
return f'''Energetic electron ring experiment.
Experiment: {exp_name}
Date: {date}
Operator: Jia Han
Setup:
- Plasma condition
- Helium backside pressure 42 Psi
- Puff with top valve only 105V for 20ms; plasma starts at ~11ms
- Discharge 20ms; bank 140V; current 4.2kA
- Pressure 0.025-0.05mTorr
- Density 5e12⇒1.8e12 from 20⇒25ms (see separate data saved on diagnostic PC)
- Magnetron condition:
- Filament current 52A
- Magnetic field 4.A 25.7V
- Magnetron duration 40ms
- Charging voltage and power see scope
- X-ray camera:
- Scope descriptions: See scope_group.attrs['description']
- Channel descriptions: See channel_group.attrs['description']
Notes:
All delays are set with respect to plasma 1kA as T=0
'''
#-------------------------------------------------------------------------------------------------------------
def get_channel_description(tr): # USER EDITED
"""Return description for each channel"""
descriptions = {
# Magnetron scope channels
'magnetron_C1': 'Forward power',
'magnetron_C2': 'Reflected power',
'magnetron_C3': 'RF envelope',
'magnetron_C4': 'RF phase',
# X-ray dipole scope channels
'x-ray_dipole_C1': 'X-ray signal 1',
'x-ray_dipole_C2': 'X-ray signal 2',
'x-ray_dipole_C3': 'X-ray signal 3',
'x-ray_dipole_C4': 'X-ray signal 4',
# Bdot scope channels
'Bdot_C1': 'Bdot probe 1',
'Bdot_C2': 'Bdot probe 2',
'Bdot_C3': 'Bdot probe 3',
'Bdot_C4': 'Bdot probe 4'
}
return descriptions.get(tr, f'Channel {tr} - No description available')
def get_scope_description(scope_name): # USER EDITED
"""Return description for each scope"""
descriptions = {
'magnetron': '''RF source measurements scope
Channels: Forward/reflected power, RF envelope and phase
Timebase: 500 ns/div
Vertical scales: See channel settings''',
'x-ray_dipole': '''X-ray dipole measurements scope
Channels: X-ray signals from dipole detectors
Timebase: 1 µs/div
Vertical scales: See channel settings''',
'Bdot': '''Magnetic field measurements scope
Channels: Bdot probe signals
Timebase: 100 ns/div
Vertical scales: 5V/div'''
}
return descriptions.get(scope_name, f'Scope {scope_name} - No description available')
#===============================================================================================================================================
# Main Data Run sequence
#===============================================================================================================================================
def main():
# Create save directory if it doesn't exist
if not os.path.exists(path):
os.makedirs(path)
# Check if file already exists
if os.path.exists(save_path):
while True:
response = input(f'File "{save_path}" already exists. Overwrite? (y/n): ').lower()
if response in ['y', 'n']:
break
print("Please enter 'y' or 'n'")
if response == 'n':
print('Exiting without overwriting existing file')
sys.exit()
else:
print('Overwriting existing file')
os.remove(save_path) # Delete the existing file
print('Data run started at', datetime.datetime.now())
t_start = time.time()
try:
# Initialize and run acquisition
with MultiScopeAcquisition(
scope_ips=scope_ips,
num_loops=num_shots,
save_path=save_path,
external_delays=external_delays
) as acquisition:
acquisition.run_acquisition()
except KeyboardInterrupt:
print('\n______Halted due to Ctrl-C______', ' at', time.ctime())
except Exception as e:
print(f'\n______Halted due to error: {str(e)}______', ' at', time.ctime())
finally:
print('Data run finished at', datetime.datetime.now())
print('Time taken: %.2f hours' % ((time.time()-t_start)/3600))
# Print file size if it was created
if os.path.isfile(save_path):
size = os.stat(save_path).st_size/(1024*1024)
print(f'Wrote file "{save_path}", {size:.1f} MB')
else:
print(f'File "{save_path}" was not created')
#===============================================================================================================================================
# Test Data Run
#===============================================================================================================================================
def run_test(test_save_path, num_shots=5):
"""Run a test data acquisition with minimal settings"""
test_scope_ips = {
'magnetron': '192.168.7.64',
'x-ray_dipole': '192.168.7.66'
}
test_external_delays = {
'magnetron': 0,
'x-ray_dipole': 0
}
if os.path.exists(test_save_path):
print(f'File "{test_save_path}" already exists. Overwriting')
os.remove(test_save_path)
print('\n=== Running Test Acquisition ===')
print('Using test configuration:')
print(f'Scopes: {list(test_scope_ips.keys())}')
print(f'Save path: {test_save_path}')
print(f"Number of shots: {num_shots}")
# Run test acquisition
with MultiScopeAcquisition(
scope_ips=test_scope_ips,
num_loops=num_shots,
save_path=test_save_path,
external_delays=test_external_delays
) as acquisition:
acquisition.run_acquisition()
if os.path.isfile(test_save_path):
size = os.stat(test_save_path).st_size/(1024*1024)
print(f'\nTest successful! Wrote file "{test_save_path}", {size:.1f} MB')
else:
print('\nTest failed: File was not created')
#===============================================================================================================================================
#<o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o> <o>
#===============================================================================================================================================
if __name__ == '__main__':
# run_test(test_save_path = r"E:\Shadow data\Energetic_Electron_Ring\test.hdf5", num_shots=5) # Run a test acquisition with minimal settings
main()