Re: IndexError when trying to read masked value from variable

From: Oleksandr Huziy <guziy.sasha_at_nyahnyahspammersnyahnyah>
Date: Tue Jul 03 2012 - 16:05:48 MDT

Hi Carmen,

I am not sure if this is important, but I don't see the point in your code
as described here:
Get the data in a variable object into a *NumPy* array If the variable is
not scalar (rank > 0):

data = f.variables.['varName'][:]

or

data = f.variables.['varName'],get_value()

Assuming the shape of the variable is (5,20,30) get a slice along the first
element of the first dimension:

var = f.variables.['varName']
data = var[0]

Get the same slice but reverse the elements of the second dimension. The
following two statements are equivalent:

data = var[0,::-1,:]
data = var[0,19::-1,:]

I would test it myself but Nio (which I installed using macports),
does not work on my system.

Another option for you would be to try netcdf4-python

Cheers

--
Oleksandr (Sasha) Huziy
2012/7/3 Carmen St. Jean <carmen.stjean@noaa.gov>
> Hello all,
>
> I'm getting this strange error message when I attempt to run the
> attached code with this input file
> (
> http://jetstreak.unh.edu/netcdf/nos.creofs.fields.nowcast.20120625.t12z.nc
> ,
> it is over one GB in size):
>
> Traceback (most recent call last):
>   File "creofstest.py", line 22, in <module>
>     zvalDirectMissingVal = zval[0, 1, 64387]
>   File "/usr/local/lib/python2.7/site-packages/PyNIO/Nio.py", line
> 305, in __getitem__
>     ret = _fill_value_to_masked(self,ret)
>   File "/usr/local/lib/python2.7/site-packages/PyNIO/Nio.py", line
> 283, in _fill_value_to_masked
>     a = ma.masked_where(a == self.__dict__['_FillValue'],a,copy=0)
>   File "/usr/local/lib/python2.7/site-packages/numpy/ma/core.py", line
> 1802, in masked_where
>     " (got %s and %s)" % (cshape, ashape))
> IndexError: Inconsistant shape between the condition and the input
> (got (1,) and ())
>
> My code is very simple; it's just trying to access the zval variable
> at different valid indices.
>
> I can directly access a specific value from the zval variable that
> happens to not contain the missing value (e.g., zval[0, 0, 64387])
> without a problem.  But when I try to directly access a value that I
> know to be a missing value (e.g., zval[0, 1, 64387]), then I get the
> above error.
>
> I am, however, able to indirectly access that value zval[0, 1, 64387]
> by saving zval[0, :, 64387] to a new variable and taking the 1st index
> of that.  This correctly prints out as a missing value.
>
> Does anyone have any ideas of why this might be happening?
>
> Thanks,
>
> Carmen
>
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
>
>

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Tue Jul 3 16:05:57 2012

This archive was generated by hypermail 2.1.8 : Thu Sep 13 2012 - 15:38:36 MDT