def _checkOrth(self, T, TT, eps=0.0001, output=False): """check if the basis is orthogonal on a set of points x: TT == T*transpose(T) == c*Identity INPUT: T: matrix of values of polynomials calculated at common reference points (x) TT = T * transpose(T) eps: max numeric error """ TTd0 = (-1.*Numeric.identity(Numeric.shape(TT)[0])+1) * TT # TTd0 = TT with 0s on the main diagonal s = Numeric.sum(Numeric.sum(Numeric.absolute(TTd0))) minT = MLab.min(MLab.min(T)) maxT = MLab.max(MLab.max(T)) minTTd0 = MLab.min(MLab.min(TTd0)) maxTTd0 = MLab.max(MLab.max(TTd0)) if not s < eps: out = "NOT ORTHOG, min(T), max(T):\t%f\t%f\n" % (minT, maxT) out += " min(TTd0), max(TTd0), sum-abs-el(TTd0):\t%f\t%f\t%f" % (minTTd0, maxTTd0, s) if output: print out return False else: raise out elif output: out = "ORTHOGONAL, min(T), max(T):\t%f\t%f\n" % (minT, maxT) out += " min(TTd0), max(TTd0), sum-abs-el(TTd0):\t%f\t%f\t%f" % (minTTd0, maxTTd0, s) print out return True
def _create_matrix_plot(z_, r_x=0, r_y=0, colorcode=0, min_area=100000, scale=1): import numpy.oldnumeric.mlab as ml # Scale z and find appropriate colormap. z = z_.copy() zmax = ml.max(ml.max(z)) zmin = ml.min(ml.min(z)) if (zmin < 0) and (0 < zmax) and (not colorcode): colormap = create_bipolar_colormap() zmax = ml.max(asarray([-zmin, zmax])) z += zmax z *= (len(colormap)-1)/(2*zmax) else: if colorcode == whiteblack: colormap = create_white_black_colormap() elif colorcode == blackwhite: colormap = create_black_white_colormap() else: colormap = create_unipolar_colormap() z -= zmin if (zmax != zmin): z *= (len(colormap)-1)/(zmax-zmin) return _create_scaled_matrix_plot(colormap, z, r_x, r_y, min_area = min_area, scale = scale)
def _checkOrth(self, T, TT, eps=0.0001, output=False): """check if the basis is orthogonal on a set of points x: TT == T*transpose(T) == c*Identity INPUT: T: matrix of values of polynomials calculated at common reference points (x) TT = T * transpose(T) eps: max numeric error """ TTd0 = (-1. * Numeric.identity(Numeric.shape(TT)[0]) + 1) * TT # TTd0 = TT with 0s on the main diagonal s = Numeric.sum(Numeric.sum(Numeric.absolute(TTd0))) minT = MLab.min(MLab.min(T)) maxT = MLab.max(MLab.max(T)) minTTd0 = MLab.min(MLab.min(TTd0)) maxTTd0 = MLab.max(MLab.max(TTd0)) if not s < eps: out = "NOT ORTHOG, min(T), max(T):\t%f\t%f\n" % (minT, maxT) out += " min(TTd0), max(TTd0), sum-abs-el(TTd0):\t%f\t%f\t%f" % ( minTTd0, maxTTd0, s) if output: print out return False else: raise out elif output: out = "ORTHOGONAL, min(T), max(T):\t%f\t%f\n" % (minT, maxT) out += " min(TTd0), max(TTd0), sum-abs-el(TTd0):\t%f\t%f\t%f" % ( minTTd0, maxTTd0, s) print out return True
def _create_arrow_plot(px, pz, r_x=0, r_y=0, min_area=100000, scale=1): import numpy.oldnumeric.mlab as ml # Scale pz & px pmax = max( ml.max(ml.max(abs(pz))), ml.max(ml.max(abs(px)))) if (pmax == 0): cst = 0 else: cst = ARROWSIZE/pmax pz = pz*cst px = px*cst return _create_scaled_arrow_plot(px, pz, r_x, r_y, min_area = min_area, scale = scale)
def legend(text,linetypes=None,lleft=None,color=None,tfont='helvetica',fontsize=14,nobox=0): """Construct and place a legend. Description: Build a legend and place it on the current plot with an interactive prompt. Inputs: text -- A list of strings which document the curves. linetypes -- If not given, then the text strings are associated with the curves in the order they were originally drawn. Otherwise, associate the text strings with the corresponding curve types given. See plot for description. """ global _hold global _textcolor if color is None: color = _textcolor else: _textcolor = color if color is None: color = 'black' sys = gist.plsys() if sys == 0: gist.plsys(1) viewp = gist.viewport() gist.plsys(sys) DX = viewp[1] - viewp[0] DY = viewp[3] - viewp[2] width = DY / 10.0; if lleft is None: lleft = gist.mouse(0,0,"Click on point for lower left coordinate.") llx = lleft[0] lly = lleft[1] else: llx,lly = lleft[:2] savesys = gist.plsys() dx = width / 3.0 legarr = Numeric.arange(llx,llx+width,dx) legy = Numeric.ones(legarr.shape) dy = fontsize*points*1.2 deltay = fontsize*points / 2.8 deltax = fontsize*points / 2.6 * DX / DY ypos = lly + deltay; if linetypes is None: linetypes = _GLOBAL_LINE_TYPES[:] # copy them out gist.plsys(0) savehold = _hold _hold = 1 for k in range(len(text)): plot(legarr,ypos*legy,linetypes[k]) print linetypes[k], text[k] print llx+width+deltax, ypos-deltay if text[k] != "": gist.plt(text[k],llx+width+deltax,ypos-deltay, color=color,font=tfont,height=fontsize,tosys=0) ypos = ypos + dy _hold = savehold if nobox: pass else: gist.plsys(0) maxlen = MLab.max(map(len,text)) c1 = (llx-deltax,lly-deltay) c2 = (llx + width + deltax + fontsize*points* maxlen/1.8 + deltax, lly + len(text)*dy) linesx0 = [c1[0],c1[0],c2[0],c2[0]] linesy0 = [c1[1],c2[1],c2[1],c1[1]] linesx1 = [c1[0],c2[0],c2[0],c1[0]] linesy1 = [c2[1],c2[1],c1[1],c1[1]] gist.pldj(linesx0,linesy0,linesx1,linesy1,color=color) gist.plsys(savesys) return
def _create_phasor_movie(z_, r_x=0, r_y=0, min_area=100000, scale=1, ln=0): import numpy.oldnumeric.mlab as ml # Make movie memory. movie = [] frames = 16 z = z_.copy() if ln: colormap = create_unipolar_colormap() # Scale factors for z. # We're not sure about the lowest zmin value during the calculations. # So, we make it our own by adding a 'zcst' to each one. # Log(z**2) gives a (much) nicer plot than log(abs(z)). # We should get positive values anyhow. # Supplement to make sure the z isn't zero this really changes # the feeling of the image.. so not that correct. zcst = 1e-8 zmax = 2 * np.log(ml.max(ml.max(np.abs(z))) + zcst) zmin = np.log(zcst) # Around -23. z_scale = (len(colormap) - 1) / (zmax - zmin) # Calculate each frame. for Nr in range(0, frames): pic = _create_scaled_matrix_plot( colormap, ((np.log(z.real**2 + zcst) - zmin) * z_scale), r_x, r_y, min_area=min_area, scale=scale) movie.append(pic) z *= np.exp(2j * pi / frames) else: colormap = create_bipolar_colormap() # Scale factors for z. zmax = ml.max(ml.max(np.abs(z))) if (zmax == 0): # in this case, z=0, the middle of the color palet #(z+zmax)*z_scale) should be = len(colormap)/2 z_scale = (len(colormap) - 1) / 2 zmax = 1 else: z_scale = (len(colormap) - 1) / (2 * zmax) # Calculate each frame. for Nr in range(0, frames): pic = \ _create_scaled_matrix_plot( colormap,((z+zmax)*z_scale).real,r_x,r_y, min_area = min_area, scale = scale) movie.append(pic) z *= np.exp(2j * np.pi / frames) return movie