Skip to content

Commit b7fb2db

Browse files
authored
Merge pull request #595 from EarthyScience/jp/nc_chunk_fix
Netcdf chunked grab fix
2 parents 1953bae + 181ffac commit b7fb2db

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

src/components/ui/Colorbar.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ const Colorbar = ({units, metadata, valueScales} : {units: string, metadata: Rec
7676
origMax: valueScales.maxVal
7777
}),[valueScales])
7878
const range = origMax - origMin
79-
const zeroPoint = (0 - origMin) / range; // Used to account for shifting values
79+
8080
const [tickCount, setTickCount] = useState<number>(5)
8181
const [newMin, setNewMin] = useState(origMin)
8282
const [newMax, setNewMax] = useState(origMax)
83-
const [displayMin, setDisplayMin] = useState(Num2String(origMin))
84-
const [displayMax, setDisplayMax] = useState(Num2String(origMax))
83+
const [displayMin, setDisplayMin] = useState(Num2String(origMin*Math.pow(10, scalingFactor??0)))
84+
const [displayMax, setDisplayMax] = useState(Num2String(origMax*Math.pow(10, scalingFactor??0)))
8585
const prevVals = useRef<{ min: number | null; max: number | null }>({ min: null, max: null });
86-
86+
8787
const colors = useMemo(()=>{
8888
const sourceData = colormap.source.data;
8989
if (!sourceData || !sourceData.data) {
@@ -162,11 +162,11 @@ const Colorbar = ({units, metadata, valueScales} : {units: string, metadata: Rec
162162
},[newMin, newMax])
163163

164164
useEffect(()=>{ // Update internal vals when global vals change
165-
setDisplayMin(Num2String(origMin))
166-
setDisplayMax(Num2String(origMax))
165+
setDisplayMin(Num2String(origMin*Math.pow(10, scalingFactor??0)))
166+
setDisplayMax(Num2String(origMax*Math.pow(10, scalingFactor??0)))
167167
setNewMin(origMin)
168168
setNewMax(origMax)
169-
},[origMax, origMin])
169+
},[origMax, origMin, scalingFactor])
170170

171171
useEffect(() => {
172172
if (canvasRef.current) {
@@ -181,7 +181,6 @@ const Colorbar = ({units, metadata, valueScales} : {units: string, metadata: Rec
181181
}
182182
}, [colors]);
183183
const analysisString = useMemo(()=>{
184-
185184
if (analysisMode){
186185
const twoVar = variable2 != "Default";
187186
const thisOperation = (operation === "Convolution") ? kernelOperation : operation
@@ -192,6 +191,7 @@ const Colorbar = ({units, metadata, valueScales} : {units: string, metadata: Rec
192191
return `[${units}]`
193192
}
194193
},[analysisMode, execute])
194+
195195
return (
196196
<>
197197
<div className='colorbar' >

src/components/zarr/NCGetters.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export async function GetNCArray(variable: string){
167167
const getStartsAndCounts = () => {
168168
const starts = new Array(rank).fill(0);
169169
const counts = new Array(rank).fill(1);
170-
if (rank > 3) { //When rank is 4 or 5. The first will always be depth. In the case of 5 that will only be if last dimension is vector variable
170+
if (rank > 3) { //When rank is 4 or 5. The first will always be depth. In the case of 5 that will only be if last dimension is vector variable. This case not handled yet
171171
starts[0] = idx4D;
172172
counts[0] = 1;
173173
}
@@ -220,23 +220,22 @@ export async function GetNCArray(variable: string){
220220
chunkF16 = coarsen3DArray(chunkF16, chunkShape, chunkStride as [number, number, number], kernelSize, kernelDepth, newSize)
221221
chunkStride = calculateStrides(thisShape)
222222
}
223-
if (newScalingFactor != null && newScalingFactor != scalingFactor){ // If the scalingFactor has changed, need to rescale main array
224-
if (scalingFactor == null || newScalingFactor > scalingFactor){
225-
const thisScaling = scalingFactor ? newScalingFactor - scalingFactor : newScalingFactor
226-
RescaleArray(typedArray, thisScaling)
227-
scalingFactor = newScalingFactor
228-
for (const id of rescaleIDs){ // Set new scalingFactor on the chunks
229-
const tempName = `${cacheBase}_chunk_${id}`
230-
const tempChunk = cache.get(tempName)
231-
tempChunk.scaling = scalingFactor
232-
RescaleArray(tempChunk.data, thisScaling)
233-
cache.set(tempName, tempChunk)
234-
}
223+
if (newScalingFactor != null
224+
&& newScalingFactor != scalingFactor){ // If the scalingFactor has changed, need to rescale main array. Not worried about shrinking values at the moment.
225+
const thisScaling = scalingFactor ? newScalingFactor - scalingFactor : newScalingFactor
226+
RescaleArray(typedArray, thisScaling)
227+
scalingFactor = newScalingFactor
228+
for (const id of rescaleIDs){ // Set new scalingFactor on the chunks
229+
const tempName = `${cacheBase}_chunk_${id}`
230+
const tempChunk = cache.get(tempName)
231+
tempChunk.scaling = scalingFactor
232+
RescaleArray(tempChunk.data, thisScaling)
233+
cache.set(tempName, tempChunk)
235234
}
236235
}
237236
if (hasZ)copyChunkToArray(
238237
chunkF16,
239-
thisShape,
238+
chunkShape,
240239
chunkStride as [number, number, number],
241240
typedArray,
242241
outputShape,
@@ -246,7 +245,7 @@ export async function GetNCArray(variable: string){
246245
)
247246
else copyChunkToArray2D(
248247
chunkF16,
249-
thisShape,
248+
chunkShape,
250249
chunkStride as [number, number],
251250
typedArray,
252251
outputShape,

src/components/zarr/ZarrLoaderLRU.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export function ToFloat16(array : Float32Array, scalingFactor: number | null) :
3232
const additionalScaling = Math.ceil(Math.log10(maxVal/65504))
3333
const needsRescale =
3434
additionalScaling > 0 ||
35-
additionalScaling <= -6 ||
36-
(scalingFactor && scalingFactor <= -6 && additionalScaling < 0)
35+
additionalScaling <= -6
36+
//I think this is complicating things. Because if it was already scaled then there should already by enough variance in the data it doesn't need to go further
37+
// (scalingFactor && scalingFactor <= -6 && additionalScaling < 0)
3738
const newScalingFactor = needsRescale ?
3839
additionalScaling + initialScale :
3940
initialScale
@@ -43,7 +44,7 @@ export function ToFloat16(array : Float32Array, scalingFactor: number | null) :
4344
for (let i = 0; i < array.length; i++) {
4445
newArray[i] = array[i] * multiplier;
4546
}
46-
return [newArray, newScalingFactor]
47+
return [newArray, newScalingFactor != 0 ? newScalingFactor : null]
4748
}
4849

4950
export function testToFloat16(){
@@ -67,8 +68,9 @@ export function testToFloat16(){
6768

6869

6970
export function RescaleArray(array: Float16Array, scalingFactor: number){ // Rescales built array when new chunk has higher scalingFactor
71+
const multipler = 1/Math.pow(10,scalingFactor)
7072
for (let i = 0; i < array.length; i++) {
71-
array[i] /= Math.pow(10,scalingFactor);
73+
array[i] *= multipler;
7274
}
7375
}
7476

src/utils/HelperFuncs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export function parseTimeUnit(units: string | undefined): [number, number] {
5858
let baseDate;
5959
if (referenceDate.length <= 10){
6060
const [year, month, day] = referenceDate.split('-');
61-
baseDate = new Date(Date.UTC(parseInt(year),parseInt(month),parseInt(day)))
61+
baseDate = new Date(Date.UTC(parseInt(year),parseInt(month)-1,parseInt(day)))
6262
} else {
6363
baseDate = referenceDate ? new Date(referenceDate) : new Date();
6464
}

0 commit comments

Comments
 (0)