Skip to content

Add density-dependent interpolation of BGC tracers to ROMS-Tools BC and IC#607

Open
kthyng wants to merge 3 commits into
CWorthy-ocean:mainfrom
kthyng:claude/busy-cohen-128fd6
Open

Add density-dependent interpolation of BGC tracers to ROMS-Tools BC and IC#607
kthyng wants to merge 3 commits into
CWorthy-ocean:mainfrom
kthyng:claude/busy-cohen-128fd6

Conversation

@kthyng

@kthyng kthyng commented May 19, 2026

Copy link
Copy Markdown
Contributor

Used UCLA matlab script to start (Add_bgc2ini.m). That code uses nearest neighbor to interpolate in the water column within grid cells, and uses the same for extrapolation. This code uses linear interpolation to interpolate and nearest neighbor to extrapolate.

The interpolation methods give similar results in some areas and different results in others. Here is an example boundary from the end to end notebook domain (Gulf of Mexico eastern boundary), depth-based interpolation:
image

and density-based interpolation — note the sudden change in behavior midway through the transect:
image

Example profile from eta_rho=10 where they look similar in the boundary slice images. The reasonable density profile leads to a reasonable resulting alkalinity.
image

Example profile from eta_rho=29 where they do not look similar in the boundary slice images. The uniform density profile leads to a strange resulting alkalinity.
image

https://cworthy.atlassian.net/browse/CSD-869

  • Tests added
  • Passes pre-commit run --all-files
  • Changes are documented in docs/releases.md
  • New functionality has documentation

Kristen Thyng added 2 commits May 15, 2026 09:50
* Density-space vertical interpolation for BGC tracers in `InitialConditions` and `BoundaryForcing` via new `use_density_interpolation` parameter (default `True`). For `BoundaryForcing`, pass the physics `BoundaryForcing` as `physics_forcing=` to activate.
* updated notebooks
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@kthyng kthyng requested a review from blsaenz May 19, 2026 21:46
@kthyng

kthyng commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

I set this to be the new default — not sure if that is the desired behavior. I had to update some of the test data accordingly.

mostly to deal with unchunking in the vertical dimension so xgcm does not break there
@kthyng

kthyng commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

@blsaenz I know you're out this week but when you get a chance can you let me know if you think someone else should instead or also be a reviewer?

@blsaenz

blsaenz commented May 20, 2026

Copy link
Copy Markdown
Contributor

Looking now!

Comment thread roms_tools/setup/utils.py
source_depth_coords=phys_depth_coord,
target_depth_coords=bgc_depth_coord,
)
source_density = transpose_dimensions(source_density)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am curious about these array transpose calls. Looking at the dask dashboard I saw the transpose is 90% of the processing for the roms-tools tidal preparation. I wonder if we could avoid this somehow. I think if it works I'm happy to approve as is, but it would be good to know how we got into the situation of needing to transpose dimensions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From using xgcm in the past (xgcm does the vertical interpolation here), I remember always having to transpose afterward back into time x depth x lat/lon proper order, but I can experiment a bit and see if I can avoid it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have just been running this and looking at the dask graph and profile and I am not seeing transpose being a lot of the processing for the example I am running. For the example you are trying it with, do you see a big difference for the density-based interpolation compared to the depth-based interpolation?

As a side note, as I am trying another thing, I do see transpose being a lot of the initial call for the BGC boundary forcing with 2D fill on (it is not present with 1D fill), but I don't think the actual interpolation happens until the save function is called subsequently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And I don't think I can avoid needing the transpose after using xgcm.

@blsaenz

blsaenz commented May 20, 2026

Copy link
Copy Markdown
Contributor

I am a bit confused by the plots. The density-based one seem invalid for a slice with the sharp changes? Does that mean we have extreme density differences in adjacent cells also? I can see some differences near the surface which is where I expected the major changes, but it seems like something is off, maybe in the lateral fill? Can we try with 2D interpolation on for fill?

@kthyng

kthyng commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

I am a bit confused by the plots. The density-based one seem invalid for a slice with the sharp changes? Does that mean we have extreme density differences in adjacent cells also? I can see some differences near the surface which is where I expected the major changes, but it seems like something is off, maybe in the lateral fill? Can we try with 2D interpolation on for fill?

I can try to 2D fill and compare to see if that changes anything, but I think the interpolation is valid — it just gives weird results when the density is mostly uniform. Here are the density vs Alk at the same weird location:
image

So the alkalinity is being interpolated from the blue x densities to the orange circle densities, but since the orange circles have almost entirely the same density, they get the same alkalinity which is calculated using the x values in the plot. Does that make sense? There may be a better plot to show to illustrate this.

@blsaenz

blsaenz commented May 20, 2026 via email

Copy link
Copy Markdown
Contributor

@kthyng

kthyng commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

Ok actually with 2D fill this boundary plot does look different right in the area that I was showing my test case from (eta_rho=29):
image

So I will investigate further on how this relates.

@blsaenz

blsaenz commented May 20, 2026

Copy link
Copy Markdown
Contributor

Now that I see the results I can't believe the UCLA's version could give good results either, interpolating alkalinity or other BGC values directly against density. Is UCLA somehow normalizing the density (source and target), so that the whole profile is always mapped? Perhaps we should try something like that?

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.

2 participants