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)
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]))