-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to choose source of global attributes in MFDataset. #835
Comments
added |
@juseg, could you please test the pull request (branch |
@jswhit Thanks very much! It works, but the time coordinate is reordered (starting with the master file, and then all other files in order). Potentially this could be solved by either re-ordering subdatasets by filenames, or adding a separate PS. I've noticed that the current behaviour of netCDF4 (using global attributes from the first file) is similar to other tools such as |
@juseg - what do you mean that the time coordinate is re-ordered? If you are aggregating along the time dimension the order of the time coordinate should be set by the order of the files in the |
@jswhit Sorry that was a mistake, things work exactly as they should. I think we can close this issue. import numpy as np
import netCDF4 as nc
# prepare fake data
time = np.arange(1000)
data = time**2
# write to multiple netcdf files
for i in range(10):
filename = 'ds' + str(i) + '.nc'
ds = nc.Dataset(filename, 'w', format='NETCDF4_CLASSIC')
ds.createDimension('time', None)
ds.createVariable('time', 'i4', ('time',))
ds.createVariable('data', 'i4', ('time',))
ds.variables['time'][:] = time[100*i:100*i+100]
ds.variables['data'][:] = data[100*i:100*i+100]
ds.history = 'Created ' + filename + '.'
ds.close()
# open as mfdataset and assert time is increasing
ds = nc.MFDataset('ds?.nc', master_file='ds9.nc')
assert ds.history == 'Created ds9.nc.'
assert np.all(np.diff(ds.variables['time'][:]) > 0)
ds.close() Many thanks! |
@jswhit I mean after merging the |
Just a suggestion... Could we add a keyword argument on MFDataset to choose the index (or name) of the file to be used as a master file? Or, the file to pick global attributes from?
I typically use MFDatasets to combine model output from consecutive model runs. When creating an MFDataset instance history is taken from the first run and all subsequent history is lost.
netcdf4-python/netCDF4/_netCDF4.pyx
Line 5864 in 151ccb3
Thanks for considering!
The text was updated successfully, but these errors were encountered: