Skip to content

Commit 3d6831d

Browse files
authored
Merge pull request #631 from EarthyScience/jp/getarray
Fixed some bugs in getArray
2 parents 0c560bf + 61293fa commit 3d6831d

2 files changed

Lines changed: 23 additions & 28 deletions

File tree

next.config.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,7 @@ const nextConfig = {
4242
(config.resolve.alias as { [key: string]: string })['@/components'] = path.resolve(__dirname, 'src/components');
4343
return config;
4444
},
45-
async headers() { // Needed for SharedArrayBuffer. Security reasons won't let sharedArrayBuffer
46-
return [
47-
{
48-
source: '/(.*)',
49-
headers: [
50-
{
51-
key: 'Cross-Origin-Opener-Policy',
52-
value: 'same-origin',
53-
},
54-
{
55-
key: 'Cross-Origin-Embedder-Policy',
56-
value: 'require-corp',
57-
},
58-
],
59-
},
60-
]
61-
},
45+
6246
};
6347

6448
console.log('Current NODE_ENV:', process.env.NODE_ENV);

src/components/zarr/GetArray.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export async function GetArray(varOveride?: string) {
1212
const { idx4D, initStore, variable, setProgress, setStrides, setStatus } = useGlobalStore.getState();
1313
const { compress, xSlice, ySlice, zSlice, coarsen, kernelSize, kernelDepth, fetchNC, setCurrentChunks, setArraySize } = useZarrStore.getState();
1414
const { cache } = useCacheStore.getState();
15-
const fetcher = fetchNC ? NCFetcher() : zarrFetcher()
15+
const useNC = initStore.startsWith("local") && fetchNC // In case a user has NetCDF switched but then goes to a remote
16+
const fetcher = useNC ? NCFetcher() : zarrFetcher()
1617
const targetVariable = varOveride ?? variable;
1718
const meta = await fetcher.getMetadata(targetVariable);
1819
const { shape, chunkShape, fillValue, dtype } = meta;
@@ -69,15 +70,26 @@ export async function GetArray(varOveride?: string) {
6970

7071
if (isCacheValid) {
7172
const chunkData = cachedChunk.compressed ? DecompressArray(cachedChunk.data) : cachedChunk.data.slice();
72-
copyChunkToArray(
73-
chunkData,
74-
cachedChunk.shape,
75-
cachedChunk.stride,
76-
typedArray,
77-
outputShape,
78-
destStride as any, [z, y, x],
79-
[zDim.start, yDim.start, xDim.start]
80-
);
73+
if (hasZ) {
74+
copyChunkToArray(
75+
chunkData,
76+
cachedChunk.shape,
77+
cachedChunk.stride,
78+
typedArray,
79+
outputShape,
80+
destStride as any, [z, y, x],
81+
[zDim.start, yDim.start, xDim.start]
82+
)
83+
} else {
84+
copyChunkToArray2D(
85+
chunkData,
86+
cachedChunk.shape,
87+
cachedChunk.stride,
88+
typedArray,
89+
outputShape,
90+
destStride as any, [y, x],
91+
[yDim.start, xDim.start])
92+
}
8193
} else {
8294
const raw = await fetcher.fetchChunk({ variable:targetVariable, rank, shape, chunkShape, x, y, z, xDimIndex, yDimIndex, zDimIndex, idx4D });
8395

@@ -124,7 +136,6 @@ export async function GetArray(varOveride?: string) {
124136
}
125137
}
126138
}
127-
128139
setProgress(0);
129140
return { data: typedArray, shape: outputShape, dtype, scalingFactor };
130141
}

0 commit comments

Comments
 (0)