string in netcdf file python

Solutions on MaxInterview for string in netcdf file python by the best coders in the world

showing results for - "string in netcdf file python"
Arnaud
23 Apr 2020
1import netCDF4
2import numpy as np
3
4str_out = netCDF4.stringtochar(np.array(['test'], 'S4'))
5
6nc = netCDF4.Dataset('./test.nc', 'w', format='NETCDF4_CLASSIC')
7nc.createDimension('lat', 1)
8nc.createDimension('lon', 1)
9nc.createDimension('nchar', 4)
10
11lat = nc.createVariable('lat', 'f4', ('lat',))
12lon = nc.createVariable('lon', 'f4', ('lon',))
13place = nc.createVariable('place', 'S1', ('nchar'))
14
15lat[:] = 17.002
16lon[:] = -81.501
17place[:] = str_out
18
19nc.close()