Skip to content

Commit d694b3d

Browse files
anna-grimanna-grim
andauthored
Feat support s3 swcs (#141)
* feat: tools for reading from s3 * refactor: updated toml * feat: s3 support for swcs functional --------- Co-authored-by: anna-grim <[email protected]>
1 parent faf76a7 commit d694b3d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/segmentation_skeleton_metrics/utils/swc_util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,19 @@ def read_from_gcs_zip(self, bucket_name, path):
426426
swc_dicts.append(result)
427427
return swc_dicts
428428

429-
def read_from_s3_swcs(self, s3_path):
429+
def read_from_s3(self, s3_path):
430430
# List filenames
431431
bucket_name, prefix = parse_cloud_path(s3_path)
432432
swc_paths = util.list_s3_paths(bucket_name, prefix, extension=".swc")
433433

434434
# Parse SWC files
435435
swc_dicts = deque()
436436
for path in swc_paths:
437-
contents = util.read_txt_from_s3(bucket_name, path)
437+
content = util.read_txt_from_s3(bucket_name, path).splitlines()
438+
filename = os.path.basename(path)
439+
result = self.parse(content, filename)
440+
if result:
441+
swc_dicts.append(result)
438442
return swc_dicts
439443

440444
def confirm_read(self, filename):

src/segmentation_skeleton_metrics/utils/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def read_txt_from_s3(bucket_name, path):
369369
"""
370370
s3 = boto3.client("s3", config=Config(signature_version=UNSIGNED))
371371
obj = s3.get_object(Bucket=bucket_name, Key=path)
372-
return obj['Body'].read().decode('utf-8').splitlines()
372+
return obj['Body'].read().decode('utf-8')
373373

374374

375375
# --- Miscellaneous ---

0 commit comments

Comments
 (0)