Package reflectometry :: Package model1d :: Package profileview :: Module reflutils

Source Code for Module reflectometry.model1d.profileview.reflutils

  1  """ 
  2  Supplementary or auxiliary Functions 
  3  """ 
  4  import scipy.special 
  5   
  6   
  7  # Some global variables for interactor 
  8  #pickradius 
  9  interface_pickradius   = 3 
 10  roughness_pickradius   = 5 
 11  flatlayer_pickradius   = 5 
 12  slopelayer_pickradius  = 10 
 13  splinelayer_pickradius = 5 
 14   
 15  #colors 
 16  interface_color = 'black' 
 17  roughness_color = 'black' 
 18  disable_color   = 'gray' 
 19  active_color    = 'red' 
 20  rho_color       = 'black' 
 21  mu_color        = 'green' 
 22  phi_color       = 'blue' 
 23  theta_color     = 'orange' 
 24  title_color     = 'red' 
 25   
 26   
 27   
28 -def showErrorMsg(parent, msg, title):
29 """ 30 Show error message 31 """ 32 import wx 33 msg = wx.MessageDialog(parent, msg, title, wx.ICON_ERROR|wx.OK) 34 msg.ShowModal()
35 #msg.Destroy() 36 37
38 -def showWarningMsg(parent, msg, title):
39 """ 40 Show Warning message 41 """ 42 import wx 43 msg = wx.MessageDialog(parent, msg, title, wx.ICON_WARNING|wx.OK) 44 msg.ShowModal()
45 #msg.Destroy() 46 47
48 -def CheckValid( s ):
49 """ 50 Translate the string into float, and check it. 51 """ 52 try: 53 val = float(s) 54 except: 55 val = 1.0 56 msg="%s can't change to float"%(s) 57 raise ValueError(msg) 58 59 return val
60 61
62 -def twinx(ax=None):
63 """ 64 Make a second axes overlay ax 65 (or the current axes if ax is None) sharing the xaxis. 66 67 The ticks for ax2 will be placed on the right, 68 and the ax2 instance is returned. See examples/two_scales.py 69 70 Warning: This is a function to simulate the pylab.twinx in WX 71 """ 72 if ax == None: 73 return None 74 75 ax2 = ax.figure.add_axes( ax.get_position(), sharex=ax, frameon=False ) 76 ax2.yaxis.tick_right() 77 ax2.yaxis.set_label_position('right') 78 ax.yaxis.tick_left() 79 80 return ax2
81 82
83 -def clear_axes( ax ):
84 """ 85 Clear axes from a figure 86 """ 87 ax.legend_=None 88 ax.set_title(r"") 89 ax.set_xlabel(r"") 90 ax.set_ylabel(r"") 91 ax.figure.canvas.draw_idle()
92 93 94
95 -def filterP( f ):
96 """ 97 Translate a obj parameter into "string" format 98 """ 99 if hasattr(f,'build'): 100 return f.build() 101 else: 102 return f
103 104 105
106 -def decodeP( p ):
107 108 from reflectometry.model1d.model.bspline import BSpline 109 from reflectometry.model1d.model.tetheredPolymer import TetheredPolymer 110 """ 111 Translate a parameter into obj format 112 113 Decompose a parameter. 114 In this code. It only works for spline obj 115 """ 116 try: ret = eval(p) 117 except: ret = p 118 return ret
119