Skip to content

Commit

Permalink
Rename Feature.export as to_zip (fixes #552)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmetNSimsek committed Feb 1, 2024
1 parent 594b439 commit 66d8450
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions e2e/features/connectivity/test_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def test_copy_is_returned():
def test_export():
# for now, only test the first feature, given the ci resource concern
feat: RegionalConnectivity = all_conn_instances[0]
feat.export("file.zip")
feat.to_zip("file.zip")
with ZipFile("file.zip") as z:
filenames = [info.filename for info in z.filelist]
assert len([f for f in filenames if f.endswith(".csv")]) == 1
os.remove("file.zip")

cf: CompoundFeature = compound_conns[0]
cf.export("file_compound.zip")
cf.to_zip("file_compound.zip")
with ZipFile("file_compound.zip") as cz:
filenames = [info.filename for info in cz.filelist]
assert len([f for f in filenames if f.endswith(".csv")]) == len(cf)
Expand Down
2 changes: 1 addition & 1 deletion siibra/features/connectivity/regional_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _plot_matrix(
)

def _export(self, fh: ZipFile):
super()._export(fh)
super()._to_zip(fh)
if self.feature is None:
fh.writestr(f"sub/{self._filename}/matrix.csv", self.data.to_csv())
else:
Expand Down
2 changes: 1 addition & 1 deletion siibra/features/dataset/ebrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ def __eq__(self, o: object) -> bool:
return self._dataset == o._dataset

def _export(self, fh: ZipFile):
super()._export(fh)
super()._to_zip(fh)
fh.writestr("doi.md", DOI_TMPL.format(doi=self.url))
8 changes: 4 additions & 4 deletions siibra/features/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def id(self):
break
return prefix + md5(self.name.encode("utf-8")).hexdigest()

def _export(self, fh: ZipFile):
def _to_zip(self, fh: ZipFile):
"""
Internal implementation. Subclasses can override but call super()._export(fh).
This allows all classes in the __mro__ to have the opportunity to append files
Expand Down Expand Up @@ -308,7 +308,7 @@ def _export(self, fh: ZipFile):
)
)

def export(self, filelike: Union[str, BinaryIO]):
def to_zip(self, filelike: Union[str, BinaryIO]):
"""
Export as a zip archive.
Expand All @@ -319,7 +319,7 @@ def export(self, filelike: Union[str, BinaryIO]):
correct extension (.zip) is set.
"""
fh = ZipFile(filelike, "w")
self._export(fh)
self._to_zip(fh)
fh.close()

@staticmethod
Expand Down Expand Up @@ -883,7 +883,7 @@ def _get_instance_by_id(cls, feature_id: str, **kwargs):
raise ParseCompoundFeatureIdException

def _export(self, fh: ZipFile):
super()._export(fh)
super()._to_zip(fh)
for idx, element in siibra_tqdm(self._elements.items(), desc="Exporting elements", unit="element"):
if '/' in str(idx):
logger.warning(f"'/' will be replaced with ' ' of the file for element with index {idx}")
Expand Down
2 changes: 1 addition & 1 deletion siibra/features/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
self._name_cached = name

def _export(self, fh: ZipFile):
super()._export(fh)
super()._to_zip(fh)
# How, what do we download?
# e.g. for marcel's volume, do we download at full resolution?
# cannot implement until Volume has an export friendly method
Expand Down
2 changes: 1 addition & 1 deletion siibra/features/tabular/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def data(self):
return self._data_cached.copy()

def _export(self, fh: ZipFile):
super()._export(fh)
super()._to_zip(fh)
fh.writestr("tabular.csv", self.data.to_csv())

def plot(self, *args, backend="matplotlib", **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion siibra/volumes/parcellationmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from ..retrieval import requests

import numpy as np
from typing import Union, Dict, List, TYPE_CHECKING, Iterable, Tuple
from zipfile import ZipFile
from typing import Union, Dict, List, TYPE_CHECKING, Iterable, Tuple, BinaryIO
from scipy.ndimage import distance_transform_edt
from collections import defaultdict
from nilearn import image
Expand Down

0 comments on commit 66d8450

Please sign in to comment.