Skip to content

Commit 8b38b12

Browse files
authored
Merge pull request #534 from EarthyScience/jp/coarsen
Coarsen Datasets
2 parents f387d5b + 94cba94 commit 8b38b12

File tree

11 files changed

+333
-172
lines changed

11 files changed

+333
-172
lines changed

src/GlobalStates/PlotStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ type PlotState ={
5555
useOrtho: boolean;
5656
rotateFlat: boolean;
5757
fillValue: number | undefined,
58+
coarsen: boolean, //Seperate from zarr store so dependencies don't update when changing coarsen in a menu
59+
kernel:{kernelSize:number, kernelDepth:number}
5860

5961
setQuality: (quality: number) => void;
6062
setTimeScale: (timeScale : number) =>void;
@@ -165,6 +167,8 @@ export const usePlotStore = create<PlotState>((set, get) => ({
165167
useOrtho: false,
166168
rotateFlat: false,
167169
fillValue: undefined,
170+
coarsen: false,
171+
kernel:{kernelDepth:1, kernelSize:1},
168172

169173
setVTransferRange: (vTransferRange) => set({ vTransferRange }),
170174
setVTransferScale: (vTransferScale) => set({ vTransferScale }),

src/GlobalStates/ZarrStore.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type ZarrState = {
1515
useNC: boolean, // This one is more static and so toggling switch doesn't break all other logic
1616
fetchNC: boolean,
1717
ncModule: any,
18+
coarsen: boolean,
19+
kernelSize: number,
20+
kernelDepth: number,
1821

1922
setZSlice: (zSlice: [number , number | null]) => void;
2023
setYSlice: (ySlice: [number , number | null]) => void;
@@ -27,6 +30,9 @@ type ZarrState = {
2730
setArraySize: (arraySize: number) => void;
2831
setUseNC: (useNC: boolean) => void;
2932
setFetchNC: (fetchNC: boolean) => void;
33+
setCoarsen: (coarsen: boolean) => void;
34+
setKernelSize: (kernelSize: number) => void;
35+
setKernelDepth: (kernelDepth: number) => void;
3036
}
3137

3238
export const useZarrStore = create<ZarrState>((set, get) => ({
@@ -41,6 +47,9 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
4147
useNC: false,
4248
fetchNC: false,
4349
ncModule: null,
50+
coarsen: false,
51+
kernelSize: 2,
52+
kernelDepth: 2,
4453

4554
setZSlice: (zSlice) => set({ zSlice }),
4655
setYSlice: (ySlice) => set({ ySlice }),
@@ -53,4 +62,7 @@ export const useZarrStore = create<ZarrState>((set, get) => ({
5362
setArraySize: (arraySize) => set({ arraySize }),
5463
setUseNC: (useNC) => set({ useNC }),
5564
setFetchNC: (fetchNC) => set({ fetchNC }),
65+
setCoarsen: (coarsen) => set({ coarsen }),
66+
setKernelSize: (kernelSize) => set({ kernelSize }),
67+
setKernelDepth: (kernelDepth) => set({ kernelDepth }),
5668
}))

src/components/plots/AxisLines.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"use client";
22

3-
import { useAnalysisStore, useGlobalStore, useImageExportStore, usePlotStore } from '@/GlobalStates'
3+
import { useAnalysisStore, useGlobalStore, useImageExportStore, usePlotStore, useZarrStore } from '@/GlobalStates'
44
import React, {useState, useMemo} from 'react'
55
import { useShallow } from 'zustand/shallow'
66
import { Text } from '@react-three/drei'
77
import { LineSegmentsGeometry } from 'three/addons/lines/LineSegmentsGeometry.js';
88
import { LineSegments2 } from 'three/addons/lines/LineSegments2.js';
99
import { LineMaterial } from 'three-stdlib';
1010
import { useFrame } from '@react-three/fiber';
11-
import { parseLoc } from '@/utils/HelperFuncs';
11+
import { parseLoc, coarsenFlatArray } from '@/utils/HelperFuncs';
1212
import { useCSSVariable } from '../ui';
1313
import * as THREE from 'three'
1414

@@ -37,32 +37,33 @@ const CubeAxis = ({flipX, flipY, flipDown}: {flipX: boolean, flipY: boolean, fli
3737
is4D: state.is4D
3838
})))
3939

40-
const {xRange, yRange, zRange, plotType, timeScale, animProg, zSlice, ySlice, xSlice} = usePlotStore(useShallow(state => ({
40+
const {xRange, yRange, zRange, plotType, timeScale, animProg, zSlice, ySlice, xSlice, coarsen} = usePlotStore(useShallow(state => ({
4141
xRange: state.xRange, yRange: state.yRange,
4242
zRange: state.zRange, plotType: state.plotType,
4343
timeScale: state.timeScale, animProg: state.animProg,
4444
zSlice: state.zSlice, ySlice: state.ySlice,
45-
xSlice: state.xSlice,
45+
xSlice: state.xSlice, coarsen: state.coarsen,
4646
})))
47-
4847
const {hideAxis, hideAxisControls} = useImageExportStore(useShallow( state => ({
4948
hideAxis: state.hideAxis,
5049
hideAxisControls: state.hideAxisControls
5150
})))
5251

5352
const shapeLength = dimArrays.length
5453

55-
const dimLengths = [
56-
(zSlice[1] ? zSlice[1] : dimArrays[shapeLength - 3].length) - zSlice[0],
57-
(ySlice[1] ? ySlice[1] : dimArrays[shapeLength - 2].length) - ySlice[0],
58-
(xSlice[1] ? xSlice[1] : dimArrays[shapeLength - 1].length) - xSlice[0],
59-
]
60-
61-
const dimSlices = [
62-
dimArrays[shapeLength-3].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
63-
revY ? dimArrays[shapeLength-2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined).reverse() : dimArrays[shapeLength-2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
64-
dimArrays[shapeLength-1].slice(xSlice[0], xSlice[1] ? xSlice[1] : undefined),
65-
]
54+
const dimSlices = useMemo(()=> {
55+
let slices = [
56+
dimArrays[shapeLength-3].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
57+
revY ? dimArrays[shapeLength-2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined).reverse() : dimArrays[shapeLength-2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
58+
dimArrays[shapeLength-1].slice(xSlice[0], xSlice[1] ? xSlice[1] : undefined),
59+
]
60+
if (coarsen) {
61+
const {kernelDepth, kernelSize} = useZarrStore.getState()
62+
slices = slices.map((val, idx) => coarsenFlatArray(val, (idx === 0 ? kernelDepth : kernelSize)))
63+
}
64+
return slices
65+
},[revY, dimArrays, zSlice, ySlice, xSlice, coarsen])
66+
const dimLengths = dimSlices.map(val => val.length)
6667

6768
const [xResolution, setXResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)
6869
const [yResolution, setYResolution] = useState<number>(AXIS_CONSTANTS.INITIAL_RESOLUTION)

src/components/plots/FlatMap.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import React, {useMemo, useEffect, useRef, useState} from 'react'
44
import * as THREE from 'three'
5-
import { useAnalysisStore, useGlobalStore, usePlotStore } from '@/GlobalStates'
5+
import { useAnalysisStore, useGlobalStore, usePlotStore, useZarrStore } from '@/GlobalStates'
66
import { vertShader } from '@/components/computation/shaders'
77
import { flatFrag3D, fragmentFlat } from '../textures/shaders';
88
import { useShallow } from 'zustand/shallow'
99
import { ThreeEvent } from '@react-three/fiber';
10-
import { GetCurrentArray, GetTimeSeries, parseUVCoords } from '@/utils/HelperFuncs';
10+
import { coarsenFlatArray, GetCurrentArray, GetTimeSeries, parseUVCoords } from '@/utils/HelperFuncs';
1111
import { evaluate_cmap } from 'js-colormaps-es';
1212

1313
interface InfoSettersProps{
@@ -39,14 +39,14 @@ const FlatMap = ({textures, infoSetters} : {textures : THREE.DataTexture | THREE
3939
})))
4040

4141
const {cScale, cOffset, animProg, nanTransparency, nanColor,
42-
zSlice, ySlice, xSlice, selectTS,
42+
zSlice, ySlice, xSlice, selectTS, coarsen,
4343
getColorIdx, incrementColorIdx} = usePlotStore(useShallow(state => ({
4444
cOffset: state.cOffset, cScale: state.cScale,
4545
resetAnim: state.resetAnim, animate: state.animate,
4646
animProg: state.animProg, nanTransparency: state.nanTransparency,
4747
nanColor: state.nanColor, zSlice: state.zSlice,
4848
ySlice: state.ySlice, xSlice: state.xSlice,
49-
selectTS: state.selectTS,
49+
selectTS: state.selectTS, coarsen: state.coarsen,
5050
getColorIdx: state.getColorIdx,
5151
incrementColorIdx: state.incrementColorIdx
5252
})))
@@ -55,20 +55,27 @@ const FlatMap = ({textures, infoSetters} : {textures : THREE.DataTexture | THREE
5555
analysisMode: state.analysisMode,
5656
analysisArray: state.analysisArray
5757
})))
58+
const {kernelSize, kernelDepth} = useZarrStore(useShallow(state => ({
59+
kernelSize: state.kernelSize,
60+
kernelDepth: state.kernelDepth
61+
})))
5862

5963
const shapeLength = dimArrays.length
60-
const is4D = shapeLength === 4
61-
62-
const dimSlices = isFlat
63-
? [
64-
dimArrays[0].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
65-
dimArrays[1].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
66-
]
67-
: [
68-
dimArrays[shapeLength - 3].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
69-
dimArrays[shapeLength - 2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
70-
dimArrays[shapeLength - 1].slice(xSlice[0], xSlice[1] ? xSlice[1] : undefined )
71-
]
64+
65+
const dimSlices = useMemo (() => {
66+
let slices = isFlat
67+
? [
68+
dimArrays[0].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
69+
dimArrays[1].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
70+
]
71+
: [
72+
dimArrays[shapeLength - 3].slice(zSlice[0], zSlice[1] ? zSlice[1] : undefined),
73+
dimArrays[shapeLength - 2].slice(ySlice[0], ySlice[1] ? ySlice[1] : undefined),
74+
dimArrays[shapeLength - 1].slice(xSlice[0], xSlice[1] ? xSlice[1] : undefined )
75+
]
76+
if (coarsen) slices = slices.map((val, idx) => coarsenFlatArray(val, (idx === 0 ? kernelDepth : kernelSize)))
77+
return slices
78+
} ,[dimArrays, zSlice, ySlice, xSlice, coarsen])
7279

7380
const shapeRatio = useMemo(()=> {
7481
if (dataShape.length == 2){

src/components/plots/Plot.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Navbar, Colorbar, ExportExtent } from '../ui';
1111
import AnalysisInfo from './AnalysisInfo';
1212
import { OrbitControls as OrbitControlsImpl } from 'three-stdlib';
1313
import AnalysisWG from './AnalysisWG';
14-
import { ParseExtent, GetDimInfo } from '@/utils/HelperFuncs';
14+
import { ParseExtent, GetDimInfo, coarsenFlatArray } from '@/utils/HelperFuncs';
1515
import ExportCanvas from '@/utils/ExportCanvas';
1616
import KeyFrames from '../ui/KeyFrames';
1717

@@ -164,11 +164,14 @@ const Plot = () => {
164164
setPlotType: state.setPlotType
165165
})))
166166

167-
const {zSlice, ySlice, xSlice, reFetch} = useZarrStore(useShallow(state=> ({
167+
const {zSlice, ySlice, xSlice, reFetch, coarsen, kernelDepth, kernelSize} = useZarrStore(useShallow(state=> ({
168168
zSlice: state.zSlice,
169169
ySlice: state.ySlice,
170170
xSlice: state.xSlice,
171-
reFetch: state.reFetch
171+
reFetch: state.reFetch,
172+
coarsen: state.coarsen,
173+
kernelDepth: state.kernelDepth,
174+
kernelSize: state.kernelSize
172175
})))
173176
const {analysisMode} = useAnalysisStore(useShallow(state => ({
174177
analysisMode: state.analysisMode
@@ -182,7 +185,8 @@ const Plot = () => {
182185
const [textures, setTextures] = useState<THREE.DataTexture[] | THREE.Data3DTexture[] | null>(null)
183186
const [show, setShow] = useState<boolean>(true) //Prevents rendering of 3D objects until data is fully loaded in
184187
const [stableMetadata, setStableMetadata] = useState<Record<string, any>>({});
185-
//DATA LOADING
188+
189+
//DATA LOADING
186190
useEffect(() => {
187191
if (variable != "Default") {
188192
setShow(false)
@@ -234,10 +238,11 @@ const Plot = () => {
234238
})
235239
GetDimInfo(variable).then((arrays)=>{
236240
let {dimArrays, dimUnits, dimNames}= arrays;
241+
237242
if (is4D){
238-
dimArrays = dimArrays.slice();
239-
dimUnits = dimUnits.slice();
240-
dimNames = dimNames.slice();
243+
dimArrays = dimArrays.slice(1);
244+
dimUnits = dimUnits.slice(1);
245+
dimNames = dimNames.slice(1);
241246
}
242247
setDimNames(dimNames)
243248
setDimArrays(dimArrays)

src/components/ui/MainPanel/AnalysisOptions.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {KernelVisualizer} from "@/components/ui";
1313
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
1414
import { BsFillQuestionCircleFill } from "react-icons/bs";
1515
import { Switch } from '../switch';
16+
import { HandleKernelNums } from '@/utils/HelperFuncs';
1617
import {
1718
Select,
1819
SelectContent,
@@ -181,16 +182,6 @@ const AnalysisOptions = () => {
181182
return () => window.removeEventListener("resize", handleResize);
182183
}, []);
183184

184-
function HandleKernelNums(e: string){
185-
const newVal = parseInt(e);
186-
if (newVal % 2 == 0){
187-
return Math.max(1, newVal - 1)
188-
}
189-
else{
190-
return newVal
191-
}
192-
}
193-
194185
return (
195186
<>
196187
<Popover>

0 commit comments

Comments
 (0)