brkraw 0.3.11__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. brkraw/__init__.py +9 -3
  2. brkraw/apps/__init__.py +12 -0
  3. brkraw/apps/addon/__init__.py +30 -0
  4. brkraw/apps/addon/core.py +35 -0
  5. brkraw/apps/addon/dependencies.py +402 -0
  6. brkraw/apps/addon/installation.py +500 -0
  7. brkraw/apps/addon/io.py +21 -0
  8. brkraw/apps/hook/__init__.py +25 -0
  9. brkraw/apps/hook/core.py +636 -0
  10. brkraw/apps/loader/__init__.py +10 -0
  11. brkraw/apps/loader/core.py +622 -0
  12. brkraw/apps/loader/formatter.py +288 -0
  13. brkraw/apps/loader/helper.py +797 -0
  14. brkraw/apps/loader/info/__init__.py +11 -0
  15. brkraw/apps/loader/info/scan.py +85 -0
  16. brkraw/apps/loader/info/scan.yaml +90 -0
  17. brkraw/apps/loader/info/study.py +69 -0
  18. brkraw/apps/loader/info/study.yaml +156 -0
  19. brkraw/apps/loader/info/transform.py +92 -0
  20. brkraw/apps/loader/types.py +220 -0
  21. brkraw/cli/__init__.py +5 -0
  22. brkraw/cli/commands/__init__.py +2 -0
  23. brkraw/cli/commands/addon.py +327 -0
  24. brkraw/cli/commands/config.py +205 -0
  25. brkraw/cli/commands/convert.py +903 -0
  26. brkraw/cli/commands/hook.py +348 -0
  27. brkraw/cli/commands/info.py +74 -0
  28. brkraw/cli/commands/init.py +214 -0
  29. brkraw/cli/commands/params.py +106 -0
  30. brkraw/cli/commands/prune.py +288 -0
  31. brkraw/cli/commands/session.py +371 -0
  32. brkraw/cli/hook_args.py +80 -0
  33. brkraw/cli/main.py +83 -0
  34. brkraw/cli/utils.py +60 -0
  35. brkraw/core/__init__.py +13 -0
  36. brkraw/core/config.py +380 -0
  37. brkraw/core/entrypoints.py +25 -0
  38. brkraw/core/formatter.py +367 -0
  39. brkraw/core/fs.py +495 -0
  40. brkraw/core/jcamp.py +600 -0
  41. brkraw/core/layout.py +451 -0
  42. brkraw/core/parameters.py +781 -0
  43. brkraw/core/zip.py +1121 -0
  44. brkraw/dataclasses/__init__.py +14 -0
  45. brkraw/dataclasses/node.py +139 -0
  46. brkraw/dataclasses/reco.py +33 -0
  47. brkraw/dataclasses/scan.py +61 -0
  48. brkraw/dataclasses/study.py +131 -0
  49. brkraw/default/__init__.py +3 -0
  50. brkraw/default/pruner_specs/deid4share.yaml +42 -0
  51. brkraw/default/rules/00_default.yaml +4 -0
  52. brkraw/default/specs/metadata_dicom.yaml +236 -0
  53. brkraw/default/specs/metadata_transforms.py +92 -0
  54. brkraw/resolver/__init__.py +7 -0
  55. brkraw/resolver/affine.py +539 -0
  56. brkraw/resolver/datatype.py +69 -0
  57. brkraw/resolver/fid.py +90 -0
  58. brkraw/resolver/helpers.py +36 -0
  59. brkraw/resolver/image.py +188 -0
  60. brkraw/resolver/nifti.py +370 -0
  61. brkraw/resolver/shape.py +235 -0
  62. brkraw/schema/__init__.py +3 -0
  63. brkraw/schema/context_map.yaml +62 -0
  64. brkraw/schema/meta.yaml +57 -0
  65. brkraw/schema/niftiheader.yaml +95 -0
  66. brkraw/schema/pruner.yaml +55 -0
  67. brkraw/schema/remapper.yaml +128 -0
  68. brkraw/schema/rules.yaml +154 -0
  69. brkraw/specs/__init__.py +10 -0
  70. brkraw/specs/hook/__init__.py +12 -0
  71. brkraw/specs/hook/logic.py +31 -0
  72. brkraw/specs/hook/validator.py +22 -0
  73. brkraw/specs/meta/__init__.py +5 -0
  74. brkraw/specs/meta/validator.py +156 -0
  75. brkraw/specs/pruner/__init__.py +15 -0
  76. brkraw/specs/pruner/logic.py +361 -0
  77. brkraw/specs/pruner/validator.py +119 -0
  78. brkraw/specs/remapper/__init__.py +27 -0
  79. brkraw/specs/remapper/logic.py +924 -0
  80. brkraw/specs/remapper/validator.py +314 -0
  81. brkraw/specs/rules/__init__.py +6 -0
  82. brkraw/specs/rules/logic.py +263 -0
  83. brkraw/specs/rules/validator.py +103 -0
  84. brkraw-0.5.0.dist-info/METADATA +81 -0
  85. brkraw-0.5.0.dist-info/RECORD +88 -0
  86. {brkraw-0.3.11.dist-info → brkraw-0.5.0.dist-info}/WHEEL +1 -2
  87. brkraw-0.5.0.dist-info/entry_points.txt +13 -0
  88. brkraw/lib/__init__.py +0 -4
  89. brkraw/lib/backup.py +0 -641
  90. brkraw/lib/bids.py +0 -0
  91. brkraw/lib/errors.py +0 -125
  92. brkraw/lib/loader.py +0 -1220
  93. brkraw/lib/orient.py +0 -194
  94. brkraw/lib/parser.py +0 -48
  95. brkraw/lib/pvobj.py +0 -301
  96. brkraw/lib/reference.py +0 -245
  97. brkraw/lib/utils.py +0 -471
  98. brkraw/scripts/__init__.py +0 -0
  99. brkraw/scripts/brk_backup.py +0 -106
  100. brkraw/scripts/brkraw.py +0 -744
  101. brkraw/ui/__init__.py +0 -0
  102. brkraw/ui/config.py +0 -17
  103. brkraw/ui/main_win.py +0 -214
  104. brkraw/ui/previewer.py +0 -225
  105. brkraw/ui/scan_info.py +0 -72
  106. brkraw/ui/scan_list.py +0 -73
  107. brkraw/ui/subj_info.py +0 -128
  108. brkraw-0.3.11.dist-info/METADATA +0 -25
  109. brkraw-0.3.11.dist-info/RECORD +0 -28
  110. brkraw-0.3.11.dist-info/entry_points.txt +0 -3
  111. brkraw-0.3.11.dist-info/top_level.txt +0 -2
  112. tests/__init__.py +0 -0
  113. {brkraw-0.3.11.dist-info → brkraw-0.5.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,57 @@
1
+ ---
2
+ $schema: "https://json-schema.org/draft/2020-12/schema"
3
+ title: "BrkRaw Spec Metadata"
4
+ type: object
5
+ additionalProperties: false
6
+ required:
7
+ - name
8
+ - version
9
+ - description
10
+ - category
11
+ properties:
12
+ name:
13
+ type: string
14
+ pattern: "^[a-z][a-z0-9]*(?:_[a-z0-9]+){0,3}$"
15
+ description: "Python-friendly identifier (max 4 tokens)."
16
+ version:
17
+ type: string
18
+ minLength: 1
19
+ description:
20
+ type: string
21
+ minLength: 1
22
+ category:
23
+ type: string
24
+ minLength: 1
25
+ authors:
26
+ type: array
27
+ items:
28
+ $ref: "#/$defs/person"
29
+ minItems: 1
30
+ developers:
31
+ type: array
32
+ items:
33
+ $ref: "#/$defs/person"
34
+ minItems: 1
35
+ doi:
36
+ type: string
37
+ citation:
38
+ type: string
39
+ $defs:
40
+ person:
41
+ type: object
42
+ additionalProperties: false
43
+ required:
44
+ - name
45
+ properties:
46
+ name:
47
+ type: string
48
+ minLength: 1
49
+ email:
50
+ type: string
51
+ minLength: 1
52
+ affiliations:
53
+ type: array
54
+ items:
55
+ type: string
56
+ minLength: 1
57
+ minItems: 1
@@ -0,0 +1,95 @@
1
+ ---
2
+ $schema: "https://json-schema.org/draft/2020-12/schema"
3
+ title: "BrkRaw NIfTI Header Overrides"
4
+ type: object
5
+ additionalProperties: false
6
+ properties:
7
+ flip_x:
8
+ type: boolean
9
+ slice_code:
10
+ type: integer
11
+ slope_inter:
12
+ type: array
13
+ items:
14
+ type: number
15
+ minItems: 2
16
+ maxItems: 2
17
+ time_step:
18
+ type:
19
+ - number
20
+ - "null"
21
+ slice_duration:
22
+ type:
23
+ - number
24
+ - "null"
25
+ xyzt_unit:
26
+ type: array
27
+ items:
28
+ - $ref: "#/$defs/xyz_unit"
29
+ - $ref: "#/$defs/t_unit"
30
+ minItems: 2
31
+ maxItems: 2
32
+ qform:
33
+ $ref: "#/$defs/matrix4x4"
34
+ sform:
35
+ $ref: "#/$defs/matrix4x4"
36
+ qform_code:
37
+ type: integer
38
+ sform_code:
39
+ type: integer
40
+ dim_info:
41
+ type: array
42
+ items:
43
+ type:
44
+ - integer
45
+ - "null"
46
+ minItems: 3
47
+ maxItems: 3
48
+ slice_start:
49
+ type: integer
50
+ slice_end:
51
+ type: integer
52
+ intent_code:
53
+ type: integer
54
+ intent_name:
55
+ type: string
56
+ descrip:
57
+ type: string
58
+ aux_file:
59
+ type: string
60
+ cal_min:
61
+ type: number
62
+ cal_max:
63
+ type: number
64
+ pixdim:
65
+ type: array
66
+ items:
67
+ type: number
68
+ minItems: 1
69
+ $defs:
70
+ xyz_unit:
71
+ type: string
72
+ enum:
73
+ - unknown
74
+ - meter
75
+ - mm
76
+ - micron
77
+ t_unit:
78
+ type: string
79
+ enum:
80
+ - sec
81
+ - msec
82
+ - usec
83
+ - hz
84
+ - ppm
85
+ - rads
86
+ matrix4x4:
87
+ type: array
88
+ minItems: 4
89
+ maxItems: 4
90
+ items:
91
+ type: array
92
+ minItems: 4
93
+ maxItems: 4
94
+ items:
95
+ type: number
@@ -0,0 +1,55 @@
1
+ ---
2
+ $schema: "https://json-schema.org/draft/2020-12/schema"
3
+ title: "BrkRaw Pruner Spec"
4
+ type: object
5
+ additionalProperties: false
6
+ properties:
7
+ __meta__:
8
+ type: object
9
+ additionalProperties: true
10
+ files:
11
+ type: array
12
+ minItems: 1
13
+ items:
14
+ type:
15
+ - string
16
+ - number
17
+ mode:
18
+ type: string
19
+ enum: ["keep", "drop"]
20
+ update_params:
21
+ type: object
22
+ additionalProperties:
23
+ type: object
24
+ additionalProperties:
25
+ type:
26
+ - string
27
+ - number
28
+ - boolean
29
+ - "null"
30
+ dirs:
31
+ type: array
32
+ items:
33
+ type: object
34
+ additionalProperties: false
35
+ required: ["level", "dirs"]
36
+ properties:
37
+ level:
38
+ type: integer
39
+ minimum: 1
40
+ dirs:
41
+ type: array
42
+ minItems: 1
43
+ items:
44
+ type:
45
+ - string
46
+ - number
47
+ add_root:
48
+ type: boolean
49
+ root_name:
50
+ type: string
51
+ strip_jcamp_comments:
52
+ type: boolean
53
+ required:
54
+ - __meta__
55
+ - files
@@ -0,0 +1,128 @@
1
+ $schema: "https://json-schema.org/draft/2020-12/schema"
2
+ title: "BrkRaw Parameter Mapping Spec"
3
+ description: "Map Bruker parameter files into a structured output dict."
4
+ type: object
5
+ properties:
6
+ __meta__:
7
+ type: object
8
+ additionalProperties: true
9
+ properties:
10
+ transforms_source:
11
+ anyOf:
12
+ - type: string
13
+ - type: array
14
+ items:
15
+ type: string
16
+ include:
17
+ anyOf:
18
+ - type: string
19
+ - type: array
20
+ items:
21
+ type: string
22
+ include_mode:
23
+ type: string
24
+ enum:
25
+ - override
26
+ - strict
27
+ required:
28
+ - __meta__
29
+ additionalProperties:
30
+ $ref: "#/$defs/Rule"
31
+
32
+ $defs:
33
+ Rule:
34
+ type: object
35
+ properties:
36
+ sources:
37
+ type: array
38
+ items: { $ref: "#/$defs/SourceItem" }
39
+ description: "Ordered list of sources to resolve a single output value."
40
+ inputs:
41
+ type: object
42
+ additionalProperties: { $ref: "#/$defs/Input" }
43
+ description: "Named inputs that are passed to a transform or returned as-is."
44
+ const: {}
45
+ ref:
46
+ type: string
47
+ description: "Dot path to a previously resolved output value."
48
+ transform:
49
+ anyOf:
50
+ - type: string
51
+ - type: array
52
+ items: { type: string }
53
+ description: "Transform name(s) to apply. Arrays execute in order."
54
+ default: {}
55
+ additionalProperties: false
56
+ oneOf:
57
+ - required: ["sources"]
58
+ - required: ["inputs"]
59
+ - required: ["const"]
60
+ - required: ["ref"]
61
+
62
+ Source:
63
+ type: object
64
+ properties:
65
+ file:
66
+ type: string
67
+ enum: ["method", "acqp", "visu_pars", "reco", "subject"]
68
+ description: "Parameter file namespace."
69
+ key:
70
+ type: string
71
+ description: "Key name in the parameter file."
72
+ reco_id:
73
+ type: integer
74
+ minimum: 1
75
+ description: "Reco id used when file targets reco-specific data."
76
+ required: ["file", "key"]
77
+ additionalProperties: false
78
+ SourceItem:
79
+ anyOf:
80
+ - $ref: "#/$defs/Source"
81
+ - $ref: "#/$defs/InlineInputs"
82
+
83
+ InlineInputs:
84
+ type: object
85
+ properties:
86
+ inputs:
87
+ type: object
88
+ additionalProperties: { $ref: "#/$defs/Input" }
89
+ description: "Named inputs that are passed to a transform or returned as-is."
90
+ transform:
91
+ anyOf:
92
+ - type: string
93
+ - type: array
94
+ items: { type: string }
95
+ description: "Transform name(s) to apply. Arrays execute in order."
96
+ additionalProperties: false
97
+ required: ["inputs"]
98
+
99
+ Input:
100
+ anyOf:
101
+ - type: string
102
+ pattern: "^\\$[A-Za-z_][A-Za-z0-9_]*$"
103
+ description: "Context variable reference (e.g., $scan_id)."
104
+ - type: object
105
+ properties:
106
+ sources:
107
+ type: array
108
+ items: { $ref: "#/$defs/Source" }
109
+ description: "Ordered list of sources to resolve an input value."
110
+ const: {}
111
+ ref:
112
+ type: string
113
+ description: "Dot path to a previously resolved output value."
114
+ transform:
115
+ anyOf:
116
+ - type: string
117
+ - type: array
118
+ items: { type: string }
119
+ description: "Transform name(s) to apply. Arrays execute in order."
120
+ default: {}
121
+ required:
122
+ type: boolean
123
+ description: "If true, missing input raises instead of returning None."
124
+ additionalProperties: false
125
+ oneOf:
126
+ - required: ["sources"]
127
+ - required: ["const"]
128
+ - required: ["ref"]
@@ -0,0 +1,154 @@
1
+ ---
2
+ $schema: "https://json-schema.org/draft/2020-12/schema"
3
+ title: "BrkRaw Rules"
4
+ type: object
5
+ properties:
6
+ info_spec:
7
+ $ref: "#/$defs/rule_list"
8
+ metadata_spec:
9
+ $ref: "#/$defs/rule_list"
10
+ converter_hook:
11
+ $ref: "#/$defs/rule_list"
12
+ additionalProperties: false
13
+ $defs:
14
+ rule_list:
15
+ type: array
16
+ items:
17
+ $ref: "#/$defs/rule"
18
+ rule:
19
+ type: object
20
+ properties:
21
+ name:
22
+ type: string
23
+ minLength: 1
24
+ description:
25
+ type: string
26
+ version:
27
+ type: string
28
+ when:
29
+ $ref: "#/$defs/when"
30
+ if:
31
+ $ref: "#/$defs/expr"
32
+ use:
33
+ type: string
34
+ minLength: 1
35
+ required:
36
+ - name
37
+ - use
38
+ additionalProperties: false
39
+ when:
40
+ type: object
41
+ minProperties: 1
42
+ additionalProperties:
43
+ $ref: "#/$defs/when_binding"
44
+ when_binding:
45
+ type: object
46
+ properties:
47
+ sources:
48
+ type: array
49
+ items:
50
+ $ref: "#/$defs/source"
51
+ minItems: 1
52
+ transform:
53
+ type: string
54
+ required:
55
+ - sources
56
+ additionalProperties: false
57
+ source:
58
+ type: object
59
+ properties:
60
+ file:
61
+ type: string
62
+ enum:
63
+ - method
64
+ - acqp
65
+ - visu_pars
66
+ - reco
67
+ - subject
68
+ key:
69
+ type: string
70
+ minLength: 1
71
+ reco_id:
72
+ type: integer
73
+ minimum: 1
74
+ required:
75
+ - file
76
+ - key
77
+ additionalProperties: false
78
+ expr:
79
+ oneOf:
80
+ - $ref: "#/$defs/expr_any"
81
+ - $ref: "#/$defs/expr_all"
82
+ - $ref: "#/$defs/expr_not"
83
+ - $ref: "#/$defs/expr_op"
84
+ expr_any:
85
+ type: object
86
+ properties:
87
+ any:
88
+ type: array
89
+ items:
90
+ $ref: "#/$defs/expr"
91
+ minItems: 1
92
+ required:
93
+ - any
94
+ additionalProperties: false
95
+ expr_all:
96
+ type: object
97
+ properties:
98
+ all:
99
+ type: array
100
+ items:
101
+ $ref: "#/$defs/expr"
102
+ minItems: 1
103
+ required:
104
+ - all
105
+ additionalProperties: false
106
+ expr_not:
107
+ type: object
108
+ properties:
109
+ not:
110
+ $ref: "#/$defs/expr"
111
+ required:
112
+ - not
113
+ additionalProperties: false
114
+ expr_op:
115
+ type: object
116
+ minProperties: 1
117
+ maxProperties: 1
118
+ properties:
119
+ eq:
120
+ $ref: "#/$defs/binop"
121
+ ne:
122
+ $ref: "#/$defs/binop"
123
+ in:
124
+ $ref: "#/$defs/inop"
125
+ regex:
126
+ $ref: "#/$defs/binop"
127
+ startswith:
128
+ $ref: "#/$defs/binop"
129
+ contains:
130
+ $ref: "#/$defs/binop"
131
+ always:
132
+ type: boolean
133
+ gt:
134
+ $ref: "#/$defs/binop"
135
+ ge:
136
+ $ref: "#/$defs/binop"
137
+ lt:
138
+ $ref: "#/$defs/binop"
139
+ le:
140
+ $ref: "#/$defs/binop"
141
+ additionalProperties: false
142
+ binop:
143
+ type: array
144
+ items: {}
145
+ minItems: 2
146
+ maxItems: 2
147
+ inop:
148
+ type: array
149
+ prefixItems:
150
+ - {}
151
+ - type: array
152
+ items: false
153
+ minItems: 2
154
+ maxItems: 2
@@ -0,0 +1,10 @@
1
+ from __future__ import annotations
2
+
3
+ from . import hook, pruner, remapper, rules
4
+
5
+ __all__ = [
6
+ "hook",
7
+ "pruner",
8
+ "remapper",
9
+ "rules",
10
+ ]
@@ -0,0 +1,12 @@
1
+ from __future__ import annotations
2
+
3
+ from .logic import DEFAULT_GROUP, resolve_hook
4
+ from .validator import validate_hook, CONVERTER_KEYS
5
+
6
+ __all__ = [
7
+ "CONVERTER_KEYS",
8
+ "DEFAULT_GROUP",
9
+ "resolve_hook",
10
+ "validate_hook",
11
+ ]
12
+
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, Callable, Dict, Union
5
+
6
+ from ...core.entrypoints import list_entry_points
7
+ from .validator import validate_hook
8
+
9
+ DEFAULT_GROUP = "brkraw.converter_hook"
10
+
11
+
12
+ def resolve_hook(
13
+ hook: Union[Mapping[str, Callable[..., Any]], str],
14
+ *,
15
+ group: str = DEFAULT_GROUP,
16
+ ) -> Dict[str, Callable[..., Any]]:
17
+ if isinstance(hook, str):
18
+ matches = list_entry_points(group, hook)
19
+ if not matches:
20
+ raise LookupError(
21
+ f"Converter hook not found: {hook!r} (group={group!r})"
22
+ )
23
+ entry = matches[0].load()
24
+ validate_hook(entry)
25
+ return dict(entry)
26
+ validate_hook(hook)
27
+ return dict(hook)
28
+
29
+
30
+ __all__ = ["DEFAULT_GROUP", "resolve_hook"]
31
+
@@ -0,0 +1,22 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping
4
+ from typing import Any, List
5
+
6
+ CONVERTER_KEYS = {"get_dataobj", "get_affine", "convert"}
7
+
8
+
9
+ def validate_hook(hook: Any, *, raise_on_error: bool = True) -> List[str]:
10
+ errors: List[str] = []
11
+ if not isinstance(hook, Mapping):
12
+ errors.append("converter_hook: must be a mapping.")
13
+ else:
14
+ for key, value in hook.items():
15
+ if key not in CONVERTER_KEYS:
16
+ errors.append(f"converter_hook: invalid key {key!r}.")
17
+ if not callable(value):
18
+ errors.append(f"converter_hook[{key!r}]: must be callable.")
19
+ if errors and raise_on_error:
20
+ raise ValueError("Invalid converter hook:\n" + "\n".join(errors))
21
+ return errors
22
+
@@ -0,0 +1,5 @@
1
+ from __future__ import annotations
2
+
3
+ from .validator import validate_meta
4
+
5
+ __all__ = ["validate_meta"]