-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Proposed new feature or change:
I have a script where I am trying to either load unstructured CAM-SE data (unstructured) or AORC data (structured). The data all represents hourly precipitation.
I want to be able to use uxarray subsetting to calculate regional statistics. The most logical way I can think of is to have an interface layer at the top of the script that reads either the CAM-SE or the AORC data, standardizes them to a ux DataArray, and then goes from there. That way everything below the interface layer just purely works with "unstructured" data (the structured mesh is just a special case of unstructured data)
Currently, when I use the AORC data:
data_filenames = "./aorc/PrecipitationAORC_2004*.nc"
xrds = xr.open_mfdataset(data_filenames)
uxgrid = ux.Grid.from_structured(lon=xrds.longitude, lat=xrds.latitude)
print(uxgrid.face_areas)
uxds = ux.UxDataset.from_xarray(xrds, uxgrid=uxgrid)
print(uxds)
The uxgrid from_structured data does indeed contain a column of face_areas. However, when creating a new uxds using UxDataset.from_xarray the notion of the data being face centered doesn't populate.
<uxarray.Grid>
Original Grid Type: structured
Grid Dimensions:
* n_node: 35305204
* n_face: 35292601
* n_max_face_nodes: 4
Grid Coordinates (Spherical):
* node_lon: (35305204,)
* node_lat: (35305204,)
Grid Coordinates (Cartesian):
Grid Connectivity Variables:
* face_node_connectivity: (35292601, 4)
Grid Descriptor Variables:
<xarray.UxDataset> Size: 68GB
Dimensions: (time: 240, latitude: 4201, longitude: 8401)
Coordinates:
* time (time) datetime64[ns] 2kB 2004-09-04 ... 2004-09-13T23:00:00
* latitude (latitude) float64 34kB 20.0 20.01 20.02 ... 54.98 54.99 55.0
* longitude (longitude) float64 67kB -130.0 -130.0 -130.0 ... -60.01 -60.0
Data variables:
APCP_surface (time, latitude, longitude) float64 68GB dask.array<chunksize=(1, 400, 400), meta=np.ndarray>
This leads to errors when a function needs to query the form of the data (i.e., face-centered, edge-centered, etc.) such as:
radial_subset = hourly_max.subset.bounding_circle(center_coord, r)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[55], line 4
1 # Subsetting
2 center_coord = [landfall_lon, landfall_lat]
----> 4 radial_subset = hourly_max.subset.bounding_circle(center_coord, r)
6 print(radial_subset)
File [~/miniconda3/envs/uxarray/lib/python3.11/site-packages/uxarray/subset/dataarray_accessor.py:93](http://localhost:8888/lab/workspaces/auto-h/tree/~/miniconda3/envs/uxarray/lib/python3.11/site-packages/uxarray/subset/dataarray_accessor.py#line=92), in DataArraySubsetAccessor.bounding_circle(self, center_coord, r, element, inverse_indices, **kwargs)
73 """Subsets an unstructured grid by returning all elements within some
74 radius (in degrees) from a center coord.
75
(...) 88 - False: No index storage (default)
89 """
90 grid = self.uxda.uxgrid.subset.bounding_circle(
91 center_coord, r, element, inverse_indices=inverse_indices, **kwargs
92 )
---> 93 return self.uxda._slice_from_grid(grid)
File [~/miniconda3/envs/uxarray/lib/python3.11/site-packages/uxarray/core/dataarray.py:1706](http://localhost:8888/lab/workspaces/auto-h/tree/~/miniconda3/envs/uxarray/lib/python3.11/site-packages/uxarray/core/dataarray.py#line=1705), in UxDataArray._slice_from_grid(self, sliced_grid)
1701 da_sliced = self.isel(
1702 n_node=sliced_grid._ds["subgrid_node_indices"], ignore_grid=True
1703 )
1705 else:
-> 1706 raise ValueError(
1707 "Data variable must be either node, edge, or face centered."
1708 )
1710 return UxDataArray(da_sliced, uxgrid=sliced_grid)
ValueError: Data variable must be either node, edge, or face centered.
Maybe I'm missing something obvious!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status