Skip to content

Commit

Permalink
Dev/tests (#86)
Browse files Browse the repository at this point in the history
Adding tests to improve coverage.
  • Loading branch information
rhoadesScholar authored Feb 14, 2024
2 parents 350c744 + c7625dd commit 07fcb70
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# DaCapo ![DaCapo](docs/source/_static/icon_dacapo.png)

[![tests](https://github.com/funkelab/dacapo/actions/workflows/tests.yaml/badge.svg)](https://github.com/funkelab/dacapo/actions/workflows/tests.yaml)
[![black](https://github.com/funkelab/dacapo/actions/workflows/black.yaml/badge.svg)](https://github.com/funkelab/dacapo/actions/workflows/black.yaml)
[![mypy](https://github.com/funkelab/dacapo/actions/workflows/mypy.yaml/badge.svg)](https://github.com/funkelab/dacapo/actions/workflows/mypy.yaml)
[![docs](https://github.com/funkelab/dacapo/actions/workflows/docs.yaml/badge.svg)](https://funkelab.github.io/dacapo/)
[![tests](https://github.com/janelia-cellmap/dacapo/actions/workflows/tests.yaml/badge.svg)](https://github.com/janelia-cellmap/dacapo/actions/workflows/tests.yaml)
[![black](https://github.com/janelia-cellmap/dacapo/actions/workflows/black.yaml/badge.svg)](https://github.com/janelia-cellmap/dacapo/actions/workflows/black.yaml)
[![mypy](https://github.com/janelia-cellmap/dacapo/actions/workflows/mypy.yaml/badge.svg)](https://github.com/janelia-cellmap/dacapo/actions/workflows/mypy.yaml)
[![docs](https://github.com/janelia-cellmap/dacapo/actions/workflows/docs.yaml/badge.svg)](https://janelia-cellmap.github.io/dacapo/)
[![codecov](https://codecov.io/gh/janelia-cellmap/dacapo/branch/main/graph/badge.svg)](https://codecov.io/gh/janelia-cellmap/dacapo)

A framework for easy application of established machine learning techniques on large, multi-dimensional images.

Expand Down
9 changes: 6 additions & 3 deletions dacapo/store/file_config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ def __save_insert(self, collection, data, ignore=None):

file_store = collection / name
if not file_store.exists():
pickle.dump(dict(data), file_store.open("wb"))
with file_store.open("wb") as fd:
pickle.dump(dict(data), fd)

else:
existing = pickle.load(file_store.open("rb"))
with file_store.open("rb") as fd:
existing = pickle.load(fd)

if not self.__same_doc(existing, data, ignore):
raise DuplicateNameError(
Expand All @@ -113,7 +115,8 @@ def __save_insert(self, collection, data, ignore=None):
def __load(self, collection, name):
file_store = collection / name
if file_store.exists():
return pickle.load(file_store.open("rb"))
with file_store.open("rb") as fd:
return pickle.load(fd)
else:
raise ValueError(f"No config with name: {name} in collection: {collection}")

Expand Down
12 changes: 8 additions & 4 deletions dacapo/store/file_stats_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ def __store_training_stats(self, stats, begin, end, run_name):

if docs:
file_store = self.training_stats / run_name
pickle.dump(docs, file_store.open("wb"))
with file_store.open("wb") as fd:
pickle.dump(docs, fd)

def __read_training_stats(self, run_name):
file_store = self.training_stats / run_name
if file_store.exists():
docs = pickle.load(file_store.open("rb"))
with file_store.open("rb") as fd:
docs = pickle.load(fd)
else:
docs = []
stats = TrainingStats(converter.structure(docs, List[TrainingIterationStats]))
Expand All @@ -117,12 +119,14 @@ def __store_validation_iteration_scores(

if docs:
file_store = self.validation_scores / run_name
pickle.dump(docs, file_store.open("wb"))
with file_store.open("wb") as fd:
pickle.dump(docs, fd)

def __read_validation_iteration_scores(self, run_name):
file_store = self.validation_scores / run_name
if file_store.exists():
docs = pickle.load(file_store.open("rb"))
with file_store.open("rb") as fd:
docs = pickle.load(fd)
else:
docs = []
scores = converter.structure(docs, List[ValidationIterationScores])
Expand Down
9 changes: 4 additions & 5 deletions dacapo/store/local_weights_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ def store_best(self, run: str, iteration: int, dataset: str, criterion: str):
def retrieve_best(self, run: str, dataset: str, criterion: str) -> int:
logger.info("Retrieving weights for run %s, criterion %s", run, criterion)

weights_info = json.loads(
(self.__get_weights_dir(run) / criterion / f"{dataset}.json")
.open("r")
.read()
)
with (self.__get_weights_dir(run) / criterion / f"{dataset}.json").open(
"r"
) as fd:
weights_info = json.load(fd)

return weights_info["iteration"]

Expand Down

0 comments on commit 07fcb70

Please sign in to comment.