arrayprobe 0.1.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.
- arrayprobe/__init__.py +219 -0
- arrayprobe/__main__.py +19 -0
- arrayprobe/_v314_lazy.py +48 -0
- arrayprobe/ai_ready.py +212 -0
- arrayprobe/attributed_export.py +1333 -0
- arrayprobe/authordefaults.py +267 -0
- arrayprobe/cli.py +3510 -0
- arrayprobe/combine.py +12 -0
- arrayprobe/compare.py +950 -0
- arrayprobe/config.py +1239 -0
- arrayprobe/constants.py +12 -0
- arrayprobe/count_closure.py +204 -0
- arrayprobe/diagnostic_views.py +769 -0
- arrayprobe/diode_report.py +265 -0
- arrayprobe/driver/__init__.py +5 -0
- arrayprobe/driver/_load_record.py +331 -0
- arrayprobe/driver/preflight_inputs.py +250 -0
- arrayprobe/driver/reprocess.py +553 -0
- arrayprobe/driver/run_flight.py +8166 -0
- arrayprobe/driver/tas_from_probe_housekeeping.py +124 -0
- arrayprobe/dropsize.py +519 -0
- arrayprobe/friendly.py +206 -0
- arrayprobe/geometry/__init__.py +77 -0
- arrayprobe/geometry/min_rectangle.py +92 -0
- arrayprobe/intarr.py +12 -0
- arrayprobe/intarr_analysis.py +16 -0
- arrayprobe/intarr_plots.py +12 -0
- arrayprobe/inventory.py +129 -0
- arrayprobe/jit_kernels.py +344 -0
- arrayprobe/lwc.py +44 -0
- arrayprobe/masks.py +349 -0
- arrayprobe/matio.py +410 -0
- arrayprobe/matlab_compat.py +13 -0
- arrayprobe/ncio.py +26 -0
- arrayprobe/particle.py +55 -0
- arrayprobe/particle_perimeter.py +12 -0
- arrayprobe/products.py +78 -0
- arrayprobe/profiles.py +179 -0
- arrayprobe/provenance.py +21 -0
- arrayprobe/py.typed +11 -0
- arrayprobe/readers/__init__.py +9 -0
- arrayprobe/readers/dmt.py +603 -0
- arrayprobe/readers/mask_csv.py +12 -0
- arrayprobe/readers/pms.py +12 -0
- arrayprobe/readers/sea.py +433 -0
- arrayprobe/readers/tasinfo.py +12 -0
- arrayprobe/regimes.py +507 -0
- arrayprobe/render.py +728 -0
- arrayprobe/reproduce_report.py +149 -0
- arrayprobe/review_agreement.py +135 -0
- arrayprobe/review_sampling.py +327 -0
- arrayprobe/run_page.py +624 -0
- arrayprobe/sample_area.py +12 -0
- arrayprobe/selector.py +206 -0
- arrayprobe/sizing.py +151 -0
- arrayprobe/time_convert.py +12 -0
- arrayprobe/timing_closure.py +141 -0
- arrayprobe/tools/__init__.py +27 -0
- arrayprobe/tools/make_demo_flight.py +1089 -0
- arrayprobe/tools/make_tas_file.py +760 -0
- arrayprobe/tools/probe_comparison.py +569 -0
- arrayprobe/tools/synthetic_truth.py +698 -0
- arrayprobe/tools/tas_sources.py +705 -0
- arrayprobe/triage_context.py +488 -0
- arrayprobe/triage_server.py +5215 -0
- arrayprobe/tune/__init__.py +15 -0
- arrayprobe/tune/diodes.py +400 -0
- arrayprobe/tune/distributions.py +300 -0
- arrayprobe/tune/sample.py +243 -0
- arrayprobe/tune/score.py +230 -0
- arrayprobe/tune/settings.py +354 -0
- arrayprobe/validate_by_condition.py +208 -0
- arrayprobe/validation_report.py +166 -0
- arrayprobe-0.1.0.dist-info/METADATA +260 -0
- arrayprobe-0.1.0.dist-info/RECORD +189 -0
- arrayprobe-0.1.0.dist-info/WHEEL +5 -0
- arrayprobe-0.1.0.dist-info/entry_points.txt +2 -0
- arrayprobe-0.1.0.dist-info/licenses/LICENSE +31 -0
- arrayprobe-0.1.0.dist-info/licenses/LICENSES/BSD-3-Clause.txt +47 -0
- arrayprobe-0.1.0.dist-info/licenses/NOTICE.md +369 -0
- arrayprobe-0.1.0.dist-info/top_level.txt +4 -0
- arrayprobe_soda2/__init__.py +131 -0
- arrayprobe_soda2/angles.py +143 -0
- arrayprobe_soda2/aspect_ratio.py +541 -0
- arrayprobe_soda2/backfill.py +100 -0
- arrayprobe_soda2/binary_dof.py +181 -0
- arrayprobe_soda2/buildindex.py +113 -0
- arrayprobe_soda2/decompress_dmt.py +285 -0
- arrayprobe_soda2/enhancement_hooks.py +275 -0
- arrayprobe_soda2/export_ascii.py +732 -0
- arrayprobe_soda2/export_ncdf.py +683 -0
- arrayprobe_soda2/export_ncdf_raf.py +396 -0
- arrayprobe_soda2/fillholes.py +161 -0
- arrayprobe_soda2/find_radius.py +105 -0
- arrayprobe_soda2/findsize.py +407 -0
- arrayprobe_soda2/fit_poisson.py +170 -0
- arrayprobe_soda2/fix2dimage.py +63 -0
- arrayprobe_soda2/fixraking.py +162 -0
- arrayprobe_soda2/fixstuckbits.py +146 -0
- arrayprobe_soda2/hvps4_read_frame.py +121 -0
- arrayprobe_soda2/jit_kernels.py +152 -0
- arrayprobe_soda2/label_blobs.py +177 -0
- arrayprobe_soda2/min_circle_fast.py +320 -0
- arrayprobe_soda2/particlesort.py +703 -0
- arrayprobe_soda2/pbp_writer.py +558 -0
- arrayprobe_soda2/poisson_spot_correct.py +183 -0
- arrayprobe_soda2/princomp.py +107 -0
- arrayprobe_soda2/probespecs.py +361 -0
- arrayprobe_soda2/process_2d.py +1364 -0
- arrayprobe_soda2/process_2d_parallel.py +626 -0
- arrayprobe_soda2/process_hk.py +512 -0
- arrayprobe_soda2/processbuffer_2dc.py +155 -0
- arrayprobe_soda2/processbuffer_cip.py +213 -0
- arrayprobe_soda2/processbuffer_f2dc.py +139 -0
- arrayprobe_soda2/processbuffer_spec.py +441 -0
- arrayprobe_soda2/processbuffer_tail.py +350 -0
- arrayprobe_soda2/pth_readers.py +245 -0
- arrayprobe_soda2/py.typed +11 -0
- arrayprobe_soda2/read2dbuffer.py +371 -0
- arrayprobe_soda2/reject.py +246 -0
- arrayprobe_soda2/reprocess_pbp.py +156 -0
- arrayprobe_soda2/sample_area.py +264 -0
- arrayprobe_soda2/save_writer.py +480 -0
- arrayprobe_soda2/sea.py +324 -0
- arrayprobe_soda2/spec_absolutepointers.py +109 -0
- arrayprobe_soda2/spec_decompress.py +203 -0
- arrayprobe_soda2/spec_index.py +476 -0
- arrayprobe_soda2/spec_read_frame.py +286 -0
- arrayprobe_soda2/spec_read_hk.py +301 -0
- arrayprobe_soda2/spec_readint.py +127 -0
- arrayprobe_soda2/timeconv.py +77 -0
- arrayprobe_soda2/update_op.py +101 -0
- arrayprobe_uiops/__init__.py +45 -0
- arrayprobe_uiops/combine.py +192 -0
- arrayprobe_uiops/combine_fork.py +359 -0
- arrayprobe_uiops/constants.py +830 -0
- arrayprobe_uiops/decode_naming.py +113 -0
- arrayprobe_uiops/diode_mask.py +250 -0
- arrayprobe_uiops/engine_absence.py +41 -0
- arrayprobe_uiops/export_oap.py +325 -0
- arrayprobe_uiops/geometry_core.py +366 -0
- arrayprobe_uiops/habit.py +749 -0
- arrayprobe_uiops/habit_core.py +248 -0
- arrayprobe_uiops/hollow_size_rule.py +376 -0
- arrayprobe_uiops/imgproc.py +2081 -0
- arrayprobe_uiops/imgproc_core.py +275 -0
- arrayprobe_uiops/intarr.py +167 -0
- arrayprobe_uiops/intarr_analysis.py +569 -0
- arrayprobe_uiops/intarr_plots.py +119 -0
- arrayprobe_uiops/jit_kernels.py +430 -0
- arrayprobe_uiops/lwc.py +70 -0
- arrayprobe_uiops/matlab_compat.py +860 -0
- arrayprobe_uiops/measure.py +346 -0
- arrayprobe_uiops/min_circle.py +204 -0
- arrayprobe_uiops/min_ellipse.py +161 -0
- arrayprobe_uiops/min_rectangle.py +200 -0
- arrayprobe_uiops/ncar_2dc_timing.py +100 -0
- arrayprobe_uiops/ncio.py +810 -0
- arrayprobe_uiops/oap_read.py +228 -0
- arrayprobe_uiops/particle.py +51 -0
- arrayprobe_uiops/particle_perimeter.py +94 -0
- arrayprobe_uiops/particle_physics.py +199 -0
- arrayprobe_uiops/pecan_params.py +134 -0
- arrayprobe_uiops/probe_cases.py +298 -0
- arrayprobe_uiops/product_sanity.py +337 -0
- arrayprobe_uiops/profile.py +71 -0
- arrayprobe_uiops/profiles.py +756 -0
- arrayprobe_uiops/provenance.py +804 -0
- arrayprobe_uiops/py.typed +11 -0
- arrayprobe_uiops/qc.py +169 -0
- arrayprobe_uiops/readers/__init__.py +8 -0
- arrayprobe_uiops/readers/mask_csv.py +74 -0
- arrayprobe_uiops/readers/pms.py +239 -0
- arrayprobe_uiops/readers/tasinfo.py +57 -0
- arrayprobe_uiops/rect_ellipse.py +129 -0
- arrayprobe_uiops/register_image_assisted.py +25 -0
- arrayprobe_uiops/reject.py +501 -0
- arrayprobe_uiops/reject_core.py +220 -0
- arrayprobe_uiops/sample_area.py +93 -0
- arrayprobe_uiops/sizedist.py +1923 -0
- arrayprobe_uiops/sizedist_core.py +814 -0
- arrayprobe_uiops/sizedist_tables.py +642 -0
- arrayprobe_uiops/spec.py +1094 -0
- arrayprobe_uiops/spec_core.py +703 -0
- arrayprobe_uiops/stray_pixel.py +103 -0
- arrayprobe_uiops/tas.py +191 -0
- arrayprobe_uiops/time_convert.py +41 -0
- uiops/__init__.py +402 -0
- uiops/py.typed +11 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""The author-editable defaults file -- minimal form.
|
|
3
|
+
|
|
4
|
+
Scope (project decision, 2026-09-28): *"Minimal
|
|
5
|
+
version: base profile plus the six reject thresholds, name carrying a content hash, stamp
|
|
6
|
+
``authordefaults:<path>#<sha>``, reached by ``[fidelity].authordefaults``."* This module is
|
|
7
|
+
that minimal form and nothing more; every wider reading floated in the archived planning notes
|
|
8
|
+
(option B:
|
|
9
|
+
a free-form threshold/correction file) is explicitly **not** built here -- the agreed
|
|
10
|
+
scope is one axis.
|
|
11
|
+
|
|
12
|
+
**Why this does not break the no-raw-thresholds rule** (``config.py``: a config file may
|
|
13
|
+
*select* a documented behaviour, never *describe* one). This file does not talk to the port.
|
|
14
|
+
It is TOML *input to a generator*, exactly the shape option B always was: the six
|
|
15
|
+
:class:`~arrayprobe_uiops.reject_core.RejectConfig` fields it may set are assembled in Python into a
|
|
16
|
+
full, fully-specified :class:`~arrayprobe.profiles.FidelityProfile` and handed to
|
|
17
|
+
:func:`arrayprobe.profiles.register_profile`, which enforces the same completeness and
|
|
18
|
+
uniqueness rules a fork's own hand-written registration would. The six reject thresholds are
|
|
19
|
+
the one axis :func:`arrayprobe.config.load_config` already exempts from that rule in part
|
|
20
|
+
(``[thresholds].area_ratio_z``/``default_int_arr_thresh``) -- this file is the same
|
|
21
|
+
kind of lift, generalised to the reject-config axis and routed through registration rather
|
|
22
|
+
than through a raw config key, because these six are ``FidelityProfile`` fields, not
|
|
23
|
+
``sizeDist`` call arguments.
|
|
24
|
+
|
|
25
|
+
Every override carries a **citation** -- who chose the value and why -- refused if missing,
|
|
26
|
+
because a threshold with no author behind it is indistinguishable from a guess (the project's
|
|
27
|
+
"never invent a fact" rule, applied to a number instead of a literature claim).
|
|
28
|
+
|
|
29
|
+
**The file name carries a content hash** (``authordefaults-<sha256 prefix>.toml``) so an edit
|
|
30
|
+
without a rename is caught rather than silently changing what a run reproduces -- the same
|
|
31
|
+
"a check must draw its two sides from different places" shape as every other guard in this
|
|
32
|
+
project: the name is a claim, the bytes are the fact, and :func:`load_authordefaults` refuses
|
|
33
|
+
to run when they disagree.
|
|
34
|
+
|
|
35
|
+
Absent ``[fidelity].authordefaults``, none of this runs: :mod:`arrayprobe.config` behaves
|
|
36
|
+
exactly as it did before this module existed (``tests/test_authordefaults.py``).
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
from __future__ import annotations
|
|
40
|
+
|
|
41
|
+
import hashlib
|
|
42
|
+
import re
|
|
43
|
+
import tomllib
|
|
44
|
+
from dataclasses import dataclass, replace
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
|
|
47
|
+
from . import profiles
|
|
48
|
+
from .profiles import FidelityProfile
|
|
49
|
+
|
|
50
|
+
__all__ = [
|
|
51
|
+
"THRESHOLD_KEYS",
|
|
52
|
+
"AuthorDefaultsError",
|
|
53
|
+
"AuthorDefaults",
|
|
54
|
+
"content_hash",
|
|
55
|
+
"expected_filename",
|
|
56
|
+
"load_authordefaults",
|
|
57
|
+
"resolve_profile",
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class AuthorDefaultsError(ValueError):
|
|
62
|
+
"""An ``authordefaults*.toml`` file that cannot be trusted as written."""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
#: The six thresholds ``calculate_reject_unified.m:71-77`` assigns -- every field of
|
|
66
|
+
#: :class:`arrayprobe_uiops.reject_core.RejectConfig` -- and the only ones this file may override.
|
|
67
|
+
#: Every
|
|
68
|
+
#: other :class:`~arrayprobe.profiles.FidelityProfile` field stays a Python registration
|
|
69
|
+
#: (the same rule): those name a divergence between two MATLAB *trees*, not a per-run choice.
|
|
70
|
+
THRESHOLD_KEYS: frozenset[str] = frozenset(
|
|
71
|
+
{"rej_zero_area", "rej_split", "rej_hollow", "shadowed_area", "max_edge_img_ar",
|
|
72
|
+
"max_comp_img_ar"}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
#: rej_zero_area/rej_split/rej_hollow are booleans on RejectConfig; the other three are
|
|
76
|
+
#: numeric (float, though the shipped defaults are written as plain ints in Python).
|
|
77
|
+
_BOOL_KEYS = frozenset({"rej_zero_area", "rej_split", "rej_hollow"})
|
|
78
|
+
|
|
79
|
+
_HASH_LEN = 16 # hex chars: 64 bits, ample to catch an accidental collision, short in a filename
|
|
80
|
+
_NAME_RE = re.compile(rf"^authordefaults-([0-9a-f]{{{_HASH_LEN}}})\.toml$")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _resolve_base_profile_name(name: str) -> str | None:
|
|
84
|
+
"""A base-profile name as ``load_authordefaults`` accepts it -- either spelling.
|
|
85
|
+
|
|
86
|
+
``arrayprobe.config`` builds the CONSTANT-style alias table (``STOCK_V314`` for
|
|
87
|
+
``stock-v3.1.4``) from :data:`arrayprobe.profiles.SHIPPED` the same way; it is not
|
|
88
|
+
imported from there because ``config.py`` imports this module, and reusing the same
|
|
89
|
+
one-line transform here is simpler than restructuring either module to avoid the cycle.
|
|
90
|
+
Returns the canonical (hyphenated) registry key, or ``None`` if ``name`` is neither.
|
|
91
|
+
"""
|
|
92
|
+
if name in profiles.PROFILES:
|
|
93
|
+
return name
|
|
94
|
+
alias = name.upper().replace("-", "_").replace(".", "")
|
|
95
|
+
table = {n.upper().replace("-", "_").replace(".", ""): n for n in profiles.SHIPPED}
|
|
96
|
+
return table.get(alias)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def content_hash(data: bytes) -> str:
|
|
100
|
+
"""The filename's hash segment: the first 16 hex chars of the file's own SHA-256."""
|
|
101
|
+
return hashlib.sha256(data).hexdigest()[:_HASH_LEN]
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def expected_filename(data: bytes) -> str:
|
|
105
|
+
"""What this file's name must be, given its bytes."""
|
|
106
|
+
return f"authordefaults-{content_hash(data)}.toml"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass(frozen=True)
|
|
110
|
+
class AuthorDefaults:
|
|
111
|
+
"""One validated ``authordefaults*.toml`` file: a base profile plus cited overrides."""
|
|
112
|
+
|
|
113
|
+
path: Path
|
|
114
|
+
hash: str
|
|
115
|
+
base_profile_name: str
|
|
116
|
+
overrides: dict[str, bool | float]
|
|
117
|
+
citations: dict[str, str]
|
|
118
|
+
|
|
119
|
+
def stamp(self) -> str:
|
|
120
|
+
"""The ``.call`` sidecar fragment: ``authordefaults:<path>#<sha>``."""
|
|
121
|
+
return f"authordefaults:{self.path}#{self.hash}"
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def load_authordefaults(path) -> AuthorDefaults:
|
|
125
|
+
"""Read and validate an author-editable defaults file.
|
|
126
|
+
|
|
127
|
+
Raises :class:`AuthorDefaultsError` for anything that would let the file describe a
|
|
128
|
+
threshold without a citation, name a key that is not one of the six, or run under a
|
|
129
|
+
name that does not match its own content.
|
|
130
|
+
"""
|
|
131
|
+
path = Path(path)
|
|
132
|
+
if path.is_dir():
|
|
133
|
+
raise AuthorDefaultsError(f"{path} is a directory; name the .toml file inside it")
|
|
134
|
+
try:
|
|
135
|
+
data = path.read_bytes()
|
|
136
|
+
except FileNotFoundError:
|
|
137
|
+
raise
|
|
138
|
+
if not _NAME_RE.match(path.name):
|
|
139
|
+
expected = expected_filename(data)
|
|
140
|
+
raise AuthorDefaultsError(
|
|
141
|
+
f"{path.name!r} is not a valid author-defaults file name (expected "
|
|
142
|
+
f"authordefaults-<16 hex chars>.toml, e.g. {expected!r} for this file's current "
|
|
143
|
+
"content) -- the name carries a content hash so an edit without a rename is caught "
|
|
144
|
+
"rather than silently changing what a run reproduces"
|
|
145
|
+
)
|
|
146
|
+
expected = expected_filename(data)
|
|
147
|
+
if path.name != expected:
|
|
148
|
+
raise AuthorDefaultsError(
|
|
149
|
+
f"{path.name} does not match its own content: expected {expected!r}. Rename the "
|
|
150
|
+
"file (or regenerate it) after any edit -- the mismatch is the whole point of the "
|
|
151
|
+
"hash: a file that could drift from its name silently could change a run's reject "
|
|
152
|
+
"thresholds with no record that it happened."
|
|
153
|
+
)
|
|
154
|
+
try:
|
|
155
|
+
text = data.decode("utf-8")
|
|
156
|
+
except UnicodeDecodeError as exc:
|
|
157
|
+
raise AuthorDefaultsError(f"{path} is not UTF-8: {exc}") from exc
|
|
158
|
+
try:
|
|
159
|
+
doc = tomllib.loads(text)
|
|
160
|
+
except tomllib.TOMLDecodeError as exc:
|
|
161
|
+
raise AuthorDefaultsError(f"{path} is not valid TOML: {exc}") from exc
|
|
162
|
+
|
|
163
|
+
unknown_sections = sorted(set(doc) - {"fidelity", "thresholds"})
|
|
164
|
+
if unknown_sections:
|
|
165
|
+
raise AuthorDefaultsError(
|
|
166
|
+
f"unknown section(s) {unknown_sections} in {path}; an author-defaults file may hold "
|
|
167
|
+
"only [fidelity] (base_profile) and [thresholds] (the six reject thresholds)"
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
fid = doc.get("fidelity")
|
|
171
|
+
if not isinstance(fid, dict) or "base_profile" not in fid:
|
|
172
|
+
raise AuthorDefaultsError(
|
|
173
|
+
f"{path}: [fidelity].base_profile is required -- no base profile is ever assumed"
|
|
174
|
+
)
|
|
175
|
+
extra_fid = sorted(set(fid) - {"base_profile"})
|
|
176
|
+
if extra_fid:
|
|
177
|
+
raise AuthorDefaultsError(
|
|
178
|
+
f"[fidelity] has unknown key(s) {extra_fid} in {path}; known: ['base_profile']"
|
|
179
|
+
)
|
|
180
|
+
given_base_name = fid["base_profile"]
|
|
181
|
+
base_name = _resolve_base_profile_name(given_base_name) if isinstance(given_base_name, str) \
|
|
182
|
+
else None
|
|
183
|
+
if base_name is None:
|
|
184
|
+
known = sorted(profiles.PROFILES)
|
|
185
|
+
raise AuthorDefaultsError(
|
|
186
|
+
f"unknown base profile {given_base_name!r} in {path}; known: {known}"
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
thresholds = doc.get("thresholds", {})
|
|
190
|
+
if not isinstance(thresholds, dict):
|
|
191
|
+
raise AuthorDefaultsError(
|
|
192
|
+
f"[thresholds] in {path} must be a table of <threshold name> = "
|
|
193
|
+
"{value = ..., citation = \"...\"}"
|
|
194
|
+
)
|
|
195
|
+
unknown_thresholds = sorted(set(thresholds) - THRESHOLD_KEYS)
|
|
196
|
+
if unknown_thresholds:
|
|
197
|
+
verb = "is" if len(unknown_thresholds) == 1 else "are"
|
|
198
|
+
raise AuthorDefaultsError(
|
|
199
|
+
f"[thresholds] names {unknown_thresholds} in {path}, which {verb} not one of the "
|
|
200
|
+
f"six reject thresholds this file may override: {sorted(THRESHOLD_KEYS)}. Every "
|
|
201
|
+
"other FidelityProfile field is a scientific claim registered in Python "
|
|
202
|
+
"(register_profile()), never described in a config file: thresholds are never set "
|
|
203
|
+
"in a config file, only selected."
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
overrides: dict[str, bool | float] = {}
|
|
207
|
+
citations: dict[str, str] = {}
|
|
208
|
+
for key, entry in thresholds.items():
|
|
209
|
+
if not isinstance(entry, dict) or set(entry) != {"value", "citation"}:
|
|
210
|
+
got = sorted(entry) if isinstance(entry, dict) else entry
|
|
211
|
+
raise AuthorDefaultsError(
|
|
212
|
+
f"[thresholds.{key}] in {path} must be a table with exactly 'value' and "
|
|
213
|
+
f"'citation' keys, got {got!r}"
|
|
214
|
+
)
|
|
215
|
+
citation = entry["citation"]
|
|
216
|
+
if not isinstance(citation, str) or not citation.strip():
|
|
217
|
+
raise AuthorDefaultsError(
|
|
218
|
+
f"[thresholds.{key}] in {path} has no citation -- who chose this value and why "
|
|
219
|
+
"is required for every override, never left implicit"
|
|
220
|
+
)
|
|
221
|
+
value = entry["value"]
|
|
222
|
+
if key in _BOOL_KEYS:
|
|
223
|
+
if not isinstance(value, bool):
|
|
224
|
+
raise AuthorDefaultsError(
|
|
225
|
+
f"[thresholds.{key}].value in {path} must be true or false, got {value!r}"
|
|
226
|
+
)
|
|
227
|
+
else:
|
|
228
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
229
|
+
raise AuthorDefaultsError(
|
|
230
|
+
f"[thresholds.{key}].value in {path} must be a number, got {value!r}"
|
|
231
|
+
)
|
|
232
|
+
overrides[key] = value
|
|
233
|
+
citations[key] = citation
|
|
234
|
+
|
|
235
|
+
return AuthorDefaults(
|
|
236
|
+
path=path,
|
|
237
|
+
hash=content_hash(data),
|
|
238
|
+
base_profile_name=base_name,
|
|
239
|
+
overrides=overrides,
|
|
240
|
+
citations=citations,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def resolve_profile(defaults: AuthorDefaults) -> FidelityProfile:
|
|
245
|
+
"""Build (and register, once per interpreter) the profile this file selects.
|
|
246
|
+
|
|
247
|
+
The name is derived from the file's own content hash (``authordefaults-<hash>``), so a
|
|
248
|
+
config loaded twice in one process -- or by a ``--jobs``/``--chunks`` worker that has
|
|
249
|
+
never seen this file before -- resolves to the same registration rather than raising on
|
|
250
|
+
the second call: idempotent by construction, the same property
|
|
251
|
+
``[fidelity].profile_module`` relies on for a fork's own registered variant.
|
|
252
|
+
"""
|
|
253
|
+
base = profiles.PROFILES[defaults.base_profile_name]
|
|
254
|
+
name = f"authordefaults-{defaults.hash}"
|
|
255
|
+
if name in profiles.PROFILES:
|
|
256
|
+
return profiles.PROFILES[name]
|
|
257
|
+
# mypy cannot check a **dict against mixed-type fields; load_authordefaults validated it.
|
|
258
|
+
reject = replace(base.reject_thresholds, **defaults.overrides) # type: ignore[arg-type]
|
|
259
|
+
description = (
|
|
260
|
+
f"Author-editable defaults ({defaults.path.name}), base {base.name}: "
|
|
261
|
+
+ "; ".join(f"{k}={v} ({defaults.citations[k]})" for k, v in defaults.overrides.items())
|
|
262
|
+
if defaults.overrides
|
|
263
|
+
else f"Author-editable defaults ({defaults.path.name}), base {base.name}: no overrides"
|
|
264
|
+
)
|
|
265
|
+
new = replace(base, name=name, description=description, reject_thresholds=reject)
|
|
266
|
+
cites_tree = "3.5" if base.name in profiles._V35_TREE_PROFILES else "3.1.4"
|
|
267
|
+
return profiles.register_profile(new, cites_tree=cites_tree)
|