gridmarthe.stack_coords
- gridmarthe.stack_coords(ds, coords=('z', 'y', 'x'), dropna=False)[source]
Transform a 3 or 4D aray into 1 or 2D array inverse of
assign_coords()- Parameters:
- dsxarray.Dataset
dataset of Marthe variable(s)
- coordslist, optional
list of coordinates to stack. Default is [‘z’, ‘y’, ‘x’] if z is not present in ds.coords, it will be ignored.
- dropnabool, optional
drop NaN values in stacked dataset. Default is False.
- Returns:
- xr.Dataset
Dataset with stacked coordinates as single dimension zone.
Notes
For nested grids, the total number of zones cannot be checked when flattening back to 1D from cartesian coords/arrays. It will lead to incorrect total number of zones as different cell sizes exist in the 3D grid. For such cases, it is advised to use dropna=True to remove empty zones. Then write back to marthe grid with
gridmarthe.write_marthe_grid()using a permh file as template.TODO: add a sort option to ensure sorted coords in output based on z,y,x order AND dx, dy scale (larger scale first, then smaller)