Skip to content

Commit fc044a2

Browse files
anna-grimanna-grim
andauthored
Feat s3 loading (#175)
* refactor: improved txt reader * remove print * feat: load swcs from s3 * feat: read json --------- Co-authored-by: anna-grim <anna.grim@alleninstitute.org>
1 parent 37c429c commit fc044a2

File tree

1 file changed

+25
-8
lines changed
  • src/segmentation_skeleton_metrics/utils

1 file changed

+25
-8
lines changed

src/segmentation_skeleton_metrics/utils/util.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,21 @@ def list_paths(directory, extension=None):
133133

134134

135135
# --- IO Utils ---
136-
def read_zip(zip_file, path):
136+
def read_json(path):
137137
"""
138-
Reads a txt file contained in the given ZIP archive.
138+
Reads JSON file located at the given path.
139139
140140
Parameters
141141
----------
142-
zip_file : ZipFile
143-
ZIP archive containing TXT file.
142+
path : str
143+
Path to JSON file to be read.
144144
145145
Returns
146146
-------
147-
str
148-
Contents of a TXT file.
147+
dict
148+
Contents of JSON file.
149149
"""
150-
with zip_file.open(path) as f:
151-
return f.read().decode("utf-8")
150+
return pd.read_json(path, storage_options={"anon": True}, typ="series")
152151

153152

154153
def read_txt(path):
@@ -174,6 +173,24 @@ def read_txt(path):
174173
return f.read().splitlines()
175174

176175

176+
def read_zip(zip_file, path):
177+
"""
178+
Reads txt file contained in the given ZIP archive.
179+
180+
Parameters
181+
----------
182+
zip_file : ZipFile
183+
ZIP archive containing TXT file.
184+
185+
Returns
186+
-------
187+
str
188+
Contents of a TXT file.
189+
"""
190+
with zip_file.open(path) as f:
191+
return f.read().decode("utf-8")
192+
193+
177194
def update_txt(path, text, verbose=True):
178195
"""
179196
Appends the given text to a specified text file and prints the text.

0 commit comments

Comments
 (0)