Add 'constant' dimension to xarray Dataset

前端 未结 2 1190
萌比男神i
萌比男神i 2020-12-18 07:06

I have a series of monthly gridded datasets in CSV form. I want to read them, add a few dimensions, and then write to netcdf. I\'ve had great experience using xarray (xray)

2条回答
  •  感情败类
    2020-12-18 07:22

    You can use .expand_dims() to add a new dimension and .assign_coords() to add coordinate values for the corresponding dimension. Below code adds new_dim dimension to ds dataset and sets a corresponding corrdinate with the list_of_values you provide.

    expanded_ds = ds.expand_dims("new_dim").assign_coords(new_dim=("new_dim", [list_of_values]))
    

提交回复
热议问题