xarray
¶Xarray open_mfdataset without time dim
Xarray have a convenient method to open multi-dataset parallelly. However, sometimes time are encoded in the filename and are not in th .nc
coordinate. So we need a method. For example, the dataset of my lab CAQRA[1] do this.
¶Stackoverflow [2]:
Create a function which adds a time dimension to a DataArray, and fill it with a arbitrary date:
1 | def add_time_dim(xda): |
Then, pass this function to the preprocess
argument when running the open_mfdataset
functions:
1 | data = xr.open_mfdataset(files, preprocess = add_time_dim) |
Finally, fill the time
dimension with my dates:
1 | data['time'] = dates |
¶Github [3]
I inspired also by an issue in Github and get the code below:
1 | def func(ds): |
¶xarray add crs data
Use rioxarray instead
¶load
1 | rds = xarray.open_dataset("../../test/test_data/input/PLANET_SCOPE_3D.nc", decode_coords="all") |
¶write
1 | xda.rio.write_crs(4326, inplace=True) |