EnesYildirim / netcdf4-python

Automatically exported from code.google.com/p/netcdf4-python
Other
0 stars 0 forks source link

slicing of multi-dimensional NetCDF file sometimes not working #197

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create NetCDF file (tested with NETCDF4_CLASSIC) with multi-dimensional data 
inside e.g. (1, 61, 1, 4, 1000) The first dimension is the record (time in my 
case).

2. Open the NetCDF file as Dataset (from netCDF4 import Dataset) and read the 
data into the variable e.g. myData

3. Try to make a slice from the last dimension like:
  print myData[:,:,:,:,index]
    where index is random, sorted list of integers between 1..1000, the array length can be different

What is the expected output? What do you see instead?
For some index array it works e.g. for index=[1,2,3,4] but for some other no 
e.g. if index=[1,2,3,400] =>
  File "netCDF4.pyx", line 2496, in netCDF4.Variable.__getitem__ (netCDF4.c:23340)
ValueError: array dimensions are not compatible for copy

It might be related to the older found issue:
http://code.google.com/p/netcdf4-python/issues/detail?id=34

Indeed if the dimension of the data is (1, 61, 4, 1000) instead of (1, 61, 1, 
4, 1000) it works! (The 3rd dimension equal to 1 is intentional in my case as 
in some other situations is not 1 and I wanted to keep the structure the same..)

What version of the product are you using? On what operating system?
2.7

Please provide any additional information below.
Tested only with NETCDF4_CLASSIC format as the older formats have another 
severe problems e.g. coping with big files (>2-3GB) in python..

Original issue reported on code.google.com by richard....@gmail.com on 6 Sep 2013 at 2:36

GoogleCodeExporter commented 8 years ago
Looks like the logic for squeezing out singleton dimensions is too aggressive. 
One solution would be to not squeeze a singleton dimension in the sliced array 
if the netCDF4 variable has the same singleton dimension.  This would fix your 
use case anyway.

Could you post a sample script that triggers the error so I can test this?

Original comment by whitaker.jeffrey@gmail.com on 6 Sep 2013 at 2:52

GoogleCodeExporter commented 8 years ago
Thank you for your good point to not to squeeze a singleton dimension, it 
works. I've attached the simple quick & dirty python script and the test file.
Thank you very much for your support.

Original comment by richard....@gmail.com on 9 Sep 2013 at 8:23

Attachments:

GoogleCodeExporter commented 8 years ago
I've got a fix in svn HEAD. Can you give it a try and confirm it works for you?

Original comment by whitaker.jeffrey@gmail.com on 9 Sep 2013 at 3:51

GoogleCodeExporter commented 8 years ago

Original comment by whitaker.jeffrey@gmail.com on 26 Feb 2014 at 2:04