Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CLIMATE-952 - Update ocw.data_processor.write_netcdf to compatible wi…
…th xarray

- write_netcdf and write_netcdf_multiple_datasets_with_subregions have been updated
- now the time dimension is unlimited
- x and y are names for the dimensions for longitudinal and latitudinal coordinates
  • Loading branch information
huikyole committed Jun 13, 2018
1 parent fd8ca98 commit 38c240aa1ab9bc4ad648511e86e40a2aa62251e1
Showing 1 changed file with 9 additions and 9 deletions.
@@ -631,31 +631,31 @@ def write_netcdf(dataset, path, compress=True):
if dataset.lats.ndim == 2:
lat_len = dataset.lats.shape[0]
lon_len = dataset.lons.shape[1]
lat_dim_info = ('lat', 'lon')
lon_dim_info = ('lat', 'lon')
lat_dim_info = ('y', 'x')
lon_dim_info = ('y', 'x')

else:
lat_len = len(dataset.lats)
lon_len = len(dataset.lons)
lat_dim_info = ('lat',)
lon_dim_info = ('lon',)
lat_dim_info = ('y',)
lon_dim_info = ('x',)

time_len = len(dataset.times)

# Create attribute dimensions
out_file.createDimension('lat', lat_len)
out_file.createDimension('lon', lon_len)
out_file.createDimension('time', time_len)
out_file.createDimension('y', lat_len)
out_file.createDimension('x', lon_len)
out_file.createDimension('time', None)

# Create variables
lats = out_file.createVariable('lat', 'f8', lat_dim_info, zlib=compress)
lons = out_file.createVariable('lon', 'f8', lon_dim_info, zlib=compress)
times = out_file.createVariable('time', 'f8', ('time',), zlib=compress)
times = out_file.createVariable('time', 'f8', ('time'), zlib=compress)

var_name = dataset.variable if dataset.variable else 'var'
values = out_file.createVariable(var_name,
'f8',
('time', 'lat', 'lon'),
('time', 'y', 'x'),
zlib=compress)

# Set the time variable units

0 comments on commit 38c240a

Please sign in to comment.