本文整理汇总了Python中snapshot.Snapshot.arm方法的典型用法代码示例。如果您正苦于以下问题:Python Snapshot.arm方法的具体用法?Python Snapshot.arm怎么用?Python Snapshot.arm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snapshot.Snapshot
的用法示例。
在下文中一共展示了Snapshot.arm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from snapshot import Snapshot [as 别名]
# 或者: from snapshot.Snapshot import arm [as 别名]
class Correlation:
def __init__(self, fpga, comb, f_start, f_stop, logger=logging.getLogger(__name__)):
""" f_start and f_stop must be in Hz
"""
self.logger = logger
snap_name = "snap_{a}x{b}".format(a=comb[0], b=comb[1])
self.snapshot0 = Snapshot(fpga,
"{name}_0".format(name = snap_name),
dtype='>i8',
cvalue=True,
logger=self.logger.getChild("{name}_0".format(name = snap_name)))
self.snapshot1 = Snapshot(fpga,
"{name}_1".format(name = snap_name),
dtype='>i8',
cvalue=True,
logger=self.logger.getChild("{name}_1".format(name = snap_name)))
self.f_start = np.uint64(f_start)
self.f_stop = np.uint64(f_stop)
# this will change from None to an array of phase offsets for each frequency bin
# if calibration gets applied at a later stage.
# this is an array of phases introduced by the system. So if a value is positive,
# it means that the system is introducing a phase shift between comb[0] and comb[1]
# in other words comb1 is artificially delayed.
self.calibration_phase_offsets = None
self.calibration_cable_length_offsets = None
self.arm()
self.fetch_signal()
self.frequency_bins = np.linspace(
start = self.f_start,
stop = self.f_stop,
num = len(self.signal),
endpoint = False)
def add_frequency_bin_calibration(self, frequencies, phases):
assert(len(frequencies) == len(phases))
self.calibration_phase_offsets = np.ndarray(len(self.frequency_bins))
for idx, f in enumerate(self.frequency_bins):
# find index in of the frequency in frequencies which is losest to f
frequencies_idx = np.argmin(np.abs(frequencies - f))
self.calibration_phase_offsets[idx] = phases[frequencies_idx]
self.logger.info("Added calibration factors based on each frequency bin")
def add_cable_length_calibration(self, length_a, velocity_factor_a, length_b, velocity_factor_b):
""" 'a' values are for comb[0]. 'b' values are for comb[1]
TODO: remove what follows in docstring
A positive number will produce a positive phase correlation factor.
This means that that a positive number implies that comb[1] is artificially delayed
with respect to comb[0].
This will happen if comb[1]s cable is longer than comb[0]s.
Hence this should be len(cable1) - len(cable0)
"""
self.calibration_cable_length_offsets = np.ndarray(len(self.frequency_bins))
# calculate total time delay.
t_a = length_a / (scipy.constants.c * velocity_factor_a)
t_b = length_b / (scipy.constants.c * velocity_factor_b)
# for each frequency bin, calculate corresponding
for idx, f in enumerate(self.frequency_bins):
# this will produce a positive number if As length is longer than Bs
phase = 2*np.pi * (t_a - t_b) * f
self.calibration_cable_length_offsets[idx] = phase
self.logger.info("Added calibration factors base on cable length")
def arm(self):
self.snapshot0.arm()
self.snapshot1.arm()
def apply_frequency_domain_calibrations(self):
if self.calibration_phase_offsets != None:
offsets = np.exp(1j*self.calibration_phase_offsets)
self.signal = self.signal * np.conj(offsets)
if self.calibration_cable_length_offsets != None:
offsets = np.exp(1j*self.calibration_cable_length_offsets)
self.signal = self.signal * offsets
self.logger.debug("Applied calibration factors")
def fetch_signal(self):
self.snapshot0.fetch_signal()
self.snapshot1.fetch_signal()
# F: index the elements in column-major order, with the first index changing fastest
self.signal = np.ravel( (self.snapshot0.signal, self.snapshot1.signal), order='F')
def strongest_frequency(self):
""" Returns the frequency in Hz which has the strongest signal.
Frequency will be the centre of the bin.
Excludes DC bin
"""
# add 1 because we're excluding the initial bin
bin_number = np.argmax(np.abs(self.signal[1:])) + 1
return self.frequency_bins[bin_number]
def strongest_frequency_in_range(self, f_start, f_stop):
idx_start = np.searchsorted(self.frequency_bins, f_start)
idx_stop= np.searchsorted(self.frequency_bins, f_stop)
subsig = self.signal[idx_start:idx_stop]
offset_to_max = np.argmax(np.abs(subsig))
frequency = self.frequency_bins[idx_start + offset_to_max]
return frequency
def phase_at_freq(self, f):
""" Note: this formula may need fixing!! Check against actual data
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from snapshot import Snapshot [as 别名]
# 或者: from snapshot.Snapshot import arm [as 别名]
class Correlator:
def __init__(self, ip_addr='localhost', num_channels=4, fs=800e6, logger=logging.getLogger(__name__)):
"""The interface to a ROACH cross correlator
Keyword arguments:
ip_addr -- IP address (or hostname) of the ROACH. (default: localhost)
num_channels -- antennas in the correlator. (default: 4)
fs -- sample frequency of antennas. (default 800e6; 800 MHz)
logger -- logger to use. (default: new default logger)
"""
self.logger = logger
self.fpga = corr.katcp_wrapper.FpgaClient(ip_addr)
time.sleep(0.1)
self.num_channels = num_channels
self.fs = np.float64(fs)
self.cross_combinations = list(itertools.combinations(range(num_channels), 2)) # [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
self.control_register = ControlRegister(self.fpga, self.logger.getChild('control_reg'))
self.set_accumulation_len(100)
self.re_sync()
self.control_register.allow_trigger() # necessary as Correlations auto fetch signal
# only 0x0 has been implemented
#self.auto_combinations = [(x, x) for x in range(num_channels)] # [(0, 0), (1, 1), (2, 2), (3, 3)]
self.auto_combinations = [(0, 0)]
self.frequency_correlations = {}
for comb in (self.cross_combinations + self.auto_combinations):
self.frequency_correlations[comb] = Correlation(fpga = self.fpga,
comb = comb,
f_start = 0,
f_stop = fs/2,
logger = self.logger.getChild("{a}x{b}".format(a = comb[0], b = comb[1])) )
self.time_domain_snap = Snapshot(fpga = self.fpga,
name = 'dram_snapshot',
dtype = np.int8,
cvalue = False,
logger = self.logger.getChild('time_domain_snap'))
self.upsample_factor = 100
self.subsignal_length_max = 2**17
self.time_domain_padding = 100
self.time_domain_calibration_values = None
self.time_domain_calibration_cable_values = None
self.control_register.block_trigger()
def impulse_arm(self):
self.control_register.pulse_impulse_arm()
self.time_domain_snap.arm()
def impulse_fetch(self):
""" Will fetch and re-arm if an impulse has occurred.
Will do nothing if no impulse.
Return True if fetched (ie: an impulse happened) or
False if not
"""
pre_delay = 256 * 4
impulse_len = self.fpga.read_uint('impulse_length')
if impulse_len != 0:
self.logger.info("Got an impulse of length: {}".format(impulse_len))
time.sleep(0.1)
if self.fpga.read_uint('impulse_length') != impulse_len:
self.logger.warning('Impulse has gone on for too long. Adjust setpoint?')
self.fetch_time_domain_snapshot()
self.impulse_arm()
return True
return False
def set_impulse_setpoint(self, level):
self.fpga.write_int('setppoint', level)
self.logger.info("Impulse detection setpoint changed to: {}".format(level))
def get_current_impulse_level(self):
level = self.fpga.read_uint('current_impulse_level')
self.logger.debug("Current impulse level: {}".format(level))
return level
def set_impulse_filter_len(self, length):
assert(length > 5)
assert(length < 1000)
self.fpga.write_int('impulse_filter_len', length)
self.logger.info("Impulse filter length set to: {}".format(length))
def fetch_time_domain_snapshot(self, force=False):
self.time_domain_snap.fetch_signal(force)
sig = self.time_domain_snap.signal
# shorten to fit exactly
new_length = (4 * self.num_channels) * np.floor(len(sig) / (4 * self.num_channels))
sig = sig[0:new_length]
self.time_domain_signals = np.ndarray((self.num_channels, len(sig)/self.num_channels),
dtype = np.float64)
sig = sig.reshape(len(sig)/self.num_channels, self.num_channels)
for chan in range(self.num_channels):
self.time_domain_signals[chan] = sig[chan::self.num_channels].flatten().astype(np.float64)
# remove DC offset
mean = np.mean(self.time_domain_signals[chan])
self.time_domain_signals[chan] -= mean
self.logger.info("After: DC offset for {chan} = {offset}".format(
chan = chan,
offset = np.mean(self.time_domain_signals[chan])))
self.time_domain_axis = np.linspace(0,
len(self.time_domain_signals[0])/self.fs,
len(self.time_domain_signals[0]),
endpoint = False)
#.........这里部分代码省略.........