@sines.html
001|
002| from sys import argv, exc_info
003| from traceback import extract_tb
004| from os import path
005| from math import pi,tau, sin,cos, factorial, fabs
006| from cmath import exp, phase as cphase
007| import numpy as np
008| from logger import logger, info, debug, trace
009| from mlchart import mlchart
010|
011| Log = logger('sines')
012| BasePath = r'C:\CJS\prj\Python\charts'
013| ImgsPath = path.join(BasePath,'img')
014|
015| CMND = 'test'
016| ARGS = {
017|
018|
019|
020|
021|
022|
023| }
024|
025| Radians = lambda d: (tau * (d/360.0))
026| ZStr = lambda z: ('(%+9.6f, %+9.6fi)' % (z.real,z.imag))
027|
028|
029| class sines_chart (mlchart):
030|
031| def __init__ (self, **kwargs):
032| super().__init__(**kwargs)
033| self.dims = (8.8, 4.0)
034| self.margins = dict(left=0.07, right=0.96, bottom=0.10, top=0.92)
035| self.title = 'Sine Waves'
036| self.x_title = ''
037| self.y_title = ''
038| self.x_tickf = '%.1f'
039| self.y_tickf = '%.2f'
040| self.x_grids = (pi, pi/4.0)
041| self.y_grids = (1.0, 0.25)
042| self.x0 = -2.0
043| self.x1 = +2.0
044| self.y0 = -1.50
045| self.y1 = +1.50
046| self.calculate_limits()
047|
048| def calculate_limits (self):
049| self.x_limit = (self.x0 * pi, self.x1 * pi)
050| self.y_limit = (self.y0, self.y1)
051| self.xt = np.linspace(self.x_limit[0], self.x_limit[1], 501)
052| self.xticks = np.linspace(self.x0, self.x1, 5)
053|
054| def make_x_axis_spcl (self):
055| self.ax.set_xticks([x*pi for x in self.xticks])
056| self.ax.set_xticklabels(['%+.1f $pi$' % x for x in self.xticks])
057|
058|
059| class taylor_series_chart (sines_chart):
060| def __init__ (self, **kwargs):
061| super().__init__(**kwargs)
062| self.title = 'Taylor Series for Sine (1,3,5,..17)'
063| self.x0 = -3.00
064| self.x1 = +3.00
065| self.y0 = -2.40
066| self.y1 = +2.40
067| self.xmin = (self.x0 * pi)
068| self.xmax = (self.x1 * pi)
069| self.x_limit = (self.xmin, self.xmax)
070| self.y_limit = (self.y0, self.y1)
071| self.xticks = np.linspace(self.x0, self.x1, 7)
072| self.xx = np.linspace(self.xmin, self.xmax, 201)
073| self.tex = r'$\frac{x^1}{1!} - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + ...$'
074|
075| def plotter (self):
076| Taylor = lambda x,n: ((x**n) / factorial(n))
077|
078| dx1 = [+Taylor(x, 1) for x in self.xx]
079| dx2 = [-Taylor(x, 3) for x in self.xx]
080| dx3 = [+Taylor(x, 5) for x in self.xx]
081| dx4 = [-Taylor(x, 7) for x in self.xx]
082| dx5 = [+Taylor(x, 9) for x in self.xx]
083| dx6 = [-Taylor(x,11) for x in self.xx]
084| dx7 = [+Taylor(x,13) for x in self.xx]
085| dx8 = [-Taylor(x,15) for x in self.xx]
086| dx9 = [+Taylor(x,17) for x in self.xx]
087| dx0 = [sum(t) for t in zip(dx1,dx2,dx3,dx4,dx5,dx6,dx7,dx8,dx9)]
088| sx0 = [sin(x) for x in self.xx]
089|
090| self.ax.plot(self.xx,dx1, color='#00001f', lw=0.75, zorder=11, alpha=1.00)
091| self.ax.plot(self.xx,dx2, color='#1f1f3f', lw=0.75, zorder=12, alpha=1.00)
092| self.ax.plot(self.xx,dx3, color='#3f3f5f', lw=0.75, zorder=13, alpha=1.00)
093| self.ax.plot(self.xx,dx4, color='#5f5f7f', lw=0.75, zorder=14, alpha=1.00)
094| self.ax.plot(self.xx,dx5, color='#7f7f9f', lw=0.75, zorder=15, alpha=1.00)
095| self.ax.plot(self.xx,dx6, color='#9f9faf', lw=0.75, zorder=16, alpha=1.00)
096| self.ax.plot(self.xx,dx7, color='#afafcf', lw=0.75, zorder=17, alpha=1.00)
097| self.ax.plot(self.xx,dx8, color='#cfcfdf', lw=0.75, zorder=18, alpha=1.00)
098| self.ax.plot(self.xx,dx9, color='#dfdfff', lw=0.75, zorder=19, alpha=1.00)
099|
100| p2 = self.ax.plot(self.xx,sx0, color='#0000ff', lw=1.20, zorder=20, alpha=1.00)
101| p1 = self.ax.plot(self.xx,dx0, color='#ff0000', lw=2.00, zorder=21, alpha=0.80)
102|
103| self.ax.axhline(0.0, color='k', lw=1.8, zorder=30)
104| self.ax.axvline(0.0, color='k', lw=1.8, zorder=30)
105| self.ax.legend([p1[0],p2[0]],[self.tex,'sin(x)'], loc='upper left', shadow=True)
106|
107|
108|
109|
110|
111| def do_taylor_series (**kwargs):
112| Log.info('taylor-series:: %s' % str(list(kwargs.keys())))
113| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
114| fname = kwargs['fname'] if 'fname' in kwargs else 'taylor-series.png'
115| Log.info('fpath="%s"' % fpath)
116| Log.info('fname="%s"' % fname)
117| Log.info()
118|
119| cht = taylor_series_chart(fname=fname, fpath=fpath)
120| cht.make()
121|
122| Log.info()
123| return 'Done'
124|
125|
126| def do_sines_1 (**kwargs):
127| Log.info('sines-1:: %s' % str(list(kwargs.keys())))
128| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
129| fname = kwargs['fname'] if 'fname' in kwargs else 'sines-1.png'
130| Log.info('fpath="%s"' % fpath)
131| Log.info('fname="%s"' % fname)
132| Log.info()
133|
134| class sines_1_chart (sines_chart):
135| def __init__ (self, **kwargs):
136| super().__init__(**kwargs)
137| self.title = r'Square Wave [$sin(x)+\frac{1}{3}\;sin(3x)+\frac{1}{5}\;sin(5x)+\ldots+\frac{1}{17}\;sin(17x)$]'
138| def plotter (self):
139| dx1 = [sin(x*1)/1.0 for x in self.xt]
140| dx2 = [sin(x*3)/3.0 for x in self.xt]
141| dx3 = [sin(x*5)/5.0 for x in self.xt]
142| dx4 = [sin(x*7)/7.0 for x in self.xt]
143| dx5 = [sin(x*9)/9.0 for x in self.xt]
144| dx6 = [sin(x*11)/11.0 for x in self.xt]
145| dx7 = [sin(x*13)/13.0 for x in self.xt]
146| dx8 = [sin(x*15)/15.0 for x in self.xt]
147| dx9 = [sin(x*17)/17.0 for x in self.xt]
148| dx0 = [sum(t) for t in zip(dx1,dx2,dx3,dx4,dx5,dx6,dx7,dx8,dx9)]
149|
150| self.ax.plot(self.xt,dx1, color='#000000', lw=0.80, zorder=11, alpha=0.85)
151| self.ax.plot(self.xt,dx2, color='#1f1f1f', lw=0.80, zorder=12, alpha=0.85)
152| self.ax.plot(self.xt,dx3, color='#3f3f3f', lw=0.80, zorder=13, alpha=0.85)
153| self.ax.plot(self.xt,dx4, color='#5f5f5f', lw=0.80, zorder=14, alpha=0.85)
154| self.ax.plot(self.xt,dx5, color='#7f7f7f', lw=0.80, zorder=15, alpha=0.85)
155| self.ax.plot(self.xt,dx6, color='#9f9f9f', lw=0.80, zorder=16, alpha=0.85)
156| self.ax.plot(self.xt,dx7, color='#afafaf', lw=0.80, zorder=17, alpha=0.85)
157| self.ax.plot(self.xt,dx8, color='#cfcfcf', lw=0.80, zorder=18, alpha=0.85)
158| self.ax.plot(self.xt,dx9, color='#dfdfdf', lw=0.80, zorder=19, alpha=0.85)
159| self.ax.plot(self.xt,dx0, color='#ff0000', lw=1.60, zorder=20, alpha=0.85)
160|
161| cht = sines_1_chart(fname=fname, fpath=fpath)
162| cht.make()
163|
164| Log.info()
165| return 'Done'
166|
167|
168| def do_sines_2 (**kwargs):
169| Log.info('sines-2:: %s' % str(list(kwargs.keys())))
170| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
171| fname = kwargs['fname'] if 'fname' in kwargs else 'sines-2.png'
172| Log.info('fpath="%s"' % fpath)
173| Log.info('fname="%s"' % fname)
174| Log.info()
175|
176| class sines_2_chart (sines_chart):
177| def __init__ (self, **kwargs):
178| super().__init__(**kwargs)
179| self.title = r'Triangle Wave [$sin(x)-\frac{1}{3^2}\;sin(3x)+\frac{1}{5^2}\;sin(5x)-\ldots+\frac{1}{17^2}\;sin(17x)$]'
180| def plotter (self):
181| dx1 = [+sin(x*1)/1.0 for x in self.xt]
182| dx2 = [-sin(x*3)/9.0 for x in self.xt]
183| dx3 = [+sin(x*5)/25.0 for x in self.xt]
184| dx4 = [-sin(x*7)/49.0 for x in self.xt]
185| dx5 = [+sin(x*9)/81.0 for x in self.xt]
186| dx6 = [-sin(x*11)/121.0 for x in self.xt]
187| dx7 = [+sin(x*13)/169.0 for x in self.xt]
188| dx8 = [-sin(x*15)/225.0 for x in self.xt]
189| dx9 = [+sin(x*17)/289.0 for x in self.xt]
190| dx0 = [sum(t) for t in zip(dx1,dx2,dx3,dx4,dx5,dx6,dx7,dx8,dx9)]
191|
192| self.ax.plot(self.xt,dx1, color='#000000', lw=0.80, zorder=11, alpha=0.85)
193| self.ax.plot(self.xt,dx2, color='#1f1f1f', lw=0.80, zorder=12, alpha=0.85)
194| self.ax.plot(self.xt,dx3, color='#3f3f3f', lw=0.80, zorder=13, alpha=0.85)
195| self.ax.plot(self.xt,dx4, color='#5f5f5f', lw=0.80, zorder=14, alpha=0.85)
196| self.ax.plot(self.xt,dx5, color='#7f7f7f', lw=0.80, zorder=15, alpha=0.85)
197| self.ax.plot(self.xt,dx6, color='#9f9f9f', lw=0.80, zorder=16, alpha=0.85)
198| self.ax.plot(self.xt,dx7, color='#afafaf', lw=0.80, zorder=17, alpha=0.85)
199| self.ax.plot(self.xt,dx8, color='#cfcfcf', lw=0.80, zorder=18, alpha=0.85)
200| self.ax.plot(self.xt,dx9, color='#dfdfdf', lw=0.80, zorder=19, alpha=0.85)
201| self.ax.plot(self.xt,dx0, color='#ff0000', lw=1.60, zorder=20, alpha=0.85)
202|
203| cht = sines_2_chart(fname=fname, fpath=fpath)
204| cht.make()
205|
206| Log.info()
207| return 'Done'
208|
209|
210| def do_sines_3 (**kwargs):
211| Log.info('sines-3:: %s' % str(list(kwargs.keys())))
212| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
213| fname = kwargs['fname'] if 'fname' in kwargs else 'sines-3.png'
214| Log.info('fpath="%s"' % fpath)
215| Log.info('fname="%s"' % fname)
216| Log.info()
217|
218| class sines_3_chart (sines_chart):
219| def __init__ (self, **kwargs):
220| super().__init__(**kwargs)
221| self.title = r'Sawtooth Wave [$-sin(x)-\frac{1}{2}\;sin(2x)-\frac{1}{3}\;sin(3x)-\ldots-\frac{1}{9}\;sin(9x)$]'
222| def plotter (self):
223| dx1 = [-sin(x*1)/1.0 for x in self.xt]
224| dx2 = [-sin(x*2)/2.0 for x in self.xt]
225| dx3 = [-sin(x*3)/3.0 for x in self.xt]
226| dx4 = [-sin(x*4)/4.0 for x in self.xt]
227| dx5 = [-sin(x*5)/5.0 for x in self.xt]
228| dx6 = [-sin(x*6)/6.0 for x in self.xt]
229| dx7 = [-sin(x*7)/7.0 for x in self.xt]
230| dx8 = [-sin(x*8)/8.0 for x in self.xt]
231| dx9 = [-sin(x*9)/9.0 for x in self.xt]
232| dx0 = [sum(t) for t in zip(dx1,dx2,dx3,dx4,dx5,dx6,dx7,dx8,dx9)]
233|
234| self.ax.plot(self.xt,dx1, color='#000000', lw=0.80, zorder=11, alpha=0.85)
235| self.ax.plot(self.xt,dx2, color='#1f1f1f', lw=0.80, zorder=12, alpha=0.85)
236| self.ax.plot(self.xt,dx3, color='#3f3f3f', lw=0.80, zorder=13, alpha=0.85)
237| self.ax.plot(self.xt,dx4, color='#5f5f5f', lw=0.80, zorder=14, alpha=0.85)
238| self.ax.plot(self.xt,dx5, color='#7f7f7f', lw=0.80, zorder=15, alpha=0.85)
239| self.ax.plot(self.xt,dx6, color='#9f9f9f', lw=0.80, zorder=16, alpha=0.85)
240| self.ax.plot(self.xt,dx7, color='#afafaf', lw=0.80, zorder=17, alpha=0.85)
241| self.ax.plot(self.xt,dx8, color='#cfcfcf', lw=0.80, zorder=18, alpha=0.85)
242| self.ax.plot(self.xt,dx9, color='#dfdfdf', lw=0.80, zorder=19, alpha=0.85)
243| self.ax.plot(self.xt,dx0, color='#ff0000', lw=1.60, zorder=20, alpha=0.85)
244|
245| cht = sines_3_chart(fname=fname, fpath=fpath)
246| cht.make()
247|
248| Log.info()
249| return 'Done'
250|
251|
252| def do_sines_4 (**kwargs):
253| Log.info('sines-4:: %s' % str(list(kwargs.keys())))
254| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
255| fname = kwargs['fname'] if 'fname' in kwargs else 'sines-4.png'
256| Log.info('fpath="%s"' % fpath)
257| Log.info('fname="%s"' % fname)
258| Log.info()
259|
260| class sines_4_chart (sines_chart):
261| def __init__ (self, **kwargs):
262| super().__init__(**kwargs)
263| self.title = r'Sine Waves'
264| self.x0 = -12.0
265| self.x1 = +12.0
266| self.calculate_limits()
267| def plotter (self):
268| dxs = []
269| for ix in range(10):
270| n = 1+(1.9*ix)
271| dx = [sin(x*n) / float(n) for x in self.xt]
272| dxs.append(dx)
273| dx0 = [sum(d) for d in zip(*dxs)]
274|
275| for ix,dx in enumerate(dxs):
276| c = (float(ix+1) / 10.0)
277| self.ax.plot(self.xt,dx, color=(c,c,c), lw=0.80, zorder=3, alpha=0.85)
278| self.ax.plot(self.xt,dx0, color='#ff0000', lw=1.60, zorder=9, alpha=0.85)
279|
280| cht = sines_4_chart(fname=fname, fpath=fpath)
281| cht.make()
282|
283| Log.info()
284| return 'Done'
285|
286|
287| def do_sines_5 (**kwargs):
288| Log.info('sines-5:: %s' % str(list(kwargs.keys())))
289| fpath = kwargs['fpath'] if 'fpath' in kwargs else ImgsPath
290| fname = kwargs['fname'] if 'fname' in kwargs else 'sines-5.png'
291| Log.info('fpath="%s"' % fpath)
292| Log.info('fname="%s"' % fname)
293| Log.info()
294|
295| class sines_5_chart (sines_chart):
296| def __init__ (self, **kwargs):
297| super().__init__(**kwargs)
298| self.title = r'Sine Waves'
299| self.x_grids = (pi, pi/2.0)
300| self.y_grids = (5.0, 1.00)
301| self.x0 = -12.0
302| self.x1 = +12.0
303| self.y0 = -15.0
304| self.y1 = +15.0
305| self.calculate_limits()
306| def plotter (self):
307| dxs = []
308| for ix in range(1,26):
309| n = 0.15*ix
310| dx = [np.cos(x*n) for x in self.xt]
311| dxs.append(dx)
312| dx0 = [sum(d) for d in zip(*dxs)]
313|
314| for ix,dx in enumerate(dxs[0:10]):
315| c = (float(ix+1) / 10.0)
316| self.ax.plot(self.xt,dx, color=(c,c,c), lw=0.80, zorder=3, alpha=0.85)
317| self.ax.plot(self.xt,dx0, color='#ff0000', lw=1.60, zorder=9, alpha=0.85)
318|
319| cht = sines_5_chart(fname=fname, fpath=fpath)
320| cht.make()
321|
322| Log.info()
323| return 'Done'
324|
325|
326| def do_traveling_wave (**kwargs):
327| Log.info('traveling-wave:: %s' % str(list(kwargs.keys())))
328| fpath = kwargs['fpath'] if 'fpath' in kwargs else BasePath
329| fname = kwargs['fname'] if 'fname' in kwargs else 'traveling-wave.png'
330| which = int(kwargs['which']) if 'which' in kwargs else 0
331| Log.info('fpath="%s"' % fpath)
332| Log.info('fname="%s"' % fname)
333| Log.info()
334|
335| e1,e2 = complex(1,0), complex(0,-1)
336| v = [e1, e2]
337| k = 1.0
338| w = tau*0.15
339| tsteps = 15
340| xsteps = 90
341| ticks = []
342| for t in [(n/tsteps) for n in range(tsteps)]:
343| xs = []
344| for x in [tau*(n/xsteps) for n in range(xsteps+1)]:
345| z = exp(complex(0,1)*(((k*x)-(w*t))))
346| g = (t, x, z, (e1*z, e2*z))
347| xs.append(g)
348| ticks.append(xs)
349|
350| class wheel_chart (sines_chart):
351| def __init__ (self, **kwargs):
352| super().__init__(**kwargs)
353| self.title = r'Traveling Wave Function'
354| self.x0 = 0.0
355| self.x1 = +2.0
356| self.y0 = -1.05
357| self.y1 = +1.05
358| self.calculate_limits()
359| def plotter (self):
360|
361| for tx,tick in enumerate(ticks):
362| xs = [x for _,x,_,_ in tick]
363| alfa = 0.25+(0.75*((1+tx)/tsteps))
364| if which==0:
365| ys1 = [z.real for _,_,z,_ in tick]
366| ys2 = [z.imag for _,_,z,_ in tick]
367| self.ax.plot(xs,ys1, color='#ff3f1f', lw=1.00, zorder=((10*tx)+2), alpha=alfa)
368| self.ax.plot(xs,ys2, color='#1f3fff', lw=1.00, zorder=((10*tx)+1), alpha=alfa)
369| continue
370| if which==1:
371| ys1 = [zz[0].real for _,_,_,zz in tick]
372| ys2 = [zz[0].imag for _,_,_,zz in tick]
373| self.ax.plot(xs,ys1, color='#3fbf3f', lw=1.00, zorder=((10*tx)+2), alpha=alfa)
374| self.ax.plot(xs,ys2, color='#3f7f3f', lw=1.00, zorder=((10*tx)+1), alpha=alfa)
375| continue
376| if which==2:
377| ys1 = [zz[1].real for _,_,_,zz in tick]
378| ys2 = [zz[1].imag for _,_,_,zz in tick]
379| self.ax.plot(xs,ys1, color='#3fbf3f', lw=1.00, zorder=((10*tx)+2), alpha=alfa)
380| self.ax.plot(xs,ys2, color='#3f7f3f', lw=1.00, zorder=((10*tx)+1), alpha=alfa)
381| continue
382| if which==3:
383| ys1 = [zz[0].real for _,_,_,zz in tick]
384| ys2 = [zz[1].real for _,_,_,zz in tick]
385| self.ax.plot(xs,ys1, color='#ff3f1f', lw=1.00, zorder=((10*tx)+2), alpha=alfa)
386| self.ax.plot(xs,ys2, color='#7f3f1f', lw=1.00, zorder=((10*tx)+1), alpha=alfa)
387| continue
388| if which==4:
389| ys1 = [zz[0].imag for _,_,_,zz in tick]
390| ys2 = [zz[1].imag for _,_,_,zz in tick]
391| self.ax.plot(xs,ys1, color='#1f3fff', lw=1.00, zorder=((10*tx)+2), alpha=alfa)
392| self.ax.plot(xs,ys2, color='#1f3f7f', lw=1.00, zorder=((10*tx)+1), alpha=alfa)
393| continue
394|
395| cht = wheel_chart(fname=fname, fpath=fpath)
396| cht.make()
397|
398| Log.info()
399| return 'Done'
400|
401|
402| def do_dual_wheel (**kwargs):
403| Log.info('dual-wheel:: %s' % str(list(kwargs.keys())))
404| fpath = kwargs['fpath'] if 'fpath' in kwargs else BasePath
405| fname = kwargs['fname'] if 'fname' in kwargs else 'dual-wheel.png'
406| phase = float(kwargs['phase']) if 'phase' in kwargs else 0.05
407| co_a = float(kwargs['co_a']) if 'co_a' in kwargs else 0.5
408| co_b = float(kwargs['co_b']) if 'co_b' in kwargs else 0.5
409| Log.info('fpath="%s"' % fpath)
410| Log.info('fname="%s"' % fname)
411| Log.info()
412|
413| class wheel_chart (sines_chart):
414| def __init__ (self, data, **kwargs):
415| super().__init__(**kwargs)
416| self.title = r'Polarization'
417| self.x0 = 0.0
418| self.x1 = +2.0
419| self.y0 = -1.05
420| self.y1 = +1.05
421| self.calculate_limits()
422| self.data = data
423| def plotter (self):
424|
425| ys1 = [z.real for z in self.data[0]]
426| ys2 = [z.imag for z in self.data[0]]
427| xs = [tau*t[1] for t in self.data[1]]
428| ys3 = [t[0].real for t in self.data[1]]
429| ys4 = [t[0].imag for t in self.data[1]]
430| ys5 = [t[0].real for t in self.data[2]]
431| ys6 = [t[0].imag for t in self.data[2]]
432| self.ax.plot(xs,ys1, color='#ff3f1f', lw=2.50, zorder=19, alpha=0.80)
433| self.ax.plot(xs,ys2, color='#1f3fff', lw=2.50, zorder=18, alpha=0.80)
434| self.ax.plot(xs,ys3, color='#3fbf7f', lw=2.00, zorder=17, alpha=0.80)
435| self.ax.plot(xs,ys4, color='#3fbf7f', lw=1.00, zorder=16, alpha=0.80)
436| self.ax.plot(xs,ys5, color='#bf7f3f', lw=2.00, zorder=15, alpha=0.80)
437| self.ax.plot(xs,ys6, color='#bf7f3f', lw=1.00, zorder=14, alpha=0.80)
438|
439| i2pi_p = complex(0,+1)*complex(tau,0)
440| i2pi_n = complex(0,-1)*complex(tau,0)
441|
442| def wheel (steps=36, cycles=1.00, faze=0.0, rev=False):
443| out = []
444| for ix in range(1+int(cycles*steps)):
445| a = (float(ix)/float(steps))+faze
446| f = (i2pi_n*a) if rev else (i2pi_p*a)
447| z = exp(f)
448| t = (z, a, ix)
449| out.append(t)
450| Log.info('%4d: %9.6f -> (%+11.8f, %+11.8fi)' % (ix,a,z.real,z.imag))
451| Log.info()
452| return out
453| def wheel_adder (a, b, ra=0.5, rb=0.5):
454| out = [((ra*a[0])+(rb*b[0])) for a,b in zip(a,b)]
455| for ix,z in enumerate(out):
456| Log.info('%3d: %s' % (ix,ZStr(z)))
457| Log.info()
458| return out
459|
460| wx = wheel(steps=60, faze=0.00, rev=False)
461| wy = wheel(steps=60, faze=phase, rev=True)
462| ww = wheel_adder(wx,wy, ra=co_a, rb=co_b)
463|
464| cht = wheel_chart((ww,wx,wy), fname=fname, fpath=fpath)
465| cht.make()
466|
467| Log.info()
468| return 'Done'
469|
470|
471| def do_test (**kwargs):
472| Log.info('test:: %s' % str(list(kwargs.keys())))
473| fpath = kwargs['fpath'] if 'fpath' in kwargs else BasePath
474| fname = kwargs['fname'] if 'fname' in kwargs else 'test.png'
475| Log.info('fpath="%s"' % fpath)
476| Log.info('fname="%s"' % fname)
477| Log.info()
478|
479| i2pi = complex(0,+1)*complex(tau,0)
480| steps = 500
481| ticks = [t/steps for t in range(steps)]
482| clock1 = [exp(i2pi*t*3.0) for t in ticks]
483| clock2 = [exp(i2pi*t*-3.0) for t in ticks]
484| phase0 = [p if 0<p else -p for p in [cphase(c1/c2)/pi for c1,c2 in zip(clock1,clock2)]]
485|
486|
487|
488| class test_chart (sines_chart):
489| def __init__ (self, **kwargs):
490| super().__init__(**kwargs)
491| self.title = r'Sine (red) and Cosine (blue)'
492| self.x0 = 0.0
493| self.x1 = +4.0
494| self.y0 = -1.05
495| self.y1 = +1.05
496| self.calculate_limits()
497| def plotter (self):
498| xs = [2.0*tau*t for t in ticks]
499| ys1 = [sin(x) for x in xs]
500| ys2 = [cos(x) for x in xs]
501|
502|
503|
504|
505|
506| self.ax.plot(xs,ys1, color='#ff0000', lw=1.75, zorder=11, alpha=0.80)
507| self.ax.plot(xs,ys2, color='#0000ff', lw=1.75, zorder=12, alpha=0.80)
508|
509|
510|
511|
512|
513|
514| cht = test_chart(fname=fname, fpath=fpath)
515| cht.make()
516|
517| Log.info()
518| return 'Done'
519|
520| def dispatch (cmd, **kwargs):
521| Log.info('command: %s' % cmd)
522| for kw in kwargs:
523| Log.info('argument[%s]: %s' % (kw,kwargs[kw]))
524| Log.info()
525| if cmd == '2-wheel': return do_dual_wheel(**kwargs)
526| if cmd == 'twave-1': return do_traveling_wave(**kwargs)
527| if cmd == 'taylor': return do_taylor_series(**kwargs)
528| if cmd == 'sines-1': return do_sines_1(**kwargs)
529| if cmd == 'sines-2': return do_sines_2(**kwargs)
530| if cmd == 'sines-3': return do_sines_3(**kwargs)
531| if cmd == 'sines-4': return do_sines_4(**kwargs)
532| if cmd == 'sines-5': return do_sines_5(**kwargs)
533| if cmd == 'test': return do_test(**kwargs)
534| return 'Nothing to do!'
535|
536| if __name__ == '__main__':
537| print('autorun: %s' % argv[0])
538| Log.start(path.join(BasePath,'@sines.log'))
539| Log.level(debug())
540| cmd = argv[1] if 1 < len(argv) else CMND
541| kwargs = ARGS
542| for a in argv[2:]:
543| nv = a.split('=', 2)
544| kwargs[nv[0]] = (nv[1] if 1<len(nv) else '')
545| Log.debug('%s: "%s"' % (nv[0], kwargs[nv[0]]))
546| try:
547| obj = dispatch(cmd, **kwargs)
548| print()
549| print(obj)
550| Log.info()
551| Log.info(obj)
552| except:
553| etype, evalue, tb = exc_info()
554| ts = extract_tb(tb)
555| Log.error()
556| Log.error('%s: %s' % (etype.__name__,str(evalue)))
557| for t in ts[-5:]:
558| Log.error('[%d] %s (%s)' % (t[1], t[2], t[0]))
559| Log.error(' %s' % t[3])
560| raise
561| finally:
562| Log.end()
563|
564| '''eof'''
565|