netCDF4 usage issues

Nathan longbotham at gmail.com
Thu Jul 23 18:05:34 EDT 2009


I am having issues correctly implementing the multi-file read
functionality in the Python module netCDF4 (whitaker -
http://code.google.com/p/netcdf4-python/).  I am a relative beginner
to Python, so I may be missing something simple.  I've done my best to
follow the example in the documentation at the website referenced
above (reprinted):

>>> from netCDF4 import MFDataset
>>> f = MFDataset('mftest*nc')
>>> print f.variables['x'][:]
[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
23 24
 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
48 49
 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74
 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
98 99]
>>>

Where I attempt to follow the same flow, I don't get the full data set
returned.  I only get a data set for the first file in my list (see
notes in the code below).

>from netCDF4 import MFDataset
>f = MFDataset('E*nc')   # All files I want to read are .nc files in a single directory, each file starting with E
>temp = f.variables['TEMP'][:]
>temp.shape
Out[17]: (8940, 150)  #This is the exact shape of the TEMP variables
array in the first file I need to read verified by an external netCDF
reader application
>f.file_format #There are two files I am trying to read in this example
Out[33]: ['NETCDF3_CLASSIC', 'NETCDF3_CLASSIC']

Does the module only support netcdf4 files? If so, why is it getting
data out of one of the files?  I'm unsure how to trouble shoot this.

Any suggestions would be appreciated.  If this should be posted
elsewhere, please direct me to another list/forum as I didn't find any
directly related to netCDF or this specific netCDF module.  Thank you!



More information about the Python-list mailing list