Changeset 3477478 in sasview for src/sas/plottools
- Timestamp:
- Mar 5, 2015 12:38:29 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- b9dbd6b
- Parents:
- 2df0b74
- Location:
- src/sas/plottools
- Files:
-
- 1 added
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/plottools/PlotPanel.py
r121f72c r3477478 40 40 for a in obj.get_children(): show_tree(a, d + 1) 41 41 42 from unitConverter import UnitConvertion as convertUnit42 from convert_units import convert_unit 43 43 44 44 … … 1790 1790 if self.xLabel == "x^(2)": 1791 1791 item.transformX(transform.toX2, transform.errToX2) 1792 xunits = convert Unit(2, xunits)1792 xunits = convert_unit(2, xunits) 1793 1793 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1794 1794 if self.xLabel == "x^(4)": 1795 1795 item.transformX(transform.toX4, transform.errToX4) 1796 xunits = convert Unit(4, xunits)1796 xunits = convert_unit(4, xunits) 1797 1797 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1798 1798 if self.xLabel == "ln(x)": … … 1805 1805 if self.xLabel == "log10(x^(4))": 1806 1806 item.transformX(transform.toX4, transform.errToX4) 1807 xunits = convert Unit(4, xunits)1807 xunits = convert_unit(4, xunits) 1808 1808 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1809 1809 _xscale = 'log' … … 1820 1820 if self.yLabel == "y^(2)": 1821 1821 item.transformY(transform.toX2, transform.errToX2) 1822 yunits = convert Unit(2, yunits)1822 yunits = convert_unit(2, yunits) 1823 1823 self.graph._yaxis_transformed("%s^{2}" % yname, "%s" % yunits) 1824 1824 if self.yLabel == "1/y": 1825 1825 item.transformY(transform.toOneOverX, transform.errOneOverX) 1826 yunits = convert Unit(-1, yunits)1826 yunits = convert_unit(-1, yunits) 1827 1827 self.graph._yaxis_transformed("1/%s" % yname, "%s" % yunits) 1828 1828 if self.yLabel == "y*x^(4)": 1829 1829 item.transformY(transform.toYX4, transform.errToYX4) 1830 xunits = convert Unit(4, self.xaxis_unit)1830 xunits = convert_unit(4, self.xaxis_unit) 1831 1831 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), 1832 1832 "%s%s" % (yunits, xunits)) … … 1834 1834 item.transformY(transform.toOneOverSqrtX, 1835 1835 transform.errOneOverSqrtX) 1836 yunits = convert Unit(-0.5, yunits)1836 yunits = convert_unit(-0.5, yunits) 1837 1837 self.graph._yaxis_transformed("1/\sqrt{%s}" % yname, 1838 1838 "%s" % yunits) … … 1843 1843 if self.yLabel == "ln(y*x^(2))": 1844 1844 item.transformY(transform.toLogYX2, transform.errToLogYX2) 1845 xunits = convert Unit(2, self.xaxis_unit)1845 xunits = convert_unit(2, self.xaxis_unit) 1846 1846 self.graph._yaxis_transformed("\ln (%s \ \ %s^{2})" % (yname, xname), 1847 1847 "%s%s" % (yunits, xunits)) 1848 1848 if self.yLabel == "ln(y*x^(4))": 1849 1849 item.transformY(transform.toLogYX4, transform.errToLogYX4) 1850 xunits = convert Unit(4, self.xaxis_unit)1850 xunits = convert_unit(4, self.xaxis_unit) 1851 1851 self.graph._yaxis_transformed("\ln (%s \ \ %s^{4})" % (yname, xname), 1852 1852 "%s%s" % (yunits, xunits)) 1853 1853 if self.yLabel == "log10(y*x^(4))": 1854 1854 item.transformY(transform.toYX4, transform.errToYX4) 1855 xunits = convert Unit(4, self.xaxis_unit)1855 xunits = convert_unit(4, self.xaxis_unit) 1856 1856 _yscale = 'log' 1857 1857 self.graph._yaxis_transformed("%s \ \ %s^{4}" % (yname, xname), … … 1859 1859 if self.viewModel == "Guinier lny vs x^(2)": 1860 1860 item.transformX(transform.toX2, transform.errToX2) 1861 xunits = convert Unit(2, xunits)1861 xunits = convert_unit(2, xunits) 1862 1862 self.graph._xaxis_transformed("%s^{2}" % xname, "%s" % xunits) 1863 1863 item.transformY(transform.toLogX, transform.errToLogX) … … 1865 1865 if self.viewModel == "Porod y*x^(4) vs x^(4)": 1866 1866 item.transformX(transform.toX4, transform.errToX4) 1867 xunits = convert Unit(4, self.xaxis_unit)1867 xunits = convert_unit(4, self.xaxis_unit) 1868 1868 self.graph._xaxis_transformed("%s^{4}" % xname, "%s" % xunits) 1869 1869 item.transformY(transform.toYX4, transform.errToYX4) -
src/sas/plottools/PropertyDialog.py
r79492222 r3477478 8 8 def __init__(self, parent, id=-1, title="Select the scale of the graph"): 9 9 wx.Dialog.__init__(self, parent, id, title) 10 """11 for the properties window12 """13 10 self.parent = parent 14 11 vbox = wx.BoxSizer(wx.VERTICAL) 15 sizer = wx.GridBagSizer(5, 5)12 sizer = wx.GridBagSizer(5, 5) 16 13 17 14 x_size = 70 … … 28 25 self.xvalue = wx.ComboBox(self, -1) 29 26 x_size += self.xvalue.GetSize()[0] 30 sizer.Add(self.xvalue, (iy, ix), (1, 1), wx.EXPAND |wx.ADJUST_MINSIZE, 0)31 27 sizer.Add(self.xvalue, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 28 32 29 ix += 2 33 30 self.yvalue = wx.ComboBox(self, -1) 34 31 x_size += self.yvalue.GetSize()[0] 35 sizer.Add(self.yvalue, (iy, ix), (1, 1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)36 32 sizer.Add(self.yvalue, (iy, ix), (1, 1), wx.EXPAND | wx.ADJUST_MINSIZE, 0) 33 37 34 ix += 2 38 35 self.view = wx.ComboBox(self, -1) 39 36 x_size += self.view.GetSize()[0] 40 37 self.view.SetMinSize((160, 30)) 41 sizer.Add(self.view, (iy, ix), (1,1),42 wx.EXPAND |wx.RIGHT|wx.ADJUST_MINSIZE, 10)38 sizer.Add(self.view, (iy, ix), (1, 1), 39 wx.EXPAND | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 43 40 self.SetMinSize((x_size, 50)) 44 vbox.Add(sizer, 0, wx.EXPAND |wx.ADJUST_MINSIZE, 0)45 46 btCancel = wx.Button(self, wx.ID_CANCEL,'Cancel')47 btOk= wx.Button(self, wx.ID_OK, "OK")41 vbox.Add(sizer, 0, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 42 43 cancel_button = wx.Button(self, wx.ID_CANCEL, 'Cancel') 44 ok_button = wx.Button(self, wx.ID_OK, "OK") 48 45 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 49 sizer_button.Add((20, 20), 1, wx.EXPAND |wx.ADJUST_MINSIZE, 0)50 sizer_button.Add( btOk, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)51 sizer_button.Add( btCancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)46 sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 47 sizer_button.Add(ok_button, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 48 sizer_button.Add(cancel_button, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 52 49 vbox.Add(sizer_button, 0, 53 wx.EXPAND |wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 10)50 wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ADJUST_MINSIZE, 10) 54 51 # scale value for x 55 52 self.xvalue.SetValue("ln(x)") … … 60 57 self.xvalue.Insert("log10(x)", 4) 61 58 self.xvalue.Insert("log10(x^(4))", 5) 62 59 63 60 # scale value for y 64 61 self.yvalue.SetValue("ln(y)") … … 81 78 self.view.Insert("XS Guinier ln(y*x) vs x^(2)", 3) 82 79 self.view.Insert("Porod y*x^(4) vs x^(4)", 4) 83 self.view.Insert("Kratky y*x^(2) vs x", 5)80 self.view.Insert("Kratky y*x^(2) vs x", 5) 84 81 self.SetSizer(vbox) 85 82 self.Fit() 86 83 self.Centre() 87 84 88 85 def setValues(self, x, y, view): 89 86 """ 90 87 """ 91 return self.xvalue.SetValue(x), self.yvalue.SetValue(y), \88 return self.xvalue.SetValue(x), self.yvalue.SetValue(y), \ 92 89 self.view.SetValue(view) 93 90 94 91 def getValues(self): 95 92 """ 96 93 """ 97 return self.xvalue.GetValue(), self.yvalue.GetValue(), \94 return self.xvalue.GetValue(), self.yvalue.GetValue(), \ 98 95 self.view.GetValue() -
src/sas/plottools/SimpleFont.py
r79492222 r3477478 20 20 21 21 class SimpleFont(wx.Dialog): 22 def __init__(self, parent,id,title):22 def __init__(self, parent, id, title): 23 23 24 wx.Dialog.__init__(self, parent,id,title,size=(440,160))24 wx.Dialog.__init__(self, parent, id, title, size=(440, 160)) 25 25 self.parent = parent 26 26 # self.SetWindowVariant(variant=FONT_VARIANT) … … 35 35 self.Centre() 36 36 self.Show() 37 37 38 38 def InitUI(self): 39 vbox = wx.BoxSizer(wx.VERTICAL) 40 hbox1 = wx.BoxSizer(wx.HORIZONTAL) 41 hbox2 = wx.BoxSizer(wx.HORIZONTAL) 42 hbox3 = wx.BoxSizer(wx.HORIZONTAL) 39 self.font_family = wx.ComboBox(self, pos=(80, 10), style=wx.CB_READONLY, size=(100, -1)) 40 self.font_style = wx.ComboBox(self, pos=(80, 60), style=wx.CB_READONLY, size=(100, -1)) 41 self.font_point = wx.ComboBox(self, pos=(300, 10), style=wx.CB_READONLY, size=(100, -1)) 42 self.font_weight = wx.ComboBox(self, pos=(300, 60), style=wx.CB_READONLY, size=(100, -1)) 43 self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100), size=(15, -1)) 44 self.tick_label_check.SetValue(False) 45 wx.Button(self, wx.ID_OK, 'OK', pos=(215, 100)) 46 wx.Button(self, wx.ID_CANCEL, 'Cancel', pos=(315, 100)) 43 47 44 gs = wx.GridSizer(2,4,-1,-1)45 46 self.fontFamily = wx.ComboBox(self,pos=(80,10),style=wx.CB_READONLY,47 size=(100,-1))48 self.fontStyle = wx.ComboBox(self,pos=(80,60),style=wx.CB_READONLY,49 size=(100,-1))50 51 self.fontPoint = wx.ComboBox(self,pos=(300,10),style=wx.CB_READONLY,52 size=(100,-1))53 self.fontWeight = wx.ComboBox(self,pos=(300,60),54 style=wx.CB_READONLY,size=(100,-1))55 self.tick_label_check = wx.CheckBox(self, -1, label='', pos=(80, 100),56 size=(15, -1))57 self.tick_label_check.SetValue(False)58 self.okButton = wx.Button(self,wx.ID_OK,'OK',pos=(215,100))59 self.closeButton = wx.Button(self,wx.ID_CANCEL,'Cancel',pos=(315,100))60 61 48 self._set_family_list() 62 49 self._set_style_list() 63 50 self._set_weight_list() 64 51 self._set_point_list() 65 66 familyText = wx.StaticText(self, label='Family:', pos=(10,12))67 sizeText = wx.StaticText(self, label='Size:',pos=(220,12))68 styleText = wx.StaticText(self, label='Style:',pos=(10,62))69 w eightText = wx.StaticText(self, label='Weight:',pos=(220,62))70 tick_label_text = wx.StaticText(self, label='Tick label?', pos=(10, 100))52 53 wx.StaticText(self, label='Family:', pos=(10, 12)) 54 wx.StaticText(self, label='Size:', pos=(220, 12)) 55 wx.StaticText(self, label='Style:', pos=(10, 62)) 56 wx.StaticText(self, label='Weight:', pos=(220, 62)) 57 tick_label_text = wx.StaticText(self, label='Tick label?', pos=(10, 100)) 71 58 tick_label_text.SetToolTipString("Apply to tick label too.") 72 59 73 60 def _set_family_list(self): 74 61 # list of font family 75 list = FAMILY 76 for idx in range(len(list)): 77 self.fontFamily.Append(list[idx],idx) 62 for idx in range(len(FAMILY)): 63 self.font_family.Append(FAMILY[idx], idx) 78 64 79 65 def _set_style_list(self): 80 66 # list of styles 81 list = STYLE 82 for idx in range(len(list)): 83 self.fontStyle.Append(list[idx],idx) 67 for idx in range(len(STYLE)): 68 self.font_style.Append(STYLE[idx], idx) 84 69 85 70 def _set_weight_list(self): 86 #list of weights 87 list = WEIGHT 88 for idx in range(len(list)): 89 self.fontWeight.Append(list[idx],idx) 71 # list of weights 72 for idx in range(len(WEIGHT)): 73 self.font_weight.Append(WEIGHT[idx], idx) 90 74 91 75 def _set_point_list(self): 92 76 # list of point sizes 93 list = SIZE 94 for idx in range(len(list)): 95 self.fontPoint.Append(str(list[idx]),idx) 77 for idx in range(len(SIZE)): 78 self.font_point.Append(str(SIZE[idx]), idx) 96 79 97 80 def get_ticklabel_check(self): … … 108 91 self.tick_label_check.SetValue(check) 109 92 110 def set_default_font(self, font):111 93 def set_default_font(self, font): 94 112 95 if not font: 113 self.font Family.SetSelection(1)114 self.font Weight.SetSelection(1)115 self.font Point.SetSelection(3)116 self.font Style.SetSelection(0)96 self.font_family.SetSelection(1) 97 self.font_weight.SetSelection(1) 98 self.font_point.SetSelection(3) 99 self.font_style.SetSelection(0) 117 100 else: 118 self.fontWeight.SetStringSelection(str(font.get_weight()))119 self.fontPoint.SetStringSelection(str(int(font.get_size())))120 self.fontFamily.SetStringSelection(str(font.get_family()[0]))121 self.fontStyle.SetStringSelection(str(font.get_style()))122 101 self.font_weight.SetStringSelection(str(font.get_weight())) 102 self.font_point.SetStringSelection(str(int(font.get_size()))) 103 self.font_family.SetStringSelection(str(font.get_family()[0])) 104 self.font_style.SetStringSelection(str(font.get_style())) 105 123 106 def get_font(self): 124 FONT= FontProperties()125 font = FONT.copy()126 font.set_size(str(self.font Point.GetValue()))127 font.set_name(str(self.font Family.GetValue()))128 font.set_slant(str(self.font Style.GetValue()))129 font.set_weight(str(self.font Weight.GetValue()))107 font_properties = FontProperties() 108 font = font_properties.copy() 109 font.set_size(str(self.font_point.GetValue())) 110 font.set_name(str(self.font_family.GetValue())) 111 font.set_slant(str(self.font_style.GetValue())) 112 font.set_weight(str(self.font_weight.GetValue())) 130 113 131 114 return font -
src/sas/plottools/SizeDialog.py
r79492222 r3477478 11 11 hbox = wx.BoxSizer(wx.HORIZONTAL) 12 12 text1 = "Enter in a custom size (> 0 accepted)" 13 msg = wx.StaticText(self, -1, text1, (30, 15), style=wx.ALIGN_CENTRE)13 msg = wx.StaticText(self, -1, text1, (30, 15), style=wx.ALIGN_CENTRE) 14 14 msg.SetLabel(text1) 15 self.myTxtCtrl = wx.TextCtrl(self, -1, '', (100, 50)) 16 17 textbox.Add(self.myTxtCtrl, flag=wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 18 border=10) 15 self.text_ctrl = wx.TextCtrl(self, -1, '', (100, 50)) 16 17 textbox.Add(self.text_ctrl, flag=wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, border=10) 19 18 vbox.Add(msg, flag=wx.ALL, border=10, proportion=1) 20 vbox.Add(textbox, flag=wx.EXPAND|wx.TOP|wx.BOTTOM|wx.ADJUST_MINSIZE, 21 border=10) 22 self.myTxtCtrl.SetValue(str(5)) 23 24 okButton = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 25 closeButton = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 19 vbox.Add(textbox, flag=wx.EXPAND | wx.TOP | wx.BOTTOM | wx.ADJUST_MINSIZE, border=10) 20 self.text_ctrl.SetValue(str(5)) 26 21 27 hbox.Add(okButton) 22 ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(70, 25)) 23 close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(70, 25)) 24 25 hbox.Add(ok_button) 28 26 hbox.Add((20, 20)) 29 hbox.Add(close Button)30 27 hbox.Add(close_button) 28 31 29 mainbox.Add(vbox, flag=wx.ALL, border=10) 32 mainbox.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5) 33 mainbox.Add(hbox, flag=wx.CENTER, 34 border=10) 30 mainbox.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5) 31 mainbox.Add(hbox, flag=wx.CENTER, border=10) 35 32 self.SetSizer(mainbox) 36 33 37 34 def getText(self): 38 35 """ 39 36 Get text typed 40 37 """ 41 return self. myTxtCtrl.GetValue()38 return self.text_ctrl.GetValue() -
src/sas/plottools/TextDialog.py
r79492222 r3477478 22 22 wx.Dialog.__init__(self, parent, id, title, size=(PNL_WIDTH, 280)) 23 23 self.parent = parent 24 # Font24 # Font 25 25 self.SetWindowVariant(variant=FONT_VARIANT) 26 26 # default … … 31 31 self.color = COLOR[0] 32 32 self.tick_label = False 33 # Dialog interface34 vbox 33 # Dialog interface 34 vbox = wx.BoxSizer(wx.VERTICAL) 35 35 text_box = wx.BoxSizer(wx.HORIZONTAL) 36 36 sizer = wx.GridBagSizer(1, 3) 37 37 _BOX_WIDTH = 60 38 font_size = 12 39 font_description= wx.StaticBox(self, -1, 'Font', 40 size=(PNL_WIDTH-20, 70)) 38 font_description = wx.StaticBox(self, -1, 'Font', size=(PNL_WIDTH - 20, 70)) 41 39 font_box = wx.StaticBoxSizer(font_description, wx.VERTICAL) 42 40 family_box = wx.BoxSizer(wx.HORIZONTAL) 43 41 style_box = wx.BoxSizer(wx.HORIZONTAL) 44 # tcA42 # tcA 45 43 if unit != None: 46 44 styles = wx.TAB_TRAVERSAL … … 53 51 tick_label_text = wx.StaticText(self, -1, 'Tick label') 54 52 tick_label_text.SetToolTipString("Apply to tick label too.") 55 self.tick_label_check = wx.CheckBox(self, -1, 56 '', (10, 10)) 53 self.tick_label_check = wx.CheckBox(self, -1, '', (10, 10)) 57 54 self.tick_label_check.SetValue(False) 58 55 self.tick_label_check.SetToolTipString("Apply to tick label too.") 59 wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(), 56 wx.EVT_CHECKBOX(self, self.tick_label_check.GetId(), 60 57 self.on_tick_label) 61 58 enter_text = 'Enter text:' 62 59 else: 63 styles = wx.TAB_TRAVERSAL |wx.TE_MULTILINE|wx.TE_LINEWRAP|\64 wx.TE_PROCESS_ENTER |wx.SUNKEN_BORDER|wx.HSCROLL60 styles = wx.TAB_TRAVERSAL | wx.TE_MULTILINE | wx.TE_LINEWRAP | \ 61 wx.TE_PROCESS_ENTER | wx.SUNKEN_BORDER | wx.HSCROLL 65 62 height = 60 66 63 unit_text = None … … 74 71 else: 75 72 enter_text += ":" 76 self.textString = wx.TextCtrl(self, -1, size=(PNL_WIDTH-30, height ),\ 77 style=styles) 78 self.textString.SetValue(str(label)) 79 self.textString.SetToolTipString("The text that will be displayed.") 80 #font family 81 self.fontFamily = wx.ComboBox(self, -1, style=wx.CB_READONLY) 82 wx.EVT_COMBOBOX(self.fontFamily, -1, self.on_family) 83 self.fontFamily.SetMinSize((_BOX_WIDTH, -1)) 73 self.text_string = wx.TextCtrl(self, -1, size=(PNL_WIDTH - 30, height), style=styles) 74 self.text_string.SetValue(str(label)) 75 self.text_string.SetToolTipString("The text that will be displayed.") 76 # font family 77 self.font_family = wx.ComboBox(self, -1, style=wx.CB_READONLY) 78 wx.EVT_COMBOBOX(self.font_family, -1, self.on_family) 79 self.font_family.SetMinSize((_BOX_WIDTH, -1)) 84 80 self._set_family_list() 85 self.font Family.SetSelection(1)86 self.font Family.SetToolTipString("Font family of the text.")87 # font weight88 self.font Weight = wx.ComboBox(self, -1, style=wx.CB_READONLY)89 wx.EVT_COMBOBOX(self.font Weight, -1, self.on_weight)90 self.font Weight.SetMinSize((_BOX_WIDTH, -1))81 self.font_family.SetSelection(1) 82 self.font_family.SetToolTipString("Font family of the text.") 83 # font weight 84 self.font_weight = wx.ComboBox(self, -1, style=wx.CB_READONLY) 85 wx.EVT_COMBOBOX(self.font_weight, -1, self.on_weight) 86 self.font_weight.SetMinSize((_BOX_WIDTH, -1)) 91 87 self._set_weight_list() 92 self.font Weight.SetSelection(1)93 self.font Weight.SetToolTipString("Font weight of the text.")94 # font family95 self.font Size = wx.ComboBox(self, -1, style=wx.CB_READONLY)96 wx.EVT_COMBOBOX(self.font Size, -1, self.on_size)97 self.font Size.SetMinSize((_BOX_WIDTH, -1))88 self.font_weight.SetSelection(1) 89 self.font_weight.SetToolTipString("Font weight of the text.") 90 # font family 91 self.font_size = wx.ComboBox(self, -1, style=wx.CB_READONLY) 92 wx.EVT_COMBOBOX(self.font_size, -1, self.on_size) 93 self.font_size.SetMinSize((_BOX_WIDTH, -1)) 98 94 self._set_size_list() 99 self.font Size.SetSelection(5)100 self.font Size.SetToolTipString("Font size of the text.")101 # font style102 self.font Style = wx.ComboBox(self, -1, style=wx.CB_READONLY)103 wx.EVT_COMBOBOX(self.font Style, -1, self.on_style)104 self.font Style.SetMinSize((_BOX_WIDTH, -1))95 self.font_size.SetSelection(5) 96 self.font_size.SetToolTipString("Font size of the text.") 97 # font style 98 self.font_style = wx.ComboBox(self, -1, style=wx.CB_READONLY) 99 wx.EVT_COMBOBOX(self.font_style, -1, self.on_style) 100 self.font_style.SetMinSize((_BOX_WIDTH, -1)) 105 101 self._set_style_list() 106 self.font Style.SetSelection(0)107 self.font Style.SetToolTipString("Font style of the text.")108 # font color109 self.font Color = wx.ComboBox(self, -1, style=wx.CB_READONLY)110 wx.EVT_COMBOBOX(self.font Color, -1, self.on_color)111 self.font Color.SetMinSize((_BOX_WIDTH, -1))102 self.font_style.SetSelection(0) 103 self.font_style.SetToolTipString("Font style of the text.") 104 # font color 105 self.font_color = wx.ComboBox(self, -1, style=wx.CB_READONLY) 106 wx.EVT_COMBOBOX(self.font_color, -1, self.on_color) 107 self.font_color.SetMinSize((_BOX_WIDTH, -1)) 112 108 self._set_color_list() 113 self.font Color.SetSelection(0)114 self.font Color.SetToolTipString("Font color of the text.")109 self.font_color.SetSelection(0) 110 self.font_color.SetToolTipString("Font color of the text.") 115 111 # Buttons on the bottom 116 112 self.static_line_1 = wx.StaticLine(self, -1) 117 self.okButton = wx.Button(self,wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25)) 118 self.closeButton = wx.Button(self,wx.ID_CANCEL, 'Cancel', 119 size=(_BOX_WIDTH, 25)) 120 113 self.ok_button = wx.Button(self, wx.ID_OK, 'OK', size=(_BOX_WIDTH, 25)) 114 self.close_button = wx.Button(self, wx.ID_CANCEL, 'Cancel', size=(_BOX_WIDTH, 25)) 115 121 116 # Intro 122 117 explanation = "Select font properties :" … … 125 120 iy = 1 126 121 sizer.Add(wx.StaticText(self, -1, explanation), (iy, ix), 127 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)122 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 128 123 family_box.Add(wx.StaticText(self, -1, 'Family :'), -1, 0) 129 family_box.Add(self.font Family, -1, 0)130 family_box.Add((_BOX_WIDTH /2,-1))124 family_box.Add(self.font_family, -1, 0) 125 family_box.Add((_BOX_WIDTH / 2, -1)) 131 126 family_box.Add(wx.StaticText(self, -1, 'Size :'), -1, 0) 132 family_box.Add(self.font Size, -1, 0)127 family_box.Add(self.font_size, -1, 0) 133 128 if unit_box != None: 134 family_box.Add((_BOX_WIDTH /2, -1))129 family_box.Add((_BOX_WIDTH / 2, -1)) 135 130 family_box.Add(tick_label_text, -1, 0) 136 131 family_box.Add(self.tick_label_check, -1, 0) 137 132 style_box.Add(wx.StaticText(self, -1, 'Style :'), -1, 0) 138 style_box.Add(self.font Style, -1, 0)139 style_box.Add((_BOX_WIDTH /2,-1))133 style_box.Add(self.font_style, -1, 0) 134 style_box.Add((_BOX_WIDTH / 2, -1)) 140 135 style_box.Add(wx.StaticText(self, -1, 'Weight :'), -1, 0) 141 style_box.Add(self.font Weight, -1, 0)142 style_box.Add((_BOX_WIDTH /2,-1))136 style_box.Add(self.font_weight, -1, 0) 137 style_box.Add((_BOX_WIDTH / 2, -1)) 143 138 style_box.Add(wx.StaticText(self, -1, 'Color :'), -1, 0) 144 style_box.Add(self.font Color, -1, 0)139 style_box.Add(self.font_color, -1, 0) 145 140 font_box.Add(family_box, -1, 10) 146 141 font_box.Add(style_box, -1, 10) … … 148 143 ix = 0 149 144 sizer.Add(font_box, (iy, ix), 150 (1, 1), wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)145 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 151 146 iy += 2 152 147 ix = 0 153 148 sizer.Add(wx.StaticText(self, -1, enter_text), (iy, ix), 154 (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)149 (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 155 150 text_box.Add((15, 10)) 156 text_box.Add(self.text String)151 text_box.Add(self.text_string) 157 152 vbox.Add(text_box, 0, wx.EXPAND, 15) 158 153 if unit_box != None: 159 154 unit_box.Add(unit_text, -1, 0) 160 155 unit_box.Add(self.unit_ctrl, -1, 0) 161 vbox.Add((5, 5))162 vbox.Add(unit_box, 0, wx.LEFT, 15)163 156 vbox.Add((5, 5)) 157 vbox.Add(unit_box, 0, wx.LEFT, 15) 158 164 159 vbox.Add((10, 10)) 165 160 vbox.Add(self.static_line_1, 0, wx.EXPAND, 10) 166 161 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 167 sizer_button.Add((20, 20), 1, wx.EXPAND |wx.ADJUST_MINSIZE, 0)168 sizer_button.Add(self.ok Button, 0,169 wx.LEFT |wx.RIGHT|wx.ADJUST_MINSIZE, 10)170 sizer_button.Add(self.close Button, 0,171 wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)172 vbox.Add(sizer_button, 0, wx.EXPAND |wx.BOTTOM|wx.TOP, 10)162 sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) 163 sizer_button.Add(self.ok_button, 0, 164 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 165 sizer_button.Add(self.close_button, 0, 166 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 167 vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 173 168 self.SetSizer(vbox) 174 169 self.Centre() 175 170 176 171 def _set_family_list(self): 177 172 """ … … 179 174 """ 180 175 # list of family choices 181 list = FAMILY 182 for idx in range(len(list)): 183 self.fontFamily.Append(list[idx], idx) 184 176 for idx in range(len(FAMILY)): 177 self.font_family.Append(FAMILY[idx], idx) 178 185 179 def _set_size_list(self): 186 180 """ … … 188 182 """ 189 183 # list of size choices 190 list = SIZE 191 for idx in range(len(list)): 192 self.fontSize.Append(str(list[idx]),idx) 193 184 for idx in range(len(SIZE)): 185 self.font_size.Append(str(SIZE[idx]), idx) 186 194 187 def _set_weight_list(self): 195 188 """ … … 197 190 """ 198 191 # list of weight choices 199 list = WEIGHT 200 for idx in range(len(list)): 201 self.fontWeight.Append(list[idx], idx) 202 192 for idx in range(len(WEIGHT)): 193 self.font_weight.Append(WEIGHT[idx], idx) 194 203 195 def _set_style_list(self): 204 196 """ … … 206 198 """ 207 199 # list of style choices 208 list = STYLE 209 for idx in range(len(list)): 210 self.fontStyle.Append(list[idx], idx) 211 200 for idx in range(len(STYLE)): 201 self.font_style.Append(STYLE[idx], idx) 202 212 203 def _set_color_list(self): 213 204 """ … … 215 206 """ 216 207 # list of tyle choices 217 list = COLOR 218 for idx in range(len(list)): 219 self.fontColor.Append(list[idx], idx) 220 208 for idx in range(len(COLOR)): 209 self.font_color.Append(COLOR[idx], idx) 210 221 211 def on_tick_label(self, event): 222 212 """ … … 225 215 event.Skip() 226 216 self.tick_label = self.tick_label_check.GetValue() 227 217 228 218 def on_family(self, event): 229 219 """ … … 231 221 """ 232 222 event.Skip() 233 self.family = self.font Family.GetValue()234 223 self.family = self.font_family.GetValue() 224 235 225 def on_style(self, event): 236 226 """ … … 238 228 """ 239 229 event.Skip() 240 self.style = self.font Style.GetValue()241 230 self.style = self.font_style.GetValue() 231 242 232 def on_weight(self, event): 243 233 """ … … 245 235 """ 246 236 event.Skip() 247 self.weight = self.font Weight.GetValue()248 237 self.weight = self.font_weight.GetValue() 238 249 239 def on_size(self, event): 250 240 """ … … 252 242 """ 253 243 event.Skip() 254 self.size = self.font Size.GetValue()255 244 self.size = self.font_size.GetValue() 245 256 246 def on_color(self, event): 257 247 """ … … 259 249 """ 260 250 event.Skip() 261 self.color = self.font Color.GetValue()262 251 self.color = self.font_color.GetValue() 252 263 253 def getText(self): 264 254 """ 265 255 Returns text string as input by user. 266 256 """ 267 return self.text String.GetValue()268 257 return self.text_string.GetValue() 258 269 259 def getUnit(self): 270 260 """ … … 272 262 """ 273 263 return self.unit_ctrl.GetValue() 274 275 def getX(self): 276 """ 277 Returns x coordinate of text box 278 """ 279 return float(self.xString.GetValue()) 280 281 def getY(self): 282 """ 283 Returns y coordinate of text box 284 """ 285 return float(self.yString.GetValue()) 286 264 287 265 def getFamily(self): 288 266 """ … … 290 268 """ 291 269 return str(self.family) 292 270 293 271 def getStyle(self): 294 272 """ … … 302 280 """ 303 281 return str(self.weight) 304 282 305 283 def getSize(self): 306 284 """ … … 308 286 """ 309 287 return int(self.size) 310 288 311 289 def getColor(self): 312 290 """ … … 314 292 """ 315 293 return str(self.color) 316 294 317 295 def getTickLabel(self): 318 296 """ -
src/sas/plottools/plottable_interactor.py
r79492222 r3477478 2 2 This module allows more interaction with the plot 3 3 """ 4 import plottables5 4 from BaseInteractor import _BaseInteractor 6 5 … … 26 25 self._dragged = False 27 26 self.connect_markers([self.axes]) 28 27 29 28 def _color(self, c): 30 29 """Return a particular colour""" 31 30 return self.colorlist[c % len(self.colorlist)] 32 31 33 32 def _symbol(self, s): 34 33 """Return a particular symbol""" 35 34 return self.symbollist[s % len(self.symbollist)] 36 35 37 def points(self, x, y, dx=None, dy=None, color=0, symbol=0, zorder=1, 36 def points(self, x, y, dx=None, dy=None, color=0, symbol=0, zorder=1, 38 37 markersize=5, label=None, hide_error=False): 39 38 """ 40 39 """ 41 # Draw curve40 # Draw curve 42 41 if self._symbol(symbol) == '-' or self._symbol(symbol) == '--': 43 42 l_width = markersize * 0.4 44 return self.curve(x=x, y=y, color=color, symbol=symbol, 43 return self.curve(x=x, y=y, color=color, symbol=symbol, 45 44 label=label, width=l_width) 46 # return45 # return 47 46 if self._symbol(symbol) == 'vline': 48 47 l_width = markersize * 0.4 49 return self.vline(x=x, y=y, color=color, 50 label=label, width=l_width) 48 return self.vline(x=x, y=y, color=color, label=label, width=l_width) 51 49 if self._symbol(symbol) == 'step': 52 50 l_width = markersize * 0.4 53 return self.step(x=x, y=y, color=color, 54 label=label, width=l_width) 51 return self.step(x=x, y=y, color=color, label=label, width=l_width) 55 52 if not self.marker == None: 56 53 self.base.connect.clear([self.marker]) … … 60 57 # Convert tuple (lo,hi) to array [(x-lo),(hi-x)] 61 58 if dx != None and type(dx) == type(()): 62 dx = nx.vstack((x -dx[0], dx[1]-x)).transpose()59 dx = nx.vstack((x - dx[0], dx[1] - x)).transpose() 63 60 if dy != None and type(dy) == type(()): 64 dy = nx.vstack((y -dy[0], dy[1]-y)).transpose()65 61 dy = nx.vstack((y - dy[0], dy[1] - y)).transpose() 62 66 63 if dx == None and dy == None: 67 # zorder = 164 # zorder = 1 68 65 self.marker = self.axes.plot(x, y, color=self.color, 69 66 marker=self._symbol(symbol), … … 72 69 zorder=zorder)[0] 73 70 else: 74 71 75 72 if hide_error: 76 # zorder = 173 # zorder = 1 77 74 self.marker = self.axes.plot(x, y, color=self.color, 78 75 marker=self._symbol(symbol), … … 81 78 zorder=1)[0] 82 79 else: 83 # zorder = 280 # zorder = 2 84 81 self.marker = self.axes.errorbar(x, y, yerr=dy, 85 82 xerr=None, … … 95 92 label=label, 96 93 zorder=1)[0] 97 98 self.connect_markers([self.marker]) 99 self.update() 100 101 def curve(self, x, y, dy=None, color=0, symbol=0, zorder=10, 94 95 self.connect_markers([self.marker]) 96 self.update() 97 98 def curve(self, x, y, dy=None, color=0, symbol=0, zorder=10, 102 99 label=None, width=2.0): 103 100 """ … … 109 106 marker='', linestyle=self._symbol(symbol), 110 107 label=label, zorder=zorder)[0] 111 112 self.connect_markers([self.marker]) 113 self.update() 114 115 116 def vline(self, x, y, dy=None, color=0, symbol=0, zorder=1, 108 109 self.connect_markers([self.marker]) 110 self.update() 111 112 113 def vline(self, x, y, dy=None, color=0, symbol=0, zorder=1, 117 114 label=None, width=2.0): 118 115 """ … … 124 121 y_min = 0.0 125 122 else: 126 y_min = min(y) *9/10127 self.marker = self.axes.vlines(x=x, ymin=y_min, ymax=y, 128 color=self.color,129 linestyle='-', label=label,130 lw=width, zorder=zorder)123 y_min = min(y) * 9 / 10 124 self.marker = self.axes.vlines(x=x, ymin=y_min, ymax=y, 125 color=self.color, 126 linestyle='-', label=label, 127 lw=width, zorder=zorder) 131 128 self.connect_markers([self.marker]) 132 129 self.update() 133 130 134 131 def step(self, x, y, dy=None, color=0, symbol=0, zorder=1, 135 label=None, width=2.0): 136 """ 137 """ 138 if not self.marker == None: 139 self.base.connect.clear([self.marker]) 140 self.color = self._color(color) 141 if self.markersize != None: 142 markersize = self.markersize 143 132 label=None, width=2.0): 133 """ 134 """ 135 if not self.marker == None: 136 self.base.connect.clear([self.marker]) 137 self.color = self._color(color) 144 138 self.marker = self.axes.step(x, y, color=self.color, 145 146 147 148 self.connect_markers([self.marker]) 149 self.update() 150 139 marker='', 140 linestyle='-', label=label, 141 lw=width, zorder=zorder)[0] 142 self.connect_markers([self.marker]) 143 self.update() 144 151 145 def connect_markers(self, markers): 152 146 """ … … 163 157 def clear(self): 164 158 print "plottable_interactor.clear()" 165 159 166 160 def _on_click(self, evt): 167 161 """ … … 183 177 if evt.button == 3: 184 178 self._context_menu = True 185 179 186 180 def _on_enter(self, evt): 187 181 """ … … 191 185 if not evt.artist.__class__.__name__ == "AxesSubplot": 192 186 self.base.plottable_selected(self.id) 193 187 194 188 if evt.artist.get_color() == 'y': 195 189 try: … … 212 206 213 207 self.axes.figure.canvas.draw_idle() 214 208 215 209 def _on_leave(self, evt): 216 210 """ … … 230 224 evt.artist.set_edgecolor(self.color) 231 225 self.axes.figure.canvas.draw_idle() 232 226 233 227 def update(self): 234 228 """ -
src/sas/plottools/plottables.py
r79492222 r3477478 45 45 import numpy 46 46 import sys 47 47 import logging 48 48 49 49 if 'any' not in dir(__builtins__): … … 53 53 return True 54 54 return False 55 55 56 56 def all(L): 57 57 for cond in L: … … 61 61 62 62 63 class Graph :63 class Graph(object): 64 64 """ 65 65 Generic plottables graph structure. 66 66 67 67 Plot styles are based on color/symbol lists. The user gets to select 68 68 the list of colors/symbols/sizes to choose from, not the application … … 77 77 the plottable objects themselves will need to provide the transformations. 78 78 Here are some examples from reflectometry: :: 79 79 80 80 independent: x -> f(x) 81 81 monitor scaling: y -> M*y … … 91 91 spin asymmetry: x -> x1, y -> (y1 - y2)/(y1 + y2) 92 92 vector net: x -> x1, y -> y1*cos(y2*pi/180) 93 93 94 94 Multiple transformations are possible, such as Q4 spin asymmetry 95 95 … … 122 122 Graphs need to be printable. A page layout program for entire plots 123 123 would be nice. 124 124 125 125 """ 126 126 def _xaxis_transformed(self, name, units): … … 134 134 self.prop["xlabel"] = name 135 135 self.prop["xunit"] = units 136 136 137 137 def _yaxis_transformed(self, name, units): 138 138 """ … … 145 145 self.prop["ylabel"] = name 146 146 self.prop["yunit"] = units 147 147 148 148 def xaxis(self, name, units): 149 149 """ … … 167 167 self.prop["ylabel_base"] = name 168 168 self.prop["yunit_base"] = units 169 169 170 170 def title(self, name): 171 171 """ … … 173 173 """ 174 174 self.prop["title"] = name 175 175 176 176 def get(self, key): 177 177 """ … … 216 216 """Detect if any graphed plottables have changed""" 217 217 return any([p.changed() for p in self.plottables]) 218 218 219 219 def get_range(self): 220 220 """ 221 221 Return the range of all displayed plottables 222 222 """ 223 min = None224 max = None223 min_value = None 224 max_value = None 225 225 for p in self.plottables: 226 226 if p.hidden == True: … … 228 228 if not p.x == None: 229 229 for x_i in p.x: 230 if min == None or x_i < min:231 min = x_i232 if max == None or x_i > max:233 max = x_i234 return min , max235 230 if min_value == None or x_i < min_value: 231 min_value = x_i 232 if max_value == None or x_i > max_value: 233 max_value = x_i 234 return min_value, max_value 235 236 236 def replace(self, plottable): 237 237 """Replace an existing plottable from the graph""" … … 252 252 del self.plottables[plottable] 253 253 self.color = len(self.plottables) 254 254 255 255 def reset_scale(self): 256 256 """ … … 268 268 "title": ""} 269 269 self.plottables = {} 270 270 271 271 def _make_labels(self): 272 272 """ … … 284 284 labels.update(c.labels(sets[c])) 285 285 return labels 286 286 287 287 def get_plottable(self, name): 288 288 """ … … 294 294 return item 295 295 return None 296 296 297 297 def returnPlottable(self): 298 298 """ … … 302 302 """ 303 303 return self.plottables 304 305 def render(self, plot):304 305 def render(self, plot): 306 306 """Redraw the graph""" 307 307 plot.connect.clearall() … … 312 312 if p.custom_color is not None: 313 313 p.render(plot, color=p.custom_color, symbol=0, 314 markersize=p.markersize, label=labels[p])314 markersize=p.markersize, label=labels[p]) 315 315 else: 316 316 p.render(plot, color=self.plottables[p], symbol=0, 317 markersize=p.markersize, label=labels[p])317 markersize=p.markersize, label=labels[p]) 318 318 plot.render() 319 319 320 320 def __init__(self, **kw): 321 321 self.reset() … … 328 328 # No need to inherit from this class, just need to provide 329 329 # the same methods. 330 class Transform :330 class Transform(object): 331 331 """ 332 332 Define a transform plugin to the plottable architecture. 333 333 334 334 Transforms operate on axes. The plottable defines the 335 335 set of transforms available for it, and the axes on which 336 336 they operate. These transforms can operate on the x axis 337 337 only, the y axis only or on the x and y axes together. 338 338 339 339 This infrastructure is not able to support transformations 340 340 such as log and polar plots as these require full control 341 341 over the drawing of axes and grids. 342 342 343 343 A transform has a number of attributes. 344 344 345 345 name 346 346 user visible name for the transform. This will 347 347 appear in the context menu for the axis and the transform 348 348 menu for the graph. 349 349 350 350 type 351 351 operational axis. This determines whether the … … 353 353 menus, or if it should appear in the context menu for 354 354 the graph. 355 355 356 356 inventory 357 (not implemented) 357 (not implemented) 358 358 a dictionary of user settable parameter names and 359 359 their associated types. These should appear as keyword 360 360 arguments to the transform call. For example, Fresnel 361 361 reflectivity requires the substrate density: 362 ``{ 'rho': type.Value(10e-6/units.angstrom**2) }`` 362 ``{ 'rho': type.Value(10e-6/units.angstrom**2) }`` 363 363 Supply reasonable defaults in the callback so that 364 364 limited plotting clients work even though they cannot 365 365 set the inventory. 366 366 367 367 """ 368 368 def __call__(self, plottable, **kwargs): … … 375 375 plottable should store the underlying data but set 376 376 the standard x,dx,y,dy,z,dz attributes appropriately. 377 377 378 378 If the call raises a NotImplemented error the dataline 379 379 will not be plotted. The associated string will usually … … 381 381 The application may or may not display the message to the 382 382 user, along with an indication of which plottable was at fault. 383 383 384 384 """ 385 385 raise NotImplemented, "Not a valid transform" … … 428 428 name = None 429 429 # Data 430 x 431 y 430 x = None 431 y = None 432 432 dx = None 433 433 dy = None … … 438 438 custom_color = None 439 439 markersize = 5 # default marker size is 'size 5' 440 440 441 441 def __init__(self): 442 442 self.view = View() … … 445 445 self._yaxis = "" 446 446 self._yunit = "" 447 447 448 448 def __setattr__(self, name, value): 449 449 """ … … 454 454 if name in ['x', 'y', 'dx', 'dy']: 455 455 self.reset_view() 456 # print "self.%s has been called" % name456 # print "self.%s has been called" % name 457 457 458 458 def set_data(self, x, y, dx=None, dy=None): … … 464 464 self.dx = dx 465 465 self.transformView() 466 466 467 467 def xaxis(self, name, units): 468 468 """ 469 469 Set the name and unit of x_axis 470 470 471 471 :param name: the name of x-axis 472 472 :param units: the units of x_axis 473 473 474 474 """ 475 475 self._xaxis = name … … 479 479 """ 480 480 Set the name and unit of y_axis 481 481 482 482 :param name: the name of y-axis 483 483 :param units: the units of y_axis 484 484 485 485 """ 486 486 self._yaxis = name 487 487 self._yunit = units 488 488 489 489 def get_xaxis(self): 490 490 """Return the units and name of x-axis""" 491 491 return self._xaxis, self._xunit 492 492 493 493 def get_yaxis(self): 494 494 """ Return the units and name of y- axis""" … … 500 500 Construct a set of unique labels for a collection of plottables of 501 501 the same type. 502 502 503 503 Returns a map from plottable to name. 504 504 505 505 """ 506 506 n = len(collection) 507 map= {}507 label_dict = {} 508 508 if n > 0: 509 509 basename = str(cls).split('.')[-1] 510 510 if n == 1: 511 map[collection[0]] = basename511 label_dict[collection[0]] = basename 512 512 else: 513 513 for i in xrange(len(collection)): 514 map[collection[i]] = "%s %d" % (basename, i)515 return map516 517 # #Use the following if @classmethod doesn't work514 label_dict[collection[i]] = "%s %d" % (basename, i) 515 return label_dict 516 517 # #Use the following if @classmethod doesn't work 518 518 # labels = classmethod(labels) 519 519 def setLabel(self, labelx, labely): 520 520 """ 521 521 It takes a label of the x and y transformation and set View parameters 522 522 523 523 :param transx: The label of x transformation is sent by Properties Dialog 524 524 :param transy: The label of y transformation is sent Properties Dialog 525 525 526 526 """ 527 527 self.view.xLabel = labelx 528 528 self.view.yLabel = labely 529 529 530 530 def set_View(self, x, y): 531 531 """Load View""" … … 533 533 self.y = y 534 534 self.reset_view() 535 535 536 536 def reset_view(self): 537 537 """Reload view with new value to plot""" … … 541 541 self.view.DXreel = self.view.dx 542 542 self.view.DYreel = self.view.dy 543 543 544 544 def render(self, plot): 545 545 """ 546 546 The base class makes sure the correct units are being used for 547 547 subsequent plottable. 548 548 549 549 For now it is assumed that the graphs are commensurate, and if you 550 put a Qx object on a Temperature graph then you had better hope 550 put a Qx object on a Temperature graph then you had better hope 551 551 that it makes sense. 552 552 553 553 """ 554 554 plot.xaxis(self._xaxis, self._xunit) 555 555 plot.yaxis(self._yaxis, self._yunit) 556 556 557 557 def is_empty(self): 558 558 """ … … 563 563 return True 564 564 return False 565 565 566 566 def colors(self): 567 567 """Return the number of colors need to render the object""" 568 568 return 1 569 569 570 570 def transformView(self): 571 571 """ … … 573 573 """ 574 574 self.view.transform(self.x, self.y, self.dx, self.dy) 575 575 576 576 def returnValuesOfView(self): 577 577 """ … … 579 579 """ 580 580 return self.view.returnXview() 581 581 582 582 def check_data_PlottableX(self): 583 583 """ … … 586 586 """ 587 587 self.view.check_data_logX() 588 588 589 589 def check_data_PlottableY(self): 590 590 """ 591 Since no transformation is made for log10(y), check that 591 Since no transformation is made for log10(y), check that 592 592 no negative values is plot in log scale 593 593 """ 594 594 self.view.check_data_logY() 595 595 596 596 def transformX(self, transx, transdx): 597 597 """ 598 598 Receive pointers to function that transform x and dx 599 599 and set corresponding View pointers 600 600 601 601 :param transx: pointer to function that transforms x 602 602 :param transdx: pointer to function that transforms dx 603 603 604 604 """ 605 605 self.view.setTransformX(transx, transdx) 606 606 607 607 def transformY(self, transy, transdy): 608 608 """ 609 609 Receive pointers to function that transform y and dy 610 610 and set corresponding View pointers 611 611 612 612 :param transy: pointer to function that transforms y 613 613 :param transdy: pointer to function that transforms dy 614 614 615 615 """ 616 616 self.view.setTransformY(transy, transdy) 617 617 618 618 def onReset(self): 619 619 """ … … 621 621 """ 622 622 self.view.onResetView() 623 623 624 624 def onFitRange(self, xmin=None, xmax=None): 625 625 """ 626 626 It limits View data range to plot from min to max 627 627 628 628 :param xmin: the minimum value of x to plot. 629 629 :param xmax: the maximum value of x to plot 630 630 631 631 """ 632 632 self.view.onFitRangeView(xmin, xmax) 633 634 635 class View :633 634 635 class View(object): 636 636 """ 637 637 Representation of the data that might include a transformation … … 672 672 :param dx: array of errors values on x 673 673 :param dy: array of error values on y 674 674 675 675 """ 676 676 # Sanity check … … 678 678 has_err_x = not (dx == None or len(dx) == 0) 679 679 has_err_y = not (dy == None or len(dy) == 0) 680 680 681 681 if(x != None) and (y != None): 682 682 if not dx == None and not len(dx) == 0 and not len(x) == len(dx): … … 689 689 msg += "and x are not of the same length" 690 690 raise ValueError, msg 691 691 692 692 if not dy == None and not len(dy) == 0 and not len(y) == len(dy): 693 693 msg = "Plottable.View: Given y and dy are not of the same " … … 750 750 self.DXreel = self.dx 751 751 self.DYreel = self.dy 752 752 753 753 def onResetView(self): 754 754 """ … … 760 760 self.dx = self.DXreel 761 761 self.dy = self.DYreel 762 762 763 763 def setTransformX(self, funcx, funcdx): 764 764 """ 765 765 Receive pointers to function that transform x and dx 766 766 and set corresponding View pointers 767 767 768 768 :param transx: pointer to function that transforms x 769 769 :param transdx: pointer to function that transforms dx … … 771 771 self.funcx = funcx 772 772 self.funcdx = funcdx 773 773 774 774 def setTransformY(self, funcy, funcdy): 775 775 """ 776 776 Receive pointers to function that transform y and dy 777 777 and set corresponding View pointers 778 778 779 779 :param transx: pointer to function that transforms y 780 780 :param transdx: pointer to function that transforms dy … … 782 782 self.funcy = funcy 783 783 self.funcdy = funcdy 784 784 785 785 def returnXview(self): 786 786 """ … … 788 788 """ 789 789 return self.x, self.y, self.dx, self.dy 790 790 791 791 def check_data_logX(self): 792 792 """ … … 805 805 for i in range(len(self.x)): 806 806 try: 807 if (self.x[i] > 0):807 if self.x[i] > 0: 808 808 tempx.append(self.x[i]) 809 809 tempdx.append(self.dx[i]) … … 811 811 tempdy.append(self.dy[i]) 812 812 except: 813 print "check_data_logX: skipping point x %g" % self.x[i] 814 print sys.exc_value 815 pass 813 logging.error("check_data_logX: skipping point x %g", self.x[i]) 814 logging.error(sys.exc_value) 816 815 self.x = tempx 817 816 self.y = tempy 818 817 self.dx = tempdx 819 818 self.dy = tempdy 820 819 821 820 def check_data_logY(self): 822 821 """ 823 822 Remove negative value in y vector 824 823 to avoid plotting negative value of Log10 825 824 826 825 """ 827 826 tempx = [] … … 833 832 if self.dy == None: 834 833 self.dy = numpy.zeros(len(self.y)) 835 if (self.yLabel == "log10(y)"):834 if self.yLabel == "log10(y)": 836 835 for i in range(len(self.x)): 837 836 try: 838 if (self.y[i] > 0):837 if self.y[i] > 0: 839 838 tempx.append(self.x[i]) 840 839 tempdx.append(self.dx[i]) … … 842 841 tempdy.append(self.dy[i]) 843 842 except: 844 print "check_data_logY: skipping point %g" % self.y[i]845 print sys.exc_value846 pass 843 logging.error("check_data_logY: skipping point %g", self.y[i]) 844 logging.error(sys.exc_value) 845 847 846 self.x = tempx 848 847 self.y = tempy 849 848 self.dx = tempdx 850 849 self.dy = tempdy 851 850 852 851 def onFitRangeView(self, xmin=None, xmax=None): 853 852 """ 854 853 It limits View data range to plot from min to max 855 854 856 855 :param xmin: the minimum value of x to plot. 857 856 :param xmax: the maximum value of x to plot 858 857 859 858 """ 860 859 tempx = [] … … 866 865 if self.dy == None: 867 866 self.dy = numpy.zeros(len(self.y)) 868 if (xmin != None) and (xmax != None):867 if xmin != None and xmax != None: 869 868 for i in range(len(self.x)): 870 if (self.x[i] >= xmin) and (self.x[i] <= xmax):869 if self.x[i] >= xmin and self.x[i] <= xmax: 871 870 tempx.append(self.x[i]) 872 871 tempdx.append(self.dx[i]) … … 878 877 self.dy = tempdy 879 878 880 879 881 880 class Data2D(Plottable): 882 881 """ … … 884 883 """ 885 884 def __init__(self, image=None, qx_data=None, qy_data=None, 886 887 885 err_image=None, xmin=None, xmax=None, ymin=None, 886 ymax=None, zmin=None, zmax=None): 888 887 """ 889 888 Draw image … … 898 897 self.source = None 899 898 self.detector = [] 900 901 # # Units for Q-values899 900 # # Units for Q-values 902 901 self.xy_unit = 'A^{-1}' 903 # # Units for I(Q) values902 # # Units for I(Q) values 904 903 self.z_unit = 'cm^{-1}' 905 904 self._zaxis = '' … … 910 909 self._yaxis = '\\rm{Q_{y}}' 911 910 self._yunit = 'A^{-1}' 912 913 # ## might remove that later914 # # Vector of Q-values at the center of each bin in x911 912 # ## might remove that later 913 # # Vector of Q-values at the center of each bin in x 915 914 self.x_bins = [] 916 # # Vector of Q-values at the center of each bin in y915 # # Vector of Q-values at the center of each bin in y 917 916 self.y_bins = [] 918 919 # x and y boundaries917 918 # x and y boundaries 920 919 self.xmin = xmin 921 920 self.xmax = xmax 922 921 self.ymin = ymin 923 922 self.ymax = ymax 924 923 925 924 self.zmin = zmin 926 925 self.zmax = zmax 927 926 self.id = None 928 927 929 928 def xaxis(self, label, unit): 930 929 """ 931 930 set x-axis 932 931 933 932 :param label: x-axis label 934 933 :param unit: x-axis unit 935 934 936 935 """ 937 936 self._xaxis = label 938 937 self._xunit = unit 939 938 940 939 def yaxis(self, label, unit): 941 940 """ 942 941 set y-axis 943 942 944 943 :param label: y-axis label 945 944 :param unit: y-axis unit 946 945 947 946 """ 948 947 self._yaxis = label 949 948 self._yunit = unit 950 949 951 950 def zaxis(self, label, unit): 952 951 """ 953 952 set z-axis 954 953 955 954 :param label: z-axis label 956 955 :param unit: z-axis unit 957 956 958 957 """ 959 958 self._zaxis = label 960 959 self._zunit = unit 961 960 962 961 def setValues(self, datainfo=None): 963 962 """ 964 963 Use datainfo object to initialize data2D 965 964 966 965 :param datainfo: object 967 966 968 967 """ 969 968 self.image = copy.deepcopy(datainfo.data) … … 971 970 self.qy_data = copy.deepcopy(datainfo.qy_data) 972 971 self.err_image = copy.deepcopy(datainfo.err_data) 973 972 974 973 self.xy_unit = datainfo.Q_unit 975 974 self.z_unit = datainfo.I_unit 976 975 self._zaxis = datainfo._zaxis 977 976 978 977 self.xaxis(datainfo._xunit, datainfo._xaxis) 979 978 self.yaxis(datainfo._yunit, datainfo._yaxis) 980 # x and y boundaries979 # x and y boundaries 981 980 self.xmin = datainfo.xmin 982 981 self.xmax = datainfo.xmax 983 982 self.ymin = datainfo.ymin 984 983 self.ymax = datainfo.ymax 985 # # Vector of Q-values at the center of each bin in x984 # # Vector of Q-values at the center of each bin in x 986 985 self.x_bins = datainfo.x_bins 987 # # Vector of Q-values at the center of each bin in y986 # # Vector of Q-values at the center of each bin in y 988 987 self.y_bins = datainfo.y_bins 989 988 990 989 def set_zrange(self, zmin=None, zmax=None): 991 990 """ … … 996 995 else: 997 996 raise "zmin is greater or equal to zmax " 998 997 999 998 def render(self, plot, **kw): 1000 999 """ 1001 1000 Renders the plottable on the graph 1002 1001 1003 1002 """ 1004 1003 plot.image(self.data, self.qx_data, self.qy_data, 1005 1004 self.xmin, self.xmax, self.ymin, 1006 1005 self.ymax, self.zmin, self.zmax, **kw) 1007 1006 1008 1007 def changed(self): 1009 1008 """ 1010 1009 """ 1011 1010 return False 1012 1011 1013 1012 @classmethod 1014 1013 def labels(cls, collection): 1015 1014 """Build a label mostly unique within a collection""" 1016 map= {}1015 label_dict = {} 1017 1016 for item in collection: 1018 #map[item] = label(item, collection)1019 #map[item] = r"$\rm{%s}$" % item.name1020 1017 if item.label == "Data2D": 1021 1018 item.label = item.name 1022 map[item] = item.label1023 return map1019 label_dict[item] = item.label 1020 return label_dict 1024 1021 1025 1022 … … 1028 1025 Data plottable: scatter plot of x,y with errors in x and y. 1029 1026 """ 1030 1027 1031 1028 def __init__(self, x, y, dx=None, dy=None): 1032 1029 """ … … 1056 1053 self.zorder = 1 1057 1054 self.hide_error = False 1058 1055 1059 1056 def render(self, plot, **kw): 1060 1057 """ … … 1068 1065 plot.interactive_points(self.view.x, self.view.y, 1069 1066 dx=self.view.dx, dy=self.view.dy, 1070 name=self.name, zorder=self.zorder, **kw)1067 name=self.name, zorder=self.zorder, **kw) 1071 1068 else: 1072 kw['id'] = 1069 kw['id'] = self.id 1073 1070 kw['hide_error'] = self.hide_error 1074 1071 kw['symbol'] = self.symbol … … 1076 1073 kw['markersize'] = self.markersize 1077 1074 plot.points(self.view.x, self.view.y, dx=self.view.dx, 1078 dy=self.view.dy, zorder=self.zorder,1079 marker=self.symbollist[self.symbol], **kw)1080 1075 dy=self.view.dy, zorder=self.zorder, 1076 marker=self.symbollist[self.symbol], **kw) 1077 1081 1078 def changed(self): 1082 1079 return False … … 1085 1082 def labels(cls, collection): 1086 1083 """Build a label mostly unique within a collection""" 1087 map= {}1084 label_dict = {} 1088 1085 for item in collection: 1089 #map[item] = label(item, collection)1090 #map[item] = r"$\rm{%s}$" % item.name1091 1086 if item.label == "data": 1092 1087 item.label = item.name 1093 map[item] = item.label1094 return map1095 1096 1088 label_dict[item] = item.label 1089 return label_dict 1090 1091 1097 1092 class Theory1D(Plottable): 1098 1093 """ 1099 1094 Theory plottable: line plot of x,y with confidence interval y. 1100 1101 1095 """ 1102 1096 def __init__(self, x, y, dy=None): … … 1105 1099 Confidence intervals in x are given by dx[i] or by (xlo[i],xhi[i]) 1106 1100 if the limits are asymmetric. 1107 1101 1108 1102 The title is the name that will show up on the legend. 1109 1103 """ 1110 1104 Plottable.__init__(self) 1111 msg = "Theory1D is no longer supported, please use Data1D and change" 1112 msg += " symbol.\n" 1105 msg = "Theory1D is no longer supported, please use Data1D and change symbol.\n" 1113 1106 raise DeprecationWarning, msg 1114 self.name = "theory" 1115 self.label = "theory" 1116 self.x = x 1117 self.y = y 1118 self.dy = dy 1119 self.xaxis('', '') 1120 self.yaxis('', '') 1121 self.view = View(self.x, self.y, None, self.dy) 1122 self.symbol = 0 1123 self.id = None 1124 self.zorder = 10 1125 1126 def render(self, plot, **kw): 1127 """ 1128 """ 1129 if self.interactive == True: 1130 kw['id'] = self.id 1131 plot.interactive_curve(self.view.x, self.view.y, 1132 dy=self.view.dy, 1133 name=self.name, zorder=self.zorder, **kw) 1134 else: 1135 kw['id'] = self.id 1136 plot.curve(self.view.x, self.view.y, dy=self.view.dy, 1137 zorder=self.zorder, **kw) 1138 1139 def changed(self): 1140 return False 1141 1142 @classmethod 1143 def labels(cls, collection): 1144 """Build a label mostly unique within a collection""" 1145 map = {} 1146 for item in collection: 1147 if item.label == "theory": 1148 item.label = item.name 1149 map[item] = item.label 1150 return map 1151 1152 1107 1153 1108 class Fit1D(Plottable): 1154 1109 """ … … 1159 1114 1160 1115 The color of the data and theory will be shared. 1161 1116 1162 1117 """ 1163 1118 def __init__(self, data=None, theory=None): … … 1194 1149 self.xpos = xpos 1195 1150 self.ypos = ypos 1196 1151 1197 1152 def render(self, plot, **kw): 1198 1153 """ … … 1206 1161 self.text, 1207 1162 label=self.name, 1208 transform=xcoords, 1209 ) 1210 1163 transform=xcoords) 1164 1211 1165 def setText(self, text): 1212 1166 """Set the text string.""" … … 1230 1184 """ 1231 1185 self.ypos = y 1232 1186 1233 1187 1234 1188 # --------------------------------------------------------------- … … 1244 1198 Plottable.__init__(self) 1245 1199 self.name = "chisq" 1246 #super( Chisq, self).__init__(None, None, None, None)1247 1200 self._chisq = chisq 1248 1201 self.xpos = 0.5 1249 1202 self.ypos = 0.9 1250 1203 1251 1204 def render(self, plot, **kw): 1252 1205 """ … … 1260 1213 1261 1214 xcoords = transforms.blended_transform_factory(plot.subplot.transAxes, 1262 plot.subplot.transAxes)1215 plot.subplot.transAxes) 1263 1216 plot.subplot.text(self.xpos, 1264 1217 self.ypos, 1265 1218 chisqTxt, label='chisq', 1266 transform=xcoords ,)1267 1219 transform=xcoords) 1220 1268 1221 def setChisq(self, chisq): 1269 1222 """ … … 1277 1230 def sample_graph(): 1278 1231 import numpy as nx 1279 1232 1280 1233 # Construct a simple graph 1281 1234 if False: 1282 x = nx.array([1, 2,3,4,5,6], 'd')1283 y = nx.array([4, 5,6,5,4,5], 'd')1235 x = nx.array([1, 2, 3, 4, 5, 6], 'd') 1236 y = nx.array([4, 5, 6, 5, 4, 5], 'd') 1284 1237 dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) 1285 1238 else: … … 1300 1253 import wx 1301 1254 from pylab_plottables import Plotter 1302 # from mplplotter import Plotter1255 # from mplplotter import Plotter 1303 1256 1304 1257 # Make a frame to show it … … 1310 1263 # render the graph to the pylab plotter 1311 1264 graph.render(plotter) 1312 1313 class GraphUpdate :1265 1266 class GraphUpdate(object): 1314 1267 callnum = 0 1315 1268 1316 1269 def __init__(self, graph, plotter): 1317 1270 self.graph, self.plotter = graph, plotter 1318 1271 1319 1272 def __call__(self): 1320 1273 if self.graph.changed(): … … 1322 1275 return True 1323 1276 return False 1324 1277 1325 1278 def onIdle(self, event): 1326 1279 self.callnum = self.callnum + 1 1327 if self.__call__(): 1280 if self.__call__(): 1328 1281 pass # event.RequestMore() 1329 1282 update = GraphUpdate(graph, plotter) -
src/sas/plottools/toolbar.py
r79492222 r3477478 9 9 # Event binding code changed after version 2.5 10 10 if wx.VERSION_STRING >= '2.5': 11 def bind(actor, event,action,**kw):12 actor.Bind(event, action,**kw)11 def bind(actor, event, action, **kw): 12 actor.Bind(event, action, **kw) 13 13 else: 14 def bind(actor, event,action,id=None):14 def bind(actor, event, action, id=None): 15 15 if id is not None: 16 16 event(actor, id, action) 17 17 else: 18 event(actor, action)18 event(actor, action) 19 19 20 20 class NavigationToolBar(NavigationToolbar2WxAgg): … … 28 28 try: save_figure = NavigationToolbar2WxAgg.save 29 29 except AttributeError: pass 30 30 31 def _init_toolbar(self): 31 32 self._parent = self.canvas.GetParent() 32 _NTB2_HOME 33 self._NTB2_BACK 33 _NTB2_HOME = wx.NewId() 34 self._NTB2_BACK = wx.NewId() 34 35 self._NTB2_FORWARD = wx.NewId() 35 self._NTB2_PAN 36 self._NTB2_ZOOM 37 _NTB2_SAVE 38 _NTB2_PRINT 39 _NTB2_RESET 36 self._NTB2_PAN = wx.NewId() 37 self._NTB2_ZOOM = wx.NewId() 38 _NTB2_SAVE = wx.NewId() 39 _NTB2_PRINT = wx.NewId() 40 _NTB2_RESET = wx.NewId() 40 41 41 42 # for mpl 1.2+ compatibility … … 46 47 self.wx_ids['Zoom'] = self._NTB2_ZOOM 47 48 48 self.SetToolBitmapSize(wx.Size(24, 24))49 self.SetToolBitmapSize(wx.Size(24, 24)) 49 50 50 51 context_tip = 'Graph Menu: \n' … … 55 56 56 57 self.InsertSeparator(1) 57 58 58 59 self.AddSimpleTool(self._NTB2_BACK, _load_bitmap('back.png'), 59 60 'Back', 'Back navigation view') … … 62 63 # todo: get new bitmap 63 64 self.AddCheckTool(self._NTB2_PAN, _load_bitmap('move.png'), 64 65 65 shortHelp='Pan', 66 longHelp='Pan with left, zoom with right') 66 67 self.AddCheckTool(self._NTB2_ZOOM, _load_bitmap('zoom_to_rect.png'), 67 68 shortHelp='Zoom', longHelp='Zoom to rectangle') 68 69 69 70 self.AddSeparator() 70 71 self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'), 71 72 'Save', 'Save plot contents to file') 72 73 73 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 74 75 self.AddSimpleTool(_NTB2_PRINT, print_bmp, 'Print', 'Print plot') 75 76 76 77 reset_bmp = wx.ArtProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR) 77 78 self.AddSimpleTool(_NTB2_RESET, reset_bmp, 'Reset', 'Reset graph range') … … 114 115 except: 115 116 logging.error("Plot toolbar could not print") 116 -
src/sas/plottools/transform.py
r79492222 r3477478 1 1 import math 2 3 2 3 4 4 def toX(x, y=None): 5 5 """ 6 6 This function is used to load value on Plottable.View 7 7 8 8 :param x: Float value 9 9 10 10 :return: x 11 11 12 12 """ 13 13 return x … … 17 17 """ 18 18 This function is used to load value on Plottable.View 19 19 20 20 :param x: Float value 21 21 22 22 :return: x 23 23 24 24 """ 25 25 if not x > 0: … … 32 32 """ 33 33 This function is used to load value on Plottable.View 34 34 35 35 Calculate x^(2) 36 37 :param x: float value 38 36 37 :param x: float value 38 39 39 """ 40 40 return x * x … … 45 45 This function is used to load value on Plottable.View 46 46 Calculate square root of x 47 48 :param x: float value 49 47 48 :param x: float value 49 50 50 """ 51 51 if not x >= 0: … … 58 58 """ 59 59 This function is used to load value on Plottable.View 60 60 61 61 Calculate x^(4) 62 63 :param x: float value 64 62 63 :param x: float value 64 65 65 """ 66 66 return x * x * x * x … … 71 71 This function is used to load value on Plottable.View 72 72 Calculate square root of x 73 74 :param x: float value 75 73 74 :param x: float value 75 76 76 """ 77 77 if not x >= 0: … … 79 79 else: 80 80 return math.sqrt(math.sqrt(x)) 81 81 82 82 83 83 def toLogX(x, y=None): … … 85 85 This function is used to load value on Plottable.View 86 86 calculate log x 87 88 :param x: float value 89 87 88 :param x: float value 89 90 90 """ 91 91 if not x > 0: … … 93 93 else: 94 94 return math.log(x) 95 95 96 96 def toOneOverX(x, y=None): 97 97 """ 98 98 """ 99 99 if x != 0: 100 return 1 /x100 return 1 / x 101 101 else: 102 102 raise ValueError, "cannot divide by zero" 103 104 103 104 105 105 def toOneOverSqrtX(y, x=None): 106 106 """ 107 107 """ 108 108 if y > 0: 109 return 1 /math.sqrt(y)109 return 1 / math.sqrt(y) 110 110 else: 111 111 raise ValueError, "transform.toOneOverSqrtX: cannot be computed" 112 113 112 113 114 114 def toLogYX2(y, x): 115 115 """ 116 116 """ 117 if (y * (x **2)) > 0:118 return math.log(y * (x **2))117 if (y * (x ** 2)) > 0: 118 return math.log(y * (x ** 2)) 119 119 else: 120 120 raise ValueError, "transform.toLogYX2: cannot be computed" 121 122 121 122 123 123 def toLogYX4(y, x): 124 124 """ 125 125 """ 126 126 if (math.pow(x, 4) * y) > 0: 127 return math.log(math.pow(x, 4) * y)128 else: 129 raise ValueError, "transform.toLogYX4: input error"130 131 127 return math.log(math.pow(x, 4) * y) 128 else: 129 raise ValueError, "transform.toLogYX4: input error" 130 131 132 132 def toYX4(y, x): 133 133 """ … … 144 144 This function is used to load value on Plottable.View 145 145 calculate log x 146 147 :param x: float value 148 146 147 :param x: float value 148 149 149 """ 150 150 if not (x * y) > 0: … … 157 157 """ 158 158 calculate error of x**2 159 160 :param x: float value 161 :param dx: float value 162 159 160 :param x: float value 161 :param dx: float value 162 163 163 """ 164 164 if dx == None: … … 170 170 """ 171 171 calculate error of x**2 172 173 :param x: float value 174 :param dx: float value 175 172 173 :param x: float value 174 :param dx: float value 175 176 176 """ 177 177 if dx == None: … … 183 183 """ 184 184 calculate error of x**2 185 186 :param x: float value 187 :param dx: float value 188 185 186 :param x: float value 187 :param dx: float value 188 189 189 """ 190 190 if dx != None: … … 193 193 else: 194 194 return 0.0 195 196 195 196 197 197 def errFromX2(x, y=None, dx=None, dy=None): 198 198 """ 199 199 calculate error of sqrt(x) 200 201 :param x: float value 202 :param dx: float value 203 204 """ 205 if (x > 0):206 if (dx != None):200 201 :param x: float value 202 :param dx: float value 203 204 """ 205 if x > 0: 206 if dx != None: 207 207 err = dx / (2 * math.sqrt(x)) 208 208 else: … … 217 217 """ 218 218 calculate error of x**4 219 220 :param x: float value 221 :param dx: float value 222 223 """ 224 if 219 220 :param x: float value 221 :param dx: float value 222 223 """ 224 if dx != None: 225 225 err = 4 * math.pow(x, 3) * dx 226 226 return math.fabs(err) 227 227 else: 228 228 return 0.0 229 230 229 230 231 231 def errFromX4(x, y=None, dx=None, dy=None): 232 232 """ 233 233 calculate error of x^1/4 234 235 :param x: float value 236 :param dx: float value 237 238 """ 239 if (x > 0):240 if (dx != None):241 err = dx / (4 * math.pow(x, 3 /4))234 235 :param x: float value 236 :param dx: float value 237 238 """ 239 if x > 0: 240 if dx != None: 241 err = dx / (4 * math.pow(x, 3 / 4)) 242 242 else: 243 243 err = 0 … … 246 246 msg = "transform.errFromX4: can't compute error of negative x" 247 247 raise ValueError, msg 248 249 248 249 250 250 def errToLog10X(x, y=None, dx=None, dy=None): 251 251 """ 252 252 calculate error of Log(x) 253 254 :param x: float value 255 :param dx: float value 256 257 """ 258 if dx == None: 259 dx = 0 260 253 254 :param x: float value 255 :param dx: float value 256 257 """ 258 if dx == None: 259 dx = 0 260 261 261 # Check that the point on the graph is positive 262 262 # within errors … … 270 270 raise ValueError, "errToLogX: divide by zero" 271 271 return dx 272 273 272 273 274 274 def errToLogX(x, y=None, dx=None, dy=None): 275 275 """ 276 276 calculate error of Log(x) 277 278 :param x: float value 279 :param dx: float value 280 281 """ 282 if dx == None: 283 dx = 0 284 277 278 :param x: float value 279 :param dx: float value 280 281 """ 282 if dx == None: 283 dx = 0 284 285 285 # Check that the x point on the graph is zero 286 286 if x != 0: 287 dx = dx /x287 dx = dx / x 288 288 else: 289 289 raise ValueError, "errToLogX: divide by zero" … … 298 298 if dy == None: 299 299 dy = 0 300 err = math.sqrt((2 * x * y * dx) **2 + ((x**2) * dy)**2)300 err = math.sqrt((2 * x * y * dx) ** 2 + ((x ** 2) * dy) ** 2) 301 301 return err 302 303 302 303 304 304 def errToLogXY(x, y, dx=None, dy=None): 305 305 """ 306 306 calculate error of Log(xy) 307 307 308 """ 309 # Check that the point on the graph is positive 310 # within errors 311 if not (x - dx) > 0 or not (y - dy) > 0: 312 msg = "Transformation does not accept point " 313 msg += " that are consistent with zero." 314 raise ValueError, msg 315 if x != 0 and y != 0: 316 if dx == None: 317 dx = 0 318 if dy == None: 319 dy = 0 320 err = (dx / x) ** 2 + (dy / y) ** 2 321 else: 322 raise ValueError, "cannot compute this error" 323 324 return math.sqrt(math.fabs(err)) 325 326 327 def errToLogYX2(x, y, dx=None, dy=None): 328 """ 329 calculate error of Log(yx**2) 330 331 """ 332 # Check that the point on the graph is positive 333 # within errors 334 if not (x - dx) > 0 or not (y - dy) > 0: 335 msg = "Transformation does not accept point" 336 msg += " that are consistent with zero." 337 raise ValueError, msg 338 if x > 0 and y > 0: 339 if dx == None: 340 dx = 0 341 if dy == None: 342 dy = 0 343 err = (2.0 * dx / x) ** 2 + (dy / y) ** 2 344 else: 345 raise ValueError, "cannot compute this error" 346 return math.sqrt(math.fabs(err)) 347 348 349 def errOneOverX(x, y=None, dx=None, dy=None): 350 """ 351 calculate error on 1/x 352 353 """ 354 if x != 0: 355 if dx == None: 356 dx = 0 357 err = dx / x ** 2 358 else: 359 raise ValueError, "Cannot compute this error" 360 return math.fabs(err) 361 362 363 def errOneOverSqrtX(x, y=None, dx=None, dy=None): 364 """ 365 Calculate error on 1/sqrt(x) 366 367 """ 368 if x > 0: 369 if dx == None: 370 dx = 0 371 err = -1 / 2 * math.pow(x, -3.0 / 2.0) * dx 372 else: 373 raise ValueError, "Cannot compute this error" 374 return math.fabs(err) 375 376 377 def errToLogYX4(x, y=None, dx=None, dy=None): 378 """ 379 error for ln(y*x^(4)) 380 381 :param x: float value 382 308 383 """ 309 384 # Check that the point on the graph is positive … … 313 388 msg += " that are consistent with zero." 314 389 raise ValueError, msg 315 if (x != 0) and (y != 0): 316 if dx == None: 317 dx = 0 318 if dy == None: 319 dy = 0 320 err = (dx/x)**2 + (dy/y)**2 321 else: 322 raise ValueError, "cannot compute this error" 323 324 return math.sqrt(math.fabs(err)) 325 326 327 def errToLogYX2(x, y, dx=None, dy=None): 328 """ 329 calculate error of Log(yx**2) 330 390 if dx == None: 391 dx = 0 392 if dy == None: 393 dy = 0 394 err = math.sqrt((4.0 * dx / x) ** 2 + (dy / y) ** 2) 395 return err 396 397 398 def errToYX4(x, y=None, dx=None, dy=None): 399 """ 400 error for (y*x^(4)) 401 402 :param x: float value 403 331 404 """ 332 405 # Check that the point on the graph is positive 333 406 # within errors 334 if (not (x - dx) > 0) or (not (y - dy) > 0): 335 msg = "Transformation does not accept point" 336 msg += " that are consistent with zero." 337 raise ValueError, msg 338 if (x > 0) and (y > 0): 339 if (dx == None): 340 dx = 0 341 if (dy == None): 342 dy = 0 343 err = (2.0*dx/x)**2 + (dy/y)**2 344 else: 345 raise ValueError, "cannot compute this error" 346 return math.sqrt(math.fabs(err)) 347 348 349 def errOneOverX(x, y=None, dx=None, dy=None): 350 """ 351 calculate error on 1/x 352 353 """ 354 if (x != 0): 355 if dx == None: 356 dx = 0 357 err = dx/x**2 358 else: 359 raise ValueError, "Cannot compute this error" 360 return math.fabs(err) 361 362 363 def errOneOverSqrtX(x, y=None, dx=None, dy=None): 364 """ 365 Calculate error on 1/sqrt(x) 366 367 """ 368 if (x > 0): 369 if dx == None: 370 dx = 0 371 err = -1/2*math.pow(x, -3.0/2.0) * dx 372 else: 373 raise ValueError, "Cannot compute this error" 374 return math.fabs(err) 375 376 377 def errToLogYX4(x, y=None, dx=None, dy=None): 378 """ 379 error for ln(y*x^(4)) 380 381 :param x: float value 382 383 """ 384 # Check that the point on the graph is positive 385 # within errors 386 if (not (x - dx) > 0) or (not (y - dy) > 0): 387 msg = "Transformation does not accept point " 388 msg += " that are consistent with zero." 389 raise ValueError, msg 407 390 408 if dx == None: 391 409 dx = 0 392 410 if dy == None: 393 411 dy = 0 394 err = math.sqrt(( 4.0 * dx/x)**2 + (dy/y)**2)412 err = math.sqrt((dy * pow(x, 4)) ** 2 + (4 * y * dx * math.pow(x, 3)) ** 2) 395 413 return err 396 397 398 def errToYX4(x, y=None, dx=None, dy=None):399 """400 error for (y*x^(4))401 402 :param x: float value403 404 """405 # Check that the point on the graph is positive406 # within errors407 408 if dx == None:409 dx = 0410 if dy == None:411 dy = 0412 err = math.sqrt((dy * pow(x, 4))**2 + (4 * y * dx * math.pow(x, 3))**2)413 return err
Note: See TracChangeset
for help on using the changeset viewer.