diff --git a/src/did/+did2/+convert/+migrators/Contents.m b/src/did/+did2/+convert/+migrators/Contents.m index 5d70fd76..4fc88374 100644 --- a/src/did/+did2/+convert/+migrators/Contents.m +++ b/src/did/+did2/+convert/+migrators/Contents.m @@ -18,11 +18,6 @@ % treatment - collapse (ontologyName | ontology_name, % name) -> treatment_name; pass through % numeric_value and string_value. -% ontology_image - collapse (ontology_name, ontology_region) -% -> region. -% ontology_label - collapse (ontology_name, label_id, label) -% -> term, with the CURIE composed from the -% first two. % epochclocktimes - SUPERCLASS migrator; rename clocktype -> % epoch_clock and split t0_t1 -> (t0, t1). % Applied by the dispatcher to any document @@ -40,41 +35,30 @@ % Applied to any document that lists ngrid % in its superclass chain (e.g., hartley_calc % via reverse_correlation). -% ontology_label - extended to handle the JH single-`ontologyNode` -% idiom (no label/label_id). Looks up the -% name via ndi.ontology.lookup; falls back to -% empty name when the lookup is unavailable. -% position_metadata - semantic-shape migrator: builds -% measurement (ontology_term), units -% (ontology_term), and dimensions -% (array-of-records with axis_1, axis_2 labels) -% from v1 ontologyNode/units/dimensions. -% distance_metadata - paired A/B endpoint migrator: discovers -% labels by regex-scanning ontology_node_X -% keys and builds an endpoints array-of-records -% with measurement, integer_ids, string_ids, -% numeric_values per endpoint. -% stimulus_bath - rename location.ontologyNode -> .node; -% parse the v1 CSV mixture_table into a -% mixture array-of-records; each amount is a -% V2 `concentration` composite with -% source_unit / source_value preserved and -% the appropriate canonical sub-field (molar, -% grams_per_liter, mass_fraction, -% volume_fraction) populated when computable. % -% Calculator-base wrappers (20211116-driven): -% each calls did2.convert.calcCommon to move v1's -% `.input_parameters` into a new inherited `calculator` block. -% The calculator-identity string lives in `app.app_name` (carried in -% v1 as `app.name`) and is handled by the universal app-block field -% rename in did2.convert.universalRenames; the per-class wrapper does -% not have to know its own calculator-name string. +% The calculator-base wrappers are all deleted, with their shared helper +% calcCommon: the tuning family's (tuningcurve_calc, oridirtuning_calc, +% contrast_sensitivity_calc, contrast_tuning_calc, +% spatial_frequency_tuning_calc, temporal_frequency_tuning_calc) and then +% hartley_calc, speed_tuning_calc and simple_calc, with jrclust_clusters' +% rename. Each class has a +migrators_j migrator, so the wrapper was never +% reached; the classes read raw v1 (did2.convert.rawV1Classes; simple_calc +% is not switched, see there; [early migration pieces fixed] (1), Jess +% Haley, 2026-10-26). % -% tuningcurve_calc, oridirtuning_calc, hartley_calc, -% contrast_sensitivity_calc, contrast_tuning_calc, -% spatial_frequency_tuning_calc, speed_tuning_calc, -% temporal_frequency_tuning_calc, simple_calc +% The position_metadata, distance_metadata and stimulus_bath base migrators +% are deleted too: each class has a +migrators_j migrator, which reads raw v1 +% (distance_metadata's reshapes the v1 spelling itself, where it used to hand +% the renamed body to the base migrator). +% +% The element, ontology_image and ontology_label base migrators are deleted +% (2026-10-27): each class has a +migrators_j migrator that reads raw v1, and +% no NDI template at the locked main names element, ontologyImage or +% ontologyLabel as a superclass, so nothing reached them. element_epoch stays +% (+migrators_j/element_epoch.m and oneepoch.m call it on the raw block); +% epochclocktimes and filter stay for pyraview (not switched); ngrid stays as +% the concrete migrator of a leaf `ngrid` document (+migrators_j has only +% the +super guard); identity stays as v1_to_v2's fallback. % % See did-schema's % did-schema's per-class conversion notes (deleted with did-schema #88) for the diff --git a/src/did/+did2/+convert/+migrators/contrast_sensitivity_calc.m b/src/did/+did2/+convert/+migrators/contrast_sensitivity_calc.m deleted file mode 100644 index c064097c..00000000 --- a/src/did/+did2/+convert/+migrators/contrast_sensitivity_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = contrast_sensitivity_calc(preBody) -%CONTRAST_SENSITIVITY_CALC Base migrator: did_v1 contrast_sensitivity_calc body -> the class-preserving V2 shape. -% -% a contrast-sensitivity analysis. The v1 form -% carries `input_parameters` directly on the contrast_sensitivity_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'contrast_sensitivity_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/contrast_tuning_calc.m b/src/did/+did2/+convert/+migrators/contrast_tuning_calc.m deleted file mode 100644 index cc21a3b2..00000000 --- a/src/did/+did2/+convert/+migrators/contrast_tuning_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = contrast_tuning_calc(preBody) -%CONTRAST_TUNING_CALC Base migrator: did_v1 contrast_tuning_calc body -> the class-preserving V2 shape. -% -% a contrast tuning fit. The v1 form -% carries `input_parameters` directly on the contrast_tuning_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'contrast_tuning_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/distance_metadata.m b/src/did/+did2/+convert/+migrators/distance_metadata.m deleted file mode 100644 index 49c8c13f..00000000 --- a/src/did/+did2/+convert/+migrators/distance_metadata.m +++ /dev/null @@ -1,158 +0,0 @@ -function v2Body = distance_metadata(preBody) -%DISTANCE_METADATA Base migrator: did_v1 distance_metadata body -> the class-preserving V2 shape. -% -% v1 carries a paired A/B endpoint structure: -% -% distance_metadata.ontologyNode_A (after universalRenames: -% ontology_node_a) - CURIE -% distance_metadata.integerIDs_A (scalar or matrix) -% distance_metadata.ontologyStringValues_A (comma-separated did_uids) -% distance_metadata.ontologyNumericValues_A (matrix; often empty) -% (same set for endpoint B) -% distance_metadata.units (CURIE) -% -% V2 collapses both endpoints into a single -% `endpoints` array-of-records (mirrors the position_metadata -% dimensions pattern) with explicit per-endpoint `label`s -% preserved from v1: -% -% distance_metadata.endpoints(i).label - 'A', 'B' -% distance_metadata.endpoints(i).measurement (ontology_term) -% distance_metadata.endpoints(i).integer_ids - matrix -% distance_metadata.endpoints(i).string_ids - string array -% distance_metadata.endpoints(i).numeric_values - matrix -% distance_metadata.units (ontology_term) -% -% Ontology terms have their `name` resolved via ndi.ontology.lookup -% at conversion time; lookup failures (library unavailable, CURIE -% unknown) leave `name` empty. -% -% The migrator only walks endpoints actually present in the v1 -% doc. Most v1 docs in the JH corpus have endpoints 'A' and 'B'; -% any v1 doc that ships further endpoints (e.g., 'C') would be -% migrated as a 3-element array, preserving the v1 information. - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'distance_metadata') ... - || ~isstruct(v2Body.distance_metadata) - error('did2:convert:missingBlock', ... - 'distance_metadata body is missing the distance_metadata property block.'); -end - -block = v2Body.distance_metadata; - -labels = discoverEndpointLabels(block); -endpoints = struct('label', {}, 'measurement', {}, ... - 'integer_ids', {}, 'string_ids', {}, 'numeric_values', {}); -for k = 1:numel(labels) - L = labels{k}; - endpoints(end+1) = buildEndpoint(block, L); %#ok -end - -unitsNode = ''; -if isfield(block, 'units') - unitsNode = char(block.units); -end - -newBlock = struct(); -newBlock.endpoints = endpoints; -newBlock.units = ontologyTerm(unitsNode); -v2Body.distance_metadata = newBlock; -end - -function labels = discoverEndpointLabels(block) -% Find every label X that appears as a suffix on `ontology_node_X` -% in the v1 block. v1 in the JH corpus uses 'A' and 'B'; this is -% future-proof for any single uppercase letter. -labels = {}; -fns = fieldnames(block); -seen = containers.Map('KeyType', 'char', 'ValueType', 'logical'); -for k = 1:numel(fns) - fn = fns{k}; - tokens = regexp(fn, '^ontology_node_(.+)$', 'tokens', 'once'); - if isempty(tokens); continue; end - L = upper(tokens{1}); - if ~seen.isKey(L) - seen(L) = true; - labels{end+1} = L; %#ok - end -end -labels = sort(labels); -end - -function ep = buildEndpoint(block, label) -% Build one V2 endpoint record from v1's per-label fields. -% All fields are tolerant of absence: missing v1 fields default to -% empty values of the right type. -nodeKey = sprintf('ontology_node_%s', lower(label)); -intIdsKey = sprintf('integer_i_ds_%s', lower(label)); -stringIdsKey = sprintf('ontology_string_values_%s', lower(label)); -numericKey = sprintf('ontology_numeric_values_%s', lower(label)); - -if isfield(block, nodeKey) - nodeVal = char(block.(nodeKey)); -else - nodeVal = ''; -end -if isfield(block, intIdsKey) - intIds = double(block.(intIdsKey)); - intIds = intIds(:)'; -else - intIds = []; -end -if isfield(block, stringIdsKey) - raw = block.(stringIdsKey); - if ischar(raw) - parts = strsplit(raw, ','); - parts = cellfun(@strtrim, parts, 'UniformOutput', false); - parts = parts(~cellfun('isempty', parts)); - stringIds = string(parts); - elseif isstring(raw) - stringIds = raw(:)'; - else - stringIds = string.empty(1, 0); - end -else - stringIds = string.empty(1, 0); -end -if isfield(block, numericKey) - nums = block.(numericKey); - if isnumeric(nums) - nums = double(nums(:)'); - else - nums = []; - end -else - nums = []; -end - -ep = struct( ... - 'label', label, ... - 'measurement', ontologyTerm(nodeVal), ... - 'integer_ids', intIds, ... - 'string_ids', stringIds, ... - 'numeric_values', nums); -end - -function term = ontologyTerm(curie) -% Build an ontology_term composite. Empty input yields a node-only, -% name-empty struct. ndi.ontology.lookup failures leave name ''. -term = struct('node', char(curie), 'name', ''); -if isempty(curie) - return; -end -try - [~, resolved] = ndi.ontology.lookup(char(curie)); - if isstring(resolved) && isscalar(resolved) - term.name = char(resolved); - elseif ischar(resolved) - term.name = resolved; - end -catch - % ndi.ontology not on path or curie unknown; leave name ''. -end -end diff --git a/src/did/+did2/+convert/+migrators/element.m b/src/did/+did2/+convert/+migrators/element.m deleted file mode 100644 index 96c833cf..00000000 --- a/src/did/+did2/+convert/+migrators/element.m +++ /dev/null @@ -1,57 +0,0 @@ -function v2Body = element(preBody) -%ELEMENT Base migrator: did_v1 element body -> the class-preserving V2 shape. -% -% V2's element schema declares `direct` as integer (default 0, -% range 0..1). The did_v1 element_schema also declares it integer, -% but some v1 producers (PRED corpus, and historical writes across -% the other public corpora) emit it as a JSON boolean. After -% jsondecode that lands as a MATLAB `logical`, which V2's -% validator rejects because `isnumeric(true)` is false. This -% migrator coerces logical (and a couple of defensive char shapes) -% to integer so the corpus migrates cleanly. -% -% Other element fields pass through unchanged: V2 keeps the -% v1 names for ndi_element_class, name, reference, and type. - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'element') || ~isstruct(v2Body.element) - return; -end - -block = v2Body.element; - -if isfield(block, 'direct') - block.direct = coerceDirectToInteger(block.direct); -end - -v2Body.element = block; -end - -function out = coerceDirectToInteger(value) -if islogical(value) - out = double(value); -elseif isnumeric(value) - out = value; -elseif ischar(value) || (isstring(value) && isscalar(value)) - s = lower(strtrim(char(value))); - switch s - case {'1', 'true'} - out = 1; - case {'0', 'false', ''} - out = 0; - otherwise - n = str2double(s); - if isnan(n) - out = value; - else - out = n; - end - end -else - out = value; -end -end diff --git a/src/did/+did2/+convert/+migrators/hartley_calc.m b/src/did/+did2/+convert/+migrators/hartley_calc.m deleted file mode 100644 index 7a344edc..00000000 --- a/src/did/+did2/+convert/+migrators/hartley_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = hartley_calc(preBody) -%HARTLEY_CALC Base migrator: did_v1 hartley_calc body -> the class-preserving V2 shape. -% -% a Hartley reverse-correlation analysis. The v1 form -% carries `input_parameters` directly on the hartley_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'hartley_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/jrclust_clusters.m b/src/did/+did2/+convert/+migrators/jrclust_clusters.m deleted file mode 100644 index 87272edd..00000000 --- a/src/did/+did2/+convert/+migrators/jrclust_clusters.m +++ /dev/null @@ -1,25 +0,0 @@ -function v2Body = jrclust_clusters(preBody) -%JRCLUST_CLUSTERS Base migrator: did_v1 jrclust_clusters body -> the class-preserving V2 shape. -% -% Lowercases the v1 `res_mat_MD5_checksum` field name to -% `res_mat_md5_checksum`. universalRenames's snake_case pass treats -% the trailing-camel `Checksum` as a word boundary but leaves the -% embedded `MD5` ALLCAPS run alone, so this class-specific rename -% handles it explicitly. The companion legacy `ndi_document` block -% that v1 sometimes ships on these documents is reconciled in -% universalRenames (the universal `ndi_document -> base` rule). - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if isfield(v2Body, 'jrclust_clusters') && isstruct(v2Body.jrclust_clusters) - block = v2Body.jrclust_clusters; - if isfield(block, 'res_mat_MD5_checksum') && ~isfield(block, 'res_mat_md5_checksum') - block.res_mat_md5_checksum = block.res_mat_MD5_checksum; - block = rmfield(block, 'res_mat_MD5_checksum'); - end - v2Body.jrclust_clusters = block; -end -end diff --git a/src/did/+did2/+convert/+migrators/ontology_image.m b/src/did/+did2/+convert/+migrators/ontology_image.m deleted file mode 100644 index f457a866..00000000 --- a/src/did/+did2/+convert/+migrators/ontology_image.m +++ /dev/null @@ -1,41 +0,0 @@ -function v2Body = ontology_image(preBody) -%ONTOLOGY_IMAGE Base migrator: did_v1 ontologyImage body -> the class-preserving V2 shape. -% -% The class is renamed from ontologyImage (camelCase, V_alpha) to -% ontology_image (snake_case, V2) by -% did2.convert.universalRenames; this migrator collapses the two -% coordinated chars inside the ontology_image property block into a -% single `region` field of `ontology_term` composite type: -% -% ontology_image.ontology_name -> ontology_image.region.node -% ontology_image.ontology_region -> ontology_image.region.name -% -% See did-schema's -% did-schema's per-class conversion notes (deleted with did-schema #88). - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'ontology_image') || ~isstruct(v2Body.ontology_image) - error('did2:convert:missingBlock', ... - 'ontology_image body is missing the ontology_image property block.'); -end - -block = v2Body.ontology_image; -if isfield(block, 'ontology_name') - node = char(block.ontology_name); -else - node = ''; -end -if isfield(block, 'ontology_region') - labelName = char(block.ontology_region); -else - labelName = ''; -end - -newBlock = struct(); -newBlock.region = struct('node', node, 'name', labelName); -v2Body.ontology_image = newBlock; -end diff --git a/src/did/+did2/+convert/+migrators/ontology_label.m b/src/did/+did2/+convert/+migrators/ontology_label.m deleted file mode 100644 index 45fa6c7a..00000000 --- a/src/did/+did2/+convert/+migrators/ontology_label.m +++ /dev/null @@ -1,113 +0,0 @@ -function v2Body = ontology_label(preBody) -%ONTOLOGY_LABEL Base migrator: did_v1 ontologyLabel body -> the class-preserving V2 shape. -% -% The class is renamed from ontologyLabel (camelCase, V_alpha) to -% ontology_label (snake_case, V2) by -% did2.convert.universalRenames; this migrator produces a single -% `term` field of `ontology_term` composite type from one of two -% did_v1 idioms it has to support: -% -% 1. Three coordinated fields (PRED-era, V_alpha-flavoured): -% ontology_label.ontology_name + .label_id -> term.node = ':' -% ontology_label.label -> term.name -% The CURIE is built by lowercasing the source-ontology name -% (with spaces replaced by underscores) and appending ':'. -% Example: 'Allen CCF v3' + 12345 -> 'allen_ccf_v3:12345'. -% -% 2. Node-only (JH-era, ontology-driven): -% ontology_label.ontologyNode (after universalRenames: -% ontology_node) -> term.node -% term.name is resolved via ndi.ontology.lookup(term.node). -% Example v1: `{"ontologyNode": "EMPTY:0000129"}`. -% -% When idiom 2 fires and `ndi.ontology.lookup` is on the path, -% the migrator dispatches to it to populate `term.name`. If the -% lookup throws (curie not found, ontology data unavailable, -% library not installed), the migrator falls back to leaving -% `term.name` empty rather than quarantining -- the V2 -% `ontology_term` composite type only requires the value to be a -% struct; the inner field shape is open. -% -% See did-schema's -% did-schema's per-class conversion notes (deleted with did-schema #88). - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'ontology_label') || ~isstruct(v2Body.ontology_label) - error('did2:convert:missingBlock', ... - 'ontology_label body is missing the ontology_label property block.'); -end - -block = v2Body.ontology_label; - -% Idiom 2 (node-only) wins if the v1 doc has ontology_node. Idiom 1 -% supplies its own ontology_name + label_id and we build the CURIE. -if isfield(block, 'ontology_node') && ~isempty(block.ontology_node) - node = char(block.ontology_node); - labelName = lookupOntologyName(node); -else - if isfield(block, 'ontology_name') - prefix = normaliseCURIEPrefix(block.ontology_name); - else - prefix = ''; - end - if isfield(block, 'label_id') - labelIdText = labelIdToText(block.label_id); - else - labelIdText = ''; - end - if isfield(block, 'label') - labelName = char(block.label); - else - labelName = ''; - end - if isempty(prefix) && isempty(labelIdText) - node = ''; - else - node = sprintf('%s:%s', prefix, labelIdText); - end -end - -newBlock = struct(); -newBlock.term = struct('node', node, 'name', labelName); -v2Body.ontology_label = newBlock; -end - -function name = lookupOntologyName(curie) -% Resolve the human-readable label for a CURIE via ndi.ontology. -% Returns '' if the lookup is unavailable or fails; the V2 -% ontology_term composite type tolerates an empty name (the -% validator only requires the value to be a struct). -try - [~, name] = ndi.ontology.lookup(curie); -catch - name = ''; -end -if isstring(name) && isscalar(name) - name = char(name); -elseif ~ischar(name) - name = ''; -end -end - -function out = normaliseCURIEPrefix(raw) -out = lower(strtrim(char(raw))); -out = regexprep(out, '\s+', '_'); -end - -function out = labelIdToText(value) -if isnumeric(value) && isscalar(value) - if isfinite(value) && value == floor(value) - out = sprintf('%d', int64(value)); - else - out = sprintf('%g', value); - end -elseif ischar(value) || (isstring(value) && isscalar(value)) - out = char(value); -else - out = ''; -end -end diff --git a/src/did/+did2/+convert/+migrators/oridirtuning_calc.m b/src/did/+did2/+convert/+migrators/oridirtuning_calc.m deleted file mode 100644 index 63a0dae7..00000000 --- a/src/did/+did2/+convert/+migrators/oridirtuning_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = oridirtuning_calc(preBody) -%ORIDIRTUNING_CALC Base migrator: did_v1 oridirtuning_calc body -> the class-preserving V2 shape. -% -% an orientation/direction tuning fit. The v1 form -% carries `input_parameters` directly on the oridirtuning_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'oridirtuning_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/position_metadata.m b/src/did/+did2/+convert/+migrators/position_metadata.m deleted file mode 100644 index dbe5017b..00000000 --- a/src/did/+did2/+convert/+migrators/position_metadata.m +++ /dev/null @@ -1,116 +0,0 @@ -function v2Body = position_metadata(preBody) -%POSITION_METADATA Base migrator: did_v1 position_metadata body -> the class-preserving V2 shape. -% -% v1 carries three ontology-driven descriptor fields: -% -% position_metadata.ontologyNode (after universalRenames: -% ontology_node) - what kind of -% position -% position_metadata.units - unit (CURIE) -% position_metadata.dimensions - comma-separated -% per-axis CURIEs -% -% V2 re-shapes these into ontology_term composites and an -% array-of-records `dimensions` field with explicit per-axis -% identifiers: -% -% position_metadata.measurement (ontology_term) -% position_metadata.units (ontology_term) -% position_metadata.dimensions(i).axis - 'axis_1', 'axis_2', ... -% position_metadata.dimensions(i).node - per-axis CURIE -% position_metadata.dimensions(i).name - resolved label -% -% Human-readable names on the ontology terms are looked up via -% ndi.ontology.lookup. If the lookup throws (ndi-ontology-matlab -% not installed, CURIE unknown), the name stays empty -- the -% V2 ontology_term composite type only requires the value -% to be a struct; the inner-field-name shape is open. -% -% See did-schema's -% did-schema's per-class conversion notes (deleted with did-schema #88) -% for the full conversion spec. - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'position_metadata') ... - || ~isstruct(v2Body.position_metadata) - error('did2:convert:missingBlock', ... - 'position_metadata body is missing the position_metadata property block.'); -end - -block = v2Body.position_metadata; - -if isfield(block, 'ontology_node') - measurementNode = char(block.ontology_node); -else - measurementNode = ''; -end -if isfield(block, 'units') - unitsNode = char(block.units); -else - unitsNode = ''; -end -if isfield(block, 'dimensions') - dimsRaw = block.dimensions; -else - dimsRaw = ''; -end - -newBlock = struct(); -newBlock.measurement = ontologyTerm(measurementNode); -newBlock.units = ontologyTerm(unitsNode); -newBlock.dimensions = buildDimensionRecords(dimsRaw); -v2Body.position_metadata = newBlock; -end - -function term = ontologyTerm(curie) -% Build an ontology_term composite (node + name). Looks up the -% human-readable name via ndi.ontology.lookup; leaves the name -% empty if the lookup is unavailable or fails. -term = struct('node', char(curie), 'name', ''); -if isempty(curie) - return; -end -try - [~, resolved] = ndi.ontology.lookup(char(curie)); - if isstring(resolved) && isscalar(resolved) - term.name = char(resolved); - elseif ischar(resolved) - term.name = resolved; - end -catch - % ndi.ontology not on the path or curie unknown; leave name '' -end -end - -function records = buildDimensionRecords(raw) -% Parse v1's comma-separated `dimensions` CURIE list into an array -% of per-axis structs with explicit positional axis labels. Empty -% input -> 0-element struct array (schema marks the field optional, -% so empty is allowed). -records = struct('axis', {}, 'node', {}, 'name', {}); -if isempty(raw) - return; -end -if isstring(raw) && isscalar(raw) - raw = char(raw); -end -if ~ischar(raw) - return; -end -parts = strsplit(raw, ','); -for k = 1:numel(parts) - curie = strtrim(parts{k}); - if isempty(curie) - continue; - end - term = ontologyTerm(curie); - records(end+1) = struct( ... - 'axis', sprintf('axis_%d', k), ... - 'node', term.node, ... - 'name', term.name); %#ok -end -end diff --git a/src/did/+did2/+convert/+migrators/simple_calc.m b/src/did/+did2/+convert/+migrators/simple_calc.m deleted file mode 100644 index ad61d906..00000000 --- a/src/did/+did2/+convert/+migrators/simple_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = simple_calc(preBody) -%SIMPLE_CALC Base migrator: did_v1 simple_calc body -> the class-preserving V2 shape. -% -% a simple example calculator. The v1 form -% carries `input_parameters` directly on the simple_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'simple_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/spatial_frequency_tuning_calc.m b/src/did/+did2/+convert/+migrators/spatial_frequency_tuning_calc.m deleted file mode 100644 index 2a3fd969..00000000 --- a/src/did/+did2/+convert/+migrators/spatial_frequency_tuning_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = spatial_frequency_tuning_calc(preBody) -%SPATIAL_FREQUENCY_TUNING_CALC Base migrator: did_v1 spatial_frequency_tuning_calc body -> the class-preserving V2 shape. -% -% a spatial-frequency tuning fit. The v1 form -% carries `input_parameters` directly on the spatial_frequency_tuning_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'spatial_frequency_tuning_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/speed_tuning_calc.m b/src/did/+did2/+convert/+migrators/speed_tuning_calc.m deleted file mode 100644 index bcb190e4..00000000 --- a/src/did/+did2/+convert/+migrators/speed_tuning_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = speed_tuning_calc(preBody) -%SPEED_TUNING_CALC Base migrator: did_v1 speed_tuning_calc body -> the class-preserving V2 shape. -% -% a speed tuning fit. The v1 form -% carries `input_parameters` directly on the speed_tuning_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'speed_tuning_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/stimulus_bath.m b/src/did/+did2/+convert/+migrators/stimulus_bath.m deleted file mode 100644 index 88634114..00000000 --- a/src/did/+did2/+convert/+migrators/stimulus_bath.m +++ /dev/null @@ -1,209 +0,0 @@ -function v2Body = stimulus_bath(preBody) -%STIMULUS_BATH Base migrator: did_v1 stimulus_bath body -> the class-preserving V2 shape. -% -% v1 stimulus_bath stores an ontology-typed bath location plus an -% inline CSV `mixture_table` listing chemicals: -% -% stimulus_bath.location - {ontologyNode, name} -% stimulus_bath.mixture_table - "ontologyName,name,value,ontologyUnit,unitName\n -% ,,, -% ,\n -% ..." -% -% V2 keeps `location` as an ontology_term composite (just -% renames `ontologyNode` -> `node`) and parses the mixture CSV -% into an array-of-records `mixture` field. Each chemical row -% becomes a record with the chemical identity as an ontology_term -% and the concentration as a `concentration` composite. -% -% The `concentration` composite carries source_unit / source_value -% verbatim plus optional canonical sub-fields populated whenever -% the source unit is computable into them: -% -% molar (canonical for source_unit in {Molar, M, -% Millimolar, mM, Micromolar, uM, μM, -% Nanomolar, nM, Picomolar, pM}) -% grams_per_liter (canonical for {g/L, g/l, grams per liter, -% mg/mL, mg/ml, mg/L, mg/l, ug/mL, ug/L, -% μg/mL, μg/L}) -% mass_fraction (canonical for {w/w, %w/w}) -% volume_fraction (canonical for {v/v, %v/v}) -% -% Unknown source units leave every canonical sub-field absent but -% still preserve source_unit / source_value -- consumers retain -% the raw value and can compute canonicals later when conventions -% firm up. - -arguments - preBody (1,1) struct -end - -v2Body = preBody; -if ~isfield(v2Body, 'stimulus_bath') ... - || ~isstruct(v2Body.stimulus_bath) - error('did2:convert:missingBlock', ... - 'stimulus_bath body is missing the stimulus_bath property block.'); -end - -block = v2Body.stimulus_bath; - -newBlock = struct(); -newBlock.location = locationToOntologyTerm(block); -newBlock.mixture = parseMixtureTable(block); -v2Body.stimulus_bath = newBlock; -end - -function term = locationToOntologyTerm(block) -% v1 location is a sub-struct {ontologyNode, name}. After -% universalRenames the inner field stays `ontologyNode` (the -% snake_case pass only renames top-level block fields, not nested -% struct fields). We rename here. -term = struct('node', '', 'name', ''); -if ~isfield(block, 'location') - return; -end -loc = block.location; -if ~isstruct(loc) || ~isscalar(loc) - return; -end -if isfield(loc, 'node') - term.node = char(loc.node); -elseif isfield(loc, 'ontologyNode') - term.node = char(loc.ontologyNode); -elseif isfield(loc, 'ontology_node') - term.node = char(loc.ontology_node); -end -if isfield(loc, 'name') - term.name = char(loc.name); -end -end - -function mix = parseMixtureTable(block) -% Parse the v1 CSV mixture_table into an array-of-records. Empty -% or missing -> 0-element struct array (schema marks the field -% optional). -mix = struct('chemical', {}, 'amount', {}); -if ~isfield(block, 'mixture_table') - return; -end -raw = block.mixture_table; -if isempty(raw); return; end -if isstring(raw) && isscalar(raw); raw = char(raw); end -if ~ischar(raw); return; end - -lines = strsplit(raw, newline); -lines = lines(~cellfun('isempty', lines)); -if isempty(lines); return; end - -% Detect header row -- if its first cell is the literal -% 'ontologyName' we skip it. -startIdx = 1; -firstCells = strsplit(lines{1}, ','); -if ~isempty(firstCells) && strcmpi(strtrim(firstCells{1}), 'ontologyName') - startIdx = 2; -end - -for k = startIdx:numel(lines) - cells = strsplit(lines{k}, ','); - cells = cellfun(@strtrim, cells, 'UniformOutput', false); - if numel(cells) < 5; continue; end - chemicalNode = cells{1}; - chemicalName = cells{2}; - valueStr = cells{3}; - unitNode = cells{4}; - unitName = cells{5}; - valueNum = parseDouble(valueStr); - mix(end+1) = struct( ... - 'chemical', struct('node', chemicalNode, 'name', chemicalName), ... - 'amount', buildConcentration(valueNum, unitName, unitNode)); %#ok -end -end - -function x = parseDouble(s) -x = NaN; -if isempty(s); return; end -try - x = str2double(s); -catch - x = NaN; -end -if ~isnumeric(x); x = NaN; end -end - -function c = buildConcentration(value, unitName, ~) -% Build a `concentration` composite. Always populates -% source_unit / source_value; optionally populates one or more -% canonical sub-fields if unit_name is recognised. -c = struct( ... - 'approximate', false, ... - 'source_unit', char(unitName), ... - 'source_value', value); -if isnan(value); return; end - -molarScale = molarScaleFor(unitName); -if ~isnan(molarScale) - c.molar = value * molarScale; - return; -end -gplScale = gramsPerLiterScaleFor(unitName); -if ~isnan(gplScale) - c.grams_per_liter = value * gplScale; - return; -end -if isMassFractionUnit(unitName) - c.grams_per_gram = value; % `mass_fraction` until 2026-10-22 (Jess Haley [ratio slots named by unit]) - return; -end -if isVolumeFractionUnit(unitName) - c.liters_per_liter = value; % `volume_fraction` until 2026-10-22 ([ratio slots named by unit]) - return; -end -% Unknown unit: leave canonicals absent; source-only. -end - -function s = molarScaleFor(u) -% Unit-table lookup for source units that convert to mol/L by a -% pure scalar. Greek mu spellings are normalised to 'u' at the -% caller. Unknown unit -> NaN. -u = lower(char(u)); -switch u - case {'molar', 'm', 'mol/l', 'mol l-1'} - s = 1; - case {'millimolar', 'mm', 'mmol/l'} - s = 1e-3; - case {'micromolar', 'um', 'mumolar', 'umol/l'} - s = 1e-6; - case {'nanomolar', 'nm', 'nmol/l'} - s = 1e-9; - case {'picomolar', 'pm', 'pmol/l'} - s = 1e-12; - otherwise - s = NaN; -end -end - -function s = gramsPerLiterScaleFor(u) -u = lower(char(u)); -switch u - case {'g/l', 'g l-1', 'grams per liter', 'grams per litre', 'mg/ml', 'mg ml-1'} - s = 1; - case {'mg/l', 'mg l-1'} - s = 1e-3; - case {'ug/ml', 'ug ml-1', 'mug/ml'} - s = 1e-3; - case {'ug/l', 'ug l-1'} - s = 1e-6; - otherwise - s = NaN; -end -end - -function tf = isMassFractionUnit(u) -u = char(u); -tf = any(strcmpi(u, {'w/w', '%w/w', '%(w/w)'})); -end - -function tf = isVolumeFractionUnit(u) -u = char(u); -tf = any(strcmpi(u, {'v/v', '%v/v', '%(v/v)'})); -end diff --git a/src/did/+did2/+convert/+migrators/temporal_frequency_tuning_calc.m b/src/did/+did2/+convert/+migrators/temporal_frequency_tuning_calc.m deleted file mode 100644 index 866d0c3a..00000000 --- a/src/did/+did2/+convert/+migrators/temporal_frequency_tuning_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = temporal_frequency_tuning_calc(preBody) -%TEMPORAL_FREQUENCY_TUNING_CALC Base migrator: did_v1 temporal_frequency_tuning_calc body -> the class-preserving V2 shape. -% -% a temporal-frequency tuning fit. The v1 form -% carries `input_parameters` directly on the temporal_frequency_tuning_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'temporal_frequency_tuning_calc'); -end diff --git a/src/did/+did2/+convert/+migrators/tuningcurve_calc.m b/src/did/+did2/+convert/+migrators/tuningcurve_calc.m deleted file mode 100644 index 90aa3cb9..00000000 --- a/src/did/+did2/+convert/+migrators/tuningcurve_calc.m +++ /dev/null @@ -1,16 +0,0 @@ -function v2Body = tuningcurve_calc(preBody) -%TUNINGCURVE_CALC Base migrator: did_v1 tuningcurve_calc body -> the class-preserving V2 shape. -% -% a generic tuning-curve calculation. The v1 form -% carries `input_parameters` directly on the tuningcurve_calc block; -% V2 moves it to the inherited `calculator` block. The -% calculator-identity string lives in `app.app_name` and is -% handled by the universal `app`-block field rename in -% did2.convert.universalRenames -- not here. - -arguments - preBody (1,1) struct -end - -v2Body = did2.convert.calcCommon(preBody, 'tuningcurve_calc'); -end diff --git a/src/did/+did2/+convert/+migrators_j/+super/image_stack_parameters.m b/src/did/+did2/+convert/+migrators_j/+super/image_stack_parameters.m index f1fb4e41..8027c09c 100644 --- a/src/did/+did2/+convert/+migrators_j/+super/image_stack_parameters.m +++ b/src/did/+did2/+convert/+migrators_j/+super/image_stack_parameters.m @@ -12,6 +12,15 @@ % `image_stack_parameters` -- i.e. on every `image_stack` document. There is % no base (+migrators) migrator of this name, so nothing is being displaced. % +% SINCE 2026-10-27 a v1 `imageStack` reads RAW v1 (did2.convert.rawV1Classes, +% [migrators read raw v1]) and no superclass migrator runs on it: its leaf, +% did2.convert.migrators_j.image_stack, calls this function on the raw +% `imageStack_parameters` block for the REFUSALS below (same documents +% quarantine, same identifiers). The empty-placeholder strip has no raw +% counterpart: a raw passthrough is the untouched v1 source. This file stays +% for the v1 `image` (not switched), which runs renamed and shares the block; +% it goes when `image` switches or leaves. +% % --------------------------------------------------------------------- % WHY A SUPERCLASS MIGRATOR AND NOT A CONCRETE ONE % --------------------------------------------------------------------- diff --git a/src/did/+did2/+convert/+migrators_j/Contents.m b/src/did/+did2/+convert/+migrators_j/Contents.m index fb033970..a0f889e6 100644 --- a/src/did/+did2/+convert/+migrators_j/Contents.m +++ b/src/did/+did2/+convert/+migrators_j/Contents.m @@ -694,11 +694,12 @@ % the raw-recording observation + a lineage relation). V_eta retires the % recording-side `element` class: any identifiable thing -- an organism, a % device/probe, a derived signal or sorted unit -- is an `entity` with a -% `type` (here `cell` for a sorted unit, `group` for an ensemble, `device` -% otherwise; see elementEntityType). The element document therefore becomes an -% `entity` with its id PRESERVED, so the ~50 classes that reference it -% (`element_id` / `underlying_element_id` / `stimulator_id`) keep resolving -- -% now to an entity. +% `type` (a device for a probe, a cell or group for a sorted unit, a group for +% an ensemble; anything else carried: elementEntityType, decided 2026-10-26, +% below). The element document therefore becomes an `entity` with its id +% PRESERVED, so the ~50 classes that reference it (`element_id` / +% `underlying_element_id` / `stimulator_id`) keep resolving -- now to an +% entity. % element_epoch % Brainstorm-J migrator: element_epoch -> acquisition_epoch. % epochfiles_ingested @@ -984,8 +985,8 @@ % subject % Brainstorm-J migrator: a v1 subject -> one `entity` of type `organism`, id % preserved, carrying `local_identifier` and `description`. A v1 subject's -% handle was optional, so an empty or missing one is filled from the preserved -% document id (jEnsureLocalId). +% handle was optional; one that states none is carried whole as v1 +% (carry-033). % subject_group % Brainstorm-J migrator: did_v1 subject_group -> an `entity` of type `group`, % id preserved (+ one member_of directed_relation per member). diff --git a/src/did/+did2/+convert/+migrators_j/binaryseries_parameters.m b/src/did/+did2/+convert/+migrators_j/binaryseries_parameters.m index 706e567a..de48ee45 100644 --- a/src/did/+did2/+convert/+migrators_j/binaryseries_parameters.m +++ b/src/did/+did2/+convert/+migrators_j/binaryseries_parameters.m @@ -270,6 +270,20 @@ % and V_eta_data_body_model_plan.md (the addendum that gives the axis its own % `datum_type`, which this class is what surfaced). +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 would write it (data/binaryseries_parameters.json + base.json +% at the locked NDI-matlab `main`, 3cb19a8). NO NDI WRITER AT THAT `main` +% CONSTRUCTS ONE AND NO CORPUS HOLDS ONE: the template alone fixes its shape +% (six snake_case fields, no edges, no `app` block), so the raw document is the +% renamed one and the rules above apply unchanged. What the renamed path would +% have discarded is carried, carry-049; a field, block or edge outside the +% template carries the document, carry-100 (private/jRawAccount, jRawCarry), +% checked after the invented-field guard. did2.convert.roundtrip. +% binaryseries_parameters rebuilds the v1 document; testRawV1RoundTripDemo +% compares the two. arguments preBody (1,1) struct end @@ -287,6 +301,14 @@ end end +% THE RAW READ (see READS RAW v1 above) +[~, collision, unplaced] = jRawAccount(preBody, struct(BLOCK, {{'time_size', 'time_type', ... + 'data_size', 'data_type', 'data_dim', 'samples_regular_intervals'}}), {}); +if jRawCarry('binaryseries_parameters', preBody, collision, unplaced, 'carry-100') + bodies = {preBody}; + return; +end + if isfield(preBody, BLOCK) && isstruct(preBody.(BLOCK)) for f = {'time_size', 'data_size', 'data_dim'} name = f{1}; diff --git a/src/did/+did2/+convert/+migrators_j/cell_type_labels.m b/src/did/+did2/+convert/+migrators_j/cell_type_labels.m index 725905a2..592be3dd 100644 --- a/src/did/+did2/+convert/+migrators_j/cell_type_labels.m +++ b/src/did/+did2/+convert/+migrators_j/cell_type_labels.m @@ -20,8 +20,32 @@ % #126 (T8 binding follow-ons -- taxonomy_level, assignment_method) are % DEFERRED. +% +% READS RAW v1 (did2.convert.rawcellTypeLabelsClasses, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (`cellTypeLabels`, NDI-matlab locked `main` 3cb19a8; +% as +ndi/+fun/+doc/+gene/makeCellTypeLabels.m writes it). Pass 1 still hands it back UNCHANGED. The raw +% passthrough keeps v1's class name `cellTypeLabels`, under which V_eta keeps no class, +% so v1_to_v2 counts it as a passthrough with no schema instead of validating +% it against the renamed `cell_type_labels` class (a `retire` class), as a raw imageStack +% passthrough is; NDI's last step stores its v1 source, stamped did_v1, on +% both paths ([passthrough stays v1: how]). No DID batch pass and no NDI +% second-pass step reads the class. What the renamed path would have discarded +% is carried, carry-049, as before; a field, block or edge outside the +% template carries the document whole as v1 (private/jRawAccount, jRawCarry; +% [fields outside the template are malformed], carry-100). The table in +% did2.convert.rawcellTypeLabelsClasses joins `cellTypeLabels` to this migrator; +% did2.convert.roundtrip.cellTypeLabels rebuilds the v1 document from the passthrough; +% testRawcellTypeLabelsRoundTripGene compares the two. arguments preBody (1,1) struct end -bodies = {preBody}; +[~, collision, unplaced] = jRawAccount(preBody, struct( ... + 'files', {{'file_list', 'file_series', 'file_info'}}, ... + 'cellTypeLabels', {{'label', 'label_name', 'taxonomy_level', 'n_cells', ... + 'n_categories', 'n_unlabeled', 'assignment_method', 'is_unsupervised'}}), ... + {'^cells_document_id$', '^reference_document_id$'}); +jRawCarry('cell_type_labels', preBody, collision, unplaced, 'carry-100'); +bodies = {preBody}; % a passthrough, or the carry of the untouched v1 source end diff --git a/src/did/+did2/+convert/+migrators_j/contrast_sensitivity_calc.m b/src/did/+did2/+convert/+migrators_j/contrast_sensitivity_calc.m index 6ab65dae..e4286cde 100644 --- a/src/did/+did2/+convert/+migrators_j/contrast_sensitivity_calc.m +++ b/src/did/+did2/+convert/+migrators_j/contrast_sensitivity_calc.m @@ -14,9 +14,32 @@ % stimulus_presentation_id; v1 is_modulated_response (0/1) -> % value.significance.modulated_response (boolean), written only when present. % See did2.convert.migrators_j.private.jCalculation. +% +% READS RAW v1 (did2.convert.rawV1Classes; Decided by Jess Haley, 2026-10-26 +% [migrators read raw v1]): v1_to_v2 hands this migrator the document exactly +% as v1 wrote it (class `contrastsensitivity_calc`), with no universalRenames and no superclass +% migrator (none exists for its superclasses; the old +migrators/contrast_sensitivity_calc.m +% wrapper was never reached and is deleted, [early migration pieces fixed] +% (1)). Identity through jRawBody (did2.convert.v1read.readBase); depends_on +% in either spelling ({name, value} / {name, document_id}); the `app` block +% in either spelling ({name, version} / {app_name, app_version}; +% jSoftwareFromApp, checked by did2.convert.v1read.readApp); NDI's camelCase +% result fields (e.g. sensitivity_RBNS) read case- and underscore-insensitively +% (jTuningCurve / jContrastSensitivityValue), so the universalRenames path +% ('RawV1Classes', {}) converts the same way. Every other field is accounted +% for (jCalculation 'AccountForEveryField'); a carry is the untouched v1 +% source. did2.convert.roundtrip.contrastsensitivity_calc rebuilds the v1 document; +% testRawV1RoundTripTuning compares the two on the writer's output +% (ndi.calc.vis.contrast_sensitivity, NDIcalc-vis-matlab). + arguments preBody (1,1) struct end -bodies = jCalculation(preBody, 'contrast_sensitivity_calculation', 'csf', ... - 'contrast_sensitivity_calc', 'contrast sensitivity', 'ndi.calc.vis.contrast_sensitivity'); +body = jRawBody(preBody, 'contrastsensitivity_calc'); +bodies = jCalculation(body, 'contrast_sensitivity_calculation', 'csf', ... + char(body.document_class.class_name), 'contrast sensitivity', 'ndi.calc.vis.contrast_sensitivity', ... + 'AccountForEveryField', true); +if isscalar(bodies) && isequaln(bodies{1}, body) + bodies = {preBody}; % a carry is the untouched v1 source +end end diff --git a/src/did/+did2/+convert/+migrators_j/contrast_tuning_calc.m b/src/did/+did2/+convert/+migrators_j/contrast_tuning_calc.m index c1e8f59e..ffc2438b 100644 --- a/src/did/+did2/+convert/+migrators_j/contrast_tuning_calc.m +++ b/src/did/+did2/+convert/+migrators_j/contrast_tuning_calc.m @@ -12,9 +12,32 @@ % % Fold is 1 -> 1 with base.id + depends_on preserved. See % did2.convert.migrators_j.private.jCalculation. +% +% READS RAW v1 (did2.convert.rawV1Classes; Decided by Jess Haley, 2026-10-26 +% [migrators read raw v1]): v1_to_v2 hands this migrator the document exactly +% as v1 wrote it (class `contrasttuning_calc`), with no universalRenames and no superclass +% migrator (none exists for its superclasses; the old +migrators/contrast_tuning_calc.m +% wrapper was never reached and is deleted, [early migration pieces fixed] +% (1)). Identity through jRawBody (did2.convert.v1read.readBase); depends_on +% in either spelling ({name, value} / {name, document_id}); the `app` block +% in either spelling ({name, version} / {app_name, app_version}; +% jSoftwareFromApp, checked by did2.convert.v1read.readApp); NDI's camelCase +% result fields (e.g. naka_rushton_RB_parameters) read case- and underscore-insensitively +% (jTuningCurve / jContrastSensitivityValue), so the universalRenames path +% ('RawV1Classes', {}) converts the same way. Every other field is accounted +% for (jCalculation 'AccountForEveryField'); a carry is the untouched v1 +% source. did2.convert.roundtrip.contrasttuning_calc rebuilds the v1 document; +% testRawV1RoundTripTuning compares the two on the writer's output +% (ndi.calc.vis.contrast_tuning, NDIcalc-vis-matlab). + arguments preBody (1,1) struct end -bodies = jCalculation(preBody, 'contrast_tuning_calculation', 'contrast', ... - 'contrast_tuning', 'contrast tuning', 'ndi.calc.vis.contrast'); +body = jRawBody(preBody, 'contrasttuning_calc'); +bodies = jCalculation(body, 'contrast_tuning_calculation', 'contrast', ... + 'contrast_tuning', 'contrast tuning', 'ndi.calc.vis.contrast', ... + 'AccountForEveryField', true); +if isscalar(bodies) && isequaln(bodies{1}, body) + bodies = {preBody}; % a carry is the untouched v1 source +end end diff --git a/src/did/+did2/+convert/+migrators_j/daqmetadatareader.m b/src/did/+did2/+convert/+migrators_j/daqmetadatareader.m index 5e682868..21daa370 100644 --- a/src/did/+did2/+convert/+migrators_j/daqmetadatareader.m +++ b/src/did/+did2/+convert/+migrators_j/daqmetadatareader.m @@ -91,11 +91,39 @@ % are both REAL and both convert -- the second simply omits software_id rather % than writing it empty, because +did2/+validate/references.m:90 SKIPS empty % edges, so an empty edge is invisible rather than absent. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (NDI daqmetadatareader.json + base.json at the +% locked NDI-matlab `main`, 3cb19a8, as +ndi/+daq/metadatareader.m +% newdocument writes it). Every v1 field and where it goes; +% did2.convert.roundtrip.daqmetadatareader rebuilds the v1 document and +% testRawV1RoundTripDaq compares the two: +% +% base.id, session_id, datestamp -> the epoch_parameter_reader's +% base.name -> not written (the writer leaves '') +% ndi_daqmetadatareader_class -> the software entity's name +% tab_separated_file_parameter -> file_regex +% +% What the renamed path would have discarded is carried, carry-049, as +% before; a field or edge no part of this migrator reads now carries the +% document whole as v1 (private/jRawAccount, jRawCarry; carry-100, [fields outside the template +% are malformed]). arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above) +src = preBody; +[preBody, collision, unplaced] = jRawAccount(src, struct('daqmetadatareader', ... + {{'ndi_daqmetadatareader_class', 'tab_separated_file_parameter'}}), {}); +if jRawCarry('daqmetadatareader', src, collision, unplaced, 'carry-100') + bodies = {src}; + return; +end + blk = struct(); if isfield(preBody, 'daqmetadatareader') && isstruct(preBody.daqmetadatareader) ... && isscalar(preBody.daqmetadatareader) @@ -106,7 +134,7 @@ filePattern = jGetChar(blk, 'tab_separated_file_parameter'); if isempty(implClass) && isempty(filePattern) - bodies = {preBody}; % see THE GUARD above + bodies = {src}; % see THE GUARD above return; end diff --git a/src/did/+did2/+convert/+migrators_j/daqmetadatareader_epochdata_ingested.m b/src/did/+did2/+convert/+migrators_j/daqmetadatareader_epochdata_ingested.m index cd4cc8f3..19deff91 100644 --- a/src/did/+did2/+convert/+migrators_j/daqmetadatareader_epochdata_ingested.m +++ b/src/did/+did2/+convert/+migrators_j/daqmetadatareader_epochdata_ingested.m @@ -72,10 +72,29 @@ % existence-only (declarative), so the edge resolves against the migrated % reader document whatever the target class ends up being called. +% +% READS RAW v1 (did2.convert.rawV1Classes; Decided by Jess Haley, 2026-10-26 +% [migrators read raw v1]): v1_to_v2 hands this migrator the document exactly +% as v1 wrote it (NDI daqmetadatareader_epochdata_ingested.json + epochid.json +% + base.json at the locked NDI-matlab `main`, 3cb19a8, as +% +ndi/+daq/metadatareader.m ingest_epochfiles writes it), and pass 1 carries +% it UNTOUCHED, whatever it holds: every field reaches NDI's second pass, +% which places it or carries it (carry-086, carry-087, carry-088; [extra field +% on an ingested stimulus file is malformed]). Its id is read through +% did2.convert.v1read.readBase, so a legacy `ndi_document` identity is read +% too. The renamed path carried a document universalRenames would have +% changed with carry-049 instead; both carry it. +% did2.convert.roundtrip.daqmetadatareader_epochdata_ingested holds no +% inverse of a conversion, because pass 1 converts nothing: +% testRawV1RoundTripIngested checks the carry. + arguments preBody (1,1) struct end +b = did2.convert.v1read.readBase(preBody); +id = b.id; +if ~ischar(id); id = ''; end % did-schema #88 RETIRED `acquisition_metadata_file` (#73 review item 61): the % bytes become an opaque_body OWNED BY the stimulator term_manipulation of the % same epoch, which resolveEpochProbemap mints in a batch pass. A single @@ -90,7 +109,7 @@ % stimulus-presentation manipulation (or keeps it as v1 with none). % carry-register: carry-046 did2.convert.reportNote('carried_as_v1', 'daqmetadatareader_epochdata_ingested', ... - char(preBody.base.id), ['[carry-046] retired class: a body of the presentation, made ' ... + id, ['[carry-046] retired class: a body of the presentation, made ' ... 'by the NDI second pass ([ingested stimulus file is a body of the presentation])']); bodies = {preBody}; end diff --git a/src/did/+did2/+convert/+migrators_j/daqreader.m b/src/did/+did2/+convert/+migrators_j/daqreader.m index 83081d88..72e50a28 100644 --- a/src/did/+did2/+convert/+migrators_j/daqreader.m +++ b/src/did/+did2/+convert/+migrators_j/daqreader.m @@ -100,11 +100,40 @@ % in private/jSoftware.m. Here the merge is additionally CONSTRAINED: base.id % is preserved, so this software document's id is load-bearing for four other % classes and a merger must RETARGET rather than delete. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (NDI daqreader.json + base.json at the locked +% NDI-matlab `main`, 3cb19a8, as +ndi/+daq/reader.m newdocument writes it). +% Every v1 field and where it goes; did2.convert.roundtrip.daqreader rebuilds +% the v1 document and testRawV1RoundTripDaq compares the two: +% +% base.id, session_id, datestamp -> the acquisition_reader's (the session +% is often ndi.session.empty_id()) +% base.name -> not written (the writer leaves '') +% daqreader.ndi_daqreader_class -> the software entity's name +% +% What the renamed path would have discarded is carried, carry-049, as +% before; a field or edge no part of this migrator reads now carries the +% document whole as v1 (private/jRawAccount, jRawCarry; carry-100, [fields outside the template +% are malformed]). arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above). `reader_string` is not a field of +% NDI's daqreader template; it is what daqreader_ndr.m de-encodes onto the +% block before it hands the document on, and it is placed below. +src = preBody; +[preBody, collision, unplaced] = jRawAccount(src, struct('daqreader', ... + {{'ndi_daqreader_class', 'reader_string'}}), {}); +if jRawCarry('daqreader', src, collision, unplaced, 'carry-100') + bodies = {src}; + return; +end + blk = struct(); if isfield(preBody, 'daqreader') && isstruct(preBody.daqreader) ... && isscalar(preBody.daqreader) @@ -122,7 +151,7 @@ % a body with NEITHER a class name NOR a reader string says nothing at all, % and minting entities from it would be the hollow-document defect. if isempty(implClass) && isempty(readerString) - bodies = {preBody}; + bodies = {src}; return; end diff --git a/src/did/+did2/+convert/+migrators_j/daqreader_epochdata_ingested.m b/src/did/+did2/+convert/+migrators_j/daqreader_epochdata_ingested.m index 8bb345de..08b72b4f 100644 --- a/src/did/+did2/+convert/+migrators_j/daqreader_epochdata_ingested.m +++ b/src/did/+did2/+convert/+migrators_j/daqreader_epochdata_ingested.m @@ -1,4 +1,4 @@ -function bodies = daqreader_epochdata_ingested(preBody) +function bodies = daqreader_epochdata_ingested(preBody, delegated) %DAQREADER_EPOCHDATA_INGESTED Brainstorm-J migrator: lift the epoch's clock % extents out of `epochtable` into `relative_time_reference` documents. % @@ -91,9 +91,43 @@ % Which entries become documents, and which correctly become nothing, is in % jEpochClockReferences (NO TIMES => NO REFERENCE: `no_time` and NaN intervals % are both real, reachable values here). - +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (daqreader_epochdata_ingested.json + epochid.json + +% base.json at the locked NDI-matlab `main`, 3cb19a8, as +% +ndi/+daq/reader.m ingest_epochfiles: the epochtable and +% daqreader_id; that writer names an undefined ndi_daqreader_mfdaq_obj and +% cannot run at that `main`, so its shape is the only evidence writes it). Its blocks are snake_case already and it has no `app` +% block, so the raw shape is the renamed one but for v1's `value` edge key, +% which every reader here takes (jEpochDocId, did2.convert.epochMint, NDI's +% sliceTetanus). In pass 1 there is no epoch_id edge, so the document passes +% through as before. What the renamed path would have discarded is carried, +% carry-049, as before; a field, block or edge outside the template (which +% the passthrough met as an undeclared field) carries the document whole as +% v1 (private/jRawAccount, jRawCarry; [fields outside the template are +% malformed], carry-100). did2.convert.roundtrip.daqreader_epochdata_ingested rebuilds the v1 +% document; testRawV1RoundTripIngestedEpochs compares the two. +% +% DELEGATED (the second argument, true): daqreader_mfdaq_epochdata_ingested +% hands its de-encoded body here after accounting for every raw field itself; +% the raw read is skipped for it. arguments preBody (1,1) struct + delegated (1,1) logical = false +end + +if ~delegated + % THE RAW READ (see READS RAW v1 above) + [~, collision, unplaced] = jRawAccount(preBody, struct( ... + 'daqreader_epochdata_ingested', {{'epochtable'}}, ... + 'epochid', {{'epochid'}}, 'files', {{'file_list', 'file_info'}}), ... + {'^daqreader_id$', '^epoch_id$'}); + if jRawCarry('daqreader_epochdata_ingested', preBody, collision, unplaced, 'carry-100') + bodies = preBody; + return; + end end epochDocId = jEpochDocId(preBody); diff --git a/src/did/+did2/+convert/+migrators_j/daqreader_image_epochdata_ingested.m b/src/did/+did2/+convert/+migrators_j/daqreader_image_epochdata_ingested.m index e0cb10ff..ccde498a 100644 --- a/src/did/+did2/+convert/+migrators_j/daqreader_image_epochdata_ingested.m +++ b/src/did/+did2/+convert/+migrators_j/daqreader_image_epochdata_ingested.m @@ -290,11 +290,38 @@ % % NOTHING BELOW THIS LINE CHANGED. There is no MATLAB in the authoring % environment; this pass added evidence and tests, not behaviour. - +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (daqreader_image_epochdata_ingested.json + +% daqreader_epochdata_ingested.json + epochid.json + base.json at the locked NDI-matlab `main`, 3cb19a8, as +% +ndi/+daq/+reader/image.m ingest_epochfiles writes it). Its blocks are snake_case already and it has no `app` +% block, so the raw shape is the renamed one but for v1's `value` edge key, +% which every reader here takes (jEpochDocId, did2.convert.epochMint, NDI's +% sliceTetanus). In pass 1 there is no epoch_id edge, so the document passes +% through as before. What the renamed path would have discarded is carried, +% carry-049, as before; a field, block or edge outside the template (which +% the passthrough met as an undeclared field) carries the document whole as +% v1 (private/jRawAccount, jRawCarry; [fields outside the template are +% malformed], carry-100). did2.convert.roundtrip.daqreader_image_epochdata_ingested rebuilds the v1 +% document; testRawV1RoundTripIngestedEpochs compares the two. arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above) +[~, collision, unplaced] = jRawAccount(preBody, struct( ... + 'daqreader_image_epochdata_ingested', {{'dimension_order', 'dimension_size', ... + 'data_type', 'num_frames', 'frametimes', 'clocktype', 'metadata'}}, ... + 'daqreader_epochdata_ingested', {{'epochtable'}}, ... + 'epochid', {{'epochid'}}, 'files', {{'file_list', 'file_info'}}), ... + {'^daqreader_id$', '^epoch_id$'}); +if jRawCarry('daqreader_image_epochdata_ingested', preBody, collision, unplaced, 'carry-100') + bodies = {preBody}; + return; +end + epochDocId = jEpochDocId(preBody); if isempty(epochDocId) bodies = {preBody}; diff --git a/src/did/+did2/+convert/+migrators_j/daqreader_mfdaq_epochdata_ingested.m b/src/did/+did2/+convert/+migrators_j/daqreader_mfdaq_epochdata_ingested.m index 6c755891..a4297d66 100644 --- a/src/did/+did2/+convert/+migrators_j/daqreader_mfdaq_epochdata_ingested.m +++ b/src/did/+did2/+convert/+migrators_j/daqreader_mfdaq_epochdata_ingested.m @@ -27,12 +27,66 @@ % afterwards. did2.convert.v1_to_v2 accepts either % (normaliseMigratorOutput), and callers that invoke this migrator function % directly keep getting the struct they get today. +% +% READS RAW v1 (did2.convert.rawV1Classes; Decided by Jess Haley, 2026-10-26 +% [migrators read raw v1]): v1_to_v2 hands this migrator the document exactly +% as v1 wrote it (NDI daqreader_mfdaq_epochdata_ingested.json + +% daqreader_epochdata_ingested.json + epochid.json + base.json at the locked +% NDI-matlab `main`, 3cb19a8, as +ndi/+daq/+reader/mfdaq.m ingest_epochfiles +% writes it), identity through jRawBody. Every v1 field and where it goes; +% did2.convert.roundtrip.daqreader_mfdaq_epochdata_ingested rebuilds the v1 +% document and testRawV1RoundTripIngested compares the two: +% +% base.* -> kept (v1_to_v2 renames datestamp and makes +% session_id the edge on the way out) +% depends_on daqreader_id -> kept, as {name, document_id}: the shape +% universalRenames gave it, which the batch +% passes read. An entry with a `version` or a +% second, different id is carried, as the +% renamed path carried it (carry-049) +% files.file_list, file_info -> kept (the recording archives) +% epochid.epochid -> kept +% daqreader_epochdata_ingested.epochtable -> kept (lifted when an epoch +% edge exists, the parent migrator) +% daqreader_mfdaq_epochdata_ingested.parameters +% -> daqreader_epochdata_ingested.parameters +% +% An `ndi_document` block beside `base` is carried too (carry-049: the +% renamed path discarded it and carried the document). A field of the mfdaq +% block other than `parameters`, which the renamed path dropped without a +% word, or a legacy identity field outside base.json's four, now carries the +% document whole as v1 ([fields outside the template are malformed], +% carry-100, via private/jRawCarry). arguments preBody (1,1) struct end -v2Body = preBody; +body = jRawBody(preBody, 'daqreader_mfdaq_epochdata_ingested'); +[deps, collision] = renamedDependsOn(body); +unplaced = unreadFields(preBody); +if ~isempty(collision) + % carry-register: carry-049 (the renamed path carried this collision) + did2.convert.reportNote('carried_as_v1', 'daqreader_mfdaq_epochdata_ingested', ... + char(body.base.id), ['[carry-049] universalRenames would discard: ' ... + strjoin(collision, ', ')]); + bodies = preBody; + return; +end +if jRawCarry('daqreader_mfdaq_epochdata_ingested', preBody, {}, unplaced, 'carry-100') + bodies = preBody; % [fields outside the template are malformed], carry-100 + return; +end + +v2Body = body; +if isfield(v2Body, 'depends_on') + v2Body.depends_on = deps; +end +% the superclass list by name (did2.convert.v1read.readStamp: v1 names a +% superclass by its definition path); v1_to_v2's ensureClassBlocks rebuilds +% the V_eta chain from the class name, as on the renamed path +stamp = did2.convert.v1read.readStamp(body); +v2Body.document_class.superclasses = struct('class_name', stamp.superclasses); v2Body.document_class.class_name = 'daqreader_epochdata_ingested'; v2Body.document_class.class_version = '2.0.0'; @@ -63,5 +117,67 @@ % Hand the de-encoded body to the parent migrator so the epoch clock extents are % lifted here exactly as they are for a plain daqreader_epochdata_ingested. -bodies = did2.convert.migrators_j.daqreader_epochdata_ingested(v2Body); +bodies = did2.convert.migrators_j.daqreader_epochdata_ingested(v2Body, true); % accounted for above +end + +% ===================== the raw read ======================================== + +function [deps, collision] = renamedDependsOn(body) +%RENAMEDDEPENDSON depends_on as {name, document_id}, the shape the +% universalRenames pass wrote and the batch passes read, from the raw v1 +% entries (did2.convert.v1read.readDependsOn). COLLISION lists what that pass +% would have discarded: an entry's `version`, or a second id that differs, +% and an `ndi_document` block beside `base`. (The depends_on read is +% +migrators_j/element_epoch.m's.) +deps = struct('name', {}, 'document_id', {}); +collision = {}; +if isfield(body, 'ndi_document') && isfield(body, 'base') && ~isempty(body.ndi_document) + collision{end+1} = 'ndi_document'; +end +if ~isfield(body, 'depends_on') || isempty(body.depends_on) + if isfield(body, 'depends_on') + deps = body.depends_on; % an empty list stays as written, as the pass left it + end + return; +end +raw = did2.convert.v1read.readDependsOn(body); +for k = 1:numel(raw) + deps(end+1) = struct('name', raw(k).name, 'document_id', raw(k).document_id); %#ok + if ~isempty(raw(k).version) + collision{end+1} = sprintf('depends_on(%s).version', raw(k).name); %#ok + end + others = fieldnames(raw(k).other); + for j = 1:numel(others) + collision{end+1} = sprintf('depends_on(%s).%s', raw(k).name, others{j}); %#ok + end +end +end + +function unplaced = unreadFields(preBody) +%UNREADFIELDS What the de-encode does not read and the renamed path dropped +% or moved where nothing reads it: a field of the mfdaq block other than +% `parameters`; a legacy identity field outside base.json's four (jRawBody +% keeps only those four). +unplaced = {}; +blk = 'daqreader_mfdaq_epochdata_ingested'; +if isfield(preBody, blk) + sub = preBody.(blk); + if isstruct(sub) && isscalar(sub) + fns = fieldnames(sub); + for k = 1:numel(fns) + if ~strcmp(fns{k}, 'parameters') + unplaced{end+1} = [blk '.' fns{k}]; %#ok + end + end + elseif ~isempty(sub) + unplaced{end+1} = blk; + end +end +b = did2.convert.v1read.readBase(preBody); +if strcmp(b.source, 'ndi_document') + extra = fieldnames(b.extra); + for k = 1:numel(extra) + unplaced{end+1} = ['ndi_document.' extra{k}]; %#ok + end +end end diff --git a/src/did/+did2/+convert/+migrators_j/daqreader_ndr.m b/src/did/+did2/+convert/+migrators_j/daqreader_ndr.m index 6e2b4597..210bb41a 100644 --- a/src/did/+did2/+convert/+migrators_j/daqreader_ndr.m +++ b/src/did/+did2/+convert/+migrators_j/daqreader_ndr.m @@ -16,11 +16,46 @@ % is the stale-header trap in the header of the very file whose allow-list % entry was retired for it -- a docstring claiming MORE was carried than is, % which is the reassuring direction. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (NDI daqreader_ndr.json + daqreader.json + base.json +% at the locked NDI-matlab `main`, 3cb19a8, as +daq/+reader/+mfdaq/ndr.m and +% +daq/+reader/+image/ndr.m newdocument write it). It has NO superclass +% migrator to fold: neither `base` nor `daqreader` has one (+migrators_j/ +% daqreader.m is the concrete migrator this one hands on to). Every v1 field +% and where it goes; did2.convert.roundtrip.daqreader_ndr rebuilds the v1 +% document and testRawV1RoundTripDaq compares the two: +% +% base.id, session_id, datestamp -> the acquisition_reader's +% base.name -> not written (the writer leaves '') +% daqreader.ndi_daqreader_class -> the software entity's name +% daqreader_ndr.ndr_reader_string -> acquisition_reader.reader_string +% daqreader_ndr.ndi_daqreader_ndr_class +% -> not written: it restates the +% reader class (carry-017 otherwise) +% daqreader_ndr.file_extension -> carried (carry-039) +% +% What the renamed path would have discarded is carried, carry-049, as +% before; a field or edge no part of this migrator reads now carries the +% document whole as v1 (private/jRawAccount, jRawCarry; carry-100, [fields outside the template +% are malformed]). arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above) +src = preBody; +[preBody, collision, unplaced] = jRawAccount(src, struct( ... + 'daqreader', {{'ndi_daqreader_class'}}, ... + 'daqreader_ndr', {{'ndr_reader_string', 'ndi_daqreader_ndr_class', 'file_extension'}}), {}); +if jRawCarry('daqreader_ndr', src, collision, unplaced, 'carry-100') + v2Body = {src}; + return; +end + % `ndi_daqreader_ndr_class` is dropped only when it restates % `daqreader.ndi_daqreader_class` ([restated values checked], Jess Haley, % 2026-10-26; TEAM-SIGN-OFF [daq configuration], "dropped as redundant"). @@ -44,7 +79,7 @@ % carry-register: carry-017 (the reader class item); carry-039 (file_extension) did2.convert.reportNote('carried_as_v1', 'daqreader_ndr', char(preBody.base.id), ... ['unplaced: ' strjoin(unplaced, ', ')]); - v2Body = {preBody}; + v2Body = {src}; return; end diff --git a/src/did/+did2/+convert/+migrators_j/daqsystem.m b/src/did/+did2/+convert/+migrators_j/daqsystem.m index 71d19207..57689b4c 100644 --- a/src/did/+did2/+convert/+migrators_j/daqsystem.m +++ b/src/did/+did2/+convert/+migrators_j/daqsystem.m @@ -244,11 +244,48 @@ % it by hand". It needs a hand edit by someone who may make one. The stale % direction is the safe one (it claims LESS progress than exists), but it is % recorded here rather than left to be found. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (NDI daqsystem.json + base.json at the locked +% NDI-matlab `main`, 3cb19a8, as +ndi/+daq/system.m newdocument writes it). +% Every v1 field and where it goes; did2.convert.roundtrip.daqsystem rebuilds +% the v1 document and testRawV1RoundTripDaq compares the two: +% +% base.id, session_id, datestamp -> the acquisition_system's +% base.name -> acquisition_system.name (the join key) +% daqsystem.ndi_daqsystem_class -> the software entity's name (software_id) +% depends_on filenavigator_id -> epoch_file_pattern_id +% depends_on daqreader_id -> reader_id +% depends_on daqmetadatareader_id, _1.._N +% -> epoch_parameter_reader_id, in order (the +% template's bare entry is empty on every +% writer document) +% +% Edges are read with either key (`value`, as v1 writes them, or `id` / +% `document_id`). What the renamed path would have discarded (a depends_on +% `version`, a second id, an `ndi_document` beside `base`) is carried, +% carry-049, as before; a field or edge no part of this migrator reads, which +% the renamed path dropped without a word, now carries the document whole as +% v1 (private/jRawAccount, jRawCarry; carry-100, [fields outside the template +% are malformed]). arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above): what the migrator does not read +% carries the untouched v1 document; a legacy identity block is read as base. +src = preBody; +[preBody, collision, unplaced] = jRawAccount(src, ... + struct('daqsystem', {{'ndi_daqsystem_class'}}), ... + {'^filenavigator_id$', '^daqreader_id$', '^daqmetadatareader_id(_\d+)?$'}); +if jRawCarry('daqsystem', src, collision, unplaced, 'carry-100') + bodies = {src}; + return; +end + blk = struct(); if isfield(preBody, 'daqsystem') && isstruct(preBody.daqsystem) ... && isscalar(preBody.daqsystem) @@ -288,7 +325,7 @@ % that can carry a document on its own, via the software_id edge, so it has % to be counted as something-to-declare or a class-name-only daqsystem would % fall into a passthrough that is no longer warranted. - bodies = {preBody}; + bodies = {src}; return; end diff --git a/src/did/+did2/+convert/+migrators_j/dataset_remote.m b/src/did/+did2/+convert/+migrators_j/dataset_remote.m index a62444e4..158c845a 100644 --- a/src/did/+did2/+convert/+migrators_j/dataset_remote.m +++ b/src/did/+did2/+convert/+migrators_j/dataset_remote.m @@ -16,11 +16,49 @@ % - directed_relation dataset -stored_at-> web_resource. % - organization (if a remote org namespace is given) + web_resource % -hosted_by-> organization. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (NDI dataset_remote.json + base.json at the locked +% NDI-matlab `main`, 3cb19a8, as +ndi/+cloud/+internal/createRemoteDatasetDoc.m +% writes it: base.session_id = the dataset's id, no depends_on). Every v1 +% field and where it goes; did2.convert.roundtrip.dataset_remote rebuilds the +% v1 document and testRawV1RoundTripSession compares the two: +% +% base.session_id -> the dataset entity's id +% base.datestamp -> its creation_timestamp +% base.id -> NOT KEPT: a known finding, a question for +% the team +% base.name -> not kept ('' on every writer document) +% dataset_remote.dataset_id -> the dataset's global_identifier +% `ndicloud:` +% dataset_remote.organization_id +% -> the organization entity's name (the +% writer stores the cloud organization's +% id here, not a name: a finding), and the +% dataset -hosted_by-> organization relation +% +% A field, block or edge outside these, which the renamed path dropped +% without a word, now carries the document whole as v1 (private/jRawAccount, +% jRawCarry; carry-100, [fields outside the template are malformed]); what the renamed path would have +% discarded (an `ndi_document` beside `base`, a depends_on `version`) is +% carried, carry-049, as before. arguments preBody (1,1) struct end +% THE RAW READ (see READS RAW v1 above): what the migrator does not read +% carries the untouched v1 document; a legacy identity block is read as base. +src = preBody; +[preBody, collision, unplaced] = jRawAccount(src, ... + struct('dataset_remote', {{'dataset_id', 'organization_id'}}), {}); +if jRawCarry('dataset_remote', src, collision, unplaced, 'carry-100') + v2Body = {src}; + return; +end + block = struct(); if isfield(preBody, 'dataset_remote') && isstruct(preBody.dataset_remote) block = preBody.dataset_remote; diff --git a/src/did/+did2/+convert/+migrators_j/demo_ndi.m b/src/did/+did2/+convert/+migrators_j/demo_ndi.m index 8d056a6d..851edbdb 100644 --- a/src/did/+did2/+convert/+migrators_j/demo_ndi.m +++ b/src/did/+did2/+convert/+migrators_j/demo_ndi.m @@ -60,11 +60,30 @@ % UNVERIFIED: there is no MATLAB in the authoring environment. CI is the first % execution of every line here. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (`demoNDI`, NDI-matlab locked `main` 3cb19a8; +% no NDI writer at that `main` makes one alone (ndi.calc.example.simple makes +% demoNDIMock); no corpus holds one, and the template fixes its shape). jDemoFold reads the blocks in v1's spelling (demoNDI, demoNDIMock) +% or the renamed one. What the renamed path would have discarded is carried, +% carry-049; a field, block or edge outside the template carries the +% document, carry-100 (private/jRawAccount, jRawCarry), where the fold +% refused it before (an error, so a quarantine). did2.convert.roundtrip.demoNDI +% rebuilds the v1 document; testRawV1RoundTripDemo compares the two. arguments preBody (1,1) struct end % is_mock FALSE: a `demoNDI` document does not carry the did_v1 `mock` superclass, % and false is the value did-schema declares as `demo.is_mock`'s default_value. +% THE RAW READ (see READS RAW v1 above) +[~, collision, unplaced] = jRawAccount(preBody, struct( ... + 'demoNDI', {{'value'}}, 'files', {{'file_list', 'file_info'}}), {}); +if jRawCarry('demo_ndi', preBody, collision, unplaced, 'carry-100') + v2Body = {preBody}; + return; +end v2Body = jDemoFold(preBody, false, 'demo_ndi'); end diff --git a/src/did/+did2/+convert/+migrators_j/demo_ndi_mock.m b/src/did/+did2/+convert/+migrators_j/demo_ndi_mock.m index 8c6fd5f3..d60695c3 100644 --- a/src/did/+did2/+convert/+migrators_j/demo_ndi_mock.m +++ b/src/did/+did2/+convert/+migrators_j/demo_ndi_mock.m @@ -65,11 +65,31 @@ % UNVERIFIED: there is no MATLAB in the authoring environment. CI is the first % execution of every line here. +% +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1], did-schema +% V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator the document +% exactly as v1 wrote it (`demoNDIMock`, NDI-matlab locked `main` 3cb19a8; +% +ndi/+calc/+example/simple.m: demoNDI.value, + session newdocument(), +% add_file('filename1.ext', ...)). jDemoFold reads the blocks in v1's spelling (demoNDI, demoNDIMock) +% or the renamed one. What the renamed path would have discarded is carried, +% carry-049; a field, block or edge outside the template carries the +% document, carry-100 (private/jRawAccount, jRawCarry), where the fold +% refused it before (an error, so a quarantine). did2.convert.roundtrip.demoNDIMock +% rebuilds the v1 document; testRawV1RoundTripDemo compares the two. arguments preBody (1,1) struct end % is_mock TRUE -- and jDemoFold still READS `mock.ismock` when the body carries % it, so a stored value wins over the class name. +% THE RAW READ (see READS RAW v1 above) +[~, collision, unplaced] = jRawAccount(preBody, struct( ... + 'demoNDI', {{'value'}}, 'demoNDIMock', {{}}, 'mock', {{'ismock'}}, ... + 'files', {{'file_list', 'file_info'}}), {}); +if jRawCarry('demo_ndi_mock', preBody, collision, unplaced, 'carry-100') + v2Body = {preBody}; + return; +end v2Body = jDemoFold(preBody, true, 'demo_ndi_mock'); end diff --git a/src/did/+did2/+convert/+migrators_j/distance_metadata.m b/src/did/+did2/+convert/+migrators_j/distance_metadata.m index e6d0841d..676d693f 100644 --- a/src/did/+did2/+convert/+migrators_j/distance_metadata.m +++ b/src/did/+did2/+convert/+migrators_j/distance_metadata.m @@ -4,17 +4,27 @@ % % Routed from did2.convert.v1_to_v2 only when TargetVersion == 'V_eta'. The v1 % doc is FLAT and records the two ENDPOINTS of a distance measurement, not the -% distance itself: `ontologyNode_A` is the animal-subject doc id, `ontologyNode_B` -% a patch (ontology_table_row) doc id, `ontologyNumericValues_A/_B` are `[]` by -% design, `units` a CURIE, and `depends_on element_id` points at the `distance` -% TIMESERIES element (where the actual distances over time live). -% -% The V_eta distance_metadata schema is shape-identical to the base migrator's output (the flat -% per-endpoint A/B fields collapse into a nested `endpoints` array-of-records + -% an `units` ontology_term), so this DELEGATES to the proven, tested base -% migrator (did2.convert.migrators.distance_metadata -- regex label discovery, -% string/numeric handling, ndi.ontology.lookup name resolution) and wraps its one -% body in the cell the J pipeline expects. +% distance itself: `ontologyNode_A` / `_B` name what each endpoint is (the JH +% writer: EMPTY:0000096 "subject document identifier" and EMPTY:0000134 +% "bacterial patch document identifier"), `ontologyStringValues_A` / `_B` the +% ids of those documents (comma-separated), `integerIDs_A` / `_B` their +% indices, `ontologyNumericValues_A/_B` are `[]` by design, `units` a CURIE, +% and `depends_on element_id` points at the `distance` TIMESERIES element +% (where the actual distances over time live). +% +% The V_eta distance_metadata collapses the flat per-endpoint A/B fields into +% a nested `endpoints` array-of-records + a `units` ontology_term: +% +% endpoints(i).label 'A', 'B' (the suffix, upper case) +% endpoints(i).measurement ontology_term {node: ontologyNode_X, +% name: ndi.ontology.lookup's, else ''} +% endpoints(i).integer_ids integerIDs_X, as a row +% endpoints(i).string_ids ontologyStringValues_X split on ',' +% endpoints(i).numeric_values ontologyNumericValues_X, as a row +% units ontology_term {node: units} +% +% Endpoints are found by the `ontologyNode_` fields the document holds, in +% label order, so a third endpoint would be kept too. % % It deliberately does NOT: % - emit a `length_observation`: there is no scalar distance in the metadata @@ -26,12 +36,196 @@ % 946faf95: 4156 JH orphans, a gating failure). The endpoints can only be % resolved by the second pass, which sees the migrated-id graph. % -% The reshape clears the ~2078 JH quarantines (the old J code read a nested -% `endpoints.numeric_values` that never exists -> no-vals passthrough of the flat -% doc -> failed the required non-empty `endpoints`). See -% schemas/V_eta_distance_metadata_plan.md. +% READS RAW v1 (did2.convert.rawV1Classes, 2026-10-27; Decided by Jess Haley, +% 2026-10-26 [migrators read raw v1] and [early migration pieces fixed] (1), +% did-schema V_eta_go_forward_class_audit.md): v1_to_v2 hands this migrator +% the document exactly as v1 wrote it (NDI distance_metadata.json + base.json +% at the locked NDI-matlab `main`, 3cb19a8, as +setup/+conv/+haley/doImport.m +% writes it), and the reshape the old base migrator +% (+migrators/distance_metadata.m, deleted) did on the universalRenames +% spelling (ontology_node_a, integer_i_ds_a, ...) is done here on the v1 +% spelling (and on that one, which v1_to_v2's 'RawV1Classes', {} path still +% hands it until universalRenames is deleted). Every v1 field and where it +% goes; +% did2.convert.roundtrip.distance_metadata rebuilds the v1 document and +% testRawV1RoundTripPosition compares the two: +% +% base.id, session_id, name, datestamp -> the same document's base (and +% its session edge) +% depends_on element_id -> the same edge +% distance_metadata._ -> endpoints(i), as above +% distance_metadata.units -> units.node +% +% What the renamed path would have discarded is carried, carry-049, as +% before; a field or edge no part of this migrator reads (e.g. an +% integerIDs_C with no ontologyNode_C) now carries the document whole as v1 +% (private/jRawAccount, jRawCarry; carry-100, [fields outside the template +% are malformed]). The JH writer's +% documents hang off an element of type `distance`, which is carried +% (carry-063), so v1_to_v2 carries them too (carry-064, [dependents of a +% carried document carry]). +% +% See schemas/V_eta_distance_metadata_plan.md (did-schema). arguments preBody (1,1) struct end -bodies = { did2.convert.migrators.distance_metadata(preBody) }; + +% THE RAW READ (see READS RAW v1 above) +src = preBody; +blk = struct(); +if isfield(src, 'distance_metadata') && isstruct(src.distance_metadata) ... + && isscalar(src.distance_metadata) + blk = src.distance_metadata; +end +suffixes = endpointSuffixes(blk); +read = {'units'}; +for k = 1:numel(suffixes) + x = suffixes{k}; + read = [read, {['ontologyNode_' x], ['integerIDs_' x], ... + ['ontologyNumericValues_' x], ['ontologyStringValues_' x]}]; %#ok +end +[preBody, collision, unplaced] = jRawAccount(src, ... + struct('distance_metadata', {read}), {'^element_id$'}); +if jRawCarry('distance_metadata', src, collision, unplaced, 'carry-100') + bodies = {src}; + return; +end + +if ~isfield(preBody, 'distance_metadata') || ~isstruct(preBody.distance_metadata) + error('did2:convert:missingBlock', ... + 'distance_metadata body is missing the distance_metadata property block.'); +end + +% the endpoint labels: the v1 suffixes, and on the renamed path (v1_to_v2 +% 'RawV1Classes', {}, until universalRenames is deleted) the suffixes of the +% spelling that pass gives them (ontology_node_a, integer_i_ds_a, ...) +labels = upper(suffixes); +renamed = renamedSuffixes(blk); +labels = [labels, upper(renamed(~ismember(upper(renamed), labels)))]; +[labels, order] = sort(labels); +raw = [suffixes, repmat({''}, 1, numel(labels) - numel(suffixes))]; +raw = raw(order); +endpoints = struct('label', {}, 'measurement', {}, ... + 'integer_ids', {}, 'string_ids', {}, 'numeric_values', {}); +for k = 1:numel(labels) + endpoints(end+1) = buildEndpoint(blk, labels{k}, raw{k}); %#ok +end + +unitsNode = ''; +if isfield(blk, 'units') + unitsNode = char(blk.units); +end + +v2Body = preBody; +if isfield(v2Body, 'depends_on') && ~isempty(v2Body.depends_on) + % the {name, document_id} entries the renamed path gave the document + deps = did2.convert.v1read.readDependsOn(src); + v2Body.depends_on = struct('name', {deps.name}, 'document_id', {deps.document_id}); +end +v2Body.distance_metadata = struct('endpoints', endpoints, 'units', ontologyTerm(unitsNode)); +bodies = {v2Body}; +end + +function suffixes = endpointSuffixes(block) +% Every X with an `ontologyNode_X` field, as the document spells it. The JH +% writer uses 'A' and 'B'; any further suffix is an endpoint too. +suffixes = {}; +fns = fieldnames(block); +for k = 1:numel(fns) + tokens = regexp(fns{k}, '^ontologyNode_(.+)$', 'tokens', 'once'); + if ~isempty(tokens) && ~any(strcmp(suffixes, tokens{1})) + suffixes{end+1} = tokens{1}; %#ok + end +end +end + +function suffixes = renamedSuffixes(block) +% Every x with an `ontology_node_x` field (universalRenames' spelling). +suffixes = {}; +fns = fieldnames(block); +for k = 1:numel(fns) + tokens = regexp(fns{k}, '^ontology_node_(.+)$', 'tokens', 'once'); + if ~isempty(tokens) && ~any(strcmpi(suffixes, tokens{1})) + suffixes{end+1} = tokens{1}; %#ok + end +end +end + +function [v, found] = endpointField(block, rawName, x, renamedName, label) +% The v1 field _, else universalRenames' _