Skip to content

Instantly share code, notes, and snippets.

@monocongo
Created June 12, 2016 20:58
Show Gist options
  • Save monocongo/cc88cae9fdf4c96fce72e43cbf8fe427 to your computer and use it in GitHub Desktop.
Save monocongo/cc88cae9fdf4c96fce72e43cbf8fe427 to your computer and use it in GitHub Desktop.
# for each file in the list we concatenate it to the base dataset
output_file_name = root_file_name + '.v7_plus_first_guess.nc'
with xarray.open_dataset(base_file_name) as output_dataset:
# loop over the first guess files, concatenating (appending?) each to the base (output) dataset
for first_guess_file in first_guess_files:
# open the first guess dataset, concatenate it with the base (output) dataset
with xarray.open_dataset(first_guess_file, decode_times=False) as first_guess_dataset:
output_dataset = xarray.concat([output_dataset.precip[:, :, :], first_guess_dataset.p[0]], dim='time, lat, lon')
# write the base (output) dataset as a new NetCDF file
output_dataset.to_netcdf(output_file_name, encoding = {'precip': {'_FillValue': np.nan, 'dtype': 'float32'}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment