Skip to content

Netcdf chunked grab fix#595

Merged
TheJeran merged 3 commits intomainfrom
jp/nc_chunk_fix
Mar 18, 2026
Merged

Netcdf chunked grab fix#595
TheJeran merged 3 commits intomainfrom
jp/nc_chunk_fix

Conversation

@TheJeran
Copy link
Copy Markdown
Collaborator

@TheJeran TheJeran commented Mar 18, 2026

Thankfully this was an easy solve but a difficult debug situation.

Unfortunately Chunk2Array() was completely vibe coded. I didn't have the mental fortitude to decipher how to distribute chunk data into the main array. So while I understand what the function is doing I wasn't intimately familiar with the inputs. I thought the chunkShape input was to be the shape of the current chunk being sent to the array. Edge chunks are often smaller than the defined chunkshape.

Actually the function just wanted the globally defined chunkshape. And I never noticed that this was the value I was saving to cache. Which is why when I loaded the cached data it was being placed correctly.

Closes #594

I also had some weird issues with small values and rescaling. I decided to forego additional rescaling if the next chunk is smaller than the previous AFTER scaling. Since the initial scaling would stretch the variance out, additional scaling is probably unnecessary.

I also fixed that the colorbar didn't apply scalingFactor on first render.

Lastly, I noticed the dates for the slices were off by a month. After some debugging and reading, I learned that the Month field in the javascript Datetime constructor is zero-indexed. Whereas Day and Year are not. Odd.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses several issues related to netCDF data handling, including chunk data distribution, rescaling logic, colorbar scaling, and date handling. The changes improve the accuracy and efficiency of data processing and rendering.

Highlights

  • Chunk Data Distribution: Corrected the Chunk2Array() function to properly distribute chunk data into the main array by using the globally defined chunkshape.
  • Rescaling Logic: Improved rescaling logic to forego additional rescaling if the next chunk is smaller than the previous after scaling.
  • Colorbar Scaling: Fixed an issue where the colorbar didn't apply scalingFactor on the first render.
  • Date Handling: Corrected date calculations by adjusting the Month field in the JavaScript Datetime constructor to account for zero-indexing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several important fixes, including a correction to chunk handling in NetCDF data processing, improved data rescaling logic, and a fix for date parsing. The changes appear to correctly address the issues described.

My review includes a few suggestions:

  • In Colorbar.tsx, I've recommended a minor refactoring to improve code consistency and readability when applying the scaling factor.
  • I've pointed out a potential inconsistency in the data rescaling logic between NCGetters.ts and ZarrGetters.ts. Aligning this logic would ensure consistent behavior across different data sources.

Overall, these are valuable improvements to the application's data handling capabilities.

Comment on lines +223 to 235
if (newScalingFactor != null
&& newScalingFactor != scalingFactor){ // If the scalingFactor has changed, need to rescale main array. Not worried about shrinking values at the moment.
const thisScaling = scalingFactor ? newScalingFactor - scalingFactor : newScalingFactor
RescaleArray(typedArray, thisScaling)
scalingFactor = newScalingFactor
for (const id of rescaleIDs){ // Set new scalingFactor on the chunks
const tempName = `${cacheBase}_chunk_${id}`
const tempChunk = cache.get(tempName)
tempChunk.scaling = scalingFactor
RescaleArray(tempChunk.data, thisScaling)
cache.set(tempName, tempChunk)
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This logic for rescaling has been changed to execute whenever newScalingFactor is different from scalingFactor. However, the corresponding logic in src/components/zarr/ZarrGetters.ts (lines 310-323) still retains the condition if (scalingFactor == null || newScalingFactor > scalingFactor). This inconsistency could lead to different scaling behaviors for NetCDF and Zarr sources. To ensure consistent behavior, the scaling logic should be unified for both data source types. Was this change intended to be applied to Zarr sources as well?

Comment thread src/components/ui/Colorbar.tsx Outdated
Comment thread src/components/ui/Colorbar.tsx Outdated
@TheJeran TheJeran merged commit b7fb2db into main Mar 18, 2026
6 checks passed
@TheJeran TheJeran deleted the jp/nc_chunk_fix branch March 18, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NetCDF chunks just seem broken

1 participant