def test_netcdf_monitor_multiple_times_batched_single_var():
time_list = [
datetime(2013, 7, 20, 0),
datetime(2013, 7, 20, 6),
datetime(2013, 7, 20, 12),
]
current_state = state.copy()
try:
assert not os.path.isfile('out.nc')
monitor = NetCDFMonitor('out.nc', store_names=['air_temperature'])
for time in time_list:
current_state['time'] = time
monitor.store(current_state)
assert not os.path.isfile('out.nc') # not set to write on store
monitor.write()
assert os.path.isfile('out.nc')
with xr.open_dataset('out.nc') as ds:
assert len(ds.data_vars.keys()) == 1
assert 'air_temperature' in ds.data_vars.keys()
assert ds.data_vars['air_temperature'].attrs['units'] == 'degK'
assert tuple(ds.data_vars['air_temperature'].shape) == (
len(time_list), nx, ny, nz)
assert len(ds['time']) == len(time_list)
assert np.all(
ds['time'].values == [np.datetime64(time) for time in time_list])
finally: # make sure we remove the output file
if os.path.isfile('out.nc'):
os.remove('out.nc')
评论列表
文章目录