Skip to content

Commit

Permalink
better error with lack of l2 service
Browse files Browse the repository at this point in the history
  • Loading branch information
ceesem committed Aug 29, 2024
1 parent 78bd912 commit 6a51abb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ title: Changelog

`pcg_skel` aims to follow semantic versioning, such that major versions are potentially backward-incompatible, minor versions add new features, and patch versions are bug fixes. This changelog is a summary of the changes in each version.

## [1.0.4]

### Fixes

* Raise a clear error when a level 2 cache service, which is needed, is not available.

## [1.0.3]

### Fixes
Expand Down
20 changes: 19 additions & 1 deletion pcg_skel/chunk_cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
import numpy as np
import orjson
from sqlitedict import SqliteDict
from cachetools import LRUCache, cached
from cachetools.keys import hashkey

POSITION_ATTRIBUTE = "rep_coord_nm"


class NoL2CacheException(Exception):
pass


def cachekey(client):
return hashkey(client.datastack_name)


@cached(LRUCache(16), key=cachekey)
def check_l2cache(client):
return client.l2cache.has_cache()


def get_locs_remote(l2_ids, client):
"""Retrieve ids from the l2 cache service"""
if check_l2cache(client) is False:
raise NoL2CacheException(
f"No L2 Cache service is running for datastack {client.datastack_name} and you cannot use PCGSkel without an L2 Cache. Contact your admin for more information."
)
l2_info = client.l2cache.get_l2data(list(l2_ids), attributes=[POSITION_ATTRIBUTE])
l2loc = [l2_info[str(l2id)].get(POSITION_ATTRIBUTE, None) for l2id in l2_ids]

Expand Down Expand Up @@ -59,7 +78,6 @@ def save_ids_to_cache(l2_ids, l2_locs, cache_file):
cache_file : str
"""
ii = 0
with SqliteDict(cache_file, encode=orjson.dumps, flag="c") as cache_dict:
for k, v in zip(l2_ids, l2_locs):
if not np.any(np.isnan(v)):
Expand Down
40 changes: 38 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
base_path = pathlib.Path(__file__).parent.resolve()

TEST_DATASTACK = "minnie65_public"
TEST_DATASTACK_NOCACHE = "minnie65_public_nocache"
MAT_VERSION = 795

INFO_CACHE = {
"minnie65_public": {
TEST_DATASTACK: {
"proofreading_review_table": None,
"description": "This is the publicly released version of the minnie65 volume and segmentation. ",
"proofreading_status_table": None,
Expand All @@ -34,7 +35,29 @@
"viewer_resolution_x": 4.0,
"viewer_resolution_y": 4.0,
"viewer_resolution_z": 40.0,
}
},
TEST_DATASTACK_NOCACHE: {
"proofreading_review_table": None,
"description": "This is the publicly released version of the minnie65 volume and segmentation. ",
"proofreading_status_table": None,
"cell_identification_table": None,
"local_server": "https://minnie.microns-daf.com",
"aligned_volume": {
"description": "This is the second alignment of the IARPA 'minnie65' dataset, completed in the spring of 2020 that used the seamless approach.",
"name": "minnie65_phase3",
"id": 1,
"image_source": "precomputed://https://bossdb-open-data.s3.amazonaws.com/iarpa_microns/minnie/minnie65/em",
"display_name": "Minnie65",
},
"synapse_table": "synapses_pni_2",
"viewer_site": "https://neuroglancer.neuvue.io",
"analysis_database": None,
"segmentation_source": "graphene://https://minnie.microns-daf.com/segmentation/table/minnie65_public",
"soma_table": "nucleus_detection_v0",
"viewer_resolution_x": 4.0,
"viewer_resolution_y": 4.0,
"viewer_resolution_z": 40.0,
},
}


Expand Down Expand Up @@ -75,14 +98,27 @@ def test_client(mocker):
client = CAVEclient(TEST_DATASTACK, info_cache=INFO_CACHE)
mocker.patch.object(client.info, "segmentation_cloudvolume", return_value=test_cv)
mocker.patch.object(client.l2cache, "get_l2data", return_value=test_l2ids)
mocker.patch.object(client.l2cache, "has_cache", return_value=True)
mocker.patch.object(
client.chunkedgraph, "level2_chunk_graph", return_value=test_l2graph
)
synapse_table = mocker.PropertyMock(return_value="synapses_pni_2")
type(client.materialize).synapse_table = synapse_table
mocker.patch.object(client.materialize, "get_versions", return_value=[1])
mocker.patch.object(client.materialize, "get_timestamp", return_value="1234")
mocker.patch(
"pcg_skel.pcg_anno.get_level2_synapses",
return_value=(test_pre_synapses, test_post_synapses),
)
return client


@pytest.fixture()
def test_client_nol2cache(mocker):
client = CAVEclient(TEST_DATASTACK_NOCACHE, info_cache=INFO_CACHE)
mocker.patch.object(client.info, "segmentation_cloudvolume", return_value=test_cv)
mocker.patch.object(client.l2cache, "has_cache", return_value=False)
mocker.patch.object(
client.chunkedgraph, "level2_chunk_graph", return_value=test_l2graph
)
return client
14 changes: 13 additions & 1 deletion tests/test_pcg_skel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
import pcg_skel
from pcg_skel.chunk_cache import NoL2CacheException
import numpy as np

from conftest import test_client
from conftest import test_client, test_client_nol2cache
from conftest import root_id, center_pt


Expand Down Expand Up @@ -74,3 +75,14 @@ def test_defunct_meshwork(test_client, root_id, center_pt):
)
assert len(nrn2.anno.table_names) > 0
assert nrn2.mesh.vertices.shape[0] > 0


def test_pcg_meshwork_noclient(test_client_nol2cache, root_id, center_pt):
with pytest.raises(NoL2CacheException):
pcg_skel.pcg_skeleton(
root_id,
test_client_nol2cache,
collapse_radius=True,
root_point=center_pt,
root_point_resolution=[4, 4, 40],
)

0 comments on commit 6a51abb

Please sign in to comment.