Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions src/components/ui/MainPanel/MetaDimSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const chunkShape = meta?.chunks || [];


const { setDimArrays, setDimNames, setDimUnits, initStore, setVariable, setTextureArrayDepths, variable } = useGlobalStore(
const { setDimArrays, setDimNames, setDimUnits, initStore, setVariable, setTextureArrayDepths, variable, idx4D } = useGlobalStore(
useShallow((state) => ({
setDimArrays: state.setDimArrays,
setDimNames: state.setDimNames,
Expand All @@ -111,6 +111,7 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
setVariable: state.setVariable,
setTextureArrayDepths: state.setTextureArrayDepths,
variable: state.variable,
idx4D: state.idx4D,
})),
);

Expand Down Expand Up @@ -188,7 +189,8 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
if (mappedIdx !== undefined && mappedIdx >= 0 && mappedIdx < dims.length) {
const dim = dims[mappedIdx];
const s = ndSlices[mappedIdx];
let sel: SliceSelectionState = { ...defaultSelection(dim.size), mode: 'slice' };
const dimShape = dataShape[mappedIdx] ?? dim.size;
let sel = defaultSelection(dimShape);
if (Array.isArray(s)) {
sel = { start: String(s[0]), stop: s[1] !== null ? String(s[1]) : '', scalar: '', mode: 'slice' };
}
Expand All @@ -207,12 +209,16 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const activeDims = dims.slice(-Math.min(MAX_ACTIVE_DIMS, dims.length));
const defaultAxes: Axis[] = ['z', 'y', 'x'];
const axes = defaultAxes.slice(-activeDims.length);
return activeDims.map((d, i) => ({
id: nextId(),
dimName: d.name,
sel: { ...defaultSelection(d.size), mode: 'slice' },
axis: axes[i],
}));
return activeDims.map((d, i) => {
const dimShape = dataShape[availableDims.indexOf(d)] ?? d.size;
const sel = defaultSelection(dimShape);
return {
id: nextId(),
dimName: d.name,
sel,
axis: axes[i],
};
Comment thread
lazarusA marked this conversation as resolved.
});
};

const [rows, setRows] = useState<SlicerRow[]>(() => makeInitialRows(availableDims));
Expand Down Expand Up @@ -251,7 +257,10 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
});

const scalarIndices = ndSlicesTemp.filter(s => typeof s === "number").join("_");
const cacheBase = scalarIndices !== "" ? `${initStore}_${meta.name}_${scalarIndices}` : `${initStore}_${meta.name}`;
let cacheBase = scalarIndices !== "" ? `${initStore}_${meta.name}_${scalarIndices}` : `${initStore}_${meta.name}`;
if (meta.shape && meta.shape.length >= 4 && idx4D !== undefined && idx4D !== null) {
cacheBase = `${cacheBase}_time${idx4D}`;
}

const rowZ = rows.find((r) => r.axis === 'z');
const rowY = rows.find((r) => r.axis === 'y');
Expand All @@ -272,7 +281,7 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const start = parseInt(sel.start) || 0;
let stop = parseInt(sel.stop);
if (isNaN(stop)) stop = defaultLast;
else stop += 1;
else stop = Math.min(stop + 1, defaultLast > 0 ? defaultLast : stop + 1);
return { first: start, last: stop };
};

Expand Down Expand Up @@ -332,7 +341,7 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const start = parseInt(sel.start) || 0;
let stop = parseInt(sel.stop);
if (isNaN(stop)) stop = defaultLast;
else stop += 1;
else stop = Math.min(stop + 1, defaultLast > 0 ? defaultLast : stop + 1);
return { first: start, last: stop, steps: Math.max(1, stop - start) };
};

Expand Down Expand Up @@ -367,13 +376,16 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const start = parseInt(collSel.start) || 0;
let stop = parseInt(collSel.stop);
if (isNaN(stop)) stop = defaultLast;
else stop += 1;
else stop = Math.min(stop + 1, defaultLast > 0 ? defaultLast : stop + 1);
return Math.max(1, stop - start);
}
return defaultLast;
};

const totalSteps = availableDims.reduce((prod, d) => prod * getSelSteps(d.name, d.size), 1);
const totalSteps = availableDims.reduce((prod, d, idx) => {
const dimShape = dataShape[idx] ?? d.size;
return prod * getSelSteps(d.name, dimShape);
}, 1);
const sizeRatio = totalSteps / (dataShape.reduce((a, b) => a * b, 1) || 1);
let calculatedSize = (meta.totalSize || 0) * sizeRatio;

Expand Down Expand Up @@ -423,10 +435,11 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
const dimName = firstUnusedDim(prev);
if (!dimName) return prev;
const dim = availableDims.find((d) => d.name === dimName)!;
const dimShape = dataShape[availableDims.indexOf(dim)] ?? dim.size;
const newRows: SlicerRow[] = [...prev, {
id: nextId(),
dimName,
sel: { ...defaultSelection(dim.size), mode: 'slice' },
sel: defaultSelection(dimShape),
axis: 'z', // Placeholder, reassigned below
}];
Comment thread
lazarusA marked this conversation as resolved.

Expand All @@ -448,8 +461,10 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
setRows((prev) =>
prev.map((r) => {
if (r.id !== id) return r;
const dim = availableDims.find((d) => d.name === dimName);
return { ...r, dimName, sel: { ...defaultSelection(dim?.size), mode: 'slice' } };
const dimIndex = availableDims.findIndex((d) => d.name === dimName);
const dim = availableDims[dimIndex];
const dimShape = dataShape[dimIndex] ?? dim?.size ?? 0;
return { ...r, dimName, sel: defaultSelection(dimShape) };
}),
);
};
Expand Down Expand Up @@ -489,20 +504,23 @@ export default function MetaDimSelector({ meta, metadata, onApply, setShowMeta,
}
const start = parseInt(sel.start) || 0;
let stop = parseInt(sel.stop);
return [start, isNaN(stop) ? null : stop + 1];
if (isNaN(stop)) return [start, null];
return [start, Math.min(stop + 1, defaultLast > 0 ? defaultLast : stop + 1)];
};

setZSlice(getSliceArray(rowZ, dataShape ? dataShape[getOrigIdx(rowZ?.dimName || '')] : 0));
setYSlice(getSliceArray(rowY, dataShape ? dataShape[getOrigIdx(rowY?.dimName || '')] : 0));
setXSlice(getSliceArray(rowX, dataShape ? dataShape[getOrigIdx(rowX?.dimName || '')] : 0));

const ndSlices: (number | [number, number | null])[] = availableDims.map((dim) => {
const ndSlices: (number | [number, number | null])[] = availableDims.map((dim, idx) => {
const dimShape = dataShape ? dataShape[idx] ?? dim.size : dim.size;
const row = rows.find((r) => r.dimName === dim.name);
if (row) {
if (row.sel.mode === 'scalar') return parseInt(row.sel.scalar) || 0;
const start = parseInt(row.sel.start) || 0;
let stop = parseInt(row.sel.stop);
return [start, isNaN(stop) ? null : stop + 1];
if (isNaN(stop)) return [start, null];
return [start, Math.min(stop + 1, dimShape)];
}
const colSel = collapsedSels[dim.name];
if (colSel && colSel.mode === 'scalar') return parseInt(colSel.scalar) || 0;
Expand Down
9 changes: 6 additions & 3 deletions src/components/zarr/GetArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ export async function GetArray(varOveride?: string) {
let iter = 1;
const rescaleIDs: string[] = [];

const scalarIndices = (ndSlices && ndSlices.length > 0) ? ndSlices.filter(s => typeof s === "number").join("_") : (idx4D ?? "");
const cacheBase = scalarIndices !== "" ? `${initStore}_${targetVariable}_${scalarIndices}` : `${initStore}_${targetVariable}`;
const scalarIndices = (ndSlices && ndSlices.length > 0) ? ndSlices.filter(s => typeof s === "number").join("_") : "";
let cacheBase = scalarIndices !== "" ? `${initStore}_${targetVariable}_${scalarIndices}` : `${initStore}_${targetVariable}`;
if (rank >= 4 && idx4D !== undefined && idx4D !== null) {
cacheBase = `${cacheBase}_time${idx4D}`;
}

setStatus("Downloading...");
setProgress(0);
Expand All @@ -103,7 +106,7 @@ export async function GetArray(varOveride?: string) {
cachedChunk.kernel.kernelDepth === (coarsen ? kernelDepth : undefined);

if (isCacheValid) {
const chunkData = cachedChunk.compressed ? DecompressArray(cachedChunk.data) : cachedChunk.data.slice();
const chunkData = cachedChunk.compressed ? DecompressArray(cachedChunk.data) : new Float16Array(cachedChunk.data);
if (hasZ) {
copyChunkToArray(
chunkData,
Expand Down
9 changes: 2 additions & 7 deletions src/hooks/useDataFetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,14 @@ export const useDataFetcher = () => {
//---- DimInfo ----//
GetDimInfo(variable).then((arrays) => {
let { dimArrays, dimUnits, dimNames } = arrays;
if (is4D) {
dimArrays = dimArrays.slice(1);
dimUnits = dimUnits.slice(1);
dimNames = dimNames.slice(1);
}
setDimNames(dimNames);
setDimArrays(dimArrays);
setDimNames(dimNames);
setDimUnits(dimUnits);

const targetDim = dimArrays.length > 2 ? dimArrays[1] : dimArrays[0];
const shouldFlip = targetDim[1] < targetDim[0];
setFlipY(shouldFlip);
Comment thread
lazarusA marked this conversation as resolved.

setDimUnits(dimUnits);
ParseExtent(dimUnits, dimArrays);
});

Expand Down
Loading