mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
ZH: make sure to copy from HDF5
so it doesn't matter whether the file is closed or not
This commit is contained in:
parent
8b210514d3
commit
ab1550c8b5
2 changed files with 21 additions and 22 deletions
|
@ -10,7 +10,7 @@ import numpy as np
|
|||
import json
|
||||
import h5py
|
||||
import os.path as path
|
||||
from copy import deepcopy as copy
|
||||
from copy import deepcopy
|
||||
|
||||
from earsim import REvent, Antenna, block_filter
|
||||
import lib
|
||||
|
@ -68,25 +68,25 @@ def Antenna_from_h5ant(h5ant, traces_key='traces', raise_exception=True, read_Ax
|
|||
if raise_exception:
|
||||
raise ValueError("Traces_key not in file")
|
||||
else:
|
||||
ant.t = h5ant[traces_key][0]
|
||||
ant.Ex = h5ant[traces_key][1]
|
||||
ant.Ey = h5ant[traces_key][2]
|
||||
ant.Ez = h5ant[traces_key][3]
|
||||
ant.t = deepcopy(h5ant[traces_key][0])
|
||||
ant.Ex = deepcopy(h5ant[traces_key][1])
|
||||
ant.Ey = deepcopy(h5ant[traces_key][2])
|
||||
ant.Ez = deepcopy(h5ant[traces_key][3])
|
||||
if len(h5ant[traces_key]) > 4:
|
||||
ant.beacon = h5ant[traces_key][4]
|
||||
ant.beacon = deepcopy(h5ant[traces_key][4])
|
||||
|
||||
# E_AxB
|
||||
if read_AxB and 'E_AxB' in h5ant:
|
||||
ant.t_AxB = h5ant['E_AxB'][0]
|
||||
ant.E_AxB = h5ant['E_AxB'][1]
|
||||
ant.t_AxB = deepcopy(h5ant['E_AxB'][0])
|
||||
ant.E_AxB = deepcopy(h5ant['E_AxB'][1])
|
||||
|
||||
# Beacons
|
||||
if read_beacon_info and 'beacon' in h5ant:
|
||||
h5beacon = h5ant['beacon']
|
||||
if read_beacon_info and 'beacon_info' in h5ant:
|
||||
h5beacon = h5ant['beacon_info']
|
||||
|
||||
beacon_info = {}
|
||||
for name in h5beacon.keys():
|
||||
beacon_info[name] = h5beacon[name].attrs
|
||||
beacon_info[name] = dict(h5beacon[name].attrs)
|
||||
|
||||
ant.beacon_info = beacon_info
|
||||
|
||||
|
@ -200,20 +200,19 @@ if __name__ == "__main__":
|
|||
|
||||
beacon = lib.beacon_from(tx, antenna, f_beacon, antenna.t, t0=t0, c_light=np.inf, radiate_rsq=beacon_radiate_rsq)
|
||||
|
||||
E = np.array([antenna.Ex, antenna.Ey, antenna.Ez, beacon])
|
||||
traces = np.array([antenna.Ex, antenna.Ey, antenna.Ez, beacon])
|
||||
|
||||
# add to relevant polarisation
|
||||
# and apply block filter
|
||||
dt = antenna.t[1] - antenna.t[0]
|
||||
for j, _ in enumerate(beacon_amplitudes):
|
||||
E[j] += block_filter(beacon_amplitudes[j]*beacon, dt, low_bp, high_bp)
|
||||
traces[j] = block_filter(traces[j], dt, low_bp, high_bp)
|
||||
|
||||
append_antenna_hdf5( antennas_fname, antenna, E, name='traces', prepend_time=True, attrs_dict=dict(t0=t0))
|
||||
append_antenna_hdf5( antennas_fname, antenna, traces, name='traces', prepend_time=True, attrs_dict=dict(t0=t0))
|
||||
|
||||
# Save E field in E_AxB
|
||||
E = [np.dot(ev.uAxB,[ex,ey,ez]) for ex,ey,ez in zip(E[0], E[1], E[2])]
|
||||
E = [np.dot(ev.uAxB,[ex,ey,ez]) for ex,ey,ez in zip(traces[0], traces[1], traces[2])]
|
||||
|
||||
append_antenna_hdf5( antennas_fname, antenna, [E], name='E_AxB', prepend_time=True)
|
||||
|
||||
|
||||
print("Antenna HDF5 file written as " + str(antennas_fname))
|
||||
|
|
|
@ -138,21 +138,21 @@ if __name__ == "__main__":
|
|||
ax.legend()
|
||||
|
||||
# save to file
|
||||
h5beacon = h5ant.require_group('beacon')
|
||||
h5beacon_info = h5ant.require_group('beacon_info')
|
||||
|
||||
# only take n_sig significant digits into account
|
||||
# for naming in hdf5 file
|
||||
n_sig = 4
|
||||
n_sig = 3
|
||||
decimal = int(np.floor(np.log10(abs(frequency))))
|
||||
freq_name = str(np.around(frequency, n_sig-decimal))
|
||||
|
||||
# delete previous values
|
||||
if freq_name in h5beacon:
|
||||
del h5beacon[freq_name]
|
||||
if freq_name in h5beacon_info:
|
||||
del h5beacon_info[freq_name]
|
||||
|
||||
h5beacon_freq = h5beacon.create_group(freq_name)
|
||||
h5beacon_freq_info = h5beacon_info.create_group(freq_name)
|
||||
|
||||
h5attrs = h5beacon_freq.attrs
|
||||
h5attrs = h5beacon_freq_info.attrs
|
||||
h5attrs['freq'] = frequency
|
||||
h5attrs['phase'] = phase
|
||||
h5attrs['amplitude'] = amplitude
|
||||
|
|
Loading…
Reference in a new issue