API¶
A tutorial-like presentation is available at Examples using API.
The core public API is:
graynet.extractfor single-feature edge runsgraynet.extract_multiedgefor multi-feature runs with summary edgesgraynet.roiwise_stats_indivfor ROI-wise summary statisticsgraynet.load_runand related helpers for reading canonical run outputs
graynet 2.0 writes canonical run-level outputs in Parquet plus JSON metadata. GraphML and CSV are now optional exports derived from those canonical tables.
API Reference¶
- graynet.api.extract(subject_id_list, input_dir, base_feature=('freesurfer_thickness',), weight_method_list=('manhattan',), num_bins=25, edge_range=None, atlas='fsaverage', smoothing_param=10, node_size=None, out_dir=None, return_results=False, num_procs=2)[source]¶
Compute single-feature edge weights for one or more subjects.
Parameters mirror the classic graynet API, but outputs now follow the 2.0 run-level layout. When
out_diris provided, graynet writes a canonical run directory containingrun_metadata.jsonandedges_raw.parquet. Whenreturn_resultsisTrue, a mapping of(weight_method, subject_id) -> edge_vectoris returned in addition to writing the run outputs.
- graynet.api.extract_multiedge(subject_id_list, input_dir, base_feature_list=('freesurfer_thickness', 'freesurfer_curv'), weight_method_list=('manhattan',), summary_stats=('prod', 'median'), num_bins=25, edge_range_dict={'freesurfer_area': (0.0, 1.5), 'freesurfer_curv': (-0.3, 0.3), 'freesurfer_sulc': (-1.5, 1.5), 'freesurfer_thickness': (0.0, 5.0)}, atlas='fsaverage', smoothing_param=10, node_size=None, out_dir=None, return_results=False, overwrite_results=False, num_procs=2)[source]¶
Compute multi-feature edge tables and summary edges for one or more subjects.
Raw multi-edge rows are written to
edges_raw.parquetwith one row per(subject, base_feature, weight_method, u, v)combination. Requested summary statistics across features are written toedges_summary.parquet.When
return_resultsisTrue, the returned mapping uses keys of the form(weight_method, base_feature, subject_id).
- graynet.api.roiwise_stats_indiv(subject_id_list, input_dir, base_feature=('freesurfer_thickness',), chosen_roi_stats='median', atlas='fsaverage', smoothing_param=10, node_size=None, out_dir=None, return_results=False, num_procs=2)[source]¶
Compute ROI-wise summary statistics for one or more subjects.
Canonical outputs are written to
roi_stats.parquetin a run directory. Whenreturn_resultsisTrue, the returned mapping is keyed by(stat_name, subject_id)when multiple statistics are requested, or bysubject_idwhen only one statistic is requested.
- class graynet.results.EdgeData(table: Table, metadata: dict[str, Any])[source]¶
Bases:
objectCanonical edge table plus run metadata.
EdgeDatais the primary read-side helper for graynet 2.0 results. It wraps a Parquet-backed table and provides convenient filtering, subject-wise iteration, graph reconstruction, and conversion to dense subject-by-edge matrices for downstream analysis.- filter(subject_id: str | Sequence[str] | None = None, base_feature: str | None = None, weight_method: str | None = None, summary_stat: str | None = None) EdgeData[source]¶
Return a filtered view of the edge table.
- iter_subjects() Iterator[tuple[str, EdgeData]][source]¶
Yield
(subject_id, edge_rows_for_subject)usingstable_subject_ids()order.
- stable_subject_ids() list[str][source]¶
Subject IDs present in this table, in a defined (stabilized) order.
Order is not arbitrary Parquet row order: IDs from run metadata
subject_idscome first when they appear in the table (preserving that list’s order), then any IDs found only in the table, in first-seen column order.Note
This ordering is intentional for iteration and analysis, but it is not yet guaranteed as a stable public contract across graynet releases or if on-disk layout / metadata conventions change.
- table: Table¶
- to_ndarray(subject_ids: Sequence[str], base_feature: str | None = None, weight_method: str | None = None, summary_stat: str | None = None, fill_value: float = nan) ndarray[source]¶
Convert edge rows into a dense
Xmatrix.Rows follow the exact order of
subject_ids. Columns follow the run’snode_labelsmetadata order, using the upper-triangular edge ordering implied by(u, v)pairs.
- class graynet.results.RoiStatsData(table: Table, metadata: dict[str, Any])[source]¶
Bases:
objectCanonical ROI-statistics table plus run metadata.
- filter(subject_id: str | None = None, base_feature: str | None = None, stat_name: str | None = None) RoiStatsData[source]¶
- table: Table¶
- class graynet.results.RunData(run_dir: Path, metadata: dict[str, Any], raw_edges: EdgeData | None = None, summary_edges: EdgeData | None = None, roi_stats: RoiStatsData | None = None)[source]¶
Bases:
objectLoaded graynet run directory.
RunDatacontains run metadata plus any available canonical result tables: raw edges, summary edges, and ROI statistics.- roi_stats: RoiStatsData | None = None¶
- graynet.results.export_to_nx(edge_data: EdgeData, metadata: dict[str, Any] | None = None) Graph[source]¶
Reconstruct a
networkx.Graphfrom an edge table view.Centroid metadata is added to nodes when available in run metadata.