|
@@ -25,11 +25,11 @@ class RFExporter:
|
|
|
t_rf = np.asarray(t_rf, dtype=float)
|
|
t_rf = np.asarray(t_rf, dtype=float)
|
|
|
|
|
|
|
|
if len(rf_ampl) == 0:
|
|
if len(rf_ampl) == 0:
|
|
|
- return []
|
|
|
|
|
|
|
+ return np.empty(0)
|
|
|
|
|
|
|
|
rf_ampl_maximum = float(np.max(np.abs(rf_ampl)))
|
|
rf_ampl_maximum = float(np.max(np.abs(rf_ampl)))
|
|
|
if rf_ampl_maximum == 0:
|
|
if rf_ampl_maximum == 0:
|
|
|
- return []
|
|
|
|
|
|
|
+ return np.empty(0)
|
|
|
|
|
|
|
|
proportional_cf_rf = 127.0 / rf_ampl_maximum
|
|
proportional_cf_rf = 127.0 / rf_ampl_maximum
|
|
|
|
|
|
|
@@ -44,12 +44,12 @@ class RFExporter:
|
|
|
real_dense = np.interp(t_dense, t_rf, rf_ampl.real)
|
|
real_dense = np.interp(t_dense, t_rf, rf_ampl.real)
|
|
|
imag_dense = np.interp(t_dense, t_rf, rf_ampl.imag)
|
|
imag_dense = np.interp(t_dense, t_rf, rf_ampl.imag)
|
|
|
|
|
|
|
|
- out_rf_list: list[int] = []
|
|
|
|
|
- for r, i in zip(real_dense, imag_dense):
|
|
|
|
|
- out_rf_list.append(round(r * proportional_cf_rf))
|
|
|
|
|
- out_rf_list.append(round(i * proportional_cf_rf))
|
|
|
|
|
-
|
|
|
|
|
- return out_rf_list
|
|
|
|
|
|
|
+ # Interleaved [re, im, re, im, ...]; np.round is round-half-even,
|
|
|
|
|
+ # same as builtin round() used previously.
|
|
|
|
|
+ out = np.empty(2 * n_samples)
|
|
|
|
|
+ out[0::2] = np.round(real_dense * proportional_cf_rf)
|
|
|
|
|
+ out[1::2] = np.round(imag_dense * proportional_cf_rf)
|
|
|
|
|
+ return out
|
|
|
|
|
|
|
|
def export(self, waveforms: dict, params: dict, output_dir: str):
|
|
def export(self, waveforms: dict, params: dict, output_dir: str):
|
|
|
rf_raster_local = params["rf_raster_time"]
|
|
rf_raster_local = params["rf_raster_time"]
|
|
@@ -63,20 +63,25 @@ class RFExporter:
|
|
|
else:
|
|
else:
|
|
|
empty_block_time_delay = 0
|
|
empty_block_time_delay = 0
|
|
|
|
|
|
|
|
- rf_out = [0] * int(2 * (empty_block_time_delay // rf_raster_local))
|
|
|
|
|
- rf_out += self._radio_ampl_convertation(
|
|
|
|
|
|
|
+ head = np.zeros(int(2 * (empty_block_time_delay // rf_raster_local)))
|
|
|
|
|
+ body = self._radio_ampl_convertation(
|
|
|
waveforms["rf"],
|
|
waveforms["rf"],
|
|
|
waveforms["t_rf"],
|
|
waveforms["t_rf"],
|
|
|
rf_raster_local,
|
|
rf_raster_local,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
scale_rf = params.get("scale_rf", 1.0)
|
|
scale_rf = params.get("scale_rf", 1.0)
|
|
|
- rf_out = [round(x * scale_rf) for x in rf_out]
|
|
|
|
|
|
|
+ rf_out = np.round(np.concatenate((head, body)) * scale_rf)
|
|
|
|
|
+
|
|
|
|
|
+ if len(rf_out) and (rf_out.min() < -128 or rf_out.max() > 127):
|
|
|
|
|
+ raise ValueError(
|
|
|
|
|
+ f"RF amplitude out of int8 range after scale_rf={scale_rf}: "
|
|
|
|
|
+ f"[{rf_out.min():.0f}, {rf_out.max():.0f}]"
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
file_path = f"{output_dir}/rf_{rf_raster_local}_raster.bin"
|
|
file_path = f"{output_dir}/rf_{rf_raster_local}_raster.bin"
|
|
|
with open(file_path, "wb") as file_rf:
|
|
with open(file_path, "wb") as file_rf:
|
|
|
- for byte in rf_out:
|
|
|
|
|
- file_rf.write(int(byte).to_bytes(1, byteorder="big", signed=True))
|
|
|
|
|
|
|
+ file_rf.write(rf_out.astype(np.int8).tobytes())
|
|
|
|
|
|
|
|
np.savetxt(f"{output_dir}/rf_time.txt", np.transpose(waveforms["t_rf"]))
|
|
np.savetxt(f"{output_dir}/rf_time.txt", np.transpose(waveforms["t_rf"]))
|
|
|
np.savetxt(f"{output_dir}/rf_ampl.txt", np.transpose(waveforms["rf"]))
|
|
np.savetxt(f"{output_dir}/rf_ampl.txt", np.transpose(waveforms["rf"]))
|