Essentially, I would like to open a netcdf file, read out the time stamps for individual pixels and then write the timestamps into a new file. Here is my pseudo-code:
f10 = Dataset(nc_f10, 'r')
Time_UTC_10 = np.transpose(f10.variables['TIME_UTC'][:]) #shape is [92,104]
radiance_10 = f10.variables['RADIANCE'][:] #shape is [92,104]
f10.close()
#Manipulate Radiance Information
#python separates the characters in the timestamp, so join it back up:
for i in np.arange(92):
for j in np.arange(104):
joined_16 = ''.join(Time_UTC_16[:,i,j])
datetime_16[i,j] = datetime.datetime.strptime(joined_16, '%Y-%m-%dT%H:%M:%S.%fZ')
#Create and fill the netcdf
nc_out = Dataset(output_directory+nc_out_file, 'w', format='NETCDF4')
y = nc_out.createDimension('y',104)
x = nc_out.createDimension('x',92)
times = nc_out.createVariable('time', np.unicode_, ('x','y'))
O5s = nc_out.createVariable('O5s', np.float32, ('x', 'y'))
times[:] = datetime_16
O5s[:] = radiance_10
nc_out.close()
But when I try to run this, I get the following error: TypeError: only numpy string, unicode or object arrays can be assigned to VLEN str var slices
I feel like I may be misunderstanding something important here. Any thoughts on how I can correct this code to write the timestamps to a variable in a netcdf?