Sep-19-2016, 05:17 PM
Hello guys,
I'm working with some netCDF climatic data and I want to change specific values inside of some multidimensional variables. Here is an example to explain this.
I open a netCDF file in read/write mode:
What is the cause of this? Im I using the numpy arrays on a wrong way with the netCDF4 librairy?
I'm working with some netCDF climatic data and I want to change specific values inside of some multidimensional variables. Here is an example to explain this.
I open a netCDF file in read/write mode:
In [1]: from netCDF4 import Dataset In [2]: f = Dataset(r'G:\TRAVAIL_DE_MASTER\TestCOORD\copy.nc', 'a', format='NETCDF3_CLASSIC')If I read the value of the variable "evap" with the following coordinate (time=3rd, latitude=7th, longitude=2nd) I am able to obtain the following value:
In [4]: f.variables['evap'][3][7][2] Out[4]: 0.13604085Then I would like for example to change this specific value to 1234.0, like that:
In [6]: f.variables['evap'][3][7][2] = 1234.It returns no errors but if I look back to the variable, the value remains unchanged, I don't understand why (this occurs the same when a file is opened in write mode):
In [7]: f.variables['evap'][3][7][2] Out[7]: 0.13604085This occurs only with variables of more that 1 dimension. If I do the same with a 1 dimension variable I'm able to change de values. Here's an example with the variable "rlat" (rotated latitude) of the same dataset:
In [8]: f.variables['rlat'][3] Out[8]: -16.9 In [9]: f.variables['rlat'][3] = 1234. In [10]: f.variables['rlat'][3] Out[10]: 1234.0Here the value has sucessfully been changed to 1234.0.
What is the cause of this? Im I using the numpy arrays on a wrong way with the netCDF4 librairy?