-
Notifications
You must be signed in to change notification settings - Fork 14
/
radio_save_spec.grc
222 lines (219 loc) · 9.08 KB
/
radio_save_spec.grc
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
options:
parameters:
author: ''
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: no_gui
hier_block_src_path: '.:'
id: radio_save_spec
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: run
sizing_mode: fixed
thread_safe_setters: ''
title: radio_save_spec
window_size: ''
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: directory_name
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: directory_name
short_id: ''
type: str
value: '"."'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [123, 106]
rotation: 0
state: true
- name: file_name
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: file_name
short_id: ''
type: str
value: '"test.rad"'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [116, 203]
rotation: 0
state: true
- name: num_bins
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: num_bins
short_id: ''
type: intx
value: '4096'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [9, 204]
rotation: 0
state: true
- name: samp_rate
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: samp_rate
short_id: ''
type: intx
value: '2400000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [10, 107]
rotation: 0
state: true
- name: save_rad_file
id: epy_block
parameters:
_source_code: "\"\"\"\nEmbedded Python Blocks:\n\nEach time this file is saved,\
\ GRC will instantiate the first class it finds\nto get ports and parameters\
\ of your block. The arguments to __init__ will\nbe the parameters. All of\
\ them are required to have default values!\n\"\"\"\n\nimport numpy as np\n\
from gnuradio import gr\nimport pmt\n\nimport pathlib\nfrom datetime import\
\ datetime, timezone\nfrom math import sqrt\n\n\n# String Formatting Constants\n\
header_format = (\n \"DATE %4d:%03d:%02d:%02d:%02d obsn %3d az %4.1f el %3.1f\
\ freq_MHz \"\n \"%10.4f Tsys %6.3f Tant %6.3f vlsr %7.2f glat %6.3f glon\
\ %6.3f source %s\\n\"\n)\nstart_format = (\n \"Fstart %8.3f fstop %8.3f\
\ spacing %8.6f bw %8.3f fbw %8.3f MHz nfreq \"\n \"%d nsam %d npoint %d\
\ integ %5.0f sigma %8.3f bsw %d\\n\"\n)\nintegration_format = \"Spectrum %6.0f\
\ integration periods\\n\"\nnumber_format = \"%8.3f \"\n\n\ndef parse_time(rx_time):\n\
\ time_since_epoch = rx_time[0] + rx_time[1]\n date = datetime.fromtimestamp(time_since_epoch,\
\ timezone.utc)\n new_year_day = datetime(year=date.year, month=1, day=1,\
\ tzinfo=timezone.utc)\n day_of_year = (date - new_year_day).days + 1\n \
\ return date.year, day_of_year, date.hour, date.minute, date.second\n\n\n\
def parse_metadata(metadata):\n motor_az = metadata[\"motor_az\"]\n motor_el\
\ = metadata[\"motor_el\"]\n samp_rate = metadata[\"samp_rate\"]\n num_integrations\
\ = metadata[\"num_integrations\"]\n freq = metadata[\"freq\"]\n num_bins\
\ = metadata[\"num_bins\"]\n tsys = metadata[\"tsys\"]\n tcal = metadata[\"\
tcal\"]\n cal_pwr = metadata[\"cal_pwr\"]\n vslr = metadata[\"vslr\"]\n\
\ glat = metadata[\"glat\"]\n glon = metadata[\"glon\"]\n soutrack\
\ = metadata[\"soutrack\"]\n bsw = metadata[\"bsw\"]\n return (\n \
\ motor_az,\n motor_el,\n freq / pow(10, 6),\n samp_rate\
\ / pow(10, 6),\n num_integrations,\n num_bins,\n tsys,\n\
\ tcal,\n cal_pwr,\n vslr,\n glat,\n glon,\n\
\ soutrack,\n bsw,\n )\n\n\nclass blk(\n gr.sync_block\n\
): # other base classes are basic_block, decim_block, interp_block\n \"\"\
\"Embedded Python Block example - a simple multiply const\"\"\"\n\n def __init__(\n\
\ self, directory=\".\", filename=\"test.rad\", vec_length=4096\n \
\ ): # only default arguments here\n \"\"\"arguments to this function\
\ show up as parameters in GRC\"\"\"\n gr.sync_block.__init__(\n \
\ self,\n name=\"Embedded Python Block\", # will show up\
\ in GRC\n in_sig=[(np.float32, vec_length)],\n out_sig=None,\n\
\ )\n # if an attribute with the same name as a parameter is found,\n\
\ # a callback is registered (properties work, too).\n self.directory\
\ = directory\n self.filename = filename\n self.vec_length = vec_length\n\
\ self.obsn = 0\n\n def work(self, input_items, output_items):\n \
\ \"\"\"example: multiply with constant\"\"\"\n file = open(pathlib.Path(self.directory,\
\ self.filename), \"a+\")\n tags = self.get_tags_in_window(0, 0, len(input_items[0]))\n\
\ latest_data_dict = {\n pmt.to_python(tag.key): pmt.to_python(tag.value)\
\ for tag in tags\n }\n yr, da, hr, mn, sc = parse_time(latest_data_dict[\"\
rx_time\"])\n (\n aznow,\n elnow,\n \
\ freq,\n bw,\n integ,\n nfreq,\n \
\ tsys,\n tcal,\n calpwr,\n vlsr,\n \
\ glat,\n glon,\n soutrack,\n bsw,\n\
\ ) = parse_metadata(latest_data_dict[\"metadata\"])\n fbw = bw\
\ # Old SRT Software Had Relative Bandwidth Limits and An Unchanging Sample\
\ Rate\n f1 = 0 # Relative Lower Bound (Since Sample Rate Determines\
\ Bandwidth)\n f2 = 1 # Relative Upper Bound (Since Sample Rate Determines\
\ Bandwidth)\n istart = f1 * nfreq + 0.5\n istop = f2 * nfreq\
\ + 0.5\n efflofreq = freq - bw * 0.5\n freqsep = bw / nfreq\n\
\ nsam = nfreq # Old SRT Software Had a Specific Bundle of Samples Shuffled\
\ Out and Processed at a Time\n sigma = tsys / sqrt((nsam * integ / (2.0e6\
\ * bw)) * freqsep * 1e6)\n for input_array in input_items[0]:\n \
\ p = np.sum(input_array)\n a = len(input_array)\n \
\ pwr = (tsys + tcal) * p / (a * calpwr)\n ppwr = pwr - tsys\n\
\ header_line = header_format % (\n yr,\n \
\ da,\n hr,\n mn,\n sc,\n\
\ self.obsn,\n aznow,\n elnow,\n\
\ freq,\n tsys,\n ppwr,\n \
\ vlsr,\n glat,\n glon,\n \
\ soutrack,\n )\n start_line = start_format % (\n\
\ istart * bw / nfreq + efflofreq,\n istop * bw\
\ / nfreq + efflofreq,\n freqsep,\n bw,\n \
\ fbw,\n nfreq,\n nsam,\n \
\ istop - istart,\n integ * nsam / (2.0e6 * bw),\n \
\ sigma,\n bsw,\n )\n integration_line\
\ = integration_format % integ\n file.writelines([header_line, start_line,\
\ integration_line])\n for val in input_array:\n file.write(number_format\
\ % val)\n file.write(\"\\n\")\n self.obsn += 1\n\n \
\ file.close()\n return len(input_items[0])\n"
affinity: ''
alias: ''
comment: ''
directory: directory_name
filename: file_name
maxoutbuf: '0'
minoutbuf: '0'
vec_length: num_bins
states:
_io_cache: ('Embedded Python Block', 'blk', [('directory', "'.'"), ('filename',
"'test.rad'"), ('vec_length', '4096')], [('0', 'float', 4096)], [], 'Embedded
Python Block example - a simple multiply const', ['directory', 'filename', 'vec_length'])
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [636, 127]
rotation: 0
state: true
- name: zeromq_sub_source_0
id: zeromq_sub_source
parameters:
address: tcp://127.0.0.1:5562
affinity: ''
alias: ''
comment: ''
hwm: '-1'
maxoutbuf: '0'
minoutbuf: '0'
pass_tags: 'True'
timeout: '100'
type: float
vlen: num_bins
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [328, 119]
rotation: 0
state: true
connections:
- [zeromq_sub_source_0, '0', save_rad_file, '0']
metadata:
file_format: 1