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

uxgrid.to_xarray('scrip') should add units attribute #947

Open
zarzycki opened this issue Sep 12, 2024 · 4 comments
Open

uxgrid.to_xarray('scrip') should add units attribute #947

zarzycki opened this issue Sep 12, 2024 · 4 comments
Assignees
Labels
bug Something isn't working uchicago-hack Issues to work on during co-working at UChciago

Comments

@zarzycki
Copy link

Version

v2023.08.4

How did you install UXarray?

Conda

What happened?

When generating a SCRIP grid from a generic lat/lon mesh to use with TempestExtremes GenerateFileConnectivity, I originally got bad answers. I traced this down to to_xarray not attaching units to the variables (see here for SCRIP description)

My MCVE below shows how I converted these to radians for my purposes, but to_xarray should at the very least attach "degrees" units so that code that reads SCRIP grids can interpret the values internally.

What you get from an ncdump

netcdf mesh_C64_scrip {
dimensions:
	grid_size = 24576 ;
	grid_corners = 4 ;
	grid_rank = 1 ;
variables:
	double grid_corner_lat(grid_size, grid_corners) ;
		grid_corner_lat:_FillValue = NaN ;

What did you expect to happen?

what you should get:

netcdf mesh_C64_scrip {
dimensions:
	grid_size = 24576 ;
	grid_corners = 4 ;
	grid_rank = 1 ;
variables:
	double grid_corner_lat(grid_size, grid_corners) ;
		grid_corner_lat:_FillValue = NaN ;
		grid_corner_lat:units = "degrees" ;

Can you provide a MCVE to repoduce the bug?

import uxarray as ux
import numpy as np

uxgrid = ux.open_grid('mesh_C64.nc')
scrip = uxgrid.to_xarray('scrip')

# Verify area in rad
total_area = scrip['grid_area'].sum()
print(total_area)

# Convert from deg -> rad
scrip['grid_corner_lat'] = np.deg2rad(scrip['grid_corner_lat'])
scrip['grid_corner_lon'] = np.deg2rad(scrip['grid_corner_lon'])
scrip['grid_center_lon'] = np.deg2rad(scrip['grid_center_lon'])
scrip['grid_center_lat'] = np.deg2rad(scrip['grid_center_lat'])

scrip.to_netcdf('mesh_C64_scrip.nc')
@zarzycki zarzycki added the bug Something isn't working label Sep 12, 2024
@zarzycki
Copy link
Author

Not sure how to attach the *.nc file. Perhaps that could be added to supported file types in the repo (within reason, so no one tries to dump a 60GB file :)

The mesh (mesh_C64.nc) is ~2.4MB.

@philipc2
Copy link
Member

Not sure how to attach the *.nc file. Perhaps that could be added to supported file types in the repo (within reason, so no one tries to dump a 60GB file :)

The mesh (mesh_C64.nc) is ~2.4MB.

Feel free to share a google drive link to the mesh.

@zarzycki
Copy link
Author

Not sure how to attach the *.nc file. Perhaps that could be added to supported file types in the repo (within reason, so no one tries to dump a 60GB file :)
The mesh (mesh_C64.nc) is ~2.4MB.

Feel free to share a google drive link to the mesh.

https://drive.google.com/file/d/18KoLILLT_6VeSePN_XtTWVkodNzIuDOc/view?usp=sharing

@philipc2
Copy link
Member

Thanks!

I can get a fix started for this, thanks for catching this!

@philipc2 philipc2 self-assigned this Sep 12, 2024
@philipc2 philipc2 added the uchicago-hack Issues to work on during co-working at UChciago label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working uchicago-hack Issues to work on during co-working at UChciago
Projects
Status: 📝 To-Do
Development

No branches or pull requests

2 participants