Skip to content

Commit 7e7914b

Browse files
committed
Update mock up for validation data/optional data api
1 parent b025edd commit 7e7914b

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

src/geff/geff_reader.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def read_to_dict(
190190
validate: bool = True,
191191
node_props: list[str] | None = None,
192192
edge_props: list[str] | None = None,
193+
validate_data: bool = False,
194+
validate_optional_data: utils.ValidationConfig | None = None,
193195
) -> GraphDict:
194196
"""
195197
Read a GEFF zarr file to a dictionary representation.
@@ -200,9 +202,13 @@ def read_to_dict(
200202
Args:
201203
source (str | Path | zarr store): Either a path to the root of the geff zarr
202204
(where the .attrs contains the geff metadata), or a zarr store object
203-
validate (bool, optional): Flag indicating whether to perform validation on the
204-
geff file before loading into memory. If set to False and there are
205-
format issues, will likely fail with a cryptic error. Defaults to True.
205+
validate (bool, optional): Flag indicating whether to perform metadata/structure
206+
validation on the geff file before loading into memory. If set to False and
207+
there are format issues, will likely fail with a cryptic error. Defaults to True.
208+
validate_data (bool, optional): Flag indicating whether to perform validation on the
209+
underlying data of the geff, e.g. edges. Defaults to False.
210+
validate_optional_data (ValidationConfig, optional): Optional configuration for which
211+
optional properties to validate. Defaults to None and validation does not occur.
206212
node_props (list of str, optional): The names of the node properties to load,
207213
if None all properties will be loaded, defaults to None.
208214
edge_props (list of str, optional): The names of the edge properties to load,
@@ -218,4 +224,11 @@ def read_to_dict(
218224
file_reader.read_edge_props(edge_props)
219225

220226
graph_dict = file_reader.build()
227+
228+
if validate_data:
229+
utils.validate_zarr_data(graph_dict)
230+
231+
if validate_optional_data is not None:
232+
utils.validate_optional_data(config=validate_optional_data, graph_dict=graph_dict)
233+
221234
return graph_dict

src/geff/utils.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import numpy as np
88
import zarr
9+
from pydantic import BaseModel
910

1011
if TYPE_CHECKING:
1112
from zarr.storage import StoreLike
@@ -102,9 +103,35 @@ def validate_zarr_data(graph_dict: GraphDict):
102103
graph_dict (GraphDict): A graphdict object which contains metadata and
103104
dictionaries of node/edge property arrays
104105
"""
105-
graph_dict["metadata"]
106+
# TODO add edge validation
107+
pass
106108

107-
# TODO: Test various properties based on what is present in the metadata
109+
110+
class ValidationConfig(BaseModel):
111+
sphere: bool = False
112+
ellipsoid: bool = False
113+
lineage: bool = False
114+
tracklet: bool = False
115+
116+
117+
def validate_optional_data(config: ValidationConfig, graph_dict: GraphDict):
118+
"""Run data validation on optional data types based on the input
119+
120+
Args:
121+
config (ValidationConfig): Configuration for which validation to run
122+
graph_dict (GraphDict): A graphdict object which contains metadata and
123+
dictionaries of node/edge property arrays
124+
"""
125+
meta = graph_dict["metadata"]
126+
if config.sphere and meta.sphere is not None:
127+
pass
128+
if config.ellipsoid and meta.ellipsoid is not None:
129+
pass
130+
if meta.track_node_props is not None:
131+
if config.lineage and "lineage" in meta.track_node_props:
132+
pass
133+
if config.lineage and "tracklet" in meta.track_node_props:
134+
pass
108135

109136

110137
def validate_graph_group(group: zarr.Group, type: Literal["node", "edge"]):

0 commit comments

Comments
 (0)