On Fri, 25 Apr 2014 07:07:54 -0700, Jamie Mitchell wrote:

> Hello all,
> 
> I am trying to perform a Kolmogorov-Smirnov test in Python but I'm
> having a few difficulties.
> 
> # My files are netCDF so I import them as follows:
> 
> control=netCDF4.Dataset('/data/cr1/jmitchel/Q0/swh/controlperiod/
south_west/swhcontrol_swest_concatannavg_1D.nc','r')
> 
> # The string is simply a 1D array
> 
> # Then performing the ks test:
> 
> kstest(control,'norm')
> 
> # I then get the following error:
> 
> File "<stdin>", line 1, in <module>
>   File
>   "/usr/local/sci/lib/python2.7/site-packages/scipy/stats/stats.py",
>   line 3413, in kstest
>     N = len(vals)
> TypeError: len() of unsized object
> 
> Any ideas on why this isn't working would be great.

My guess is that you are calling len() on something that doesn't have a 
length :-)

But seriously, first of, what does "vals" contain? Look at the 
documentation for the kstest function. Does it have a parameter called 
"vals"? If so, what argument are you providing for that? Make sure that 
it is what you expect it is.

What does the documentation for netCDF4.Dataset say? Perhaps you have to 
*read* from the file, not just open it?

control = netCDF4.Dataset(filename,'r')
data = control.read()  # Perhaps this?
kstest(data,'norm')

But I'm just guessing. You'll need to read the documentation to see what 
arguments are expected, then you'll need to check what arguments you're 
actually providing. Doing:

print(repr(control))

may help.


-- 
Steven D'Aprano
http://import-that.dreamwidth.org/
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to