-
Notifications
You must be signed in to change notification settings - Fork 20
Optionally produce coeffs_reconstruct stream for MPAS-O, link coeffs file from database for Omega #448
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
Open
cbegeman
wants to merge
6
commits into
E3SM-Project:main
Choose a base branch
from
cbegeman:ocn/add-optional-coeffs-reconstruct-output
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Optionally produce coeffs_reconstruct stream for MPAS-O, link coeffs file from database for Omega #448
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8581703
Use config option to determine whether to add coeffs_reconstruct to t…
cbegeman 771813c
Remove later: test write coeffs
cbegeman f8e5d4a
If model is Omega, link coeffs file from database
cbegeman 64da2c1
Clean-up omega_pr suite order
cbegeman 2e84e77
Use mpas_tools reconstruct utility in open_model_dataset and test in …
cbegeman 9fee43c
Ensure coeff reconstruction is not used when variables present
cbegeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| mpas-ocean: | ||
| streams: | ||
| coeffs_reconstruct: | ||
| type: output | ||
| filename_template: coeffs_reconstruct.nc | ||
| output_interval: 0000_00:00:01 | ||
| clobber_mode: truncate | ||
| contents: | ||
| - coeffs_reconstruct |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| #ocean/planar/barotropic_channel/default # Supported but fails | ||
| ocean/planar/merry_go_round/default | ||
| ocean/planar/barotropic_gyre/munk/free-slip | ||
| ocean/planar/manufactured_solution/convergence_both/default | ||
| ocean/planar/manufactured_solution/convergence_both/del2 | ||
| ocean/planar/manufactured_solution/convergence_both/del4 | ||
| ocean/planar/merry_go_round/default | ||
| ocean/spherical/qu/rotation_2d | ||
| ocean/spherical/icos/rotation_2d | ||
| ocean/spherical/icos/cosine_bell/decomp | ||
| ocean/spherical/icos/cosine_bell/restart | ||
|
|
||
| # Supported but fails | ||
| #ocean/planar/barotropic_channel/default | ||
|
|
||
| # Supported but expected to fail until higher-order advection is available | ||
| #ocean/spherical/icos/nondivergent_2d | ||
| #ocean/spherical/icos/divergent_2d | ||
| #ocean/spherical/icos/correlated_tracers_2d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| import xarray as xr | ||
| from mpas_tools.io import write_netcdf | ||
| from mpas_tools.vector.reconstruct import reconstruct_variable | ||
| from ruamel.yaml import YAML | ||
|
|
||
| from polaris import Component | ||
|
|
@@ -233,7 +234,14 @@ def map_var_list_from_native_model(self, var_list): | |
| ] | ||
| return renamed_vars | ||
|
|
||
| def open_model_dataset(self, filename, **kwargs): | ||
| def open_model_dataset( | ||
| self, | ||
| filename, | ||
| mesh_filename=None, | ||
| reconstruct_variables=None, | ||
| coeffs_filename=None, | ||
| **kwargs, | ||
| ): | ||
| """ | ||
| Open the given dataset, mapping variable and dimension names from Omega | ||
| to MPAS-Ocean names if appropriate | ||
|
|
@@ -243,6 +251,15 @@ def open_model_dataset(self, filename, **kwargs): | |
| filename : str | ||
| The path for the NetCDF file to open | ||
|
|
||
| ds_mesh : xr.Dataset | ||
| The MPAS mesh dataset for the ocean model. | ||
|
|
||
| reconstruct_variables : list of str | ||
| List of variable names to reconstruct in the dataset. | ||
|
|
||
| coeffs_reconstruct : xarray.DataArray, optional | ||
| Coefficients used for reconstructing variables. | ||
|
|
||
| kwargs | ||
| keyword arguments passed to `xarray.open_dataset()` | ||
|
|
||
|
|
@@ -253,6 +270,45 @@ def open_model_dataset(self, filename, **kwargs): | |
| """ | ||
| ds = xr.open_dataset(filename, **kwargs) | ||
| ds = self.map_from_native_model_vars(ds) | ||
| if reconstruct_variables is None: | ||
| reconstruct_variables = [] | ||
| for variable in reconstruct_variables: | ||
| if variable in ds.keys(): | ||
| if 'normal' in variable: | ||
| out_var_name = variable.replace('normal', '').lower() | ||
| else: | ||
| out_var_name = variable | ||
| if ( | ||
| f'{out_var_name}Zonal' in ds.keys() | ||
| and f'{out_var_name}Meridional' in ds.keys() | ||
| ): | ||
| return ds | ||
| if mesh_filename is None: | ||
| raise ValueError( | ||
| 'mesh_filename must be provided to ' | ||
| f'open_model_dataset for reconstruction of {variable}' | ||
| ) | ||
| ds_mesh = xr.open_dataset(mesh_filename) | ||
| if coeffs_filename is None: | ||
| raise ValueError( | ||
| 'coeffs_filename must be provided to ' | ||
| f'open_model_dataset for reconstruction of {variable}' | ||
| ) | ||
| ds_coeff = xr.open_dataset(coeffs_filename) | ||
| coeffs_reconstruct = ds_coeff.coeffs_reconstruct | ||
| reconstruct_variable( | ||
| out_var_name, | ||
| ds[variable], | ||
| ds_mesh, | ||
| coeffs_reconstruct, | ||
| ds, | ||
| quiet=True, | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| f'User requested vector reconstruction for {variable} but ' | ||
| f"it isn't present in the dataset." | ||
| ) | ||
|
Comment on lines
+273
to
+311
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we move this to a helper function, just to keep things tidy?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I'll make these changes and flesh out the docs. Thanks for reviewing! |
||
| return ds | ||
|
|
||
| def _has_ocean_io_model_steps(self, tasks) -> Tuple[bool, bool]: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For whatever reason, I've been lead to believe this is preferred: