Skip to content
Snippets Groups Projects
Commit c7545b39 authored by Kien Le's avatar Kien Le
Browse files

Remove unnecessary storage in data dictionary

Make trim_waveform_data uses local variables for the start and end
index of the trimmed trace list inside of the original trace list.
Currently, these indices are saved to the data dictionary and never
used again.
parent 59f098b3
No related branches found
No related tags found
1 merge request!33Add tests and refactor trim_downsample_WFChan
......@@ -583,18 +583,15 @@ def trim_downsample_SOHChan(chan, startTm, endTm, firsttime):
def trim_waveform_data(wf_channel_data: Dict, start_time: float,
end_time: float) -> List[Dict]:
"""
Trim off waveform traces that are outside of the time range defined by
start_time and end_time.
Trim off waveform traces whose times does not intersect the closed interval
[start_time, end_time].
:param wf_channel_data: dict - a dictionary that contains the waveform
times and data of a channel. For its structure, refer to
DataTypeModel.waveformData[key]['readData'][chan_id]
:param start_time: the start of the time range to trim waveform data to
:param end_time: the start of the time range to trim waveform data to
:return:
DataTypeModel.waveformData[key]['readData'][chan_id].
:param start_time: the start of the time range to trim waveform data to.
:param end_time: the end of the time range to trim waveform data to.
:return: a list with all the waveform traces that were not trimmed.
"""
wf_channel_data['startIdx'] = 0
wf_channel_data['endIdx'] = len(wf_channel_data['tracesInfo'])
if ((start_time > wf_channel_data['tracesInfo'][-1]['endTmEpoch']) or
(end_time < wf_channel_data['tracesInfo'][0]['startTmEpoch'])):
return []
......@@ -602,23 +599,23 @@ def trim_waveform_data(wf_channel_data: Dict, start_time: float,
indexes = [index for index, tr in enumerate(wf_channel_data['tracesInfo'])
if tr['startTmEpoch'] > start_time]
if indexes != []:
wf_channel_data['startIdx'] = indexes[0]
if wf_channel_data['startIdx'] > 0:
wf_channel_data['startIdx'] -= 1 # startTm in middle of trace
start_idx = indexes[0]
if start_idx > 0:
start_idx -= 1 # startTm in middle of trace
else:
wf_channel_data['startIdx'] = 0
start_idx = 0
indexes = [idx for (idx, tr) in enumerate(wf_channel_data['tracesInfo'])
if tr['endTmEpoch'] <= end_time]
if indexes != []:
wf_channel_data['endIdx'] = indexes[-1]
if wf_channel_data['endIdx'] < len(wf_channel_data['tracesInfo']) - 1:
wf_channel_data['endIdx'] += 1 # endTm in middle of trace
end_idx = indexes[-1]
if end_idx < len(wf_channel_data['tracesInfo']) - 1:
end_idx += 1 # endTm in middle of trace
else:
wf_channel_data['endIdx'] = 0
wf_channel_data['endIdx'] += 1 # a[x:y+1] = [a[x], ...a[y]
end_idx = 0
end_idx += 1 # a[x:y+1] = [a[x], ...a[y]
trimmed_traces_list = wf_channel_data['tracesInfo'][wf_channel_data['startIdx']:wf_channel_data['endIdx']]
trimmed_traces_list = wf_channel_data['tracesInfo'][start_idx:end_idx]
return trimmed_traces_list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment