Skip to content
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

Add to_xgcm_grid_dataset function to help read into XGCM #3

Closed
mgrover1 opened this issue Oct 20, 2021 · 4 comments · Fixed by #14
Closed

Add to_xgcm_grid_dataset function to help read into XGCM #3

mgrover1 opened this issue Oct 20, 2021 · 4 comments · Fixed by #14
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@mgrover1
Copy link
Collaborator

It would be helpful to have a helper function to prepare the data for XGCM

@jthielen
Copy link
Collaborator

Or, another option could be altering the Dataset metadata to meet the CF & COMODO conventions so that xgcm can handle it natively.

@andersy005 andersy005 added this to Xdev Oct 22, 2021
@mgrover1 mgrover1 added the enhancement New feature or request label Oct 22, 2021
@mgrover1
Copy link
Collaborator Author

We could use something like the following

def to_xgcm(ds):
    """
    Converts an XGCM Grid
    """
    _required_coords = ['XLAT_M', 'XLAT_C', 'XLONG_M', 'XLONG_C']
    
    if not set(_required_coords).issubset(list(ds.coords)):
        raise ValueError(f'Missing Required Coordinates: {_required_coords}')
        
    grid = xgcm.Grid(ds, coords={"X":{"inner":"XLAT_M",
                                      "outer":"XLAT_C"},
                                 "Y":{"inner":"XLONG_M",
                                      "outer":"XLONG_C"}
                                }
                    )
    return grid

This does require those coordinates to be included in the dataset...

@mgrover1 mgrover1 mentioned this issue Oct 27, 2021
@mgrover1 mgrover1 self-assigned this Oct 28, 2021
@mgrover1 mgrover1 moved this to ▶ In Progress in Xdev Oct 28, 2021
@lpilz
Copy link
Collaborator

lpilz commented Nov 19, 2021

This doesn't work for all projections though, right? Since XGCM interpolates the data based on the coordinates, I think that you have to be careful with anything other than lat/lon runs. E.g. for lambert runs, IMO one would have to first convert the XLAT*/XLONG* coordinates to the lambert grid and then use this grid with XGCM.

Also, XLAT_M and XLAT_C are WPS/met_em specific coordinates, are they not?

@jthielen
Copy link
Collaborator

This doesn't work for all projections though, right? Since XGCM interpolates the data based on the coordinates, I think that you have to be careful with anything other than lat/lon runs. E.g. for lambert runs, IMO one would have to first convert the XLAT*/XLONG* coordinates to the lambert grid and then use this grid with XGCM.

Also, XLAT_M and XLAT_C are WPS/met_em specific coordinates, are they not?

I concur that that using the lats and lons only works for a lat/lon projection. Since derived dimension coords are a needed feature anyway, I strongly lean towards just using CF & COMODO attributes conventions (which is what I've worked towards in #14) instead of directly providing an xgcm.Grid from xwrf.

Also, unsure on XLAT_M and XLAT_C...I think we need to collect more sample WRF files alongside user stories so we know the full extent of what we're trying to handle!

@mgrover1 mgrover1 moved this from ▶ In Progress to 🌳 Todo in Xdev Nov 24, 2021
@kmpaul kmpaul added this to xWRF Dec 16, 2021
@kmpaul kmpaul moved this to In Progress in xWRF Dec 16, 2021
@kmpaul kmpaul added this to the Project xWRF milestone Dec 21, 2021
@andersy005 andersy005 moved this from 🌳 Todo to ▶ In Progress in Xdev Project Board Jan 31, 2022
Repository owner moved this from 🌳 Todo to ✅ Done in Xdev Feb 16, 2022
Repository owner moved this from ▶ In Progress to ✅ Done in Xdev Project Board Feb 16, 2022
Repository owner moved this from In Progress to Done in xWRF Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants