@photivra/engine 2.17.0 → 2.19.0
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.
- package/CHANGELOG.md +116 -1
- package/CITATION.cff +1 -1
- package/README.md +6 -6
- package/SECURITY.md +1 -1
- package/dist/camera/sensor-equivalence.d.ts +156 -0
- package/dist/camera/sensor-equivalence.js +208 -0
- package/dist/camera/sensor-equivalence.js.map +1 -0
- package/dist/capture/focus-control.js +2 -75
- package/dist/capture/focus-control.js.map +1 -1
- package/dist/capture/native-environment-lean.d.ts +1 -0
- package/dist/capture/native-environment-lean.js +1 -1
- package/dist/capture/native-environment-lean.js.map +1 -1
- package/dist/capture/native-environment-optical-stage.d.ts +1 -0
- package/dist/capture/native-environment-optical-stage.js +2 -5
- package/dist/capture/native-environment-optical-stage.js.map +1 -1
- package/dist/capture/native-environment-raw.js +1 -5
- package/dist/capture/native-environment-raw.js.map +1 -1
- package/dist/capture/native-environment-tabulated.d.ts +5 -0
- package/dist/capture/native-environment-tabulated.js +1 -1
- package/dist/capture/native-environment-tabulated.js.map +1 -1
- package/dist/capture/release-sequence.js +2 -47
- package/dist/capture/release-sequence.js.map +1 -1
- package/dist/color/white-balance.d.ts +2 -0
- package/dist/color/white-balance.js +3 -56
- package/dist/color/white-balance.js.map +1 -1
- package/dist/composition/image-formation-plan.d.ts +1 -0
- package/dist/composition/image-formation-plan.js +3 -49
- package/dist/composition/image-formation-plan.js.map +1 -1
- package/dist/core/evidence-provenance.js +1 -16
- package/dist/core/evidence-provenance.js.map +1 -1
- package/dist/core/record-validation.d.ts +54 -0
- package/dist/core/record-validation.js +176 -0
- package/dist/core/record-validation.js.map +1 -1
- package/dist/core/scientific-assurance.js +1 -18
- package/dist/core/scientific-assurance.js.map +1 -1
- package/dist/core/shared-helpers.d.ts +33 -0
- package/dist/core/shared-helpers.js +34 -0
- package/dist/core/shared-helpers.js.map +1 -0
- package/dist/core/spectral-composition.js +1 -36
- package/dist/core/spectral-composition.js.map +1 -1
- package/dist/core/spectral.js +1 -19
- package/dist/core/spectral.js.map +1 -1
- package/dist/core/version.d.ts +1 -1
- package/dist/core/version.js +1 -1
- package/dist/core/version.js.map +1 -1
- package/dist/equipment/exposure-capabilities.d.ts +1 -0
- package/dist/equipment/exposure-capabilities.js +2 -36
- package/dist/equipment/exposure-capabilities.js.map +1 -1
- package/dist/equipment/ideal-lens.d.ts +25 -0
- package/dist/equipment/ideal-lens.js +21 -0
- package/dist/equipment/ideal-lens.js.map +1 -0
- package/dist/equipment/iso-capabilities.js +2 -49
- package/dist/equipment/iso-capabilities.js.map +1 -1
- package/dist/equipment/metering-capabilities.js +1 -26
- package/dist/equipment/metering-capabilities.js.map +1 -1
- package/dist/equipment/release-capabilities.js +1 -53
- package/dist/equipment/release-capabilities.js.map +1 -1
- package/dist/exposure/auto-iso-slowest-shutter.js +1 -7
- package/dist/exposure/auto-iso-slowest-shutter.js.map +1 -1
- package/dist/exposure/exposure-duration-control.js +1 -16
- package/dist/exposure/exposure-duration-control.js.map +1 -1
- package/dist/exposure/exposure-mode-resolver.js +1 -17
- package/dist/exposure/exposure-mode-resolver.js.map +1 -1
- package/dist/exposure/filtered-exposure-time.d.ts +93 -0
- package/dist/exposure/filtered-exposure-time.js +129 -0
- package/dist/exposure/filtered-exposure-time.js.map +1 -0
- package/dist/exposure/flash-ttl.d.ts +1 -0
- package/dist/exposure/flash-ttl.js +1 -1
- package/dist/exposure/flash-ttl.js.map +1 -1
- package/dist/exposure/flash.js +1 -49
- package/dist/exposure/flash.js.map +1 -1
- package/dist/exposure/metering-scene-radiance.js +1 -25
- package/dist/exposure/metering-scene-radiance.js.map +1 -1
- package/dist/exposure/metering-target.js +1 -30
- package/dist/exposure/metering-target.js.map +1 -1
- package/dist/exposure/metering-temporal.js +1 -8
- package/dist/exposure/metering-temporal.js.map +1 -1
- package/dist/exposure/metering.js +1 -72
- package/dist/exposure/metering.js.map +1 -1
- package/dist/exposure/program-line.js +1 -45
- package/dist/exposure/program-line.js.map +1 -1
- package/dist/facade/catalogue-lens-signal.d.ts +94 -0
- package/dist/facade/catalogue-lens-signal.js +362 -0
- package/dist/facade/catalogue-lens-signal.js.map +1 -0
- package/dist/facade/defocus-image-space-provider.js +5 -2
- package/dist/facade/defocus-image-space-provider.js.map +1 -1
- package/dist/facade/develop-joined-parts.d.ts +29 -0
- package/dist/facade/develop-joined-parts.js +33 -0
- package/dist/facade/develop-joined-parts.js.map +1 -0
- package/dist/facade/display-view-lens-signal.d.ts +32 -1
- package/dist/facade/display-view-lens-signal.js +85 -10
- package/dist/facade/display-view-lens-signal.js.map +1 -1
- package/dist/facade/expected-signal-setup.d.ts +8 -0
- package/dist/facade/expected-signal-setup.js +7 -0
- package/dist/facade/expected-signal-setup.js.map +1 -1
- package/dist/facade/expected-signal.d.ts +5 -0
- package/dist/facade/expected-signal.js +5 -1
- package/dist/facade/expected-signal.js.map +1 -1
- package/dist/facade/generic-lens-capture.d.ts +5 -2
- package/dist/facade/generic-lens-capture.js +5 -2
- package/dist/facade/generic-lens-capture.js.map +1 -1
- package/dist/facade/simulate-capture.d.ts +67 -8
- package/dist/facade/simulate-capture.js +262 -126
- package/dist/facade/simulate-capture.js.map +1 -1
- package/dist/facade/simulate-display-view.js +1 -1
- package/dist/facade/simulate-display-view.js.map +1 -1
- package/dist/gpu/chart-composite-gpu.js +1 -3
- package/dist/gpu/chart-composite-gpu.js.map +1 -1
- package/dist/gpu/chart-radiance-gpu.js +1 -5
- package/dist/gpu/chart-radiance-gpu.js.map +1 -1
- package/dist/gpu/display-view-quality-gpu.d.ts +13 -1
- package/dist/gpu/display-view-quality-gpu.js +4 -8
- package/dist/gpu/display-view-quality-gpu.js.map +1 -1
- package/dist/gpu/display-view-speed-gpu.js +3 -25
- package/dist/gpu/display-view-speed-gpu.js.map +1 -1
- package/dist/gpu/sensor-stage-gpu.js +1 -5
- package/dist/gpu/sensor-stage-gpu.js.map +1 -1
- package/dist/gpu/webgpu-runtime.d.ts +2 -0
- package/dist/gpu/webgpu-runtime.js +3 -0
- package/dist/gpu/webgpu-runtime.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/motion/camera-rotation.js +1 -6
- package/dist/motion/camera-rotation.js.map +1 -1
- package/dist/motion/capture-rotation-inverse-mapping.d.ts +12 -0
- package/dist/motion/capture-rotation-inverse-mapping.js +2 -2
- package/dist/motion/capture-rotation-inverse-mapping.js.map +1 -1
- package/dist/motion/capture-rotation-temporal-quadrature.d.ts +1 -0
- package/dist/motion/capture-rotation-temporal-quadrature.js +1 -1
- package/dist/motion/capture-rotation-temporal-quadrature.js.map +1 -1
- package/dist/motion/capture-rotation-trajectory.js +2 -17
- package/dist/motion/capture-rotation-trajectory.js.map +1 -1
- package/dist/motion/capture-translation-parallax-temporal-quadrature.d.ts +1 -0
- package/dist/motion/capture-translation-parallax-temporal-quadrature.js +3 -14
- package/dist/motion/capture-translation-parallax-temporal-quadrature.js.map +1 -1
- package/dist/motion/extended-object-projection.js +5 -40
- package/dist/motion/extended-object-projection.js.map +1 -1
- package/dist/optics/atmospheric-haze.js +1 -7
- package/dist/optics/atmospheric-haze.js.map +1 -1
- package/dist/optics/brown-conrady-distortion.js +1 -7
- package/dist/optics/brown-conrady-distortion.js.map +1 -1
- package/dist/optics/complex-pupil-psf.d.ts +1 -0
- package/dist/optics/complex-pupil-psf.js +2 -84
- package/dist/optics/complex-pupil-psf.js.map +1 -1
- package/dist/optics/focus-state.js +1 -11
- package/dist/optics/focus-state.js.map +1 -1
- package/dist/optics/front-of-lens-filter.d.ts +5 -0
- package/dist/optics/front-of-lens-filter.js +3 -65
- package/dist/optics/front-of-lens-filter.js.map +1 -1
- package/dist/optics/generic-nd-filter-presets.d.ts +12 -0
- package/dist/optics/generic-nd-filter-presets.js +48 -0
- package/dist/optics/generic-nd-filter-presets.js.map +1 -0
- package/dist/optics/illumination-vignetting.js +1 -6
- package/dist/optics/illumination-vignetting.js.map +1 -1
- package/dist/optics/lens-psf-profile.d.ts +4 -1
- package/dist/optics/lens-psf-profile.js +12 -111
- package/dist/optics/lens-psf-profile.js.map +1 -1
- package/dist/optics/longitudinal-chromatic-aberration.js +1 -7
- package/dist/optics/longitudinal-chromatic-aberration.js.map +1 -1
- package/dist/optics/pupil-vignetting.js +1 -7
- package/dist/optics/pupil-vignetting.js.map +1 -1
- package/dist/optics/radial-distortion.js +1 -6
- package/dist/optics/radial-distortion.js.map +1 -1
- package/dist/optics/scene-to-sensor-irradiance.js +4 -96
- package/dist/optics/scene-to-sensor-irradiance.js.map +1 -1
- package/dist/optics/stray-light.d.ts +1 -0
- package/dist/optics/stray-light.js +1 -1
- package/dist/optics/stray-light.js.map +1 -1
- package/dist/optics/zernike-wavefront.js +1 -7
- package/dist/optics/zernike-wavefront.js.map +1 -1
- package/dist/output/capture-geometry.js +1 -8
- package/dist/output/capture-geometry.js.map +1 -1
- package/dist/output/developed-lens-corrections.d.ts +62 -0
- package/dist/output/developed-lens-corrections.js +135 -0
- package/dist/output/developed-lens-corrections.js.map +1 -0
- package/dist/output/generic-lens-corrections.d.ts +2 -6
- package/dist/output/generic-lens-corrections.js +3 -6
- package/dist/output/generic-lens-corrections.js.map +1 -1
- package/dist/output/geometric-transforms.js +1 -4
- package/dist/output/geometric-transforms.js.map +1 -1
- package/dist/output/native-capture-sdr.d.ts +2 -2
- package/dist/output/native-capture-sdr.js +3 -2
- package/dist/output/native-capture-sdr.js.map +1 -1
- package/dist/processing/development-detail.d.ts +29 -0
- package/dist/processing/development-detail.js +128 -107
- package/dist/processing/development-detail.js.map +1 -1
- package/dist/schema/illumination-temporal.js +3 -72
- package/dist/schema/illumination-temporal.js.map +1 -1
- package/dist/schema/illumination.d.ts +1 -0
- package/dist/schema/illumination.js +2 -65
- package/dist/schema/illumination.js.map +1 -1
- package/dist/schema/scene-radiance-temporal.js +2 -14
- package/dist/schema/scene-radiance-temporal.js.map +1 -1
- package/dist/schema/scene-radiance.js +2 -60
- package/dist/schema/scene-radiance.js.map +1 -1
- package/dist/schema/validation.d.ts +2 -0
- package/dist/schema/validation.js +2 -17
- package/dist/schema/validation.js.map +1 -1
- package/dist/sensor/accumulated-charge.js +2 -59
- package/dist/sensor/accumulated-charge.js.map +1 -1
- package/dist/sensor/architecture.js +1 -16
- package/dist/sensor/architecture.js.map +1 -1
- package/dist/sensor/camera-saturation-capacity.d.ts +1 -0
- package/dist/sensor/camera-saturation-capacity.js +3 -55
- package/dist/sensor/camera-saturation-capacity.js.map +1 -1
- package/dist/sensor/capture-color-sampling-binding.js +1 -26
- package/dist/sensor/capture-color-sampling-binding.js.map +1 -1
- package/dist/sensor/capture-mode-timing.js +1 -39
- package/dist/sensor/capture-mode-timing.js.map +1 -1
- package/dist/sensor/capture-mode.js +1 -23
- package/dist/sensor/capture-mode.js.map +1 -1
- package/dist/sensor/color-sampling.js +1 -26
- package/dist/sensor/color-sampling.js.map +1 -1
- package/dist/sensor/constant-rate-temporal-integration.js +2 -46
- package/dist/sensor/constant-rate-temporal-integration.js.map +1 -1
- package/dist/sensor/dark-current.js +2 -45
- package/dist/sensor/dark-current.js.map +1 -1
- package/dist/sensor/eqe-electron-rate.js +2 -35
- package/dist/sensor/eqe-electron-rate.js.map +1 -1
- package/dist/sensor/exposure-window.d.ts +5 -0
- package/dist/sensor/exposure-window.js +7 -22
- package/dist/sensor/exposure-window.js.map +1 -1
- package/dist/sensor/iso-gain.js +1 -7
- package/dist/sensor/iso-gain.js.map +1 -1
- package/dist/sensor/iso-signal-chain.js +1 -43
- package/dist/sensor/iso-signal-chain.js.map +1 -1
- package/dist/sensor/optical-stack.js +1 -25
- package/dist/sensor/optical-stack.js.map +1 -1
- package/dist/sensor/photon-energy.js +1 -26
- package/dist/sensor/photon-energy.js.map +1 -1
- package/dist/sensor/physical-charge-capacity.js +3 -77
- package/dist/sensor/physical-charge-capacity.js.map +1 -1
- package/dist/sensor/radiometry-readiness.js +2 -23
- package/dist/sensor/radiometry-readiness.js.map +1 -1
- package/dist/sensor/raw-readout.d.ts +3 -0
- package/dist/sensor/raw-readout.js +4 -66
- package/dist/sensor/raw-readout.js.map +1 -1
- package/dist/sensor/raw-reconstruction.js +2 -64
- package/dist/sensor/raw-reconstruction.js.map +1 -1
- package/dist/sensor/readout-exposure-linkage.js +1 -9
- package/dist/sensor/readout-exposure-linkage.js.map +1 -1
- package/dist/sensor/readout-timing.js +3 -57
- package/dist/sensor/readout-timing.js.map +1 -1
- package/dist/sensor/response-application-compatibility.d.ts +2 -0
- package/dist/sensor/response-application-compatibility.js +3 -29
- package/dist/sensor/response-application-compatibility.js.map +1 -1
- package/dist/sensor/response-operating-range.d.ts +1 -0
- package/dist/sensor/response-operating-range.js +3 -79
- package/dist/sensor/response-operating-range.js.map +1 -1
- package/dist/sensor/responsivity-photocurrent.js +4 -108
- package/dist/sensor/responsivity-photocurrent.js.map +1 -1
- package/dist/sensor/sampling-aperture.js +1 -25
- package/dist/sensor/sampling-aperture.js.map +1 -1
- package/dist/sensor/spatial-sample-reduction.js +2 -19
- package/dist/sensor/spatial-sample-reduction.js.map +1 -1
- package/dist/sensor/spatial-sampling-quadrature.js +1 -3
- package/dist/sensor/spatial-sampling-quadrature.js.map +1 -1
- package/dist/sensor/spatio-spectral-reduction.js +1 -18
- package/dist/sensor/spatio-spectral-reduction.js.map +1 -1
- package/dist/sensor/spectral-coverage.d.ts +10 -1
- package/dist/sensor/spectral-coverage.js +1 -1
- package/dist/sensor/spectral-coverage.js.map +1 -1
- package/dist/sensor/spectral-quadrature.js +2 -35
- package/dist/sensor/spectral-quadrature.js.map +1 -1
- package/dist/sensor/spectral-response.js +1 -47
- package/dist/sensor/spectral-response.js.map +1 -1
- package/dist/stabilization/camera-shake.js +1 -6
- package/dist/stabilization/camera-shake.js.map +1 -1
- package/dist/stabilization/system.js +2 -80
- package/dist/stabilization/system.js.map +1 -1
- package/docs/AGENT_GUIDE.md +4 -0
- package/docs/API_REFERENCE.md +69 -2
- package/docs/QUICK_START.md +136 -6
- package/docs/USAGE.md +89 -3
- package/docs/api/camera-sensor-equivalence.md +209 -0
- package/docs/api/core-version.md +1 -1
- package/docs/api/equipment-ideal-lens.md +26 -0
- package/docs/api/exports.json +118 -3
- package/docs/api/exposure-filtered-exposure-time.md +105 -0
- package/docs/api/facade-develop-joined-parts.md +32 -0
- package/docs/api/facade-simulate-capture.md +62 -8
- package/docs/api/optics-generic-nd-filter-presets.md +34 -0
- package/docs/api/optics-lens-psf-profile.md +3 -1
- package/docs/api/output-developed-lens-corrections.md +12 -0
- package/docs/api/output-generic-lens-corrections.md +0 -9
- package/llms.txt +3 -0
- package/package.json +1 -1
|
@@ -14,17 +14,10 @@ import { approximationResult } from "../core/calculation-result.js";
|
|
|
14
14
|
import { InvalidScientificInputError } from "../core/validation.js";
|
|
15
15
|
import { parseSensorColorSamplingProfile } from "./color-sampling.js";
|
|
16
16
|
import { createSensorSpectralResponseChannelBinding, parseSensorSpectralResponseProfile, resolveSensorSpectralResponseAtWavelength } from "./spectral-response.js";
|
|
17
|
-
import { requireInputKeys } from "../core/record-validation.js";
|
|
17
|
+
import { requireInputKeys, requireInputPositiveFinite as requirePositiveFinite, requireInputNonNegativeSafeInteger as requireNonNegativeSafeInteger } from "../core/record-validation.js";
|
|
18
18
|
import { InvalidConfigurationError } from "../core/configuration-error.js";
|
|
19
|
+
import { responseCurves } from "./spectral-coverage.js";
|
|
19
20
|
const MAX_SPECTRAL_QUADRATURE_NODES = 100_000;
|
|
20
|
-
function requirePositiveFinite(value, path) {
|
|
21
|
-
if (typeof value !== "number" ||
|
|
22
|
-
!Number.isFinite(value) ||
|
|
23
|
-
value <= 0) {
|
|
24
|
-
throw new InvalidScientificInputError(path + " must be finite and greater than zero.");
|
|
25
|
-
}
|
|
26
|
-
return value;
|
|
27
|
-
}
|
|
28
21
|
function channelResponse(profile, channelId) {
|
|
29
22
|
if (typeof channelId !== "string" ||
|
|
30
23
|
channelId.trim().length === 0) {
|
|
@@ -36,24 +29,6 @@ function channelResponse(profile, channelId) {
|
|
|
36
29
|
}
|
|
37
30
|
return response;
|
|
38
31
|
}
|
|
39
|
-
function responseCurves(response) {
|
|
40
|
-
if (response.kind ===
|
|
41
|
-
"effective-external-quantum-efficiency") {
|
|
42
|
-
return [
|
|
43
|
-
response.externalQuantumEfficiency
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
if (response.kind ===
|
|
47
|
-
"effective-spectral-responsivity") {
|
|
48
|
-
return [
|
|
49
|
-
response.spectralResponsivity
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
return [
|
|
53
|
-
response.channelFilterTransmittance,
|
|
54
|
-
response.detectorExternalQuantumEfficiency
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
32
|
function usableResponseRange(curves) {
|
|
58
33
|
const minimum = Math.max(...curves.map((curve) => curve.samples[0]
|
|
59
34
|
.wavelengthNanometers));
|
|
@@ -168,14 +143,6 @@ function planSegments(boundaries, maximumSubintervalWidthNanometers) {
|
|
|
168
143
|
};
|
|
169
144
|
}
|
|
170
145
|
const SPECTRAL_VALIDATION_TOLERANCE = 1e-10;
|
|
171
|
-
function requireNonNegativeSafeInteger(value, path) {
|
|
172
|
-
if (typeof value !== "number" ||
|
|
173
|
-
!Number.isSafeInteger(value) ||
|
|
174
|
-
value < 0) {
|
|
175
|
-
throw new InvalidScientificInputError(path + " must be a non-negative safe integer.");
|
|
176
|
-
}
|
|
177
|
-
return value;
|
|
178
|
-
}
|
|
179
146
|
function approximatelyEqual(actual, expected, tolerance = SPECTRAL_VALIDATION_TOLERANCE) {
|
|
180
147
|
const scale = Math.max(1, Math.abs(actual), Math.abs(expected));
|
|
181
148
|
return (Math.abs(actual - expected) <=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spectral-quadrature.js","sourceRoot":"","sources":["../../src/sensor/spectral-quadrature.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;GAUG;AAEH,OAAO,EACL,mBAAmB,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ACzB,CAAC,GAAG,UAAU,CAAC;QACjB,iCAAiC;QACjC,YAAY,EACV,QAAQ,CAAC,MAAM;QACjB,cAAc;QACd,6BAA6B;QAC7B,8BAA8B;QAC9B,KAAK;QACL,6BAA6B,EAC3B,IAAI;QACN,iBAAiB,EAAE;YACjB,oBAAoB,EAClB,YAAY,CAAC,QAAQ;YACvB,OAAO,EACL,cAAc;iBACX,iBAAiB,CAAC,OAAO;YAC9B,OAAO,EACL,cAAc;iBACX,iBAAiB,CAAC,OAAO;YAC9B,MAAM,EACJ,cAAc;iBACX,iBAAiB,CAAC,MAAM;SAC9B;QACD,sBAAsB,EAAE,KAAK;QAC7B,4BAA4B,EAC1B,KAAK;QACP,4BAA4B,EAC1B,KAAK;QACP,0BAA0B,EACxB,KAAK;QACP,gCAAgC,EAC9B,KAAK;QACP,+BAA+B,EAC7B,KAAK;QACP,uCAAuC,EACrC,IAAI;QACN,4BAA4B,EAC1B,KAAK;QACP,uCAAuC,EACrC,KAAK;QACP,8BAA8B,EAC5B,KAAK;QACP,2BAA2B,EACzB,KAAK;QACP,4BAA4B,EAC1B,KAAK;QACP,iBAAiB,EAAE,KAAK;QACxB,mBAAmB,EAAE,KAAK;QAC1B,oBAAoB,EAAE,KAAK;QAC3B,yBAAyB,EAAE,KAAK;KACjC,EACD,4BAA4B,EAC5B,OAAO,EACP;QACE,0IAA0I;QAC1I,iIAAiI;QACjI,gKAAgK;QAChK,kLAAkL;QAClL,mMAAmM;QACnM,uIAAuI;QACvI,6JAA6J;QAC7J,wMAAwM;QACxM,4NAA4N;QAC5N,oJAAoJ;QACpJ,6HAA6H;KAC9H,CACF,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Spectral quadrature: the wavelength sample points (nodes) and step widths used to integrate light\n * over wavelength for one sensor response channel.\n *\n * Each node is the midpoint of a wavelength interval, with its width dλ in nanometres. The intervals\n * stay inside the range the response supports. Lining nodes up with curve breakpoints does not prove\n * the integral has converged. Discrete (delta-like) emission lines need their own integration and are\n * never silently widened into continuous bins.\n * @see docs/MOTION_AND_SIGNAL.md for equations, coordinate/unit conventions, blockers and support\n * limits.\n */\n\nimport {\n approximationResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport type { EvidenceProvenance } from \"../core/evidence-provenance.js\";\nimport { InvalidScientificInputError } from \"../core/validation.js\";\nimport type {\n SpectralWavelengthBasis,\n SpectralWavelengthRangeNanometers\n} from \"../core/spectral.js\";\nimport {\n parseSensorColorSamplingProfile,\n type SensorColorSamplingProfile\n} from \"./color-sampling.js\";\nimport {\n createSensorSpectralResponseChannelBinding,\n parseSensorSpectralResponseProfile,\n resolveSensorSpectralResponseAtWavelength,\n type SensorSpectralReferenceConditions,\n type SensorSpectralResponseProfile,\n type SensorSpectralResponseScientificStatus,\n type SensorSpectralResponseUncertainty\n} from \"./spectral-response.js\";\nimport { requireInputKeys } from \"../core/record-validation.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\n\nconst MAX_SPECTRAL_QUADRATURE_NODES = 100_000;\n\nexport type SensorSpectralWavelengthRangeNanometers =\n SpectralWavelengthRangeNanometers;\n\nexport interface CalculateSensorSpectralQuadratureInput {\n colorSamplingProfile: SensorColorSamplingProfile;\n spectralResponseProfile: SensorSpectralResponseProfile;\n channelId: string;\n wavelengthBasis: SpectralWavelengthBasis;\n /**\n * Wavelength interval to sample. It is checked only against the range the\n * sensor response supports, not against scene-spectrum or optical-transmission\n * coverage.\n */\n wavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n /**\n * Strict upper limit on the width of each midpoint subinterval.\n *\n * Response breakpoints and any additional breakpoints split the requested\n * range first. Each segment is then subdivided until every subinterval is\n * no wider than this value.\n */\n maximumSubintervalWidthNanometers: number;\n /**\n * Optional strictly increasing wavelength breakpoints from other continuous\n * spectral inputs, such as the interpolation points of a scene spectrum or of\n * optical transmission. Values must be strictly inside the requested range.\n *\n * Passing them does not claim those other inputs are available or valid over\n * the requested range.\n */\n additionalBreakpointsNanometers?:\n readonly number[];\n}\n\nexport interface SensorSpectralQuadratureNode {\n spectralSampleIndex: number;\n segmentIndex: number;\n subdivisionIndex: number;\n segmentSubdivisionCount: number;\n /**\n * Midpoint wavelength for this subinterval. Units: nm in wavelengthBasis.\n */\n wavelengthNanometers: number;\n /**\n * dλ (wavelength width) this node stands for. Units: nm.\n *\n * It is only a wavelength width. It is not response-weighted throughput,\n * a photon count, radiant energy, current or a dimensionless probability.\n */\n wavelengthMeasureNanometers: number;\n /**\n * The wavelength width divided by the requested range width (dimensionless).\n *\n * Useful for averages, but it is not a sensor-response weight.\n */\n normalizedWavelengthWeight: number;\n}\n\nexport interface SensorSpectralQuadrature {\n profileId: string;\n colorSamplingProfileId: string;\n channelId: string;\n sourceResponseKind:\n SensorSpectralResponseProfile[\"channels\"][number][\"kind\"];\n responseScope:\n SensorSpectralResponseProfile[\"channels\"][number][\"responseScope\"];\n responseScientificStatus:\n SensorSpectralResponseScientificStatus;\n responseUncertainty:\n SensorSpectralResponseUncertainty;\n responseChannelBinding?: import(\"./spectral-response.js\").SensorSpectralResponseChannelBinding;\n responseReferenceConditions?:\n SensorSpectralReferenceConditions;\n wavelengthBasis: SpectralWavelengthBasis;\n wavelengthBasisResolved: boolean;\n wavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n responseDeclaredWavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n quadratureScheme:\n \"response-breakpoint-aware-bounded-midpoint\";\n segmentBoundarySource:\n \"requested-range-plus-response-knots-plus-optional-additional-breakpoints\";\n /**\n * Sorted, unique segment boundaries, including the ends of the requested range.\n */\n segmentBoundariesNanometers:\n readonly number[];\n maximumSubintervalWidthNanometers: number;\n segmentCount: number;\n totalNodeCount: number;\n normalizedWavelengthWeightSum: number;\n wavelengthMeasureSumNanometers: number;\n nodes: readonly SensorSpectralQuadratureNode[];\n responseKnotAlignmentIncluded: true;\n componentEvidence: {\n colorSamplingProfile: readonly EvidenceProvenance[];\n profile: readonly EvidenceProvenance[];\n channel: readonly EvidenceProvenance[];\n curves:\n readonly (readonly EvidenceProvenance[])[];\n };\n /**\n * Fixed statements of what this result does not include.\n */\n responseValuesIncluded: false;\n responseApplicationPerformed: false;\n sourceSpectralValuesIncluded: false;\n spectralIrradianceIncluded: false;\n spectralPhotonIrradianceIncluded: false;\n commonSpectralCoverageValidated: false;\n continuousSpectralDensityQuadratureOnly: true;\n discreteLineSpectrumIncluded: false;\n opticalTransmissionIncludedByQuadrature: false;\n wavelengthIntegrationPerformed: false;\n spatialIntegrationPerformed: false;\n temporalIntegrationPerformed: false;\n photonsCalculated: false;\n electronsCalculated: false;\n rawCodeValueProduced: false;\n convergenceErrorEstimated: false;\n}\n\ninterface ResponseCurveSupport {\n wavelengthBasis: SpectralWavelengthBasis;\n samples: readonly {\n wavelengthNanometers: number;\n }[];\n evidence: readonly EvidenceProvenance[];\n}\n\ninterface SegmentPlan {\n minimum: number;\n maximum: number;\n subdivisionCount: number;\n subintervalWidthNanometers: number;\n}\n\nfunction requirePositiveFinite(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isFinite(value) ||\n value <= 0\n ) {\n throw new InvalidScientificInputError(\n path + \" must be finite and greater than zero.\"\n );\n }\n return value;\n}\n\nfunction channelResponse(\n profile: SensorSpectralResponseProfile,\n channelId: string\n): SensorSpectralResponseProfile[\"channels\"][number] {\n if (\n typeof channelId !== \"string\" ||\n channelId.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n \"channelId must be a non-empty string.\"\n );\n }\n\n const response = profile.channels.find(\n (entry) => entry.channelId === channelId\n );\n if (response === undefined) {\n throw new InvalidScientificInputError(\n \"No spectral response is declared for the requested channelId.\"\n );\n }\n return response;\n}\n\nfunction responseCurves(\n response:\n SensorSpectralResponseProfile[\"channels\"][number]\n): readonly ResponseCurveSupport[] {\n if (\n response.kind ===\n \"effective-external-quantum-efficiency\"\n ) {\n return [\n response.externalQuantumEfficiency\n ];\n }\n if (\n response.kind ===\n \"effective-spectral-responsivity\"\n ) {\n return [\n response.spectralResponsivity\n ];\n }\n return [\n response.channelFilterTransmittance,\n response.detectorExternalQuantumEfficiency\n ];\n}\n\nfunction usableResponseRange(\n curves: readonly ResponseCurveSupport[]\n): SensorSpectralWavelengthRangeNanometers {\n const minimum = Math.max(\n ...curves.map(\n (curve) =>\n curve.samples[0]!\n .wavelengthNanometers\n )\n );\n const maximum = Math.min(\n ...curves.map(\n (curve) =>\n curve.samples[\n curve.samples.length - 1\n ]!.wavelengthNanometers\n )\n );\n\n if (!(minimum < maximum)) {\n throw new InvalidScientificInputError(\n \"Spectral-response curves do not have a usable overlapping wavelength interval.\"\n );\n }\n\n return { minimum, maximum };\n}\n\nfunction parseRequestedRange(\n input:\n SensorSpectralWavelengthRangeNanometers,\n usable:\n SensorSpectralWavelengthRangeNanometers\n): SensorSpectralWavelengthRangeNanometers {\n if (\n typeof input !== \"object\" ||\n input === null\n ) {\n throw new InvalidConfigurationError(\n \"wavelengthRangeNanometers must be an object.\"\n );\n }\n\n const minimum = requirePositiveFinite(\n input.minimum,\n \"wavelengthRangeNanometers.minimum\"\n );\n const maximum = requirePositiveFinite(\n input.maximum,\n \"wavelengthRangeNanometers.maximum\"\n );\n\n if (!(minimum < maximum)) {\n throw new InvalidScientificInputError(\n \"wavelengthRangeNanometers.minimum must be less than maximum.\"\n );\n }\n\n if (\n minimum < usable.minimum ||\n maximum > usable.maximum\n ) {\n throw new InvalidScientificInputError(\n \"Requested wavelength range must remain inside the usable spectral-response range; clipping, extrapolation, and implicit zero-fill are not permitted.\"\n );\n }\n\n return { minimum, maximum };\n}\n\nfunction additionalBreakpoints(\n value: readonly number[] | undefined,\n range:\n SensorSpectralWavelengthRangeNanometers\n): readonly number[] {\n if (value === undefined) {\n return [];\n }\n if (!Array.isArray(value)) {\n throw new InvalidConfigurationError(\n \"additionalBreakpointsNanometers must be an array when supplied.\"\n );\n }\n if (\n value.length >=\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"additionalBreakpointsNanometers contains too many entries for the spectral quadrature safety limit.\"\n );\n }\n\n let previous =\n Number.NEGATIVE_INFINITY;\n\n return value.map(\n (entry, index) => {\n const wavelength =\n requirePositiveFinite(\n entry,\n \"additionalBreakpointsNanometers[\" +\n index +\n \"]\"\n );\n if (\n wavelength <= range.minimum ||\n wavelength >= range.maximum\n ) {\n throw new InvalidScientificInputError(\n \"Additional spectral breakpoints must lie strictly inside the requested wavelength range.\"\n );\n }\n if (wavelength <= previous) {\n throw new InvalidScientificInputError(\n \"additionalBreakpointsNanometers must be strictly increasing with no duplicates.\"\n );\n }\n previous = wavelength;\n return wavelength;\n }\n );\n}\n\nfunction partitionBoundaries(\n curves: readonly ResponseCurveSupport[],\n range:\n SensorSpectralWavelengthRangeNanometers,\n additional:\n readonly number[]\n): readonly number[] {\n const boundaries = new Set<number>([\n range.minimum,\n range.maximum,\n ...additional\n ]);\n\n for (const curve of curves) {\n for (const sample of curve.samples) {\n if (\n sample.wavelengthNanometers >\n range.minimum &&\n sample.wavelengthNanometers <\n range.maximum\n ) {\n boundaries.add(\n sample.wavelengthNanometers\n );\n }\n }\n }\n\n return [...boundaries].sort(\n (a, b) => a - b\n );\n}\n\nfunction planSegments(\n boundaries: readonly number[],\n maximumSubintervalWidthNanometers: number\n): {\n segments: readonly SegmentPlan[];\n totalNodeCount: number;\n} {\n const segments: SegmentPlan[] = [];\n let totalNodeCount = 0;\n\n for (\n let segmentIndex = 0;\n segmentIndex < boundaries.length - 1;\n segmentIndex += 1\n ) {\n const minimum =\n boundaries[segmentIndex]!;\n const maximum =\n boundaries[segmentIndex + 1]!;\n const width =\n maximum - minimum;\n\n if (\n !Number.isFinite(width) ||\n width <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature segment widths must be finite and greater than zero.\"\n );\n }\n\n const subdivisionCount =\n Math.ceil(\n width /\n maximumSubintervalWidthNanometers\n );\n\n if (\n !Number.isSafeInteger(\n subdivisionCount\n ) ||\n subdivisionCount <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature segment subdivision count must be a positive safe integer.\"\n );\n }\n\n totalNodeCount +=\n subdivisionCount;\n\n if (\n !Number.isSafeInteger(\n totalNodeCount\n )\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature node count must remain a safe integer.\"\n );\n }\n if (\n totalNodeCount >\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature node count exceeds the safety limit of \" +\n MAX_SPECTRAL_QUADRATURE_NODES +\n \".\"\n );\n }\n\n segments.push({\n minimum,\n maximum,\n subdivisionCount,\n subintervalWidthNanometers:\n width / subdivisionCount\n });\n }\n\n if (segments.length === 0) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature requires at least one non-empty segment.\"\n );\n }\n\n return {\n segments,\n totalNodeCount\n };\n}\n\nconst SPECTRAL_VALIDATION_TOLERANCE = 1e-10;\n\nfunction requireNonNegativeSafeInteger(\n value: unknown,\n path: string\n): number {\n if (\n typeof value !== \"number\" ||\n !Number.isSafeInteger(value) ||\n value < 0\n ) {\n throw new InvalidScientificInputError(\n path + \" must be a non-negative safe integer.\"\n );\n }\n return value;\n}\n\nfunction approximatelyEqual(\n actual: number,\n expected: number,\n tolerance = SPECTRAL_VALIDATION_TOLERANCE\n): boolean {\n const scale = Math.max(\n 1,\n Math.abs(actual),\n Math.abs(expected)\n );\n return (\n Math.abs(actual - expected) <=\n tolerance * scale\n );\n}\n\n/**\n * Rechecks a supplied wavelength plan (node identities, coverage and widths in nanometres) before it\n * is used.\n *\n * Lining nodes up with breakpoints does not prove convergence. Discrete (delta-like) lines need their\n * own integration and are never silently widened into continuous bins.\n * @param quadrature - The input; see `SensorSpectralQuadrature` for its fields, units and coordinates.\n * @returns The result. Success does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the package export and its full type definitions.\n */\nexport function validateSensorSpectralQuadrature(\n quadrature: SensorSpectralQuadrature\n): Map<number, SensorSpectralQuadratureNode> {\n if (\n typeof quadrature !== \"object\" ||\n quadrature === null ||\n !Array.isArray(quadrature.nodes)\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature must contain a nodes array.\"\n );\n }\n\n for (const [field, value] of [\n [\"profileId\", quadrature.profileId],\n [\n \"colorSamplingProfileId\",\n quadrature.colorSamplingProfileId\n ],\n [\"channelId\", quadrature.channelId]\n ] as const) {\n if (\n typeof value !== \"string\" ||\n value.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature.\" +\n field +\n \" must be a non-empty string.\"\n );\n }\n }\n\n if (\n quadrature.wavelengthBasis !== \"air\" &&\n quadrature.wavelengthBasis !== \"vacuum\" &&\n quadrature.wavelengthBasis !== \"unspecified\"\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature.wavelengthBasis is invalid.\"\n );\n }\n\n const rangeMinimum = requirePositiveFinite(\n quadrature.wavelengthRangeNanometers.minimum,\n \"spectralQuadrature.wavelengthRangeNanometers.minimum\"\n );\n const rangeMaximum = requirePositiveFinite(\n quadrature.wavelengthRangeNanometers.maximum,\n \"spectralQuadrature.wavelengthRangeNanometers.maximum\"\n );\n if (!(rangeMinimum < rangeMaximum)) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature wavelength range minimum must be less than maximum.\"\n );\n }\n\n const maximumSubintervalWidthNanometers =\n requirePositiveFinite(\n quadrature.maximumSubintervalWidthNanometers,\n \"spectralQuadrature.maximumSubintervalWidthNanometers\"\n );\n\n if (\n !Array.isArray(\n quadrature.segmentBoundariesNanometers\n ) ||\n quadrature.segmentBoundariesNanometers.length <\n 2\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentBoundariesNanometers must contain at least two boundaries.\"\n );\n }\n\n let previousBoundary =\n Number.NEGATIVE_INFINITY;\n quadrature.segmentBoundariesNanometers.forEach(\n (boundary, index) => {\n const parsed = requirePositiveFinite(\n boundary,\n \"spectralQuadrature.segmentBoundariesNanometers[\" +\n index +\n \"]\"\n );\n if (parsed <= previousBoundary) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentBoundariesNanometers must be strictly increasing.\"\n );\n }\n previousBoundary = parsed;\n }\n );\n\n const segmentCount =\n requireNonNegativeSafeInteger(\n quadrature.segmentCount,\n \"spectralQuadrature.segmentCount\"\n );\n if (\n segmentCount <= 0 ||\n segmentCount !==\n quadrature.segmentBoundariesNanometers.length -\n 1\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentCount must be positive and match the boundary count.\"\n );\n }\n\n if (\n !approximatelyEqual(\n quadrature.segmentBoundariesNanometers[0]!,\n rangeMinimum\n ) ||\n !approximatelyEqual(\n quadrature.segmentBoundariesNanometers[\n quadrature.segmentBoundariesNanometers.length -\n 1\n ]!,\n rangeMaximum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature segment boundaries must exactly span the requested wavelength range.\"\n );\n }\n\n const totalNodeCount =\n requireNonNegativeSafeInteger(\n quadrature.totalNodeCount,\n \"spectralQuadrature.totalNodeCount\"\n );\n if (\n totalNodeCount <= 0 ||\n totalNodeCount !== quadrature.nodes.length\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.totalNodeCount must be positive and exactly match spectralQuadrature.nodes.length.\"\n );\n }\n if (\n totalNodeCount >\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.totalNodeCount exceeds the spectral quadrature safety limit.\"\n );\n }\n\n if (\n quadrature.responseApplicationPerformed !==\n false ||\n quadrature.responseValuesIncluded !== false ||\n quadrature.wavelengthIntegrationPerformed !==\n false ||\n quadrature.continuousSpectralDensityQuadratureOnly !==\n true ||\n quadrature.discreteLineSpectrumIncluded !==\n false\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature semantics are incompatible with pre-response continuous-density composition.\"\n );\n }\n\n const span =\n rangeMaximum - rangeMinimum;\n const nodesByIndex =\n new Map<number, SensorSpectralQuadratureNode>();\n const seenSegmentSubdivisions =\n new Set<string>();\n const segmentSubdivisionCounts =\n new Map<number, number>();\n const segmentSeenCounts =\n new Map<number, number>();\n let measureSum = 0;\n let normalizedWeightSum = 0;\n\n quadrature.nodes.forEach(\n (node, nodeArrayIndex) => {\n const spectralSampleIndex =\n requireNonNegativeSafeInteger(\n node.spectralSampleIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].spectralSampleIndex\"\n );\n if (\n nodesByIndex.has(\n spectralSampleIndex\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature contains duplicate spectralSampleIndex values.\"\n );\n }\n\n const segmentIndex =\n requireNonNegativeSafeInteger(\n node.segmentIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].segmentIndex\"\n );\n if (segmentIndex >= segmentCount) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node segmentIndex is outside the declared segment range.\"\n );\n }\n\n const subdivisionIndex =\n requireNonNegativeSafeInteger(\n node.subdivisionIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].subdivisionIndex\"\n );\n const segmentSubdivisionCount =\n requireNonNegativeSafeInteger(\n node.segmentSubdivisionCount,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].segmentSubdivisionCount\"\n );\n if (\n segmentSubdivisionCount <= 0 ||\n subdivisionIndex >=\n segmentSubdivisionCount\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node subdivision identity is invalid.\"\n );\n }\n\n const priorSegmentCount =\n segmentSubdivisionCounts.get(\n segmentIndex\n );\n if (\n priorSegmentCount !== undefined &&\n priorSegmentCount !==\n segmentSubdivisionCount\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature nodes disagree on a segment subdivision count.\"\n );\n }\n segmentSubdivisionCounts.set(\n segmentIndex,\n segmentSubdivisionCount\n );\n\n const subdivisionKey =\n segmentIndex +\n \":\" +\n subdivisionIndex;\n if (\n seenSegmentSubdivisions.has(\n subdivisionKey\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature contains duplicate segment/subdivision identities.\"\n );\n }\n seenSegmentSubdivisions.add(\n subdivisionKey\n );\n segmentSeenCounts.set(\n segmentIndex,\n (segmentSeenCounts.get(\n segmentIndex\n ) ?? 0) + 1\n );\n\n const wavelengthNanometers =\n requirePositiveFinite(\n node.wavelengthNanometers,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].wavelengthNanometers\"\n );\n const wavelengthMeasureNanometers =\n requirePositiveFinite(\n node.wavelengthMeasureNanometers,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].wavelengthMeasureNanometers\"\n );\n const normalizedWavelengthWeight =\n requirePositiveFinite(\n node.normalizedWavelengthWeight,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].normalizedWavelengthWeight\"\n );\n\n const segmentMinimum =\n quadrature.segmentBoundariesNanometers[\n segmentIndex\n ]!;\n const segmentMaximum =\n quadrature.segmentBoundariesNanometers[\n segmentIndex + 1\n ]!;\n const expectedMeasure =\n (segmentMaximum -\n segmentMinimum) /\n segmentSubdivisionCount;\n const expectedWavelength =\n segmentMinimum +\n (subdivisionIndex + 0.5) *\n expectedMeasure;\n const expectedNormalizedWeight =\n expectedMeasure / span;\n\n if (\n !approximatelyEqual(\n wavelengthMeasureNanometers,\n expectedMeasure\n ) ||\n !approximatelyEqual(\n wavelengthNanometers,\n expectedWavelength\n ) ||\n !approximatelyEqual(\n normalizedWavelengthWeight,\n expectedNormalizedWeight\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node geometry/measure does not match its declared segment/subdivision identity.\"\n );\n }\n\n if (\n wavelengthMeasureNanometers >\n maximumSubintervalWidthNanometers &&\n !approximatelyEqual(\n wavelengthMeasureNanometers,\n maximumSubintervalWidthNanometers\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node width exceeds maximumSubintervalWidthNanometers.\"\n );\n }\n\n measureSum +=\n wavelengthMeasureNanometers;\n normalizedWeightSum +=\n normalizedWavelengthWeight;\n if (\n !Number.isFinite(measureSum) ||\n !Number.isFinite(\n normalizedWeightSum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature aggregate measures must remain finite.\"\n );\n }\n\n nodesByIndex.set(\n spectralSampleIndex,\n node\n );\n }\n );\n\n for (\n let spectralSampleIndex = 0;\n spectralSampleIndex < totalNodeCount;\n spectralSampleIndex += 1\n ) {\n if (\n !nodesByIndex.has(\n spectralSampleIndex\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature spectralSampleIndex values must form the exact contiguous range 0..totalNodeCount-1.\"\n );\n }\n }\n\n for (\n let segmentIndex = 0;\n segmentIndex < segmentCount;\n segmentIndex += 1\n ) {\n const expected =\n segmentSubdivisionCounts.get(\n segmentIndex\n );\n const seen =\n segmentSeenCounts.get(\n segmentIndex\n ) ?? 0;\n if (\n expected === undefined ||\n seen !== expected\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature must contain every declared subdivision exactly once.\"\n );\n }\n }\n\n if (\n !approximatelyEqual(\n measureSum,\n span\n ) ||\n !approximatelyEqual(\n normalizedWeightSum,\n 1\n ) ||\n !approximatelyEqual(\n quadrature.wavelengthMeasureSumNanometers,\n measureSum\n ) ||\n !approximatelyEqual(\n quadrature.normalizedWavelengthWeightSum,\n normalizedWeightSum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature aggregate wavelength measures/weights are inconsistent.\"\n );\n }\n\n return nodesByIndex;\n}\n\n/**\n * Builds deterministic wavelength sample points for one exact sensor response\n * channel. It does not apply the response to any spectrum.\n *\n * The requested range must lie fully inside the channel's declared usable\n * range. The response curve's breakpoints, plus any caller-supplied breakpoints\n * from the source spectrum or optics, split that range into segments. Each\n * segment is then subdivided so no midpoint subinterval is wider than\n * maximumSubintervalWidthNanometers.\n *\n * wavelengthMeasureNanometers is dλ in nanometres, not a dimensionless response\n * weight. Multiply it only by a spectral density per nanometre, or convert\n * units explicitly first.\n *\n * QE and A/W responsivity are deliberately not applied. They lead to different\n * signals: QE is photon-to-electron efficiency, while A/W responsivity relates\n * incident radiant power to electrical current. A later step must also match\n * responseScope to the source plane and collection area before integrating any\n * signal.\n */\nexport function calculateSensorSpectralQuadrature(\n input:\n CalculateSensorSpectralQuadratureInput\n): CalculationResult<SensorSpectralQuadrature> {\n requireInputKeys(input, \"calculateSensorSpectralQuadrature\", [\"colorSamplingProfile\", \"spectralResponseProfile\", \"channelId\", \"wavelengthBasis\", \"wavelengthRangeNanometers\", \"maximumSubintervalWidthNanometers\", \"additionalBreakpointsNanometers\"]);\n const maximumSubintervalWidthNanometers =\n requirePositiveFinite(\n input.maximumSubintervalWidthNanometers,\n \"maximumSubintervalWidthNanometers\"\n );\n\n if (\n input.wavelengthBasis !== \"air\" &&\n input.wavelengthBasis !== \"vacuum\" &&\n input.wavelengthBasis !== \"unspecified\"\n ) {\n throw new InvalidConfigurationError(\n \"wavelengthBasis is invalid.\"\n );\n }\n\n const colorProfile =\n parseSensorColorSamplingProfile(\n input.colorSamplingProfile\n );\n const responseProfile =\n parseSensorSpectralResponseProfile(\n input.spectralResponseProfile\n );\n const response = channelResponse(\n responseProfile,\n input.channelId\n );\n const curves =\n responseCurves(response);\n\n if (\n !curves.every(\n (curve) =>\n curve.wavelengthBasis ===\n input.wavelengthBasis\n )\n ) {\n throw new InvalidScientificInputError(\n \"wavelengthBasis must exactly match every response curve used by the requested channel.\"\n );\n }\n\n const usable = usableResponseRange(\n curves\n );\n const range = parseRequestedRange(\n input.wavelengthRangeNanometers,\n usable\n );\n const validationWavelength =\n range.minimum +\n (range.maximum - range.minimum) /\n 2;\n const representative =\n resolveSensorSpectralResponseAtWavelength(\n {\n colorSamplingProfile:\n colorProfile,\n spectralResponseProfile:\n responseProfile,\n channelId: input.channelId,\n wavelengthNanometers:\n validationWavelength,\n wavelengthBasis:\n input.wavelengthBasis\n }\n ).value;\n\n const additional =\n additionalBreakpoints(\n input.additionalBreakpointsNanometers,\n range\n );\n const boundaries =\n partitionBoundaries(\n curves,\n range,\n additional\n );\n const {\n segments,\n totalNodeCount\n } = planSegments(\n boundaries,\n maximumSubintervalWidthNanometers\n );\n\n const totalSpan =\n range.maximum - range.minimum;\n const nodes:\n SensorSpectralQuadratureNode[] = [];\n let spectralSampleIndex = 0;\n\n for (\n let segmentIndex = 0;\n segmentIndex < segments.length;\n segmentIndex += 1\n ) {\n const segment =\n segments[segmentIndex]!;\n\n for (\n let subdivisionIndex = 0;\n subdivisionIndex <\n segment.subdivisionCount;\n subdivisionIndex += 1\n ) {\n const wavelengthNanometers =\n segment.minimum +\n (subdivisionIndex + 0.5) *\n segment\n .subintervalWidthNanometers;\n\n nodes.push({\n spectralSampleIndex,\n segmentIndex,\n subdivisionIndex,\n segmentSubdivisionCount:\n segment.subdivisionCount,\n wavelengthNanometers,\n wavelengthMeasureNanometers:\n segment\n .subintervalWidthNanometers,\n normalizedWavelengthWeight:\n segment\n .subintervalWidthNanometers /\n totalSpan\n });\n\n spectralSampleIndex += 1;\n }\n }\n\n const normalizedWavelengthWeightSum =\n nodes.reduce(\n (sum, node) =>\n sum +\n node.normalizedWavelengthWeight,\n 0\n );\n const wavelengthMeasureSumNanometers =\n nodes.reduce(\n (sum, node) =>\n sum +\n node.wavelengthMeasureNanometers,\n 0\n );\n\n return approximationResult(\n {\n profileId:\n representative.profileId,\n colorSamplingProfileId:\n representative\n .colorSamplingProfileId,\n channelId:\n representative.channelId,\n sourceResponseKind:\n representative\n .sourceResponseKind,\n responseScope:\n representative.responseScope,\n responseScientificStatus:\n representative\n .scientificStatus,\n responseUncertainty:\n representative.uncertainty,\n responseChannelBinding:\n createSensorSpectralResponseChannelBinding(\n response\n ),\n ...(representative.referenceConditions ===\n undefined\n ? {}\n : {\n responseReferenceConditions:\n representative.referenceConditions\n }),\n wavelengthBasis:\n input.wavelengthBasis,\n wavelengthBasisResolved:\n representative\n .wavelengthBasisResolved,\n wavelengthRangeNanometers:\n range,\n responseDeclaredWavelengthRangeNanometers:\n usable,\n quadratureScheme:\n \"response-breakpoint-aware-bounded-midpoint\",\n segmentBoundarySource:\n \"requested-range-plus-response-knots-plus-optional-additional-breakpoints\",\n segmentBoundariesNanometers:\n [...boundaries],\n maximumSubintervalWidthNanometers,\n segmentCount:\n segments.length,\n totalNodeCount,\n normalizedWavelengthWeightSum,\n wavelengthMeasureSumNanometers,\n nodes,\n responseKnotAlignmentIncluded:\n true,\n componentEvidence: {\n colorSamplingProfile:\n colorProfile.evidence,\n profile:\n representative\n .componentEvidence.profile,\n channel:\n representative\n .componentEvidence.channel,\n curves:\n representative\n .componentEvidence.curves\n },\n responseValuesIncluded: false,\n responseApplicationPerformed:\n false,\n sourceSpectralValuesIncluded:\n false,\n spectralIrradianceIncluded:\n false,\n spectralPhotonIrradianceIncluded:\n false,\n commonSpectralCoverageValidated:\n false,\n continuousSpectralDensityQuadratureOnly:\n true,\n discreteLineSpectrumIncluded:\n false,\n opticalTransmissionIncludedByQuadrature:\n false,\n wavelengthIntegrationPerformed:\n false,\n spatialIntegrationPerformed:\n false,\n temporalIntegrationPerformed:\n false,\n photonsCalculated: false,\n electronsCalculated: false,\n rawCodeValueProduced: false,\n convergenceErrorEstimated: false\n },\n \"sensor-spectral-quadrature\",\n \"1.0.0\",\n [\n \"The partition includes requested range edges, response-curve knots, and optional caller-supplied continuous-spectrum/optics breakpoints.\",\n \"Every segment uses deterministic equal-width midpoint subintervals whose width is bounded by maximumSubintervalWidthNanometers.\",\n \"Wavelength measures are d-lambda in nanometres and normalized wavelength weights are geometric wavelength measures only; neither is sensor-response weighting.\",\n \"The requested range is validated against sensor-response support only. Scene-spectrum, optical-transmission, and other spectral-factor coverage are not established by this API.\",\n \"The response profile, exact channel linkage, wavelength basis, response scope, and response-data provenance are validated and preserved, but response values are not applied at quadrature nodes.\",\n \"QE and A/W responsivity remain different physical representations and require different compatible downstream photon/power semantics.\",\n \"Future signal composition must match responseScope to the source plane and collection-area model so upstream transmission is not omitted or double-counted.\",\n \"This midpoint plan targets continuous spectral-density integration. Discrete/delta-like line spectra require a separate explicit representation rather than being approximated by hidden point masses.\",\n \"No source spectral values, spectral irradiance, spectral photon irradiance, optical transmission, spatial integration, temporal integration, photon/electron conversion, current calculation, or RAW output is calculated.\",\n \"Response-knot alignment and a bounded wavelength step do not prove convergence for arbitrary source spectra or other wavelength-dependent factors.\",\n \"No source-independent convergence/error estimate is reported because integration error depends on the downstream integrand.\"\n ]\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"spectral-quadrature.js","sourceRoot":"","sources":["../../src/sensor/spectral-quadrature.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC;;;;;;;;;;GAUG;AAEH,OAAO,EACL,mBAAmB,EAEpB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAKpE,OAAO,EACL,+BAA+B,EAEhC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,0CAA0C,EAC1C,kCAAkC,EAClC,yCAAyC,EAK1C,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,0BAA0B,IAAI,qBAAqB,EAAE,kCAAkC,IAAI,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AAC1L,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,6BAA6B,GAAG,OAAO,CAAC;AA6I9C,SAAS,eAAe,CACtB,OAAsC,EACtC,SAAiB;IAEjB,IACE,OAAO,SAAS,KAAK,QAAQ;QAC7B,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAC7B,CAAC;QACD,MAAM,IAAI,yBAAyB,CACjC,uCAAuC,CACxC,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC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AAc;iBACX,iBAAiB,CAAC,OAAO;YAC9B,MAAM,EACJ,cAAc;iBACX,iBAAiB,CAAC,MAAM;SAC9B;QACD,sBAAsB,EAAE,KAAK;QAC7B,4BAA4B,EAC1B,KAAK;QACP,4BAA4B,EAC1B,KAAK;QACP,0BAA0B,EACxB,KAAK;QACP,gCAAgC,EAC9B,KAAK;QACP,+BAA+B,EAC7B,KAAK;QACP,uCAAuC,EACrC,IAAI;QACN,4BAA4B,EAC1B,KAAK;QACP,uCAAuC,EACrC,KAAK;QACP,8BAA8B,EAC5B,KAAK;QACP,2BAA2B,EACzB,KAAK;QACP,4BAA4B,EAC1B,KAAK;QACP,iBAAiB,EAAE,KAAK;QACxB,mBAAmB,EAAE,KAAK;QAC1B,oBAAoB,EAAE,KAAK;QAC3B,yBAAyB,EAAE,KAAK;KACjC,EACD,4BAA4B,EAC5B,OAAO,EACP;QACE,0IAA0I;QAC1I,iIAAiI;QACjI,gKAAgK;QAChK,kLAAkL;QAClL,mMAAmM;QACnM,uIAAuI;QACvI,6JAA6J;QAC7J,wMAAwM;QACxM,4NAA4N;QAC5N,oJAAoJ;QACpJ,6HAA6H;KAC9H,CACF,CAAC;AACJ,CAAC","sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/**\n * Spectral quadrature: the wavelength sample points (nodes) and step widths used to integrate light\n * over wavelength for one sensor response channel.\n *\n * Each node is the midpoint of a wavelength interval, with its width dλ in nanometres. The intervals\n * stay inside the range the response supports. Lining nodes up with curve breakpoints does not prove\n * the integral has converged. Discrete (delta-like) emission lines need their own integration and are\n * never silently widened into continuous bins.\n * @see docs/MOTION_AND_SIGNAL.md for equations, coordinate/unit conventions, blockers and support\n * limits.\n */\n\nimport {\n approximationResult,\n type CalculationResult\n} from \"../core/calculation-result.js\";\nimport type { EvidenceProvenance } from \"../core/evidence-provenance.js\";\nimport { InvalidScientificInputError } from \"../core/validation.js\";\nimport type {\n SpectralWavelengthBasis,\n SpectralWavelengthRangeNanometers\n} from \"../core/spectral.js\";\nimport {\n parseSensorColorSamplingProfile,\n type SensorColorSamplingProfile\n} from \"./color-sampling.js\";\nimport {\n createSensorSpectralResponseChannelBinding,\n parseSensorSpectralResponseProfile,\n resolveSensorSpectralResponseAtWavelength,\n type SensorSpectralReferenceConditions,\n type SensorSpectralResponseProfile,\n type SensorSpectralResponseScientificStatus,\n type SensorSpectralResponseUncertainty\n} from \"./spectral-response.js\";\nimport { requireInputKeys, requireInputPositiveFinite as requirePositiveFinite, requireInputNonNegativeSafeInteger as requireNonNegativeSafeInteger } from \"../core/record-validation.js\";\nimport { InvalidConfigurationError } from \"../core/configuration-error.js\";\nimport { responseCurves } from \"./spectral-coverage.js\";\n\nconst MAX_SPECTRAL_QUADRATURE_NODES = 100_000;\n\nexport type SensorSpectralWavelengthRangeNanometers =\n SpectralWavelengthRangeNanometers;\n\nexport interface CalculateSensorSpectralQuadratureInput {\n colorSamplingProfile: SensorColorSamplingProfile;\n spectralResponseProfile: SensorSpectralResponseProfile;\n channelId: string;\n wavelengthBasis: SpectralWavelengthBasis;\n /**\n * Wavelength interval to sample. It is checked only against the range the\n * sensor response supports, not against scene-spectrum or optical-transmission\n * coverage.\n */\n wavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n /**\n * Strict upper limit on the width of each midpoint subinterval.\n *\n * Response breakpoints and any additional breakpoints split the requested\n * range first. Each segment is then subdivided until every subinterval is\n * no wider than this value.\n */\n maximumSubintervalWidthNanometers: number;\n /**\n * Optional strictly increasing wavelength breakpoints from other continuous\n * spectral inputs, such as the interpolation points of a scene spectrum or of\n * optical transmission. Values must be strictly inside the requested range.\n *\n * Passing them does not claim those other inputs are available or valid over\n * the requested range.\n */\n additionalBreakpointsNanometers?:\n readonly number[];\n}\n\nexport interface SensorSpectralQuadratureNode {\n spectralSampleIndex: number;\n segmentIndex: number;\n subdivisionIndex: number;\n segmentSubdivisionCount: number;\n /**\n * Midpoint wavelength for this subinterval. Units: nm in wavelengthBasis.\n */\n wavelengthNanometers: number;\n /**\n * dλ (wavelength width) this node stands for. Units: nm.\n *\n * It is only a wavelength width. It is not response-weighted throughput,\n * a photon count, radiant energy, current or a dimensionless probability.\n */\n wavelengthMeasureNanometers: number;\n /**\n * The wavelength width divided by the requested range width (dimensionless).\n *\n * Useful for averages, but it is not a sensor-response weight.\n */\n normalizedWavelengthWeight: number;\n}\n\nexport interface SensorSpectralQuadrature {\n profileId: string;\n colorSamplingProfileId: string;\n channelId: string;\n sourceResponseKind:\n SensorSpectralResponseProfile[\"channels\"][number][\"kind\"];\n responseScope:\n SensorSpectralResponseProfile[\"channels\"][number][\"responseScope\"];\n responseScientificStatus:\n SensorSpectralResponseScientificStatus;\n responseUncertainty:\n SensorSpectralResponseUncertainty;\n responseChannelBinding?: import(\"./spectral-response.js\").SensorSpectralResponseChannelBinding;\n responseReferenceConditions?:\n SensorSpectralReferenceConditions;\n wavelengthBasis: SpectralWavelengthBasis;\n wavelengthBasisResolved: boolean;\n wavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n responseDeclaredWavelengthRangeNanometers:\n SensorSpectralWavelengthRangeNanometers;\n quadratureScheme:\n \"response-breakpoint-aware-bounded-midpoint\";\n segmentBoundarySource:\n \"requested-range-plus-response-knots-plus-optional-additional-breakpoints\";\n /**\n * Sorted, unique segment boundaries, including the ends of the requested range.\n */\n segmentBoundariesNanometers:\n readonly number[];\n maximumSubintervalWidthNanometers: number;\n segmentCount: number;\n totalNodeCount: number;\n normalizedWavelengthWeightSum: number;\n wavelengthMeasureSumNanometers: number;\n nodes: readonly SensorSpectralQuadratureNode[];\n responseKnotAlignmentIncluded: true;\n componentEvidence: {\n colorSamplingProfile: readonly EvidenceProvenance[];\n profile: readonly EvidenceProvenance[];\n channel: readonly EvidenceProvenance[];\n curves:\n readonly (readonly EvidenceProvenance[])[];\n };\n /**\n * Fixed statements of what this result does not include.\n */\n responseValuesIncluded: false;\n responseApplicationPerformed: false;\n sourceSpectralValuesIncluded: false;\n spectralIrradianceIncluded: false;\n spectralPhotonIrradianceIncluded: false;\n commonSpectralCoverageValidated: false;\n continuousSpectralDensityQuadratureOnly: true;\n discreteLineSpectrumIncluded: false;\n opticalTransmissionIncludedByQuadrature: false;\n wavelengthIntegrationPerformed: false;\n spatialIntegrationPerformed: false;\n temporalIntegrationPerformed: false;\n photonsCalculated: false;\n electronsCalculated: false;\n rawCodeValueProduced: false;\n convergenceErrorEstimated: false;\n}\n\ninterface ResponseCurveSupport {\n wavelengthBasis: SpectralWavelengthBasis;\n samples: readonly {\n wavelengthNanometers: number;\n }[];\n evidence: readonly EvidenceProvenance[];\n}\n\ninterface SegmentPlan {\n minimum: number;\n maximum: number;\n subdivisionCount: number;\n subintervalWidthNanometers: number;\n}\n\nfunction channelResponse(\n profile: SensorSpectralResponseProfile,\n channelId: string\n): SensorSpectralResponseProfile[\"channels\"][number] {\n if (\n typeof channelId !== \"string\" ||\n channelId.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n \"channelId must be a non-empty string.\"\n );\n }\n\n const response = profile.channels.find(\n (entry) => entry.channelId === channelId\n );\n if (response === undefined) {\n throw new InvalidScientificInputError(\n \"No spectral response is declared for the requested channelId.\"\n );\n }\n return response;\n}\n\nfunction usableResponseRange(\n curves: readonly ResponseCurveSupport[]\n): SensorSpectralWavelengthRangeNanometers {\n const minimum = Math.max(\n ...curves.map(\n (curve) =>\n curve.samples[0]!\n .wavelengthNanometers\n )\n );\n const maximum = Math.min(\n ...curves.map(\n (curve) =>\n curve.samples[\n curve.samples.length - 1\n ]!.wavelengthNanometers\n )\n );\n\n if (!(minimum < maximum)) {\n throw new InvalidScientificInputError(\n \"Spectral-response curves do not have a usable overlapping wavelength interval.\"\n );\n }\n\n return { minimum, maximum };\n}\n\nfunction parseRequestedRange(\n input:\n SensorSpectralWavelengthRangeNanometers,\n usable:\n SensorSpectralWavelengthRangeNanometers\n): SensorSpectralWavelengthRangeNanometers {\n if (\n typeof input !== \"object\" ||\n input === null\n ) {\n throw new InvalidConfigurationError(\n \"wavelengthRangeNanometers must be an object.\"\n );\n }\n\n const minimum = requirePositiveFinite(\n input.minimum,\n \"wavelengthRangeNanometers.minimum\"\n );\n const maximum = requirePositiveFinite(\n input.maximum,\n \"wavelengthRangeNanometers.maximum\"\n );\n\n if (!(minimum < maximum)) {\n throw new InvalidScientificInputError(\n \"wavelengthRangeNanometers.minimum must be less than maximum.\"\n );\n }\n\n if (\n minimum < usable.minimum ||\n maximum > usable.maximum\n ) {\n throw new InvalidScientificInputError(\n \"Requested wavelength range must remain inside the usable spectral-response range; clipping, extrapolation, and implicit zero-fill are not permitted.\"\n );\n }\n\n return { minimum, maximum };\n}\n\nfunction additionalBreakpoints(\n value: readonly number[] | undefined,\n range:\n SensorSpectralWavelengthRangeNanometers\n): readonly number[] {\n if (value === undefined) {\n return [];\n }\n if (!Array.isArray(value)) {\n throw new InvalidConfigurationError(\n \"additionalBreakpointsNanometers must be an array when supplied.\"\n );\n }\n if (\n value.length >=\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"additionalBreakpointsNanometers contains too many entries for the spectral quadrature safety limit.\"\n );\n }\n\n let previous =\n Number.NEGATIVE_INFINITY;\n\n return value.map(\n (entry, index) => {\n const wavelength =\n requirePositiveFinite(\n entry,\n \"additionalBreakpointsNanometers[\" +\n index +\n \"]\"\n );\n if (\n wavelength <= range.minimum ||\n wavelength >= range.maximum\n ) {\n throw new InvalidScientificInputError(\n \"Additional spectral breakpoints must lie strictly inside the requested wavelength range.\"\n );\n }\n if (wavelength <= previous) {\n throw new InvalidScientificInputError(\n \"additionalBreakpointsNanometers must be strictly increasing with no duplicates.\"\n );\n }\n previous = wavelength;\n return wavelength;\n }\n );\n}\n\nfunction partitionBoundaries(\n curves: readonly ResponseCurveSupport[],\n range:\n SensorSpectralWavelengthRangeNanometers,\n additional:\n readonly number[]\n): readonly number[] {\n const boundaries = new Set<number>([\n range.minimum,\n range.maximum,\n ...additional\n ]);\n\n for (const curve of curves) {\n for (const sample of curve.samples) {\n if (\n sample.wavelengthNanometers >\n range.minimum &&\n sample.wavelengthNanometers <\n range.maximum\n ) {\n boundaries.add(\n sample.wavelengthNanometers\n );\n }\n }\n }\n\n return [...boundaries].sort(\n (a, b) => a - b\n );\n}\n\nfunction planSegments(\n boundaries: readonly number[],\n maximumSubintervalWidthNanometers: number\n): {\n segments: readonly SegmentPlan[];\n totalNodeCount: number;\n} {\n const segments: SegmentPlan[] = [];\n let totalNodeCount = 0;\n\n for (\n let segmentIndex = 0;\n segmentIndex < boundaries.length - 1;\n segmentIndex += 1\n ) {\n const minimum =\n boundaries[segmentIndex]!;\n const maximum =\n boundaries[segmentIndex + 1]!;\n const width =\n maximum - minimum;\n\n if (\n !Number.isFinite(width) ||\n width <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature segment widths must be finite and greater than zero.\"\n );\n }\n\n const subdivisionCount =\n Math.ceil(\n width /\n maximumSubintervalWidthNanometers\n );\n\n if (\n !Number.isSafeInteger(\n subdivisionCount\n ) ||\n subdivisionCount <= 0\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature segment subdivision count must be a positive safe integer.\"\n );\n }\n\n totalNodeCount +=\n subdivisionCount;\n\n if (\n !Number.isSafeInteger(\n totalNodeCount\n )\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature node count must remain a safe integer.\"\n );\n }\n if (\n totalNodeCount >\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature node count exceeds the safety limit of \" +\n MAX_SPECTRAL_QUADRATURE_NODES +\n \".\"\n );\n }\n\n segments.push({\n minimum,\n maximum,\n subdivisionCount,\n subintervalWidthNanometers:\n width / subdivisionCount\n });\n }\n\n if (segments.length === 0) {\n throw new InvalidScientificInputError(\n \"Spectral quadrature requires at least one non-empty segment.\"\n );\n }\n\n return {\n segments,\n totalNodeCount\n };\n}\n\nconst SPECTRAL_VALIDATION_TOLERANCE = 1e-10;\n\nfunction approximatelyEqual(\n actual: number,\n expected: number,\n tolerance = SPECTRAL_VALIDATION_TOLERANCE\n): boolean {\n const scale = Math.max(\n 1,\n Math.abs(actual),\n Math.abs(expected)\n );\n return (\n Math.abs(actual - expected) <=\n tolerance * scale\n );\n}\n\n/**\n * Rechecks a supplied wavelength plan (node identities, coverage and widths in nanometres) before it\n * is used.\n *\n * Lining nodes up with breakpoints does not prove convergence. Discrete (delta-like) lines need their\n * own integration and are never silently widened into continuous bins.\n * @param quadrature - The input; see `SensorSpectralQuadrature` for its fields, units and coordinates.\n * @returns The result. Success does not imply calibration.\n *\n * @see docs/API_REFERENCE.md for the package export and its full type definitions.\n */\nexport function validateSensorSpectralQuadrature(\n quadrature: SensorSpectralQuadrature\n): Map<number, SensorSpectralQuadratureNode> {\n if (\n typeof quadrature !== \"object\" ||\n quadrature === null ||\n !Array.isArray(quadrature.nodes)\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature must contain a nodes array.\"\n );\n }\n\n for (const [field, value] of [\n [\"profileId\", quadrature.profileId],\n [\n \"colorSamplingProfileId\",\n quadrature.colorSamplingProfileId\n ],\n [\"channelId\", quadrature.channelId]\n ] as const) {\n if (\n typeof value !== \"string\" ||\n value.trim().length === 0\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature.\" +\n field +\n \" must be a non-empty string.\"\n );\n }\n }\n\n if (\n quadrature.wavelengthBasis !== \"air\" &&\n quadrature.wavelengthBasis !== \"vacuum\" &&\n quadrature.wavelengthBasis !== \"unspecified\"\n ) {\n throw new InvalidConfigurationError(\n \"spectralQuadrature.wavelengthBasis is invalid.\"\n );\n }\n\n const rangeMinimum = requirePositiveFinite(\n quadrature.wavelengthRangeNanometers.minimum,\n \"spectralQuadrature.wavelengthRangeNanometers.minimum\"\n );\n const rangeMaximum = requirePositiveFinite(\n quadrature.wavelengthRangeNanometers.maximum,\n \"spectralQuadrature.wavelengthRangeNanometers.maximum\"\n );\n if (!(rangeMinimum < rangeMaximum)) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature wavelength range minimum must be less than maximum.\"\n );\n }\n\n const maximumSubintervalWidthNanometers =\n requirePositiveFinite(\n quadrature.maximumSubintervalWidthNanometers,\n \"spectralQuadrature.maximumSubintervalWidthNanometers\"\n );\n\n if (\n !Array.isArray(\n quadrature.segmentBoundariesNanometers\n ) ||\n quadrature.segmentBoundariesNanometers.length <\n 2\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentBoundariesNanometers must contain at least two boundaries.\"\n );\n }\n\n let previousBoundary =\n Number.NEGATIVE_INFINITY;\n quadrature.segmentBoundariesNanometers.forEach(\n (boundary, index) => {\n const parsed = requirePositiveFinite(\n boundary,\n \"spectralQuadrature.segmentBoundariesNanometers[\" +\n index +\n \"]\"\n );\n if (parsed <= previousBoundary) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentBoundariesNanometers must be strictly increasing.\"\n );\n }\n previousBoundary = parsed;\n }\n );\n\n const segmentCount =\n requireNonNegativeSafeInteger(\n quadrature.segmentCount,\n \"spectralQuadrature.segmentCount\"\n );\n if (\n segmentCount <= 0 ||\n segmentCount !==\n quadrature.segmentBoundariesNanometers.length -\n 1\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.segmentCount must be positive and match the boundary count.\"\n );\n }\n\n if (\n !approximatelyEqual(\n quadrature.segmentBoundariesNanometers[0]!,\n rangeMinimum\n ) ||\n !approximatelyEqual(\n quadrature.segmentBoundariesNanometers[\n quadrature.segmentBoundariesNanometers.length -\n 1\n ]!,\n rangeMaximum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature segment boundaries must exactly span the requested wavelength range.\"\n );\n }\n\n const totalNodeCount =\n requireNonNegativeSafeInteger(\n quadrature.totalNodeCount,\n \"spectralQuadrature.totalNodeCount\"\n );\n if (\n totalNodeCount <= 0 ||\n totalNodeCount !== quadrature.nodes.length\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.totalNodeCount must be positive and exactly match spectralQuadrature.nodes.length.\"\n );\n }\n if (\n totalNodeCount >\n MAX_SPECTRAL_QUADRATURE_NODES\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature.totalNodeCount exceeds the spectral quadrature safety limit.\"\n );\n }\n\n if (\n quadrature.responseApplicationPerformed !==\n false ||\n quadrature.responseValuesIncluded !== false ||\n quadrature.wavelengthIntegrationPerformed !==\n false ||\n quadrature.continuousSpectralDensityQuadratureOnly !==\n true ||\n quadrature.discreteLineSpectrumIncluded !==\n false\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature semantics are incompatible with pre-response continuous-density composition.\"\n );\n }\n\n const span =\n rangeMaximum - rangeMinimum;\n const nodesByIndex =\n new Map<number, SensorSpectralQuadratureNode>();\n const seenSegmentSubdivisions =\n new Set<string>();\n const segmentSubdivisionCounts =\n new Map<number, number>();\n const segmentSeenCounts =\n new Map<number, number>();\n let measureSum = 0;\n let normalizedWeightSum = 0;\n\n quadrature.nodes.forEach(\n (node, nodeArrayIndex) => {\n const spectralSampleIndex =\n requireNonNegativeSafeInteger(\n node.spectralSampleIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].spectralSampleIndex\"\n );\n if (\n nodesByIndex.has(\n spectralSampleIndex\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature contains duplicate spectralSampleIndex values.\"\n );\n }\n\n const segmentIndex =\n requireNonNegativeSafeInteger(\n node.segmentIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].segmentIndex\"\n );\n if (segmentIndex >= segmentCount) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node segmentIndex is outside the declared segment range.\"\n );\n }\n\n const subdivisionIndex =\n requireNonNegativeSafeInteger(\n node.subdivisionIndex,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].subdivisionIndex\"\n );\n const segmentSubdivisionCount =\n requireNonNegativeSafeInteger(\n node.segmentSubdivisionCount,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].segmentSubdivisionCount\"\n );\n if (\n segmentSubdivisionCount <= 0 ||\n subdivisionIndex >=\n segmentSubdivisionCount\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node subdivision identity is invalid.\"\n );\n }\n\n const priorSegmentCount =\n segmentSubdivisionCounts.get(\n segmentIndex\n );\n if (\n priorSegmentCount !== undefined &&\n priorSegmentCount !==\n segmentSubdivisionCount\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature nodes disagree on a segment subdivision count.\"\n );\n }\n segmentSubdivisionCounts.set(\n segmentIndex,\n segmentSubdivisionCount\n );\n\n const subdivisionKey =\n segmentIndex +\n \":\" +\n subdivisionIndex;\n if (\n seenSegmentSubdivisions.has(\n subdivisionKey\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature contains duplicate segment/subdivision identities.\"\n );\n }\n seenSegmentSubdivisions.add(\n subdivisionKey\n );\n segmentSeenCounts.set(\n segmentIndex,\n (segmentSeenCounts.get(\n segmentIndex\n ) ?? 0) + 1\n );\n\n const wavelengthNanometers =\n requirePositiveFinite(\n node.wavelengthNanometers,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].wavelengthNanometers\"\n );\n const wavelengthMeasureNanometers =\n requirePositiveFinite(\n node.wavelengthMeasureNanometers,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].wavelengthMeasureNanometers\"\n );\n const normalizedWavelengthWeight =\n requirePositiveFinite(\n node.normalizedWavelengthWeight,\n \"spectralQuadrature.nodes[\" +\n nodeArrayIndex +\n \"].normalizedWavelengthWeight\"\n );\n\n const segmentMinimum =\n quadrature.segmentBoundariesNanometers[\n segmentIndex\n ]!;\n const segmentMaximum =\n quadrature.segmentBoundariesNanometers[\n segmentIndex + 1\n ]!;\n const expectedMeasure =\n (segmentMaximum -\n segmentMinimum) /\n segmentSubdivisionCount;\n const expectedWavelength =\n segmentMinimum +\n (subdivisionIndex + 0.5) *\n expectedMeasure;\n const expectedNormalizedWeight =\n expectedMeasure / span;\n\n if (\n !approximatelyEqual(\n wavelengthMeasureNanometers,\n expectedMeasure\n ) ||\n !approximatelyEqual(\n wavelengthNanometers,\n expectedWavelength\n ) ||\n !approximatelyEqual(\n normalizedWavelengthWeight,\n expectedNormalizedWeight\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node geometry/measure does not match its declared segment/subdivision identity.\"\n );\n }\n\n if (\n wavelengthMeasureNanometers >\n maximumSubintervalWidthNanometers &&\n !approximatelyEqual(\n wavelengthMeasureNanometers,\n maximumSubintervalWidthNanometers\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature node width exceeds maximumSubintervalWidthNanometers.\"\n );\n }\n\n measureSum +=\n wavelengthMeasureNanometers;\n normalizedWeightSum +=\n normalizedWavelengthWeight;\n if (\n !Number.isFinite(measureSum) ||\n !Number.isFinite(\n normalizedWeightSum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature aggregate measures must remain finite.\"\n );\n }\n\n nodesByIndex.set(\n spectralSampleIndex,\n node\n );\n }\n );\n\n for (\n let spectralSampleIndex = 0;\n spectralSampleIndex < totalNodeCount;\n spectralSampleIndex += 1\n ) {\n if (\n !nodesByIndex.has(\n spectralSampleIndex\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature spectralSampleIndex values must form the exact contiguous range 0..totalNodeCount-1.\"\n );\n }\n }\n\n for (\n let segmentIndex = 0;\n segmentIndex < segmentCount;\n segmentIndex += 1\n ) {\n const expected =\n segmentSubdivisionCounts.get(\n segmentIndex\n );\n const seen =\n segmentSeenCounts.get(\n segmentIndex\n ) ?? 0;\n if (\n expected === undefined ||\n seen !== expected\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature must contain every declared subdivision exactly once.\"\n );\n }\n }\n\n if (\n !approximatelyEqual(\n measureSum,\n span\n ) ||\n !approximatelyEqual(\n normalizedWeightSum,\n 1\n ) ||\n !approximatelyEqual(\n quadrature.wavelengthMeasureSumNanometers,\n measureSum\n ) ||\n !approximatelyEqual(\n quadrature.normalizedWavelengthWeightSum,\n normalizedWeightSum\n )\n ) {\n throw new InvalidScientificInputError(\n \"spectralQuadrature aggregate wavelength measures/weights are inconsistent.\"\n );\n }\n\n return nodesByIndex;\n}\n\n/**\n * Builds deterministic wavelength sample points for one exact sensor response\n * channel. It does not apply the response to any spectrum.\n *\n * The requested range must lie fully inside the channel's declared usable\n * range. The response curve's breakpoints, plus any caller-supplied breakpoints\n * from the source spectrum or optics, split that range into segments. Each\n * segment is then subdivided so no midpoint subinterval is wider than\n * maximumSubintervalWidthNanometers.\n *\n * wavelengthMeasureNanometers is dλ in nanometres, not a dimensionless response\n * weight. Multiply it only by a spectral density per nanometre, or convert\n * units explicitly first.\n *\n * QE and A/W responsivity are deliberately not applied. They lead to different\n * signals: QE is photon-to-electron efficiency, while A/W responsivity relates\n * incident radiant power to electrical current. A later step must also match\n * responseScope to the source plane and collection area before integrating any\n * signal.\n */\nexport function calculateSensorSpectralQuadrature(\n input:\n CalculateSensorSpectralQuadratureInput\n): CalculationResult<SensorSpectralQuadrature> {\n requireInputKeys(input, \"calculateSensorSpectralQuadrature\", [\"colorSamplingProfile\", \"spectralResponseProfile\", \"channelId\", \"wavelengthBasis\", \"wavelengthRangeNanometers\", \"maximumSubintervalWidthNanometers\", \"additionalBreakpointsNanometers\"]);\n const maximumSubintervalWidthNanometers =\n requirePositiveFinite(\n input.maximumSubintervalWidthNanometers,\n \"maximumSubintervalWidthNanometers\"\n );\n\n if (\n input.wavelengthBasis !== \"air\" &&\n input.wavelengthBasis !== \"vacuum\" &&\n input.wavelengthBasis !== \"unspecified\"\n ) {\n throw new InvalidConfigurationError(\n \"wavelengthBasis is invalid.\"\n );\n }\n\n const colorProfile =\n parseSensorColorSamplingProfile(\n input.colorSamplingProfile\n );\n const responseProfile =\n parseSensorSpectralResponseProfile(\n input.spectralResponseProfile\n );\n const response = channelResponse(\n responseProfile,\n input.channelId\n );\n const curves =\n responseCurves(response);\n\n if (\n !curves.every(\n (curve) =>\n curve.wavelengthBasis ===\n input.wavelengthBasis\n )\n ) {\n throw new InvalidScientificInputError(\n \"wavelengthBasis must exactly match every response curve used by the requested channel.\"\n );\n }\n\n const usable = usableResponseRange(\n curves\n );\n const range = parseRequestedRange(\n input.wavelengthRangeNanometers,\n usable\n );\n const validationWavelength =\n range.minimum +\n (range.maximum - range.minimum) /\n 2;\n const representative =\n resolveSensorSpectralResponseAtWavelength(\n {\n colorSamplingProfile:\n colorProfile,\n spectralResponseProfile:\n responseProfile,\n channelId: input.channelId,\n wavelengthNanometers:\n validationWavelength,\n wavelengthBasis:\n input.wavelengthBasis\n }\n ).value;\n\n const additional =\n additionalBreakpoints(\n input.additionalBreakpointsNanometers,\n range\n );\n const boundaries =\n partitionBoundaries(\n curves,\n range,\n additional\n );\n const {\n segments,\n totalNodeCount\n } = planSegments(\n boundaries,\n maximumSubintervalWidthNanometers\n );\n\n const totalSpan =\n range.maximum - range.minimum;\n const nodes:\n SensorSpectralQuadratureNode[] = [];\n let spectralSampleIndex = 0;\n\n for (\n let segmentIndex = 0;\n segmentIndex < segments.length;\n segmentIndex += 1\n ) {\n const segment =\n segments[segmentIndex]!;\n\n for (\n let subdivisionIndex = 0;\n subdivisionIndex <\n segment.subdivisionCount;\n subdivisionIndex += 1\n ) {\n const wavelengthNanometers =\n segment.minimum +\n (subdivisionIndex + 0.5) *\n segment\n .subintervalWidthNanometers;\n\n nodes.push({\n spectralSampleIndex,\n segmentIndex,\n subdivisionIndex,\n segmentSubdivisionCount:\n segment.subdivisionCount,\n wavelengthNanometers,\n wavelengthMeasureNanometers:\n segment\n .subintervalWidthNanometers,\n normalizedWavelengthWeight:\n segment\n .subintervalWidthNanometers /\n totalSpan\n });\n\n spectralSampleIndex += 1;\n }\n }\n\n const normalizedWavelengthWeightSum =\n nodes.reduce(\n (sum, node) =>\n sum +\n node.normalizedWavelengthWeight,\n 0\n );\n const wavelengthMeasureSumNanometers =\n nodes.reduce(\n (sum, node) =>\n sum +\n node.wavelengthMeasureNanometers,\n 0\n );\n\n return approximationResult(\n {\n profileId:\n representative.profileId,\n colorSamplingProfileId:\n representative\n .colorSamplingProfileId,\n channelId:\n representative.channelId,\n sourceResponseKind:\n representative\n .sourceResponseKind,\n responseScope:\n representative.responseScope,\n responseScientificStatus:\n representative\n .scientificStatus,\n responseUncertainty:\n representative.uncertainty,\n responseChannelBinding:\n createSensorSpectralResponseChannelBinding(\n response\n ),\n ...(representative.referenceConditions ===\n undefined\n ? {}\n : {\n responseReferenceConditions:\n representative.referenceConditions\n }),\n wavelengthBasis:\n input.wavelengthBasis,\n wavelengthBasisResolved:\n representative\n .wavelengthBasisResolved,\n wavelengthRangeNanometers:\n range,\n responseDeclaredWavelengthRangeNanometers:\n usable,\n quadratureScheme:\n \"response-breakpoint-aware-bounded-midpoint\",\n segmentBoundarySource:\n \"requested-range-plus-response-knots-plus-optional-additional-breakpoints\",\n segmentBoundariesNanometers:\n [...boundaries],\n maximumSubintervalWidthNanometers,\n segmentCount:\n segments.length,\n totalNodeCount,\n normalizedWavelengthWeightSum,\n wavelengthMeasureSumNanometers,\n nodes,\n responseKnotAlignmentIncluded:\n true,\n componentEvidence: {\n colorSamplingProfile:\n colorProfile.evidence,\n profile:\n representative\n .componentEvidence.profile,\n channel:\n representative\n .componentEvidence.channel,\n curves:\n representative\n .componentEvidence.curves\n },\n responseValuesIncluded: false,\n responseApplicationPerformed:\n false,\n sourceSpectralValuesIncluded:\n false,\n spectralIrradianceIncluded:\n false,\n spectralPhotonIrradianceIncluded:\n false,\n commonSpectralCoverageValidated:\n false,\n continuousSpectralDensityQuadratureOnly:\n true,\n discreteLineSpectrumIncluded:\n false,\n opticalTransmissionIncludedByQuadrature:\n false,\n wavelengthIntegrationPerformed:\n false,\n spatialIntegrationPerformed:\n false,\n temporalIntegrationPerformed:\n false,\n photonsCalculated: false,\n electronsCalculated: false,\n rawCodeValueProduced: false,\n convergenceErrorEstimated: false\n },\n \"sensor-spectral-quadrature\",\n \"1.0.0\",\n [\n \"The partition includes requested range edges, response-curve knots, and optional caller-supplied continuous-spectrum/optics breakpoints.\",\n \"Every segment uses deterministic equal-width midpoint subintervals whose width is bounded by maximumSubintervalWidthNanometers.\",\n \"Wavelength measures are d-lambda in nanometres and normalized wavelength weights are geometric wavelength measures only; neither is sensor-response weighting.\",\n \"The requested range is validated against sensor-response support only. Scene-spectrum, optical-transmission, and other spectral-factor coverage are not established by this API.\",\n \"The response profile, exact channel linkage, wavelength basis, response scope, and response-data provenance are validated and preserved, but response values are not applied at quadrature nodes.\",\n \"QE and A/W responsivity remain different physical representations and require different compatible downstream photon/power semantics.\",\n \"Future signal composition must match responseScope to the source plane and collection-area model so upstream transmission is not omitted or double-counted.\",\n \"This midpoint plan targets continuous spectral-density integration. Discrete/delta-like line spectra require a separate explicit representation rather than being approximated by hidden point masses.\",\n \"No source spectral values, spectral irradiance, spectral photon irradiance, optical transmission, spatial integration, temporal integration, photon/electron conversion, current calculation, or RAW output is calculated.\",\n \"Response-knot alignment and a bounded wavelength step do not prove convergence for arbitrary source spectra or other wavelength-dependent factors.\",\n \"No source-independent convergence/error estimate is reported because integration error depends on the downstream integrand.\"\n ]\n );\n}\n"]}
|
|
@@ -18,52 +18,13 @@ import { parseEvidenceList } from "../core/evidence-provenance.js";
|
|
|
18
18
|
import { InvalidScientificInputError } from "../core/validation.js";
|
|
19
19
|
import { parseSpectralWavelengthBasis } from "../core/spectral.js";
|
|
20
20
|
import { parseSensorColorSamplingProfile } from "./color-sampling.js";
|
|
21
|
-
import { requireInputKeys,
|
|
21
|
+
import { requireInputKeys, rejectUnknownVariantFields, UNCERTAINTY_VARIANT_FIELDS, requireConfigRecord as requireRecord, requireConfigString as requireNonEmptyString, parseConfigScientificStatus as parseScientificStatus, requireConfigFiniteNumber as requireFinite, requireConfigFraction as requireFraction, requireConfigNumberAboveZero as requirePositiveFinite } from "../core/record-validation.js";
|
|
22
22
|
/**
|
|
23
23
|
* Current channel-binding format. v2 (package 2.0.0) serializes the parsed channel with sorted keys.
|
|
24
24
|
* v1 (package 1.5.0 and earlier) used the unparsed channel's JSON in insertion order; it is rejected
|
|
25
25
|
* with an explicit version error instead of being compared.
|
|
26
26
|
*/
|
|
27
27
|
export const SENSOR_SPECTRAL_RESPONSE_CHANNEL_BINDING_FORMAT = "photivra-spectral-channel-response-canonical-json-v2";
|
|
28
|
-
function requireRecord(value, path, allowedKeys) {
|
|
29
|
-
if (typeof value !== "object" ||
|
|
30
|
-
value === null ||
|
|
31
|
-
Array.isArray(value)) {
|
|
32
|
-
throw new InvalidConfigurationError(path + " must be an object.");
|
|
33
|
-
}
|
|
34
|
-
if (allowedKeys !== null)
|
|
35
|
-
rejectUnknownFields(value, allowedKeys, path);
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
|
-
function requireNonEmptyString(value, path) {
|
|
39
|
-
if (typeof value !== "string" ||
|
|
40
|
-
value.trim().length === 0) {
|
|
41
|
-
throw new InvalidConfigurationError(path + " must be a non-empty string.");
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
function requireFinite(value, path) {
|
|
46
|
-
if (typeof value !== "number" ||
|
|
47
|
-
!Number.isFinite(value)) {
|
|
48
|
-
throw new InvalidConfigurationError(path + " must be a finite number.");
|
|
49
|
-
}
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
function requirePositiveFinite(value, path) {
|
|
53
|
-
const number = requireFinite(value, path);
|
|
54
|
-
if (number <= 0) {
|
|
55
|
-
throw new InvalidConfigurationError(path + " must be greater than zero.");
|
|
56
|
-
}
|
|
57
|
-
return number;
|
|
58
|
-
}
|
|
59
|
-
function requireFraction(value, path) {
|
|
60
|
-
const number = requireFinite(value, path);
|
|
61
|
-
if (number < 0 || number > 1) {
|
|
62
|
-
throw new InvalidConfigurationError(path +
|
|
63
|
-
" must be a finite fraction from 0 through 1.");
|
|
64
|
-
}
|
|
65
|
-
return number;
|
|
66
|
-
}
|
|
67
28
|
function requireReusableCurveEvidence(value, path) {
|
|
68
29
|
const evidence = parseEvidenceList(value, path);
|
|
69
30
|
if (!evidence.some((entry) => entry.reuseStatus ===
|
|
@@ -245,13 +206,6 @@ function parseResponsivityCurve(value, path) {
|
|
|
245
206
|
samples: parseResponsivitySamples(record.samples, path + ".samples")
|
|
246
207
|
};
|
|
247
208
|
}
|
|
248
|
-
function parseScientificStatus(value, path) {
|
|
249
|
-
if (value !== "calibrated" &&
|
|
250
|
-
value !== "approximation") {
|
|
251
|
-
throw new InvalidConfigurationError(path + " is invalid.");
|
|
252
|
-
}
|
|
253
|
-
return value;
|
|
254
|
-
}
|
|
255
209
|
function validateCalibratedWavelengthBasis(scientificStatus, curves, path) {
|
|
256
210
|
if (scientificStatus === "calibrated" &&
|
|
257
211
|
curves.some((curve) => curve.wavelengthBasis ===
|