I first concatenated multiple DataArrays along the dimonsion of time, and then I merged a couple of meteorological variables into one Xarray.DataArray. Finally, I saved the DataArray into a netCDF file. It was strange, that the data changed after it was saved. Before it was saved, it looked normal:
.
However, when I tried to load the netCDF I created, the data looked like:
.
In order to quickly reproduce the problem, I sliced the input files to make them smaller. They together with a python script can be accessed at here (input_data_and_codes). To demonstrate, codes are as follows:
import xarray as xr
dirin = 'C:/mydata/' # Input directory
dirout = dirin # Output directory
vars = ['2m_dewpoint_temperature','2m_temperature'] # Two variables
yrs = [2009,2010] # Two years
var_datasets = []
for var in vars:
datasets = []
for yr in yrs:
input_file_name = dirin + 'test_' + var + '_' + str(yr) + '.nc'
f1 = xr.open_dataset(input_file_name)
datasets.append(f1)
ds_combined = xr.concat(datasets, dim = 'time') # Concatenate data along time
var_datasets.append(ds_combined) # Merge two variables into one DataArray
data_before = xr.merge(var_datasets)
data_before.to_netcdf(dirout + 'test_vars.nc')
data_after = xr.open_dataset(dirout + 'test_vars.nc')
# There are 2 variables: 't2m' and 'd2m'; plot to check
data_before.t2m.plot()
data_after.t2m.plot()
What could be the possible reasons? Thank you.