Skip to content

Fix blocky effect#29

Merged
SarahAlidoost merged 17 commits intomainfrom
fix_blocky_effect
Mar 17, 2026
Merged

Fix blocky effect#29
SarahAlidoost merged 17 commits intomainfrom
fix_blocky_effect

Conversation

@SarahAlidoost
Copy link
Member

@SarahAlidoost SarahAlidoost commented Mar 2, 2026

closes #17

This PR adds :

This PR fixes main things as:

  • a bug in the optimization loop in the notebook, how loss is calculated
  • a bug in the optimization loop in the notebook, how land mask is applying
  • a bug in reshaping arrays inside the model
  • a bug in the notebook in inference (prediction cell).

This PR also improves:

  • the spatial refinemnet
  • the dataset class to cover the whole input data
  • disable overlapping data batches created by dataset because it affects the loss

Results:
Note: As can be seen in the final plots, there is not spatial artifacts. I also run the notebook on residuals in this branch. The results also are without artifacts.

Note: The notebooks in this PR can be run on local systems. If the input size or data patch size are changed, the model patch size and overlap should be adjusted accordingly.

@SarahAlidoost SarahAlidoost marked this pull request as ready for review March 6, 2026 09:18
@SarahAlidoost
Copy link
Member Author

@meiertgrootes please also see the top comment when reviewing.

overlap=1,
max_H=1024,
max_W=1024,
max_H=256,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Moving to lat,lon based encoding this would be less relevant, but how does this match to the total grid size given theglobal input data?

Copy link
Member Author

Choose a reason for hiding this comment

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

Here the max_H and max_W in SpatialPositionalEncoding2D is the maximum number of patches in the height and width directions. For example, if the image is 1024×1024 pixels with a patch size of (1, 4, 4), we have 256 patches in H and W. The max_H and max_W arguments can be changed by users if needed. However, about global data, we don't usually give the large image to the model, but we subset it and embed the subsets in the batch dimensions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, thanks. So max_H, max_W are basically the total input dimensions quantised by the patch size. That is fine, of course, and I also understand that we aren't passing the full global image in one go. My point was, that as it stands, the 2d positional encodings are pre-calculated on the basis of these sizes, i.e. the sine and cosine values derive from the max_H and max_W values. Should one change input dimensions/resolution this may be a challenge to generalisation. Other approaches also have their own difficulties, this is just sth. to remain aware of.

Copy link
Collaborator

@meiertgrootes meiertgrootes left a comment

Choose a reason for hiding this comment

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

The batch handling look a lot cleaner and the carry over og lat long information will elp with global spatial embedding. This may make the chocie of max size (see comment) less critical.

@SarahAlidoost SarahAlidoost merged commit efa26c4 into main Mar 17, 2026
4 checks passed
@SarahAlidoost SarahAlidoost deleted the fix_blocky_effect branch March 17, 2026 12:41
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.

Understand origin of repetitive spatial patterns in predicted data.

2 participants