-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/coarsen on pressure #87
Conversation
Interpolating cell-centered quantities to the interfaces fails when using a 1-based indexing system for the tiles. We chose this to more closely align FV3s file naming conventions, but I think we should revert to 0-based indexing everywhere.
I did a little digging -- it's indeed a subtle issue. The root cause is the following pattern in
Note that stacking and unstacking leads to the addition of dummy coordinates to the previously unlabeled
If we have a reference dataset that has labeled Details
The upshot is, we should probably restore the horizontal coordinates on |
Thanks for looking into this Spencer. Indeed a subtle issue, nice job tracking it down! This would have been introduced when I switched f_out to be initialized from p_out instead of f_in. I’ll take a look at your suggestion and work on implementing today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @oliverwm1; I'm pleased with where this is now. Thanks for all the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good, but it seems like there is a too much code for dealing with metadata and coordinate info. I think it would be cleaner to assume all the restart data is one Dataset
with corrected metadata as returned by open_restarts
. Then this PR would introduce a single function
def coarse_grain_on_pressure(restart_data: xr.Dataset) -> xr.Dataset:
...
I am working on another PR #97, which will make it easier to use the dimension renaming code on it's own. Finally, we would need to add a function to write the single combined restart Dataset to the separate files, but that shouldn't be too hard.
I think I've addressed all your comments, @nbren12. I went back to not outputting a vertical coordinate when calculating pressure or height on layer interfaces, which reduces some of the dimension/coordinate complications. I agree the code would be simpler if we could assume all the restart data is in one xarray Dataset, but I think it is outside of the scope of this PR to build out that framework. For this PR, I took the approach of replicating the current model-level methods for coarsening, which operate separately-ish on each "restart category" (coarsening fv_tracer does depend on fv_core). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to merge, but I think we should open an issue to make this code work on the combined restart data (as returned by open_restarts). I think this will make it easier to implement with dataflow.
cc @frodre
Sounds good, I made an issue. |
) In the original implementation (#87), the default method for coarse-graining 3D fields in the restart files was to first vertically remap them to a common set of pressure levels within a coarse grid cell, and then take a masked-mass-weighted average (masking is to take into account the fact that some fine-grid cells do not have air at pressures we are interpolating to, so we ignore them in averaging). Here the masked mass was computed as the product of the masked fine-grid cell area and the original fine-grid cell pressure thickness. In reality though, since we have interpolated the fine-grid fields to constant pressure surfaces, for the pressure thickness we should use the updated pressure thickness field (i.e. "delp_coarse_on_fine"), or better yet, no pressure thickness at all, since it will be constant within a coarse grid box and so will not contribute anything meaningful to the weighting. This PR addresses this by switching to using just the masked area as weights when pressure-level coarse-graining restart files.
Introduces functions to coarsen restart files on constant pressure surfaces, as well as compute layer thicknesses assuming hydrostatic balance and a consistent surface height.