本文整理汇总了Python中shinysdr.values.LooseCell类的典型用法代码示例。如果您正苦于以下问题:Python LooseCell类的具体用法?Python LooseCell怎么用?Python LooseCell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LooseCell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _OsmoSDRTuning
class _OsmoSDRTuning(object):
def __init__(self, profile, correction_ppm, osmo_block):
self.__profile = profile
self.__correction_ppm = correction_ppm
self.__osmo_block = osmo_block
self.__vfo_cell = LooseCell(
key='freq',
value=0.0,
# TODO: Eventually we'd like to be able to make the freq range vary dynamically with the correction setting
type=convert_osmosdr_range(
osmo_block.get_freq_range(ch),
strict=False,
transform=self.from_hardware_freq,
unit=units.Hz,
add_zero=profile.e4000),
writable=True,
persists=True,
post_hook=self.__set_freq)
def __set_freq(self, freq):
self.__osmo_block.set_center_freq(self.to_hardware_freq(freq))
def to_hardware_freq(self, effective_freq):
if abs(effective_freq) < 1e-2 and self.__profile.e4000:
# Quirk: Tuning to 3686.6-3730 MHz on the E4000 causes operation effectively at 0Hz.
# Original report: <http://www.reddit.com/r/RTLSDR/comments/12d2wc/a_very_surprising_discovery/>
return 3700e6
else:
return effective_freq * (1 - 1e-6 * self.__correction_ppm)
def from_hardware_freq(self, freq):
freq = freq / (1 - 1e-6 * self.__correction_ppm)
if 3686.6e6 <= freq <= 3730e6 and self.__profile.e4000:
freq = 0.0
return freq
def get_vfo_cell(self):
return self.__vfo_cell
def get_correction_ppm(self):
return self.__correction_ppm
def set_correction_ppm(self, value):
self.__correction_ppm = float(value)
# Not using the osmosdr feature because changing it at runtime produces glitches like the sample rate got changed; therefore we emulate it ourselves. TODO: I am informed that using set_freq_corr can correct sample-clock error, so we ought to at least use it on init.
# self.osmosdr_source_block.set_freq_corr(value, 0)
self.__set_freq(self.__vfo_cell.get())
def calc_usable_bandwidth(self, sample_rate):
passband = sample_rate * (3 / 8) # 3/4 of + and - halves
if self.__profile.dc_offset:
epsilon = 1.0 # TODO: Put width in the profile.
return RangeT([(-passband, -epsilon), (epsilon, passband)])
else:
return RangeT([(-passband, passband)])
def set_block(self, value):
self.__osmo_block = value
if self.__osmo_block is not None:
self.__set_freq(self.__vfo_cell.get())
示例2: __init_center_cell
def __init_center_cell(self):
base_freq_cell = self.__rx_main.state()[_FREQ_CELL_KEY]
mode_cell = self.__rx_main.state()['MD']
sidetone_cell = self.state()['CW']
submode_cell = self.state()['DT']
iq_offset_cell = LooseCell(key='iq_offset', value=0.0, type=float)
self.__iq_center_cell = ViewCell(
base=base_freq_cell,
get_transform=lambda x: x + iq_offset_cell.get(),
set_transform=lambda x: x - iq_offset_cell.get(),
key=_FREQ_CELL_KEY,
type=base_freq_cell.type(), # runtime variable...
writable=True,
persists=base_freq_cell.metadata().persists)
def changed_iq(_value=None):
# TODO this is KX3-specific
mode = mode_cell.get()
if mode == 'CW':
iq_offset = sidetone_cell.get()
elif mode == 'CW-REV':
iq_offset = -sidetone_cell.get()
elif mode == 'AM' or mode == 'FM':
iq_offset = 11000.0
elif mode == 'DATA' or mode == 'DATA-REV':
submode = submode_cell.get()
if submode == 0: # "DATA A", SSB with less processing
iq_offset = 0.0 # ???
elif submode == 1: # "AFSK A", SSB with RTTY style filter
iq_offset = 0.0 # ???
elif submode == 2: # "FSK D", RTTY
iq_offset = 900.0
elif submode == 3: # "PSK D", PSK31
iq_offset = 1000.0 # I think so...
else:
iq_offset = 0 # fallback
if mode == 'DATA-REV':
iq_offset = -iq_offset
else: # USB, LSB, other
iq_offset = 0.0
iq_offset_cell.set(iq_offset)
self.__iq_center_cell.changed_transform()
# TODO bad practice
mode_cell._subscribe_immediate(changed_iq)
sidetone_cell._subscribe_immediate(changed_iq)
submode_cell._subscribe_immediate(changed_iq)
changed_iq()
示例3: test_specify_all_metadata
def test_specify_all_metadata(self):
# using LooseCell as an arbitrary concrete subclass
cell = LooseCell(
value=0,
type=int,
persists=False, # the non-default value
label='mylabel',
description='mydescription',
sort_key='mysortkey')
self.assertEqual(cell.metadata().value_type, to_value_type(int))
self.assertEqual(cell.metadata().persists, False)
self.assertEqual(cell.metadata().naming, EnumRow(
label='mylabel',
description='mydescription',
sort_key='mysortkey'))
示例4: _LimeSDRTuning
class _LimeSDRTuning(object):
def __init__(self, lime_block):
self.__lime_block = lime_block
self.__vfo_cell = LooseCell(
value=0.0,
type=RangeT([(10e6, 3500e6)],
strict=False,
unit=units.Hz),
writable=True,
persists=True,
post_hook=self.__set_freq)
def __set_freq(self, freq):
self.__lime_block.set_rf_freq(freq)
def get_vfo_cell(self):
return self.__vfo_cell
def calc_usable_bandwidth(self, total_bandwidth):
# Assume right up against the edges of the filter are unusable.
passband = total_bandwidth * (3 / 8) # 3/4 of + and - halves
return RangeT([(-passband, passband)])
def set_block(self, value):
self.__lime_block = value
if self.__lime_block is not None:
self.__set_freq(self.__vfo_cell.get())
示例5: setUp
def setUp(self):
self.lc = LooseCell(value=0, key='a', type=int)
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + 1,
set_transform=lambda x: x - 1,
key='b',
type=int)
示例6: setUp
def setUp(self):
self.lc = LooseCell(value=0, type=RangeT([(-100, 100)]))
self.delta = 1
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + self.delta,
set_transform=lambda x: x - self.delta,
type=int)
示例7: __init__
def __init__(self,
signal_type=None,
enable_scope=False,
freq_resolution=4096,
time_length=2048,
window_type=windows.WIN_BLACKMAN_HARRIS,
frame_rate=30.0,
input_center_freq=0.0,
paused=False,
context=None):
assert isinstance(signal_type, SignalType)
assert context is not None
itemsize = signal_type.get_itemsize()
gr.hier_block2.__init__(
self, type(self).__name__,
gr.io_signature(1, 1, itemsize),
gr.io_signature(0, 0, 0),
)
# constant parameters
self.__power_offset = 40 # TODO autoset or controllable
self.__itemsize = itemsize
self.__context = context
self.__enable_scope = enable_scope
# settable parameters
self.__signal_type = signal_type
self.__freq_resolution = int(freq_resolution)
self.__time_length = int(time_length)
self.__window_type = _window_type_enum(window_type)
self.__frame_rate = float(frame_rate)
self.__input_center_freq = float(input_center_freq)
self.__paused = bool(paused)
# interest tracking
# this is indirect because we ignore interest when paused
self.__interested_cell = LooseCell(type=bool, value=False, writable=False, persists=False)
self.__has_subscriptions = False
self.__interest = InterestTracker(self.__cell_interest_callback)
self.__fft_cell = ElementSinkCell(
info_getter=self._get_fft_info,
type=BulkDataT(array_format='b', info_format='dff'),
interest_tracker=self.__interest,
label='Spectrum')
self.__scope_cell = ElementSinkCell(
info_getter=self._get_scope_info,
type=BulkDataT(array_format='f', info_format='d'),
interest_tracker=self.__interest,
label='Scope')
# stuff created by __do_connect
self.__gate = None
self.__frame_dec = None
self.__frame_rate_to_decimation_conversion = 0.0
self.__do_connect()
示例8: TestViewCell
class TestViewCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(value=0, key='a', type=int)
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + 1,
set_transform=lambda x: x - 1,
key='b',
type=int)
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.assertEqual(1, self.vc.get())
self.vc.set(2)
self.assertEqual(1, self.lc.get())
self.assertEqual(2, self.vc.get())
self.lc.set(3)
self.assertEqual(3, self.lc.get())
self.assertEqual(4, self.vc.get())
def test_subscription(self):
fired = []
def f():
fired.append(self.vc.get())
self.vc.subscribe(f)
self.lc.set(1)
self.assertEqual([2], fired)
示例9: __init__
def __init__(self, lime_block):
self.__lime_block = lime_block
self.__vfo_cell = LooseCell(
value=0.0,
type=RangeT([(10e6, 3500e6)],
strict=False,
unit=units.Hz),
writable=True,
persists=True,
post_hook=self.__set_freq)
示例10: setUp
def setUp(self):
self.lc = LooseCell(value=0, type=RangeT([(-100, 100)]), writable=True)
self.delta = 1
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + self.delta,
set_transform=lambda x: x - self.delta,
type=int,
writable=True,
interest_tracker=LoopbackInterestTracker())
示例11: __init__
def __init__(self, profile, correction_ppm, osmo_block):
self.__profile = profile
self.__correction_ppm = correction_ppm
self.__osmo_block = osmo_block
self.__vfo_cell = LooseCell(
value=0.0,
# TODO: Eventually we'd like to be able to make the freq range vary dynamically with the correction setting
type=convert_osmosdr_range(
osmo_block.get_freq_range(ch),
strict=False,
transform=self.from_hardware_freq,
unit=units.Hz,
add_zero=profile.e4000),
writable=True,
persists=True,
post_hook=self.__set_freq)
示例12: __init__
def __init__(self, profile, correction_ppm, source):
self.__profile = profile
self.__correction_ppm = correction_ppm
self.__source = source
self.__vfo_cell = LooseCell(
key='freq',
value=0.0,
# TODO: Eventually we'd like to be able to make the freq range vary dynamically with the correction setting
ctor=convert_osmosdr_range(
source.get_freq_range(ch),
strict=False,
transform=self.from_hardware_freq,
add_zero=profile.e4000),
writable=True,
persists=True,
post_hook=self.__set_freq)
示例13: TestLooseCell
class TestLooseCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(
value=0,
type=int,
writable=True,
interest_tracker=LoopbackInterestTracker())
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.lc.set(1)
self.assertEqual(1, self.lc.get())
self.lc.set(2.1)
self.assertEqual(2, self.lc.get())
def test_subscription(self):
st = CellSubscriptionTester(self.lc)
self.lc.set(1)
st.expect_now(1)
st.unsubscribe()
self.lc.set(2)
st.advance() # check for unwanted callbacks
def test_repr(self):
if six.PY2:
self.assertEqual(repr(self.lc), '<LooseCell PythonT(<type \'int\'>) 0>')
else:
self.assertEqual(repr(self.lc), '<LooseCell PythonT(<class \'int\'>) 0>')
def test_default_writability(self):
self.assertFalse(LooseCell(value=0, type=int).isWritable())
def test_not_writable(self):
self.lc = LooseCell(value=0, type=int, writable=False)
self.assertRaises(Exception, lambda:
self.lc.set(1))
self.assertEqual(self.lc.get(), 0)
示例14: TestViewCell
class TestViewCell(unittest.TestCase):
def setUp(self):
self.lc = LooseCell(value=0, type=RangeT([(-100, 100)]))
self.delta = 1
self.vc = ViewCell(
base=self.lc,
get_transform=lambda x: x + self.delta,
set_transform=lambda x: x - self.delta,
type=int)
# TODO: Add tests for behavior when the transform is not perfectly one-to-one (such as due to floating-point error).
def test_get_set(self):
self.assertEqual(0, self.lc.get())
self.assertEqual(1, self.vc.get())
self.vc.set(2)
self.assertEqual(1, self.lc.get())
self.assertEqual(2, self.vc.get())
self.lc.set(3)
self.assertEqual(3, self.lc.get())
self.assertEqual(4, self.vc.get())
self.delta = 10
self.vc.changed_transform()
self.assertEqual(3, self.lc.get())
self.assertEqual(13, self.vc.get())
def test_subscription(self):
st = CellSubscriptionTester(self.vc)
self.lc.set(1)
st.expect_now(2)
self.delta = 10
self.vc.changed_transform()
self.assertEqual(1, self.lc.get())
st.expect_now(11)
st.unsubscribe()
self.lc.set(2)
st.advance()
def test_coerced_base_value(self):
self.vc.set(999) # out of base cell's range, gets clamped
self.assertEqual(100 + self.delta, self.vc.get())
示例15: MonitorSink
class MonitorSink(gr.hier_block2, ExportedState):
"""Convenience wrapper around all the bits and pieces to display the signal spectrum to the client.
The units of the FFT output are dB power/Hz (power spectral density) relative to unit amplitude (i.e. dBFS assuming the source clips at +/-1). Note this is different from the standard logpwrfft result of power _per bin_, which would be undesirably dependent on the sample rate and bin size.
"""
def __init__(self,
signal_type=None,
enable_scope=False,
freq_resolution=4096,
time_length=2048,
frame_rate=30.0,
input_center_freq=0.0,
paused=False,
context=None):
assert isinstance(signal_type, SignalType)
assert context is not None
itemsize = signal_type.get_itemsize()
gr.hier_block2.__init__(
self, type(self).__name__,
gr.io_signature(1, 1, itemsize),
gr.io_signature(0, 0, 0),
)
# constant parameters
self.__power_offset = 40 # TODO autoset or controllable
self.__itemsize = itemsize
self.__context = context
self.__enable_scope = enable_scope
# settable parameters
self.__signal_type = signal_type
self.__freq_resolution = int(freq_resolution)
self.__time_length = int(time_length)
self.__frame_rate = float(frame_rate)
self.__input_center_freq = float(input_center_freq)
self.__paused = bool(paused)
self.__interested_cell = LooseCell(type=bool, value=False, writable=False, persists=False)
# stuff created by __do_connect
self.__gate = None
self.__fft_sink = None
self.__scope_sink = None
self.__frame_dec = None
self.__frame_rate_to_decimation_conversion = 0.0
self.__do_connect()
def state_def(self):
for d in super(MonitorSink, self).state_def():
yield d
# TODO make this possible to be decorator style
yield 'fft', StreamCell(self, 'fft',
type=BulkDataT(array_format='b', info_format='dff'),
label='Spectrum')
yield 'scope', StreamCell(self, 'scope',
type=BulkDataT(array_format='f', info_format='d'),
label='Scope')
def __do_connect(self):
itemsize = self.__itemsize
if self.__signal_type.is_analytic():
input_length = self.__freq_resolution
output_length = self.__freq_resolution
self.__after_fft = None
else:
# use vector_to_streams to cut the output in half and discard the redundant part
input_length = self.__freq_resolution * 2
output_length = self.__freq_resolution
self.__after_fft = blocks.vector_to_streams(itemsize=output_length * gr.sizeof_float, nstreams=2)
sample_rate = self.__signal_type.get_sample_rate()
overlap_factor = int(math.ceil(_maximum_fft_rate * input_length / sample_rate))
# sanity limit -- OverlapGimmick is not free
overlap_factor = min(16, overlap_factor)
self.__frame_rate_to_decimation_conversion = sample_rate * overlap_factor / input_length
self.__gate = blocks.copy(itemsize)
self.__gate.set_enabled(not self.__paused)
overlapper = _OverlappedStreamToVector(
size=input_length,
factor=overlap_factor,
itemsize=itemsize)
self.__frame_dec = blocks.keep_one_in_n(
itemsize=itemsize * input_length,
n=int(round(self.__frame_rate_to_decimation_conversion / self.__frame_rate)))
# the actual FFT logic, which is similar to GR's logpwrfft_c
window = windows.blackmanharris(input_length)
window_power = sum(x * x for x in window)
# TODO: use fft_vfc when applicable
fft_block = (fft_vcc if itemsize == gr.sizeof_gr_complex else fft_vfc)(
fft_size=input_length,
forward=True,
window=window)
#.........这里部分代码省略.........