Python Forum
netCDF issue with filling a variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
netCDF issue with filling a variable
#1
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:

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.13604085
Then 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.13604085
This 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.0
Here 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?
Reply
#2
(Sep-19-2016, 05:17 PM)HeavyLoads Wrote: Im I using the numpy arrays on a wrong way with the netCDF4 librairy?
This is a really specialized question, so it is very difficult to help with when we can't reproduce the problem locally. Can you provide a .nc which can reproduce the problem? Can we use pip to get the module you're using?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pandas : problem with conditional filling of a column Xigris 2 593 Jul-22-2023, 11:44 AM
Last Post: Xigris
  Numpy error while filling up matrix with Characters august 4 1,799 Apr-13-2022, 10:28 PM
Last Post: august
  Variable scope issue melvin13 2 1,507 Nov-29-2021, 08:26 PM
Last Post: melvin13
  combining netcdf data sebastiansieloff 1 1,765 Nov-19-2020, 03:59 PM
Last Post: Larz60+
  [SOLVED] Filling multidict from CSV file? Winfried 3 1,908 Oct-24-2020, 08:26 PM
Last Post: Winfried
  filling and printing numpy arrays of str pjfarley3 4 3,205 Jun-07-2020, 09:09 PM
Last Post: pjfarley3
  TypeError: size; expecting a recognized type filling string dict a11_m11 0 2,487 Feb-10-2020, 08:26 AM
Last Post: a11_m11
  Variable Issue slackerman73 2 1,880 Nov-09-2019, 04:34 PM
Last Post: slackerman73
  Issue with affecting numbers to a variable Adem 3 2,248 Sep-24-2019, 07:48 AM
Last Post: Adem
  Filling an Excel file starter_student 3 2,927 Jul-05-2019, 06:29 AM
Last Post: starter_student

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020