Skip to content

Commit 0f09eb8

Browse files
committed
to zarr store
1 parent ac9da57 commit 0f09eb8

File tree

6 files changed

+40
-42
lines changed

6 files changed

+40
-42
lines changed

src/GlobalStates/GlobalStore.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { create } from "zustand";
22
import * as THREE from 'three';
33
import { GetColorMapTexture } from "@/components/textures";
4-
import { IcechunkStoreOptions, FetchStoreOptions } from "@/components/zarr/Interfaces";
54

65
const ESDC = 'https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr'
76

@@ -32,7 +31,6 @@ type StoreState = {
3231
plotDim: number;
3332
flipY:boolean;
3433
initStore:string;
35-
fetchKey: number;
3634
variable: string;
3735
variables: string[];
3836
openVariables: boolean;
@@ -48,9 +46,6 @@ type StoreState = {
4846
textureArrayDepths: number[];
4947
textureData: Uint8Array;
5048
clampExtremes: boolean;
51-
icechunkOptions: IcechunkStoreOptions | null;
52-
fetchOptions: FetchStoreOptions | null;
53-
abortController: AbortController | null;
5449

5550
// setters
5651
setDataShape: (dataShape: number[]) => void;
@@ -70,7 +65,6 @@ type StoreState = {
7065
setPlotDim: (plotDim: number) => void;
7166
setFlipY: (flipY:boolean) => void;
7267
setInitStore: (initStore:string) => void;
73-
bumpFetchKey: () => void;
7468
setVariable: (variable: string) => void;
7569
setVariables: (variables: string[]) => void;
7670
setOpenVariables: (openVariables: boolean) => void;
@@ -86,9 +80,6 @@ type StoreState = {
8680
setDPR: (DPR: number) => void;
8781
setScalingFactor: (scalingFactor: number | null) => void;
8882
setClampExtremes: (clampExtremes: boolean) => void;
89-
setIcechunkOptions: (options: IcechunkStoreOptions | null) => void;
90-
setFetchOptions: (options: FetchStoreOptions | null) => void;
91-
setAbortController: (controller: AbortController | null) => void;
9283
};
9384

9485
export const useGlobalStore = create<StoreState>((set, get) => ({
@@ -107,7 +98,6 @@ export const useGlobalStore = create<StoreState>((set, get) => ({
10798
plotDim: 0,
10899
flipY: false,
109100
initStore: ESDC,
110-
fetchKey: 0,
111101
variable: 'Default',
112102
variables: [],
113103
openVariables: false,
@@ -123,9 +113,6 @@ export const useGlobalStore = create<StoreState>((set, get) => ({
123113
DPR: 1,
124114
scalingFactor: null,
125115
clampExtremes: false,
126-
icechunkOptions: null,
127-
fetchOptions: null,
128-
abortController: null,
129116
// setters
130117

131118
setDataShape: (dataShape) => set({ dataShape }),
@@ -165,7 +152,6 @@ export const useGlobalStore = create<StoreState>((set, get) => ({
165152
setPlotDim: (plotDim) => set({ plotDim }),
166153
setFlipY: (flipY) => set({ flipY }),
167154
setInitStore: (initStore) => set({ initStore }),
168-
bumpFetchKey: () => set(s => ({ fetchKey: s.fetchKey + 1 })),
169155
setVariable: (variable) => set({ variable }),
170156
setVariables: (variables) => set({ variables }),
171157
setOpenVariables: (openVariables) => set({ openVariables }),
@@ -180,7 +166,4 @@ export const useGlobalStore = create<StoreState>((set, get) => ({
180166
setDPR: (DPR) => set({ DPR }),
181167
setScalingFactor: (scalingFactor) => set({ scalingFactor }),
182168
setClampExtremes: (clampExtremes) => set({ clampExtremes }),
183-
setIcechunkOptions: (options) => set({ icechunkOptions: options }),
184-
setFetchOptions: (options) => set({ fetchOptions: options }),
185-
setAbortController: (controller) => set({ abortController: controller }),
186169
}));

src/GlobalStates/ZarrStore.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { create } from "zustand";
22
import { GetStore } from "@/components/zarr/ZarrLoaderLRU";
3+
import { FetchStoreOptions, IcechunkStoreOptions } from "@/components/zarr/Interfaces";
34

45
const ESDC = 'https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr'
56

@@ -18,7 +19,11 @@ type ZarrState = {
1819
coarsen: boolean,
1920
kernelSize: number,
2021
kernelDepth: number,
21-
22+
icechunkOptions: IcechunkStoreOptions | null;
23+
fetchOptions: FetchStoreOptions | null;
24+
abortController: AbortController | null;
25+
fetchKey: number;
26+
2227
setZSlice: (zSlice: [number , number | null]) => void;
2328
setYSlice: (ySlice: [number , number | null]) => void;
2429
setXSlice: (xSlice: [number , number | null]) => void;
@@ -33,6 +38,10 @@ type ZarrState = {
3338
setCoarsen: (coarsen: boolean) => void;
3439
setKernelSize: (kernelSize: number) => void;
3540
setKernelDepth: (kernelDepth: number) => void;
41+
setIcechunkOptions: (options: IcechunkStoreOptions | null) => void;
42+
setFetchOptions: (options: FetchStoreOptions | null) => void;
43+
setAbortController: (controller: AbortController | null) => void;
44+
bumpFetchKey: () => void;
3645
}
3746

3847
export const useZarrStore = create<ZarrState>((set, get) => ({
@@ -50,6 +59,10 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
5059
coarsen: false,
5160
kernelSize: 2,
5261
kernelDepth: 2,
62+
icechunkOptions: null,
63+
fetchOptions: null,
64+
abortController: null,
65+
fetchKey: 0,
5366

5467
setZSlice: (zSlice) => set({ zSlice }),
5568
setYSlice: (ySlice) => set({ ySlice }),
@@ -65,4 +78,8 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
6578
setCoarsen: (coarsen) => set({ coarsen }),
6679
setKernelSize: (kernelSize) => set({ kernelSize }),
6780
setKernelDepth: (kernelDepth) => set({ kernelDepth }),
81+
setIcechunkOptions: (options) => set({ icechunkOptions: options }),
82+
setFetchOptions: (options) => set({ fetchOptions: options }),
83+
setAbortController: (controller) => set({ abortController: controller }),
84+
bumpFetchKey: () => set(s => ({ fetchKey: s.fetchKey + 1 })),
6885
}))

src/components/LandingHome.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ async function sendPing() {
2525

2626
export function LandingHome() {
2727
const {
28-
initStore, fetchKey, timeSeries, variable, plotOn,
28+
initStore, timeSeries, variable, plotOn,
2929
setZMeta, setVariables, setTitleDescription,
3030
} = useGlobalStore(useShallow(state => ({
3131
initStore: state.initStore,
32-
fetchKey: state.fetchKey,
3332
timeSeries: state.timeSeries,
3433
variable: state.variable,
3534
plotOn: state.plotOn,
@@ -38,8 +37,11 @@ export function LandingHome() {
3837
setTitleDescription: state.setTitleDescription,
3938
})))
4039

41-
const { currentStore, setCurrentStore, setZSlice, setYSlice, setXSlice, setUseNC } = useZarrStore(useShallow(state => ({
40+
const { currentStore, fetchKey,
41+
setCurrentStore, setZSlice, setYSlice, setXSlice, setUseNC
42+
} = useZarrStore(useShallow(state => ({
4243
currentStore: state.currentStore,
44+
fetchKey: state.fetchKey,
4345
setCurrentStore: state.setCurrentStore,
4446
setZSlice: state.setZSlice,
4547
setYSlice: state.setYSlice,
@@ -74,16 +76,16 @@ export function LandingHome() {
7476
}
7577
if (initStore.startsWith('local')) return; // local_ set by LocalNetCDF/LocalZarr after load
7678
setUseNC(false)
77-
const { icechunkOptions, fetchOptions } = useGlobalStore.getState();
79+
const { icechunkOptions, fetchOptions } = useZarrStore.getState();
7880
const newStore = GetStore(
7981
initStore,
8082
fetchOptions ?? undefined,
8183
icechunkOptions ?? undefined
8284
);
8385
setCurrentStore(newStore);
8486
// Clear after use
85-
useGlobalStore.getState().setIcechunkOptions(null);
86-
useGlobalStore.getState().setFetchOptions(null);
87+
useZarrStore.getState().setIcechunkOptions(null);
88+
useZarrStore.getState().setFetchOptions(null);
8789
}, [initStore, fetchKey, setCurrentStore])
8890

8991
useEffect(() => {

src/components/ui/MainPanel/RemoteIcechunk.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "@/components/ui/select";
1313
import { ChevronDown, ChevronUp, Plus, Trash2 } from 'lucide-react';
1414
import { useGlobalStore } from '@/GlobalStates/GlobalStore';
15+
import { useZarrStore } from '@/GlobalStates/ZarrStore';
1516

1617
type RefType = 'branch' | 'tag' | 'snapshot';
1718
type HeaderRow = { key: string; value: string };
@@ -120,8 +121,8 @@ const RemoteIcechunk = ({ setInitStore, onOpenDescription }: Props) => {
120121
const builtStorageHeaders = buildHeaders(storageHeaders);
121122
const builtFetchClientHeaders = buildHeaders(fetchClientHeaders);
122123

123-
useGlobalStore.getState().setFetchOptions(null);
124-
useGlobalStore.getState().setIcechunkOptions({
124+
useZarrStore.getState().setFetchOptions(null);
125+
useZarrStore.getState().setIcechunkOptions({
125126
[refType]: refValue,
126127
...(Object.keys(builtStorageHeaders).length > 0 && { headers: builtStorageHeaders }),
127128
...(credentials && { credentials }),
@@ -142,7 +143,7 @@ const RemoteIcechunk = ({ setInitStore, onOpenDescription }: Props) => {
142143
retryDelay,
143144
});
144145
useGlobalStore.getState().setStatus('Fetching...');
145-
useGlobalStore.getState().bumpFetchKey();
146+
useZarrStore.getState().bumpFetchKey();
146147
setInitStore(url);
147148
onOpenDescription();
148149
};

src/components/ui/MainPanel/RemoteZarr.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Input } from '@/components/ui/';
55
import { Button } from '@/components/ui/button-enhanced';
66

77
import { ChevronDown, ChevronUp, Plus, Trash2 } from 'lucide-react';
8+
import { useZarrStore } from '@/GlobalStates/ZarrStore';
89

910
type HeaderRow = { key: string; value: string };
1011
type AuthPreset = 'none' | 'bearer' | 'basic' | 'apikey';
@@ -82,13 +83,13 @@ const RemoteZarr = ({ initStore, setInitStore, onOpenDescription }: Props) => {
8283
...(overrides && { overrides }),
8384
};
8485

85-
useGlobalStore.getState().setIcechunkOptions(null);
86-
useGlobalStore.getState().setFetchOptions(
86+
useZarrStore.getState().setIcechunkOptions(null);
87+
useZarrStore.getState().setFetchOptions(
8788
Object.keys(fetchOptions).length > 0 ? fetchOptions : null
8889
);
8990
useGlobalStore.getState().setStatus('Fetching...');
9091

91-
useGlobalStore.getState().bumpFetchKey();
92+
useZarrStore.getState().bumpFetchKey();
9293
setInitStore(url);
9394
onOpenDescription();
9495
}}

src/components/zarr/icechunk-store.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useGlobalStore } from "@/GlobalStates/GlobalStore";
44
import { useErrorStore, ZarrError } from "@/GlobalStates/ErrorStore";
55
import { IcechunkStore } from "icechunk-js";
66
import type { NodeSnapshot } from "icechunk-js";
7-
import { Repository, HttpStorage } from "icechunk-js";
7+
// import { Repository, HttpStorage } from "icechunk-js";
88
import { ZarrMetadata, ZarrTitleDescription } from "./Interfaces";
99
import { useCacheStore } from "@/GlobalStates/CacheStore";
1010
import { getDtypeSize, calculateTotalElements, calculateChunkCount, formatBytes } from "./utils";
@@ -16,8 +16,6 @@ export async function getIcechunkNodes(store: IcechunkStore): Promise<NodeSnapsh
1616
}
1717
return await (store as any)._cachedNodes;
1818
}
19-
// For testing purposes only.
20-
// https://carbonplan-share.s3.us-west-2.amazonaws.com/zarr-layer-examples/pipeline/multi_level_virtual_hybrid_icechunk.icechunk
2119

2220
export async function getIcechunkStore(
2321
storePath: string,
@@ -36,11 +34,11 @@ export async function getIcechunkStore(
3634
...(options?.snapshot && { snapshot: options.snapshot }),
3735
...(fetchClient && { fetchClient }),
3836
});
39-
console.log(icechunkStore);
40-
const storage = new HttpStorage(storePath);
41-
console.log('Storage initialized:', storage);
42-
const repo = await Repository.open({ storage });
43-
console.log('Repository opened:', repo);
37+
// console.log(icechunkStore);
38+
// const storage = new HttpStorage(storePath);
39+
// console.log('Storage initialized:', storage);
40+
// const repo = await Repository.open({ storage });
41+
// console.log('Repository opened:', repo);
4442
// const branches = await repo.listBranches();
4543
// const tags = await repo.listTags();
4644
// console.log('Branches:', branches);
@@ -73,11 +71,9 @@ export async function getIcechunkMetadata(
7371
const variables: ZarrMetadata[] = [];
7472

7573
const allNodes = await getIcechunkNodes(icechunkStore);
76-
console.log('All icechunk nodes:', allNodes);
7774
const arrayNodes = allNodes.filter(node =>
7875
(node.nodeData as { type: string }).type === 'array'
7976
);
80-
console.log('Array nodes:', arrayNodes);
8177

8278
for (const node of arrayNodes) {
8379
const nodeData = node.nodeData as {
@@ -122,7 +118,6 @@ export async function getIcechunkMetadata(
122118
groupPath,
123119
});
124120
}
125-
console.log('Icechunk variables:', variables);
126121
return variables;
127122
}
128123

@@ -175,7 +170,6 @@ export async function getIcechunkDims(
175170
) {
176171
const { cache } = useCacheStore.getState();
177172
const allNodes = await getIcechunkNodes(group.store as IcechunkStore);
178-
console.log('All icechunk nodes:', allNodes);
179173
const normalizedVariable = variable.startsWith('/') ? variable : `/${variable}`;
180174
const node = allNodes.find(n => n.path === normalizedVariable);
181175
const dimArrays: unknown[] = [];

0 commit comments

Comments
 (0)