Я создаю файл netcdf с несколькими переменными. Я получил файл netcdf как полезный, как я ожидал, но не знаю, как определить единицы моих переменных.Определить единицы в файле netcdf с помощью python
Это то, что мой код выглядит как прямо сейчас:
import netCDF4
import numpy as np
ncfile = netCDF4.Dataset('state.global.nc', 'r')
u = ncfile.variables['U'][:,:,:,:] # [T,Z,Y,X]
v = ncfile.variables['V'][:,:,:,:]
nx = np.shape(u)[3] - 1
ny = np.shape(v)[2] - 1
nz = np.shape(u)[1]
u_c = 0.5 * (u[:,:,:,0:nx] + u[:,:,:,1:nx+1])
v_c = 0.5 * (v[:,:,0:ny,:] + v[:,:,1:ny+1,:])
u_center = np.fliplr(u_c) # Flip upside down
v_center = np.fliplr(v_c)
# Write out u_center and v_center into a new netCDF file
ncfile_out = netCDF4.Dataset('./output.nc', 'w')
ncfile_out.createDimension('X', nx)
ncfile_out.createDimension('Y', ny)
ncfile_out.createDimension('Z', nz)
ncfile_out.createDimension('time', None)
u_out = ncfile_out.createVariable('u_center', 'f4', ('time', 'Z', 'Y', 'X'))
v_out = ncfile_out.createVariable('v_center', 'f4', ('time', 'Z', 'Y', 'X'))
time = ncfile_out.createVariable('Time', 'i4', 'time')
v_out.units = 'm/s' # Define units of variables
u_out.units = 'm/s'
time.units = 's'
u_out[:,:,:,:] = u_center[:,:,:,:]
v_out[:,:,:,:] = v_center[:,:,:,:]
ncfile_out.close()
Но я прочитал окончательный файл, используя ncview, и я не вижу каких-либо единиц, и я хотел бы, чтобы определить размеры (х, у, г) единиц как 'метров' тоже. Как я могу это сделать? И, что, если я хочу поставить этот 1 шаг в «Х», это что-то вроде «500 метров»?