Log DICOM series sizes and exact volume limit failures
This commit is contained in:
1 parent
68a6801690
commit
86dc0e8d95
6 files changed
+149
-10
No files matched your search
@@ -0,0 +1,61 @@
|
||||
import {
|
||||
MAX_SERIES_FILES,
|
||||
MAX_VOLUME_BYTES,
|
||||
type DicomSource,
|
||||
} from "./dicom-series";
|
||||
|
||||
const size = (bytes: number) =>
|
||||
`${(bytes / 1024 ** 3).toFixed(3)} GiB (${bytes.toLocaleString("en-US")} bytes)`;
|
||||
|
||||
export function logDicomSeries(sources: DicomSource[]) {
|
||||
const sourceBytes = sources.reduce((total, file) => total + file.size, 0);
|
||||
const largestFileBytes = sources.reduce(
|
||||
(largest, file) => Math.max(largest, file.size),
|
||||
0
|
||||
);
|
||||
// Only sizes and counts: never include paths, share tokens or patient tags.
|
||||
console.info("[DICOM 3D] Series size", {
|
||||
fileCount: sources.length,
|
||||
sourceBytes,
|
||||
sourceSize: size(sourceBytes),
|
||||
largestFileBytes,
|
||||
largestFileSize: size(largestFileBytes),
|
||||
sourceLimit: size(MAX_VOLUME_BYTES),
|
||||
decodedVolumeLimit: size(MAX_VOLUME_BYTES),
|
||||
perFileLimit: "64 MiB",
|
||||
fileCountLimit: MAX_SERIES_FILES,
|
||||
});
|
||||
return { sourceBytes, largestFileBytes };
|
||||
}
|
||||
|
||||
export function logDicomVolumeEstimate(
|
||||
rows: number,
|
||||
cols: number,
|
||||
count: number
|
||||
) {
|
||||
const decodedBytes = rows * cols * count * Float32Array.BYTES_PER_ELEMENT;
|
||||
console.info("[DICOM 3D] Decoded volume estimate", {
|
||||
dimensions: [cols, rows, count],
|
||||
bytesPerVoxel: Float32Array.BYTES_PER_ELEMENT,
|
||||
decodedBytes,
|
||||
decodedSize: size(decodedBytes),
|
||||
decodedVolumeLimit: size(MAX_VOLUME_BYTES),
|
||||
});
|
||||
return decodedBytes;
|
||||
}
|
||||
|
||||
export function dicomLimitExceeded(
|
||||
reason: string,
|
||||
actual: number,
|
||||
limit: number
|
||||
): never {
|
||||
console.warn(`[DICOM 3D] Limit exceeded: ${reason}`, {
|
||||
actual,
|
||||
limit,
|
||||
...(reason !== "file count" && {
|
||||
actualSize: size(actual),
|
||||
limitSize: size(limit),
|
||||
}),
|
||||
});
|
||||
throw new Error("DICOM_VOLUME_LIMIT");
|
||||
}
|
||||
Reference in new issue
Block a user