Thank you  very much Smith and Paul,
                                          I was away from office due to a 
medical situation. So could not respond and thank you regarding the help. I 
have got the results now and the tips from both of you were extremely useful. I 
am facing an issue with the code when I call plt.xcorr,  in a loop. it builds 
up usage of memory by python and reaches to the RAM what ever available ( in my 
4 GB laptop it reaches almost full and in my 24 GB desktop it reaches the 
available. I suspected the plot not being closed during each iteration so have 
given a plt.close('all') in the loop. after which it is taking a good time to 
run the code which was otherwise faster until ram usage reaches its maximum.
Is there a way to get out of this situation?. I am attaching the code here and 
also the link to the data I am using. If possible kindly help.

ftp ftpser.incois.gov.in
user temp
password incoistemp
cd /home0/temp/comp
bin
mget qu_test.nc.gz gunzip qu_test.nc.gz

 
***************************************************************
Sudheer Joseph 
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***************************************************************


________________________________
 From: Sterling Smith <smit...@fusion.gat.com>
To: Sudheer Joseph <sudheer.jos...@yahoo.com> 
Cc: Paul Hobson <pmhob...@gmail.com>; "matplotlib-users@lists.sourceforge.net" 
<matplotlib-users@lists.sourceforge.net> 
Sent: Friday, 8 February 2013 10:23 PM
Subject: Re: [Matplotlib-users] cross correlation
 
Sudheer,

For the documentation you are looking for

print ax1.xcorr.__doc__

(Paul tried to give you the IPython method of getting that documentation which 
is by typing a ? (or ??) after the desired object.)

In the documentation (at the link you gave 
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr), it says 
that there are three objects returned by xcorr:
Return value is a tuple (*lags*, *c*, *line*) where:

  - *lags* are a length ``2*maxlags+1`` lag vector

  - *c* is the ``2*maxlags+1`` auto correlation vector

  - *line* is a :class:`~matplotlib.lines.Line2D` instance
     returned by :func:`~matplotlib.pyplot.plot`.

So the error you were getting is due to the fact that you have only specified 
two variables to hold the three returned objects.

Try:
lags,c,line = ax1.xcorr   .....

(Note that you have xcorr and lags backwards in your attempt.)

-Sterling

On Feb 8, 2013, at 1:56AM, Sudheer Joseph wrote:

> Thank you verymuch Hobson,
>                                       However I think I did not understand 
>the suggestion by you fully( pardon my ignorance). I use the below test code 
>from matplotlib site. How does one make a call to get lags and correlation 
>corresponding to the x and y values in the plot. a Print command of  
> In [23]: print ax1.xcorr
> <bound method AxesSubplot.xcorr of <matplotlib.axes.AxesSubplot object at 
> 0x44c1410>>
> results as above. Is it possible to assign the xcorr,lags=ax1.xcorr(x, y, 
> usevlines=True, maxlags=50, normed=True, lw=2) ? with a different syntax? I 
> get below error when I try the above .
> In [27]: xcorr,lags=ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, 
> lw=2)
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
> /home/sjo/work/PY_WORK/stats/<ipython-input-27-e1e58c045ad4> in <module>()
> ----> 1 xcorr,lags=ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, 
> lw=2)
> 
> ValueError: too many values to unpack
> 
> 
> 
> import matplotlib.pyplot as plt
> import numpy as np
> x,y = np.random.randn(2,100)
> fig = plt.figure()
> ax1 = fig.add_subplot(211)
> ax1.xcorr(x, y, usevlines=True, maxlags=50, normed=True, lw=2)
> ax1.grid(True)
> ax1.axhline(0, color='black', lw=2)
> ax2 = fig.add_subplot(212, sharex=ax1)
> ax2.acorr(x, usevlines=True, normed=True, maxlags=50, lw=2)
> ax2.grid(True)
> ax2.axhline(0, color='black', lw=2)
> plt.show()
> 
>  
> From: Paul Hobson <pmhob...@gmail.com>
> To: Sudheer Joseph <sudheer.jos...@yahoo.com> 
> Cc: "matplotlib-users@lists.sourceforge.net" 
> <matplotlib-users@lists.sourceforge.net> 
> Sent: Thursday, 7 February 2013 10:31 PM
> Subject: Re: [Matplotlib-users] cross correlation
> 
> 
> 
> 
> On Thu, Feb 7, 2013 at 3:24 AM, Sudheer Joseph <sudheer.jos...@yahoo.com> 
> wrote:
> Dear Users,
>               I am relatively new to Matplotlib. I wanted to find cross 
>correlation between 2 time series for my research and was looking at options 
>available with python and found 
>http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xcorr . However I 
>wanted to save the results in a netcdf file for further use. ie the 
>correlation, lags and significance if possible. Is there a way to get the corr 
>and lags from the axis.xcorr ?? any help in this matter will be greatly 
>appreciated. 
> Sudheer
> 
> Sudheer,
> 
> A call to axes.xcorr returns the lags, correlation (from np.correlate) and 
> the line artists on the figure.
> 
> In IPython, doing "plt.xcorr??" should provide sufficient information. It's a 
> pretty simple method.
> -paul
> 
> 
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013 
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb_______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
from mpl_toolkits.basemap import Basemap as bm, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset as ncd
from math import pow, sqrt
import sys
from scipy.stats import t
indep=120
nlags=365
lons =np.arange(30.3,120.3,.5)
lats =np.arange(-39.75,30.25,.5)
lev=np.arange(-365,366)
ncf=ncd('cross_cor.nc', 'w')
ncf.close()
ncf=ncd('cross_cor.nc','a','NETCDF4_CLASSIC')
level = ncf.createDimension('level', 731)
lat = ncf.createDimension('lat', 140)
lon = ncf.createDimension('lon', 180)
levels = ncf.createVariable('level','i2',('level'))
latitudes = ncf.createVariable('lat','f4',('lat'))
longitudes = ncf.createVariable('lon','f4',('lon'))
latitudes.units = 'degrees north'
longitudes.units = 'degrees east'
levels.units = 'days'
longitudes[:]=lons
latitudes[:]=lats
levels[:]=lev
r3d= ncf.createVariable('r3d','f4',('lon','lat','level'))
ncf.close()
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset as ncd 
from math import pow, sqrt
import sys
from scipy.stats import t
nlags=365
ncin = ncd('qu_test.nc', 'r')
lons = ncin.variables['LON'][:]
lats = ncin.variables['LAT'][:]
lonx=120
laty=80
ru = ncin.variables['QU'][:,lonx,laty]
ncin.close()
q=ru[1:2190]
for i in np.arange(len(lons)-1):
   for j in np.arange(len(lats)-1):
      print i,j
      ncin = ncd('qu_test.nc', 'r')
      qu = ncin.variables['QU'][:,j,i]
      ncin.close()
      p=qu[1:2190]
      n=len(p)
      c=plt.xcorr(p,q,usevlines=True,maxlags=nlags,normed=True,lw=2)
      lags=c[0]
      r=c[1]
      ncf=ncd('cross_cor.nc','a')
      ncf.variables['r3d'][j,i,:]=r
      ncf.sync()
      ncf.close() 
      del r,lags,qu,p,c,ncin

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to