Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/sage/sagenb/sage_notebook/worksheets/rfcard/0/code/12.py", line 15, in <module>
S=fft(s)
File "", line 1, in <module>
File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/numpy/fft/fftpack.py", line 159, in fft
return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf, _fft_cache)
File "/home/sage/sage_install/sage/local/lib/python2.6/site-packages/numpy/fft/fftpack.py", line 66, in _raw_fft
r = work_function(a, wsave)
TypeError: array cannot be safely cast to required type
>
> This work in pure python.
>
> The problem in sage is with the line
>
> s = sin(2*pi*50*t)+sin(2*pi*70*t+pi/4)
>
> However, I don't know how to get Sage to
> evaluate the sin of a numpy.ndarray.
> For example,
>
> sage: sample_rate=1000.00
> sage: import numpy
> sage: s=numpy.sin(2*numpy.pi*50*t)+numpy.sin(2*numpy.pi*70*t
> +numpy.pi/4)
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent
> call last)
>
> /home/wdj/.sage/temp/hera/27292/_home_wdj__sage_init_sage_0.py in
> <module>()
>
> AttributeError: sin
Won't Sage preparse it so the 2, 50, 70, and 4 become Sage integers?
If I recall correctly, putting r after the appropriate constants
should fix it.
Cheers,
Tim.
---
Tim Lahey
PhD Candidate, Systems Design Engineering
University of Waterloo
http://www.linkedin.com/in/timlahey
Well, I get this far:
----------------------------------------------------------------------
| Sage Version 4.1, Release Date: 2009-07-09 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: from scipy import *
sage: from pylab import *
sage: sample_rate = 1000.0
sage: t = r_[0:0.6:1/sample_rate]
sage: N = len(t)
sage: s = [sin(2*pi*50*elem) + sin(2*pi*70*elem + (pi/4)) for elem in t]
sage: S = fft(s)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/mvngu/.sage/temp/sage.math.washington.edu/6349/_home_mvngu__sage_init_sage_0.py
in <module>()
/usr/local/sage/local/lib/python2.6/site-packages/numpy/fft/fftpack.pyc
in fft(a, n, axis)
157 """
158
--> 159 return _raw_fft(a, n, axis, fftpack.cffti, fftpack.cfftf,
_fft_cache)
160
161
/usr/local/sage/local/lib/python2.6/site-packages/numpy/fft/fftpack.pyc
in _raw_fft(a, n, axis, init_function, work_function, fft_cache)
64 if axis != -1:
65 a = swapaxes(a, axis, -1)
---> 66 r = work_function(a, wsave)
67 if axis != -1:
68 r = swapaxes(r, axis, -1)
TypeError: array cannot be safely cast to required type
The problem is that Sage and NumPy do not yet talk to each other very
well. The relevant tickets to accomplish this are:
#6497
http://trac.sagemath.org/sage_trac/ticket/6497
#5081
http://trac.sagemath.org/sage_trac/ticket/5081
#6506
http://trac.sagemath.org/sage_trac/ticket/6506
--
Regards
Minh Van Nguyen
>
> The problem is that Sage and NumPy do not yet talk to each other very
> well. The relevant tickets to accomplish this are:
>
> #6497
> http://trac.sagemath.org/sage_trac/ticket/6497
>
> #5081
> http://trac.sagemath.org/sage_trac/ticket/5081
>
> #6506
> http://trac.sagemath.org/sage_trac/ticket/6506
>
These tickets need reviews, so if anyone really wants to see them in the
next version of Sage (which has a feature-freeze of tonight, I think),
please review them!
Jason
That's right. As of 27th July 2009, there will be a feature freeze
window until the release of Sage 4.1.1. Of course, the timeline for
merging features is not as rigid as one thinks, but is open to
negotiation.
See http://sagenb.org/home/pub/676/ for a working version:
from scipy import *
from pylab import *
sample_rate = 1000.0
t = r_[0:0.6:1/sample_rate].astype(float)
N = len(t)
s = sin(2*pi*50*t)+sin(2*pi*70*t+pi/4)
S = fft(s)
f=sample_rate*r_[0:(N/2)]/N
n=len(f)
line(zip(f,abs(S[0:n])/N))
As Minh points out, the need for the "astype" above will go away once
the three tickets (that are up for review!) are reviewed and merged;
hopefully in the next few days.
Thanks,
Jason