uxgrid.to_xarray('scrip') should add units attribute
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')
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.
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.
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
Thanks!
I can get a fix started for this, thanks for catching this!
@rajeeja please check
@rajeeja
Was this fixed in #1282
Yes, they are set to degrees now