Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prefetch(self):
prefetch_states = []
for i in range(self.num_to_prefetch):
idx = self.index + (i + 1) * self.batch
if idx >= len(self.todo):
break
prefetch_state = copy.deepcopy(self.viewer.state)
prefetch_state.layers['seg'].segments = self.list_segments(idx)
prefetch_state.layout = '3d'
prefetch_states.append(prefetch_state)
with self.viewer.config_state.txn() as s:
s.prefetch = [
neuroglancer.PrefetchState(state=prefetch_state, priority=-i)
for i, prefetch_state in enumerate(prefetch_states)
]
def set_state(self, viewer, frame_i, prefetch_frames):
states = self.get_frames(frame_i, frame_i + prefetch_frames)
viewer.set_state(states[0])
with viewer.config_state.txn() as s:
del s.prefetch[:]
for i, state in enumerate(states[1:]):
s.prefetch.append(
neuroglancer.PrefetchState(state=state, priority=prefetch_frames - i))
with self.viewer.txn() as s:
modify_state_for_body(s, body)
prefetch_states = []
for i in range(self.num_to_prefetch):
prefetch_index = self.index + i + 1
if prefetch_index >= len(self.bodies):
break
prefetch_state = copy.deepcopy(self.viewer.state)
prefetch_state.layout = '3d'
modify_state_for_body(prefetch_state, self.bodies[prefetch_index])
prefetch_states.append(prefetch_state)
with self.viewer.config_state.txn() as s:
s.prefetch = [
neuroglancer.PrefetchState(state=prefetch_state, priority=-i)
for i, prefetch_state in enumerate(prefetch_states)
]
label = self.state.body_labels.get(body.segment_id, '')
with self.viewer.config_state.txn() as s:
s.status_messages['status'] = (
'[Segment %d/%d : %d/%d voxels labeled = %.3f fraction] label=%s' %
(index, len(self.bodies), self.cumulative_voxels[index], self.total_voxels,
self.cumulative_voxels[index] / self.total_voxels, label))
else:
cur_state = neuroglancer.ViewerState.interpolate(a, b, t)
states_to_capture.append((frame_number, i + t, cur_state))
frame_number += 1
for frame_number, t, cur_state in states_to_capture:
prefetch_states = [
x[2]
for x in states_to_capture[frame_number + 1:frame_number + 1 + num_prefetch_frames]
]
viewer.set_state(cur_state)
if num_prefetch_frames > 0:
with viewer.config_state.txn() as s:
del s.prefetch[:]
for i, state in enumerate(prefetch_states[1:]):
s.prefetch.append(
neuroglancer.PrefetchState(state=state, priority=num_prefetch_frames - i))
frame_number, path = saver.capture(frame_number)
with lock:
num_frames_written[0] += 1
cur_num_frames_written = num_frames_written[0]
print('[%07d/%07d] keypoint %.3f/%5d: %s' %
(cur_num_frames_written, total_frames, t, len(keypoints), path))