Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_not_byte_aligned_data(self, data, group, ch_nr):
big_endian_types = (
v2c.DATA_TYPE_UNSIGNED_MOTOROLA,
v2c.DATA_TYPE_FLOAT_MOTOROLA,
v2c.DATA_TYPE_DOUBLE_MOTOROLA,
v2c.DATA_TYPE_SIGNED_MOTOROLA,
)
record_size = group['channel_group']['samples_byte_nr']
if self.memory != 'minimum':
channel = group['channels'][ch_nr]
else:
channel = Channel(
address=group['channels'][ch_nr],
stream=self._file,
)
bit_offset = channel['start_offset'] % 8
byte_offset = channel['start_offset'] // 8
bit_count = channel['bit_count']
name = name.decode('utf-8').strip(' \r\t\n\0')
name = name.split('\\')[0]
channel.name = name
dep = grp['channel_dependencies'][ch_nr]
cycles_nr = grp['channel_group']['cycles_nr']
# get data group record
if data is None:
data = self._load_group_data(grp)
info = None
# check if this is a channel array
if dep:
if dep['dependency_type'] == v2c.DEPENDENCY_TYPE_VECTOR:
shape = [dep['sd_nr'], ]
elif dep['dependency_type'] >= v2c.DEPENDENCY_TYPE_NDIM:
shape = []
i = 0
while True:
try:
dim = dep['dim_{}'.format(i)]
shape.append(dim)
i += 1
except KeyError:
break
shape = shape[::-1]
record_shape = tuple(shape)
arrays = [
'channel_group': [],
}
grp['trigger'] = [trigger, trigger_text]
grp['channel_dependencies'] = []
if record_id_nr:
grp['sorted'] = False
else:
grp['sorted'] = True
kargs = {'first_cg_addr': cg_addr,
'data_block_addr': data_addr}
if self.version in ('3.20', '3.30'):
kargs['block_len'] = v2c.DG32_BLOCK_SIZE
else:
kargs['block_len'] = v2c.DG31_BLOCK_SIZE
grp['data_group'] = DataGroup(**kargs)
# read each channel group sequentially
grp['channel_group'] = ChannelGroup(
address=cg_addr,
stream=stream,
)
# read name and comment for current channel group
cg_texts = {}
grp['texts']['channel_group'].append(cg_texts)
address = grp['channel_group']['comment_addr']
if address:
if memory != 'minimum':
types = [(channel.name, vals.dtype, vals.shape[1:]), ]
if PYVERSION == 2:
types = fix_dtype_fields(types)
types = dtype(types)
vals = fromarrays(arrays, dtype=types)
elif conversion_type == v2c.CONVERSION_TYPE_LINEAR:
a = conversion['a']
b = conversion['b']
if (a, b) != (1, 0):
vals = vals * a
if b:
vals += b
elif conversion_type in (v2c.CONVERSION_TYPE_TABI,
v2c.CONVERSION_TYPE_TABX):
nr = conversion['ref_param_nr']
raw = [conversion['raw_{}'.format(i)] for i in range(nr)]
raw = array(raw)
phys = [conversion['phys_{}'.format(i)] for i in range(nr)]
phys = array(phys)
if conversion_type == v2c.CONVERSION_TYPE_TABI:
vals = interp(vals, raw, phys)
else:
idx = searchsorted(raw, vals)
idx = clip(idx, 0, len(raw) - 1)
vals = phys[idx]
elif conversion_type == v2c.CONVERSION_TYPE_VTAB:
nr = conversion['ref_param_nr']
raw = [
elif conversion_type in (v2c.CONVERSION_TYPE_TABI,
v2c.CONVERSION_TYPE_TABX):
nr = conversion['ref_param_nr']
raw = [conversion['raw_{}'.format(i)] for i in range(nr)]
raw = array(raw)
phys = [conversion['phys_{}'.format(i)] for i in range(nr)]
phys = array(phys)
if conversion_type == v2c.CONVERSION_TYPE_TABI:
vals = interp(vals, raw, phys)
else:
idx = searchsorted(raw, vals)
idx = clip(idx, 0, len(raw) - 1)
vals = phys[idx]
elif conversion_type == v2c.CONVERSION_TYPE_VTAB:
nr = conversion['ref_param_nr']
raw = [
conversion['param_val_{}'.format(i)]
for i in range(nr)
]
raw = array(raw)
phys = [conversion['text_{}'.format(i)] for i in range(nr)]
phys = array(phys)
info = {'raw': raw, 'phys': phys}
elif conversion_type == v2c.CONVERSION_TYPE_VTABR:
nr = conversion['ref_param_nr']
conv_texts = grp['texts']['conversion_tab'][ch_nr]
texts = []
for i in range(nr):
grp_conv.append(new_conv)
else:
grp_conv.append(address)
else:
new_conv = None
if memory != 'minimum':
grp_conv.append(None)
else:
grp_conv.append(0)
vtab_texts = {}
if new_conv:
conv_type = new_conv['conversion_type']
else:
conv_type = 0
if conv_type == v2c.CONVERSION_TYPE_VTABR:
for idx in range(new_conv['ref_param_nr']):
address = new_conv['text_{}'.format(idx)]
if address:
if memory != 'minimum':
block = TextBlock(
address=address,
stream=stream,
)
vtab_texts['text_{}'.format(idx)] = block
else:
vtab_texts['text_{}'.format(idx)] = address
if vtab_texts:
grp['texts']['conversion_tab'].append(vtab_texts)
else:
grp['texts']['conversion_tab'].append(None)
else:
record = None
if memory == 'full':
group['record'] = record
t = record[parent]
else:
t = self._get_not_byte_aligned_data(
data,
group,
time_ch_nr,
)
# get timestamps
if time_conv is None:
time_conv_type = v2c.CONVERSION_TYPE_NONE
else:
time_conv_type = time_conv['conversion_type']
if time_conv_type == v2c.CONVERSION_TYPE_LINEAR:
time_a = time_conv['a']
time_b = time_conv['b']
t = t * time_a
if time_b:
t += time_b
self._master_channel_cache[index] = t
return t
vals = evaluate(v2c.RAT_CONV_TEXT)
elif conversion_type == v2c.CONVERSION_TYPE_POLY:
P1 = conversion['P1']
P2 = conversion['P2']
P3 = conversion['P3']
P4 = conversion['P4']
P5 = conversion['P5']
P6 = conversion['P6']
X = vals
coefs = (P2, P3, P5, P6)
if coefs == (0, 0, 0, 0):
if P1 != P4:
vals = evaluate(v2c.POLY_CONV_SHORT_TEXT)
else:
vals = evaluate(v2c.POLY_CONV_LONG_TEXT)
elif conversion_type == v2c.CONVERSION_TYPE_FORMULA:
formula = conversion['formula'].decode('latin-1')
formula = formula.strip(' \n\t\0')
X1 = vals
vals = evaluate(formula)
if samples_only:
res = vals
else:
if conversion:
unit = conversion['unit'].decode('latin-1').strip(' \n\t\0')
else:
unit = ''
else:
message = 'wrong conversion {}'.format(conversion_type)
raise ValueError(message)
elif conversion_type == v2c.CONVERSION_TYPE_RAT:
P1 = conversion['P1']
P2 = conversion['P2']
P3 = conversion['P3']
P4 = conversion['P4']
P5 = conversion['P5']
P6 = conversion['P6']
if (P1, P2, P3, P4, P5, P6) != (0, 1, 0, 0, 0, 1):
X = vals
vals = evaluate(v2c.RAT_CONV_TEXT)
elif conversion_type == v2c.CONVERSION_TYPE_POLY:
P1 = conversion['P1']
P2 = conversion['P2']
P3 = conversion['P3']
P4 = conversion['P4']
P5 = conversion['P5']
P6 = conversion['P6']
X = vals
coefs = (P2, P3, P5, P6)
if coefs == (0, 0, 0, 0):
if P1 != P4:
vals = evaluate(v2c.POLY_CONV_SHORT_TEXT)
else:
vals = evaluate(v2c.POLY_CONV_LONG_TEXT)
P2 = conversion['P2']
P3 = conversion['P3']
P4 = conversion['P4']
P5 = conversion['P5']
P6 = conversion['P6']
X = vals
coefs = (P2, P3, P5, P6)
if coefs == (0, 0, 0, 0):
if P1 != P4:
vals = evaluate(v2c.POLY_CONV_SHORT_TEXT)
else:
vals = evaluate(v2c.POLY_CONV_LONG_TEXT)
elif conversion_type == v2c.CONVERSION_TYPE_FORMULA:
formula = conversion['formula'].decode('latin-1')
formula = formula.strip(' \n\t\0')
X1 = vals
vals = evaluate(formula)
if samples_only:
res = vals
else:
if conversion:
unit = conversion['unit'].decode('latin-1').strip(' \n\t\0')
else:
unit = ''
comment = channel['description'].decode('latin-1')
comment = comment.strip(' \t\n\0')
t = self.get_master(gp_nr, data)