mirror of
				https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
				synced 2025-10-31 03:46:44 +01:00 
			
		
		
		
	ZH: rename beacon_phase to beacon_phase_measured
Also reorganises lib.py slightly
This commit is contained in:
		
							parent
							
								
									6523128871
								
							
						
					
					
						commit
						1e6c6ad4fd
					
				
					 5 changed files with 29 additions and 19 deletions
				
			
		| 
						 | 
					@ -9,6 +9,12 @@ beacon:
 | 
				
			||||||
clocks:
 | 
					clocks:
 | 
				
			||||||
	./ab_modify_clocks.py
 | 
						./ab_modify_clocks.py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					phases:
 | 
				
			||||||
 | 
						./ba_beacon_phases.py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					period_multiples:
 | 
				
			||||||
 | 
						./bb_beacon_multiples.py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dist-clean:
 | 
					dist-clean:
 | 
				
			||||||
	rm -f ZH_airshower/antennas.hdf5
 | 
						rm -f ZH_airshower/antennas.hdf5
 | 
				
			||||||
	rm -f ZH_airshower/clocks.csv
 | 
						rm -f ZH_airshower/clocks.csv
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ def read_tx_file(fname):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return tx, f_beacon
 | 
					    return tx, f_beacon
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def read_beacon_hdf5(fname, traces_key='traces'):
 | 
					def read_beacon_hdf5(fname, traces_key='traces', raise_exception=True):
 | 
				
			||||||
    with h5py.File(fname, 'r') as h5:
 | 
					    with h5py.File(fname, 'r') as h5:
 | 
				
			||||||
        tx_attrs = h5['tx'].attrs
 | 
					        tx_attrs = h5['tx'].attrs
 | 
				
			||||||
        f_beacon = tx_attrs.get('f_beacon')
 | 
					        f_beacon = tx_attrs.get('f_beacon')
 | 
				
			||||||
| 
						 | 
					@ -54,6 +54,11 @@ def read_beacon_hdf5(fname, traces_key='traces'):
 | 
				
			||||||
        for k, ant in h5['antennas'].items():
 | 
					        for k, ant in h5['antennas'].items():
 | 
				
			||||||
            mydict = { k:ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
 | 
					            mydict = { k:ant.attrs.get(k) for k in ['x', 'y', 'z', 'name'] }
 | 
				
			||||||
            antenna = Antenna(**mydict)
 | 
					            antenna = Antenna(**mydict)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if traces_key not in ant:
 | 
				
			||||||
 | 
					                if raise_exception:
 | 
				
			||||||
 | 
					                    raise ValueError("Traces_key not in file")
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
                antenna.t = ant[traces_key][0]
 | 
					                antenna.t = ant[traces_key][0]
 | 
				
			||||||
                antenna.Ex = ant[traces_key][1]
 | 
					                antenna.Ex = ant[traces_key][1]
 | 
				
			||||||
                antenna.Ey = ant[traces_key][2]
 | 
					                antenna.Ey = ant[traces_key][2]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,7 +71,7 @@ if __name__ == "__main__":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if not True:
 | 
					            if not True:
 | 
				
			||||||
                # only take the Beacon trace
 | 
					                # only take the Beacon trace
 | 
				
			||||||
                test_traces = traces[4]
 | 
					                test_traces = [traces[4]]
 | 
				
			||||||
                orients = ['B']
 | 
					                orients = ['B']
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                test_traces = traces[1:]
 | 
					                test_traces = traces[1:]
 | 
				
			||||||
| 
						 | 
					@ -112,7 +112,7 @@ if __name__ == "__main__":
 | 
				
			||||||
                ax.legend()
 | 
					                ax.legend()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ant_group.attrs['beacon_freq'] = frequency
 | 
					            ant_group.attrs['beacon_freq'] = frequency
 | 
				
			||||||
            ant_group.attrs['beacon_phase'] = phase
 | 
					            ant_group.attrs['beacon_phase_measured'] = phase
 | 
				
			||||||
            ant_group.attrs['beacon_amplitude'] = amplitude
 | 
					            ant_group.attrs['beacon_amplitude'] = amplitude
 | 
				
			||||||
            ant_group.attrs['beacon_orientation'] = orientation
 | 
					            ant_group.attrs['beacon_orientation'] = orientation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,12 +7,19 @@ from numpy.polynomial import Polynomial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from earsim import Antenna
 | 
					from earsim import Antenna
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					""" Beacon utils """
 | 
				
			||||||
def sine_beacon(f, t, t0=0, amplitude=1, baseline=0, phase=0):
 | 
					def sine_beacon(f, t, t0=0, amplitude=1, baseline=0, phase=0):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Return a sine appropriate as a beacon
 | 
					    Return a sine appropriate as a beacon
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    return amplitude * np.sin(2*np.pi*f*(t+t0) + phase) + baseline
 | 
					    return amplitude * np.sin(2*np.pi*f*(t+t0) + phase) + baseline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def phase_mod(phase, low=np.pi):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Modulo phase such that it falls within the
 | 
				
			||||||
 | 
					    interval $[-low, 2\pi - low)$.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    return (phase + low) % (2*np.pi) - low
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def distance(x1, x2):
 | 
					def distance(x1, x2):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
| 
						 | 
					@ -38,7 +45,7 @@ def beacon_from(tx, rx, f, t=0, t0=0, c_light=3e8, radiate_rsq=True, amplitude=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return sine_beacon(f, t, t0=t0, amplitude=amplitude,**kwargs)
 | 
					    return sine_beacon(f, t, t0=t0, amplitude=amplitude,**kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					""" Fourier """
 | 
				
			||||||
def ft_corr_vectors(freqs, time):
 | 
					def ft_corr_vectors(freqs, time):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Get the cosine and sine terms for freqs at time.
 | 
					    Get the cosine and sine terms for freqs at time.
 | 
				
			||||||
| 
						 | 
					@ -94,14 +101,6 @@ def phase_field_from_tx(x, y, tx, f_beacon, c_light=3e8, t0=0, wrap_phase=True,
 | 
				
			||||||
        return phase, (np.repeat(xs, len(ys), axis=0), np.repeat(ys, len(xs[0]), axis=1))
 | 
					        return phase, (np.repeat(xs, len(ys), axis=0), np.repeat(ys, len(xs[0]), axis=1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def phase_mod(phase, low=np.pi):
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    Modulo phase such that it falls within the
 | 
					 | 
				
			||||||
    interval $[-low, 2\pi - low)$.
 | 
					 | 
				
			||||||
    """
 | 
					 | 
				
			||||||
    return (phase + low) % (2*np.pi) - low
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def find_beacon_in_traces(
 | 
					def find_beacon_in_traces(
 | 
				
			||||||
        traces,
 | 
					        traces,
 | 
				
			||||||
        t_trace,
 | 
					        t_trace,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,7 +28,7 @@ if __name__ == "__main__":
 | 
				
			||||||
    if True:
 | 
					    if True:
 | 
				
			||||||
        beacon_frequencies = np.array([ant.attrs['beacon_freq'] for ant in antennas])
 | 
					        beacon_frequencies = np.array([ant.attrs['beacon_freq'] for ant in antennas])
 | 
				
			||||||
        beacon_amplitudes = np.array([ant.attrs['beacon_amplitude'] for ant in antennas])
 | 
					        beacon_amplitudes = np.array([ant.attrs['beacon_amplitude'] for ant in antennas])
 | 
				
			||||||
        beacon_phases = np.array([lib.phase_mod(ant.attrs['beacon_phase']) for ant in antennas])
 | 
					        beacon_phases = np.array([lib.phase_mod(ant.attrs['beacon_phase_measured']) for ant in antennas])
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        subtitle = " Phases from t0"
 | 
					        subtitle = " Phases from t0"
 | 
				
			||||||
        beacon_frequencies = np.array([ f_beacon for ant in antennas ])
 | 
					        beacon_frequencies = np.array([ f_beacon for ant in antennas ])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue