1

I am trying to write a csv file to netcdf using very similar code to what is provided here convert csv to netcdf because my data is very similar e.g. also ocean data

I am writing my variables and appending the same way as above script but am having a problem with my latitude and longitude variables. In the above example the command

 lats_out = -25.0 + 5.0 * arange(v4, dtype='float32')

is used, however when I try this I receive this error

>>> lats_out = -90.0 + 90.0 * arange(v4, dtype='float32')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'list' and 'int'

which is logical because v4 is a list and the points within it are stored as float values, but it itself is not a float value.

>>> type(v4)
<type 'list'>
>>> type(v4[1])
<type 'float'>

I do not understand how this was not a problem for the person running the previous script, or how to solve it. I cannot skip this stage out because later when trying to write a variable latitude that uses the dimension lat the slice has a different shape to each other. Any help much appreciated as I am very new to python!

MohitGhodasara
  • 2,342
  • 1
  • 22
  • 29
ellie
  • 11
  • 1
  • 1
  • 4
  • 2
    you probably want `lats_out = -90.0 + 90.0*np.array(v4)` (array instead of arange). Somehow you've ended up with a standard python `list` which is probably not what you want. – jhamman Nov 12 '15 at 15:39
  • also, I'd highly recommend you trying to go the route mentioned in this answer to the question you referred to: http://stackoverflow.com/a/28914767/1757464 – jhamman Nov 12 '15 at 15:40
  • I can't use the route mentioned as my university network does not have the pandas module. If I use an array it literally just creates a huge list. What I want to do is somehow arrange the variables i have for lattitude between -90 and +90 so that they can be used a grid reference points for another variable? – ellie Nov 13 '15 at 11:10
  • 1) "my university network does not have the pandas module." - try installing the anaconda python distribution yourself, you don't need root privileges and you'll never say those words again. 2) The rest of your comment doesn't make any sense. You probably need to break the line in question down into smaller pieces to figure out why it isn't working. – jhamman Nov 13 '15 at 22:06

0 Answers0