From: Jeff W. <js...@fa...> - 2004-11-02 22:56:17
|
Francesc: There was no good reason for using Array instead of EArray for rank-1 variables, other than I wasn't sure EArrays were appropriate for variables that were not going to be appended to. Thanks for extending the script! I noticed one typo (StringAtom was used instead of tables.StringAtom). Also, it doesn't yet work on files with netcdf character variables. I get errors like this: Traceback (most recent call last): File "nctoh5_new.py", line 175, in ? overwritefile) File "nctoh5_new.py", line 61, in nctoh5 vardata.append(var[n:n+1]) File "/sw/lib/python2.3/site-packages/tables/EArray.py", line 196, in append naarr = convertIntoNA(object, self.atom) File "/sw/lib/python2.3/site-packages/tables/utils.py", line 208, in convertIntoNA shape=arr.shape) File "/sw/src/root-numarray-py23-1.0-1/sw/lib/python2.3/site-packages/numarray/numarraycore.py", line 318, in array File "/sw/src/root-numarray-py23-1.0-1/sw/lib/python2.3/site-packages/numarray/numarraycore.py", line 256, in getTypeObject File "/sw/src/root-numarray-py23-1.0-1/sw/lib/python2.3/site-packages/numarray/numarraycore.py", line 245, in _typeFromTypeAndTypecode File "/sw/src/root-numarray-py23-1.0-1/sw/lib/python2.3/site-packages/numarray/numerictypes.py", line 457, in getType TypeError: Not a numeric type If I replace vardata.append(var[n:n+1]) with if dtype == 'c': chararr = numarray.strings.array(var[n].tolist()) newshape = list(chararr.shape) newshape.insert(0,1) chararr.setshape(tuple(newshape)) vardata.append(chararr) else: vardata.append(var[n:n+1]) it seems to work. Note that I have to reshape the chararray to have an extra singleton dimension or pytables complains that the data being appended has the wrong shape. This is also the reason I had to use var[n:n+1] instead of var[n] in the append. Is there a better way to do this? -Jeff -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/CDC R/CDC1 Email : Jef...@no... 325 Broadway Web : www.cdc.noaa.gov/~jsw Boulder, CO, USA 80303-3328 Office : Skaggs Research Cntr 1D-124 |