-
Notifications
You must be signed in to change notification settings - Fork 8
/
iono_config.py
177 lines (138 loc) · 7.05 KB
/
iono_config.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
#!/usr/bin/env python3
import numpy as n
import sweep
import sys
import numpy as n
import os
try:
import configparser
except ImportError as e:
import configparser2 as configparser
import json
import create_waveform
class iono_config:
def __init__(self, fname=None, write_waveforms=True, quiet=True):
c=configparser.ConfigParser()
self.quiet=quiet
if fname is not None:
if os.path.exists(fname):
if not quiet:
print("reading %s" % (fname))
c.read(fname)
else:
print("configuration file %s doesn't exist." % (fname))
exit(0)
self.fname=fname
self.instrument_name=json.loads(c["config"]["instrument_name"])
self.n_range_gates=int(json.loads(c["config"]["n_range_gates"]))
self.station_id=int(json.loads(c["config"]["station_id"]))
self.lat=int(json.loads(c["config"]["lat"]))
self.lon=int(json.loads(c["config"]["lon"]))
self.require_gps=bool(json.loads(c["config"]["require_gps"]))
self.spectral_whitening=bool(json.loads(c["config"]["spectral_whitening"]))
self.save_raw_voltage=bool(json.loads(c["config"]["save_raw_voltage"]))
self.min_gps_lock_time=json.loads(c["config"]["min_gps_lock_time"])
self.rx_channel=json.loads(c["config"]["rx_channel"])
self.sample_rate=int(json.loads(c["config"]["sample_rate"]))
self.dec=int(json.loads(c["config"]["dec"]))
self.data_dir=json.loads(c["config"]["data_dir"])
self.range_shift=int(json.loads(c["config"]["range_shift"]))
# self.codes=json.loads(c["config"]["codes"])
self.short_name=json.loads(c["config"]["short_name"])
self.code_len=json.loads(c["config"]["code_len"])
self.code_types=json.loads(c["config"]["code_type"])
self.pulse_lengths=json.loads(c["config"]["pulse_length"])
self.ipps=json.loads(c["config"]["ipp"])
self.bws=json.loads(c["config"]["bw"])
if not quiet:
print("Creating waveforms")
self.n_codes=len(self.code_types)
self.codes=[]
self.orig_codes=[]
for i in range(self.n_codes):
if self.pulse_lengths[i] > 0:
if n.mod(int(self.code_len), int(self.ipps[i])) != 0:
print("Code length %d must be a multiple of IPP %d."
" This is not the case. Exiting." % (self.code_len, self.ipps[i]))
exit(0)
# todo. we should avoid dumping the waveforms to files
# for all but debugging purposes. the waveforms
# created here (ocode) should be directly fed into sweep.
cfname, ocode=create_waveform.waveform_to_file(station=self.station_id,
clen=self.code_len,
oversample=self.dec,
filter_output=True,
sr=self.sample_rate,
bandwidth=self.bws[i],
power_outside_band=0.01,
pulse_length=self.pulse_lengths[i],
ipp=self.ipps[i],
code_type=self.code_types[i],
write_file=write_waveforms)
self.codes.append(cfname)
self.orig_codes.append(ocode)
self.freqs=json.loads(c["config"]["freqs"])
self.n_freqs=len(self.freqs)
for fi in range(len(self.freqs)):
# center frequency
self.freqs[fi][0]=float(self.freqs[fi][0])
# code index
self.freqs[fi][1]=int(self.freqs[fi][1])
self.transmit_amplitude=float(json.loads(c["config"]["transmit_amplitude"]))
self.frequency_duration=float(json.loads(c["config"]["frequency_duration"]))
if n.mod(int(self.frequency_duration*self.sample_rate), int(self.code_len*self.dec)) != 0:
print("frequency_duration (%1.2f s) needs to be a multiple of code_length (%1.2f s)"
% (self.frequency_duration, self.code_len*self.dec/self.sample_rate))
exit(0)
self.antenna_select_freq=float(json.loads(c["config"]["antenna_select_freq"]))
self.max_plot_range=float(json.loads(c["config"]["max_plot_range"]))
self.gps_holdover_time=float(json.loads(c["config"]["gps_holdover_time"]))
self.max_plot_dB=float(json.loads(c["config"]["max_plot_dB"]))
self.tx_addr=json.loads(c["config"]["tx_addr"])
self.rx_addr=json.loads(c["config"]["rx_addr"])
self.tx_subdev=json.loads(c["config"]["tx_subdev"])
self.rx_subdev=json.loads(c["config"]["rx_subdev"])
self.tx_subdev_refl_pwr=json.loads(c["config"]["tx_subdev_refl_pwr"])
self.ionogram_path=json.loads(c["config"]["ionogram_path"])
self.ionogram_dirname=json.loads(c["config"]["ionogram_dirname"])
self.reflected_power_cal_dB=json.loads(c["config"]["reflected_power_cal_dB"])
try:
os.mkdir(self.ionogram_path)
except Exception as e:
pass
if not os.path.exists(self.ionogram_path):
print("Output directory %s doesn't exists and cannot be created" % (self.ionogram_path))
exit(0)
try:
os.mkdir(self.ionogram_path)
except Exception as e:
pass
if not os.path.exists(self.data_dir):
print("Output directory %s doesn't exists and cannot be created" % (self.data_dir))
exit(0)
self.s=sweep.sweep(freqs=self.freqs,
codes=self.codes,
sample_rate=self.sample_rate,
code_amp=self.transmit_amplitude, # safe setting for waveform amplitude
freq_dur=self.frequency_duration)
def __str__(self):
out="Configuration\n"
for e in dir(self):
if not callable(getattr(self, e)) and not e.startswith("__"):
out+="%s = %s\n" % (e, getattr(self, e))
print("Sweep configuration")
for i in range(self.n_freqs):
out +="t=%1.2f s f=%1.2f MHz code=%s\n" % (i*self.frequency_duration,
self.freqs[i][0],
self.codes[self.freqs[i][1]])
out+="Total ionogram duration %1.2f s\n" % (self.n_freqs*self.frequency_duration)
return(out)
def get_config(config="config/default.ini", write_waveforms=True, quiet=True):
c = iono_config(config, write_waveforms=write_waveforms, quiet=quiet)
return c
if __name__ == "__main__":
if len(sys.argv) != 2:
print("provide configuration file as argument!")
exit(0)
c=get_config(config=sys.argv[1])
print(c)