Skip to content

Commit 899095c

Browse files
author
anna-grim
committed
bug: read zipped swcs
1 parent fe11868 commit 899095c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/segmentation_skeleton_metrics/utils/swc_util.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,25 @@ def read_from_gcs_swc(self, bucket_name, path):
352352
def read_from_gcs_zips(self, bucket_name, zip_paths):
353353
pbar = tqdm(total=len(zip_paths), desc="Read SWCs")
354354
swc_dicts = deque()
355-
with ThreadPoolExecutor() as executor:
355+
356+
# test
357+
for zip_path in zip_paths:
358+
self.read_from_gcs_zip(bucket_name, zip_path)
359+
pbar.update(1)
360+
361+
with ProcessPoolExecutor() as executor:
356362
# Assign processes
357-
processes = list()
363+
threads = list()
358364
for zip_path in zip_paths:
359-
processes.append(
365+
threads.append(
360366
executor.submit(
361367
self.read_from_gcs_zip, bucket_name, zip_path
362368
)
363369
)
364370

365371
# Store results
366-
for process in as_completed(processes):
367-
swc_dicts.extend(process.result())
372+
for thread in as_completed(threads):
373+
swc_dicts.extend(thread.result())
368374
pbar.update(1)
369375
print("# swcs:", len(swc_dicts))
370376
return swc_dicts
@@ -394,11 +400,11 @@ def read_from_gcs_zip(self, bucket_name, path):
394400
# Parse Zip
395401
swc_dicts = deque()
396402
zip_content = bucket.blob(path).download_as_bytes()
397-
with ZipFile(BytesIO(zip_content)) as zip_file:
403+
with ZipFile(BytesIO(zip_content), "r") as zip_file:
398404
with ThreadPoolExecutor() as executor:
399405
# Assign threads
400406
threads = list()
401-
for filename in util.list_files_in_zip(zip_content):
407+
for filename in zip_file.namelist():
402408
if self.confirm_read(filename):
403409
threads.append(
404410
executor.submit(

0 commit comments

Comments
 (0)