@@ -47,6 +47,7 @@ export async function GetArray(storePath: string, variable: string): Promise<Zar
4747 if ( outVar . is ( "number" ) || outVar . is ( "bigint" ) ) {
4848 const chunk = await zarr . get ( outVar )
4949 const typedArray = new Float32Array ( chunk . data ) ;
50+ console . log ( chunk ) ;
5051 // TypeScript will now infer the correct numeric type
5152 return {
5253 data : typedArray ,
@@ -83,6 +84,8 @@ function parseUVCoords({normal,uv}:{normal:THREE.Vector3,uv:THREE.Vector2}){
8384 }
8485}
8586
87+
88+
8689export async function GetTimeSeries ( { TimeSeriesObject} :GetTimeSeries ) {
8790 const { uv, normal, variable, storePath} = TimeSeriesObject
8891 const d_store = zarr . tryWithConsolidated (
@@ -99,6 +102,90 @@ export async function GetTimeSeries({TimeSeriesObject}:GetTimeSeries){
99102 return arr
100103}
101104
105+ interface TimeSeriesInfo {
106+ uv :THREE . Vector2 ,
107+ normal :THREE . Vector3
108+ }
109+
110+ export class ZarrDataset {
111+ private storePath : string ;
112+ private variable : string ;
113+ private cache : { [ key : string ] : any } ;
114+
115+ constructor ( storePath : string ) {
116+ this . storePath = storePath ;
117+ this . variable = "Default" ;
118+ this . cache = { } ;
119+ }
120+
121+ async GetArray ( variable : string ) {
122+ //This checks if variable is stored in cache
123+ this . variable = variable ;
124+ let outVar = null ;
125+ if ( this . cache . hasOwnProperty ( variable ) ) {
126+ console . log ( "Using Cache" )
127+ return this . cache [ variable ]
128+ }
129+ const d_store = zarr . tryWithConsolidated (
130+ new zarr . FetchStore ( this . storePath )
131+ ) ;
132+
133+ const group = await d_store . then ( store => zarr . open ( store , { kind : 'group' } ) )
134+
135+ outVar = await zarr . open ( group . resolve ( variable ) , { kind :"array" } )
136+ // Type check using zarr.Array.is
137+ if ( outVar . is ( "number" ) || outVar . is ( "bigint" ) ) {
138+ const chunk = await zarr . get ( outVar )
139+ const typedArray = new Float32Array ( chunk . data ) ;
140+ this . cache [ variable ] = chunk ;
141+ // TypeScript will now infer the correct numeric type
142+ return {
143+ data : typedArray ,
144+ shape : chunk . shape ,
145+ dtype : outVar . dtype
146+ }
147+ } else {
148+ throw new Error ( `Unsupported data type: Only numeric arrays are supported. Got: ${ outVar . dtype } ` )
149+ }
150+ }
151+
152+ async GetTimeSeries ( TimeSeriesInfo :TimeSeriesInfo ) {
153+ const { uv, normal} = TimeSeriesInfo
154+ if ( ! this . cache [ this . variable ] ) {
155+ return [ 0 ]
156+ }
157+ const { data, shape, stride} = this . cache [ this . variable ]
158+ //This is a complicated logic check but it works bb
159+ const sliceSize = parseUVCoords ( { normal, uv} )
160+
161+ const slice = sliceSize . map ( ( value , index ) =>
162+ value === null || shape [ index ] === null ? null : Math . round ( value * shape [ index ] ) ) ;
163+
164+ const mapDim = slice . indexOf ( null ) ;
165+ const dimStride = stride [ mapDim ] ;
166+ const pz = slice [ 0 ] == null ? 0 : stride [ 0 ] * slice [ 0 ]
167+ const py = slice [ 1 ] == null ? 0 : stride [ 1 ] * slice [ 1 ]
168+ const px = slice [ 2 ] == null ? 0 : stride [ 2 ] * slice [ 2 ]
169+
170+ // console.log(`
171+ // Slice:${slice}
172+ // mapDim:${mapDim}
173+ // dimStride:${dimStride}
174+ // pz:${pz}
175+ // py:${py}
176+ // px:${px}
177+ // `)
178+ const ts = [ ] ;
179+
180+ for ( let i = 0 ; i < shape [ mapDim ] ; i ++ ) {
181+ const idx = i * dimStride + pz + py + px
182+ ts . push ( data [ idx ] )
183+ }
184+ return ts ;
185+ }
186+
187+ }
188+
102189
103190
104191
0 commit comments