Repository navigation
Expand file tree
/
Copy pathscript_angular_scan.py
More file actions
118 lines (101 loc) · 4.01 KB
/
Copy pathscript_angular_scan.py
File metadata and controls
118 lines (101 loc) · 4.01 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
import os
import time
import numpy as np
from datetime import datetime
import re
import glob
import csv
import data_manage_lib as dml
from astropy.io import fits
############ ESP ################
import ESP_lib as espl
motor_controller_ip_ang = "GPIB0::2::INSTR" # Angular scan
espc = espl.ESP_commande(motor_controller_ip_ang)
############ VNA ################
import VNA_lib as vnal
vna_ip = "GPIB0::16::INSTR" # adresse IP du VNA.0
vnac = vnal.VNA_commande(vna_ip)
############ SCAN PARAMETERS ################
accel = "10"
deccel = "10"
speed = 1
Sparameters = ["S21", "S12", "S11", "S22"] # name of the scattering parameters
axis = 1 # number of the ESP axis
units = 7
alpha_min, alpha_max = 0, 380 # limits of the angular scan in degrees
sens = "-to+" # direction of the scan; -to+ for the scan to begin at alpha_min and end at alpha_max, and +to- for the scan to begin at alpha_max and end at alpha_min
pas = 10 # steps
state_avg = True # if True, the VNA will average over several sweeps for each position of the motor
count_avg = 2 # Number of sweeps to average
save_path = "C:\\Users\\Administrator\\Documents\\Scripts_Commande_VNA\\CosmoCal_data\\"
start_freq = 110E9 # start frequency of the VNA sweep in Hz.
stop_freq = 170E9 # stop frequency of the VNA sweep in Hz
IFBW = 1000 # Hz
theta_R = 0 # angle of the receiver in degrees
unit_name = espc.give_unit_name(units)
nS = len(Sparameters) # Number of S parameters
####### VNA set-up
vnac.load_calib_vna(file="wr6-5_25022026.csa")
vnac.setup_channel_vna(start_freq=start_freq, stop_freq=stop_freq, IFBW=IFBW)
vnac.setup_traces(Sparameters=Sparameters)
######## Move to initial position
##### give parameters to the axis (acceleration, speed mode...)
espc.setup_axis_parameters(axis=axis, units=units, speed=speed, accel=accel, deccel=deccel)
time.sleep(2)
if sens == '-to+':
pas = abs(pas)
start_movement = alpha_min
elif sens == '+to-':
pas = -abs(pas)
start_movement = -alpha_min
print(f'\n Going to start position {start_movement}{unit_name}')
espc.move(axis=axis, movement=start_movement, absolute=True)
time.sleep(5)
########## GET VNA frequency range
start_freq, stop_freq, points = vnac.ask_frequency_range()
###### Start the scan
nstep = int(np.ceil(np.abs(1 + (alpha_max - alpha_min) / pas )))
print(f'\nTotal number of steps {nstep}')
# Create timestamped filename for FITS file
scan_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
fits_filename = f"Scan_{scan_timestamp}.fits"
freq_samples = np.empty(points)
mag = np.empty((nstep, nS, points))
phi = np.empty((nstep, nS, points))
for i in range(nstep):
print(f'\nStep number {i+1}/{nstep}')
# Take one acquisition
freq_samples, mag[i, :, :], phi[i, :, :] = vnac.make_one_acquisition(state_avg=state_avg, count_avg=count_avg, Sparameters=Sparameters)
print(f'Magnitudes {mag.shape}:') # [nS, points]
print(f'Phases: {phi.shape}')
time.sleep(2)
# Save file at each step to avoid loosing data
np.save(f'{save_path}mag.npy', mag)
np.save(f'{save_path}phi.npy', phi)
# Also save to FITS format with header
header_info = {
'THETA_R': theta_R,
'START_FRQ': start_freq,
'STOP_FRQ': stop_freq,
'POINTS': points,
'STATE_AVG': state_avg,
'COUNT_AVG': count_avg,
'IFBW': IFBW,
'TRACES': ', '.join(Sparameters),
'ALPH_MI': alpha_min,
'ALPH_MA': alpha_max,
'STEP': pas,
'NSTEPS': nstep,
'CURRENT_S': i + 1,
'TIMESTAMP': datetime.now().isoformat()
}
dml.save_measurement_to_fits(freq_samples, mag[:i+1, :, :], phi[:i+1, :, :], save_path,
filename=fits_filename, header_info=header_info)
# Move by one step
espc.move(axis=axis, movement=pas, absolute=False)
time.sleep(pas+2)
####### Close hardware connexions
espc.return_home(axis=axis)
vnac.vna.close()
espc.esp.close()
print("Mesures terminées\nConnexions fermées")