Skip to content

Commit 41dcf22

Browse files
committed
Minor reorganization
1 parent 9583691 commit 41dcf22

File tree

9 files changed

+94
-64
lines changed

9 files changed

+94
-64
lines changed

docs/user_guide.md

Lines changed: 89 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,14 @@ keywords: HED tutorial, Python guide, validation examples, BIDS datasets,
1313
```{index} user guide, tutorial, getting started, HED, Hierarchical Event Descriptors
1414
```
1515

16-
HED (Hierarchical Event Descriptors) is a framework for systematically describing events and experimental metadata in machine-actionable form. This guide provides comprehensive documentation for using the HED Python tools for validation, BIDS integration, and analysis:
16+
HED (Hierarchical Event Descriptors) is a framework for systematically describing events and experimental metadata in machine-actionable form. This guide provides comprehensive documentation for using the HED Python tools for validation, BIDS integration, and analysis.
1717

18-
01. [What is HED?](#what-is-hed)
19-
02. [Getting started](#getting-started)
20-
03. [Working with HED schemas](#working-with-hed-schemas)
21-
04. [Validating HED strings](#validating-hed-strings)
22-
05. [Working with BIDS datasets](#working-with-bids-datasets)
23-
06. [Working with sidecars](#working-with-sidecars)
24-
07. [Jupyter notebooks](#jupyter-notebooks)
25-
08. [Command-line tools](#command-line-tools)
26-
09. [Best practices](#best-practices)
27-
10. [Troubleshooting](#troubleshooting)
28-
29-
## Getting started
18+
## Installation
3019

3120
```{index} installation, pip, PyPI
3221
```
3322

34-
### Installation
35-
36-
#### From PyPI (recommended)
23+
### From PyPI (recommended)
3724

3825
Install the latest stable release:
3926

@@ -43,7 +30,7 @@ pip install hedtools
4330

4431
**Note**: The PyPI package includes the core hedtools library but **not the example Jupyter notebooks**. To access the notebooks, see the options below.
4532

46-
#### For Jupyter notebook examples
33+
### For Jupyter notebook examples
4734

4835
The example notebooks are only available in the GitHub repository. Choose one of these options:
4936

@@ -66,7 +53,7 @@ pip install hedtools jupyter notebook
6653

6754
See [examples/README.md](https://github.com/hed-standard/hed-python/tree/main/examples) for detailed notebook documentation.
6855

69-
#### From GitHub (latest development version)
56+
### From GitHub (latest development version)
7057

7158
```bash
7259
pip install git+https://github.com/hed-standard/hed-python/@main
@@ -82,13 +69,15 @@ cd hed-python
8269
pip install -e .
8370
```
8471

85-
#### Python requirements
72+
### Python requirements
8673

8774
- **Python 3.10 or later** is required
8875
- Core dependencies: pandas, numpy, defusedxml, openpyxl
8976
- Jupyter support: Install with `pip install jupyter notebook`
9077

91-
### Basic example
78+
## Basic usage
79+
80+
### A starter example
9281

9382
Here's a simple example to get you started with HED validation:
9483

@@ -110,12 +99,12 @@ else:
11099
print("✓ HED string is valid!")
111100
```
112101

113-
## Working with HED schemas
102+
### Loading schemas
114103

115104
```{index} schema; loading, schema; validation, load_schema, load_schema_version
116105
```
117106

118-
### Loading schemas
107+
A HED schema specifies an allowed HED vocabulary. The official HED schemas are hosted in the [hed-standard/hed-schemas](https://github.com/hed-standard/hed-schemas) GitHub repository. Most HEDTools operations require that you specify which versions of the HED schemas that you are using. You may also specify a file with your own schema for testing and development. The HEDTools assume that the HED schema that you are using has been validated.
119108

120109
```python
121110
from hed import load_schema, load_schema_version
@@ -153,13 +142,11 @@ schema = load_schema_version(["score_2.1.0", "lang_1.1.0"])
153142

154143
Note: It is now standard for a library schema to be partnered with a standard schema. In general, you should not use an earlier, non-partnered versions of a library schema.
155144

156-
## Validating HED strings
145+
### Validating HED strings
157146

158147
```{index} validation; HED strings, HedString class, validate method
159148
```
160149

161-
### Basic validation
162-
163150
The HED string must be created with a schema, and validation is performed on the string object:
164151

165152
```python
@@ -172,34 +159,11 @@ issues = hed_string.validate()
172159

173160
```
174161

175-
### Batch validation
176-
177-
```python
178-
from hed import HedString, load_schema_version, get_printable_issue_string
179-
180-
181-
schema = load_schema_version("8.4.0")
182-
183-
hed_strings = [
184-
"Sensory-event, Visual-presentation",
185-
"Invalid-tag, Another-invalid",
186-
"(Red, Square)"
187-
]
188-
issues = []
189-
for i, hed_str in enumerate(hed_strings, 1):
190-
hed_string = HedString(hed_str, schema)
191-
issues += hed_string.validate()
192-
if issues:
193-
print(get_printable_issue_string(issues))
194-
```
195-
196-
## Working with BIDS datasets
162+
### Validating a BIDS dataset
197163

198164
```{index} BIDS; dataset validation, BidsDataset class, dataset_description.json
199165
```
200166

201-
### Dataset-level validation
202-
203167
```python
204168
from hed.tools import BidsDataset
205169

@@ -221,7 +185,7 @@ issues = dataset.validate(check_for_warnings=True)
221185

222186
Since a BIDS dataset includes the HED version in its `dataset_description.json`, a HED version is not necessary for validation. The `BidsDataset` only holds information about the relevant `.tsv` and `.json` files, not the imaging data. The constructor has a number of parameters that restrict which of these files are considered. The relevant JSON files are all read in, but the `.tsv` content is only loaded when needed.
223187

224-
### Working with individual event files
188+
### Validating a tabular file
225189

226190
```{index} TabularInput, event files, tsv files
227191
```
@@ -246,12 +210,14 @@ issues = tabular.validate(schema)
246210
def_dict = tabular.get_def_dict(schema)
247211
```
248212

249-
## Working with sidecars
213+
### Using sidecars
250214

251215
```{index} Sidecar class, JSON sidecar, sidecar validation
252216
```
253217

254-
### Loading and validating sidecars
218+
Sidecars are JSON files that are a BIDS mechanism for containing metadata. NWB has an equivalent mechanism.
219+
220+
#### Validating a sidecar
255221

256222
```python
257223
from hed import Sidecar, load_schema_version
@@ -266,7 +232,7 @@ sidecar = Sidecar("task-rest_events.json")
266232
issues = sidecar.validate(schema)
267233
```
268234

269-
### Extracting definitions
235+
#### Extracting definitions
270236

271237
```{index} definitions, DefinitionDict, get_def_dict
272238
```
@@ -282,7 +248,7 @@ sidecar = Sidecar("task-rest_events.json")
282248
def_dict = sidecar.get_def_dict(schema)
283249
```
284250

285-
### Saving sidecars
251+
#### Saving sidecars
286252

287253
```python
288254
from hed import Sidecar
@@ -296,6 +262,75 @@ sidecar.save_as_json("output_sidecar.json")
296262
json_string = sidecar.get_as_json_string()
297263
```
298264

265+
### Schema validation
266+
267+
```{index} schema validation, check_compliance, SchemaValidator, ComplianceSummary
268+
```
269+
270+
HED schemas can be validated for compliance — checking that attribute domains, ranges, and semantic rules are all satisfied. There are three levels of access depending on how much control you need.
271+
272+
#### Quick check via HedSchema
273+
274+
The simplest approach calls `check_compliance()` directly on a loaded schema. It returns a list of issue dictionaries in the standard HED issue format, so you can use `get_printable_issue_string` just like any other HED validation result:
275+
276+
```python
277+
from hed import load_schema_version
278+
from hed.errors import get_printable_issue_string
279+
280+
schema = load_schema_version("8.4.0")
281+
issues = schema.check_compliance()
282+
if issues:
283+
print(get_printable_issue_string(issues, title="Schema compliance issues"))
284+
else:
285+
print("Schema is compliant")
286+
```
287+
288+
Pass `check_for_warnings=False` to suppress formatting warnings and report only errors:
289+
290+
```python
291+
issues = schema.check_compliance(check_for_warnings=False)
292+
```
293+
294+
#### Getting a structured summary
295+
296+
The returned list carries a `compliance_summary` attribute (`ComplianceSummary`) that provides a human-readable report of what was checked:
297+
298+
```python
299+
issues = schema.check_compliance()
300+
print(issues.compliance_summary.get_summary())
301+
```
302+
303+
The summary shows each of the five checks (prerelease version, prologue/epilogue, invalid characters, attributes, and duplicate names) with pass/fail status, entry counts, and sub-check details.
304+
305+
#### Using SchemaValidator directly
306+
307+
For fine-grained control you can instantiate `SchemaValidator` and run individual checks:
308+
309+
```python
310+
from hed.errors.error_reporter import ErrorHandler
311+
from hed.schema.schema_validation.compliance import SchemaValidator
312+
313+
schema = load_schema_version("8.4.0")
314+
error_handler = ErrorHandler(check_for_warnings=True)
315+
sv = SchemaValidator(schema, error_handler)
316+
317+
# Run only the checks you need
318+
issues = sv.check_attributes()
319+
issues += sv.check_invalid_characters()
320+
```
321+
322+
The five available checks are:
323+
324+
| Method | What it validates |
325+
| ------------------------------- | -------------------------------------------------------- |
326+
| `check_if_prerelease_version()` | Warns if the version is newer than all known releases |
327+
| `check_prologue_epilogue()` | Validates characters in prologue and epilogue text |
328+
| `check_invalid_characters()` | Validates entry names and descriptions for illegal chars |
329+
| `check_attributes()` | Domain, range, and semantic validation of all attributes |
330+
| `check_duplicate_names()` | Detects duplicate entry names within or across libraries |
331+
332+
Each method returns a list of issue dictionaries and updates `sv.summary` (a `ComplianceSummary` instance) with what was checked.
333+
299334
## Jupyter notebooks
300335

301336
```{index} Jupyter notebooks, examples, workflows

hed/schema/schema_validation_util.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

hed/scripts/add_hed_ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hed.scripts.hed_script_util import get_prerelease_path
1+
from hed.scripts.schema_script_util import get_prerelease_path
22
from hed.scripts.hed_convert_schema import convert_and_update
33
import argparse
44
from hed.schema.schema_io.df_util import convert_filenames_to_dict

hed/scripts/hed_convert_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from hed.scripts.hed_script_util import sort_base_schemas, validate_all_schemas, add_extension
1+
from hed.scripts.schema_script_util import sort_base_schemas, validate_all_schemas, add_extension
22
from hed.schema.schema_io import load_dataframes, save_dataframes
33
from hed.schema.schema_io.hed_id_util import update_dataframes_from_schema
44
from hed.schema.hed_schema_io import load_schema, from_dataframes

hed/scripts/validate_schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sys
2-
from hed.scripts.hed_script_util import validate_all_schemas, sort_base_schemas
2+
from hed.scripts.schema_script_util import validate_all_schemas, sort_base_schemas
33
from hed.errors import get_printable_issue_string
44
import argparse
55

hed/validator/util/class_util.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ def _get_problem_indices(self, stripped_value, class_name, start_index=0):
109109
if indices:
110110
indices = [(char, index + start_index) for index, char in indices]
111111
return indices
112-
# value_classes = original_tag.value_classes.values()
113-
# allowed_characters = schema_validation_util.get_allowed_characters(original_tag.value_classes.values())
114112

115113
def _check_value_class(self, original_tag, stripped_value, report_as):
116114
"""Return any issues found if this is a value tag,

tests/scripts/test_hed_convert_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from hed import load_schema, load_schema_version
66
from hed.schema import HedSectionKey, HedKey
7-
from hed.scripts.hed_script_util import add_extension
7+
from hed.scripts.schema_script_util import add_extension
88
from hed.scripts.hed_convert_schema import convert_and_update
99
import contextlib
1010

tests/scripts/test_script_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import shutil
44
from hed import load_schema_version
5-
from hed.scripts.hed_script_util import (
5+
from hed.scripts.schema_script_util import (
66
add_extension,
77
sort_base_schemas,
88
validate_all_schema_formats,

0 commit comments

Comments
 (0)