Skip to content Skip to sidebar Skip to footer

Add A 'time' Dimension To Xarray Dataset And Assign Coordinates From Another Dataset To It

I have a Dataset object (imported from a netCDF file through xarray.open_dataset) named ds. It contains a variable named variable1 and latitude and longitude dimensions. >>&g

Solution 1:

There is an appropriate usage of expand_dims for you:

>>>dst=ds.expand_dims(time=time_da)>>>dst<xarray.Dataset>Dimensions:(latitude:681,longitude:841,time:365)Coordinates:*time(time)datetime64[ns]2017-01-01 2017-01-02...2017-12-31*latitude(latitude)int6401234567...674675676677678679680*longitude(longitude)int6401234567...834835836837838839840Data variables:variable(time,latitude,longitude)float640.039682.156...-1.752

Checking that variable is the same at each timestep:

>>> np.all(np.diff(dst["variable"], axis=0) == 0)
True

Post a Comment for "Add A 'time' Dimension To Xarray Dataset And Assign Coordinates From Another Dataset To It"