Changeset 7116b6e0 in sasview
- Timestamp:
- Jun 4, 2010 1:38:32 PM (15 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:
- 79ac6f8
- Parents:
- d84a90c
- Location:
- prview
- Files:
-
- 55 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/local_config.py
r009f827 r7116b6e0 1 1 """ 2 2 Application settings 3 3 """ 4 4 import time -
prview/perspectives/pr/explore_dialog.py
r3b865c1 r7116b6e0 1 2 ################################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 # 7 #See the license text in license.txt 8 # 9 #copyright 2009, University of Tennessee 10 ################################################################################ 11 1 12 """ 2 Dialog panel to explore the P(r) inversion results for a range 3 of D_max value. User picks a number of points and a range of 4 distances, then can toggle between inversion outputs and see 5 their distribution as a function of D_max. 13 Dialog panel to explore the P(r) inversion results for a range 14 of D_max value. User picks a number of points and a range of 15 distances, then can toggle between inversion outputs and see 16 their distribution as a function of D_max. 17 """ 6 18 7 This software was developed by the University of Tennessee as part of the 8 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 9 project funded by the US National Science Foundation. 10 11 See the license text in license.txt 12 13 copyright 2009, University of Tennessee 14 """ 19 15 20 import wx 16 21 import numpy … … 37 42 class OutputPlot(PlotPanel): 38 43 """ 39 40 44 Plot panel used to show the selected results as a function 45 of D_max 41 46 """ 42 47 def __init__(self, d_min, d_max, parent, id = -1, color = None,\ 43 48 dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 44 49 """ 45 Initialization. The parameters added to PlotPanel are: 46 47 @param d_min: Minimum value of D_max to explore 48 @param d_max: Maximum value of D_max to explore 50 Initialization. The parameters added to PlotPanel are: 51 52 :param d_min: Minimum value of D_max to explore 53 :param d_max: Maximum value of D_max to explore 54 49 55 """ 50 56 PlotPanel.__init__(self, parent, id = id, style = style, **kwargs) … … 74 80 def onContextMenu(self, event): 75 81 """ 76 77 78 #TODO: Would be nice to add printing and log/linear scales.82 Default context menu for the plot panel 83 84 :TODO: Would be nice to add printing and log/linear scales. 79 85 The current verison of plottools no longer plays well with 80 86 plots outside of guiframe. Guiframe team needs to fix this. … … 95 101 self.PopupMenu(slicerpop, pos) 96 102 97 98 103 class Results: 99 104 """ 100 101 105 Class to hold the inversion output parameters 106 as a function of D_max 102 107 """ 103 108 def __init__(self): 104 109 """ 105 106 110 Initialization. Create empty arrays 111 and dictionary of labels. 107 112 """ 108 113 # Array of output for each inversion … … 128 133 class ExploreDialog(wx.Dialog): 129 134 """ 130 131 135 The explorer dialog box. This dialog is meant to be 136 invoked by the InversionControl class. 132 137 """ 133 138 134 139 def __init__(self, pr_state, nfunc, *args, **kwds): 135 140 """ 136 Initialization. The parameters added to Dialog are: 137 138 @param pr_state: sans.pr.invertor.Invertor object 139 @param nfunc: Number of terms in the expansion 141 Initialization. The parameters added to Dialog are: 142 143 :param pr_state: sans.pr.invertor.Invertor object 144 :param nfunc: Number of terms in the expansion 145 140 146 """ 141 147 kwds["style"] = wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE … … 174 180 class Event: 175 181 """ 176 182 Class that holds the content of the form 177 183 """ 178 184 ## Number of points to be plotted … … 185 191 def _get_values(self, event=None): 186 192 """ 187 Invoked when the user changes a value of the form. 188 Check that the values are of the right type. 189 190 @return: ExploreDialog.Event object if the content is good, None otherwise 193 Invoked when the user changes a value of the form. 194 Check that the values are of the right type. 195 196 :return: ExploreDialog.Event object if the content is good, 197 None otherwise 191 198 """ 192 199 # Flag to make sure that all values are good … … 237 244 def _plot_output(self, event=None): 238 245 """ 239 240 246 Invoked when a new output type is selected for plotting, 247 or when a new computation is finished. 241 248 """ 242 249 # Get the output type selection … … 264 271 def __do_layout(self): 265 272 """ 266 273 Do the layout of the dialog 267 274 """ 268 275 # Dialog box properties … … 337 344 def _recalc(self, event=None): 338 345 """ 339 340 346 Invoked when the user changed a value on the form. 347 Process the form and compute the output to be plottted. 341 348 """ 342 349 # Get the content of the form … … 381 388 382 389 ##### testing code ############################################################ 390 """ 391 Example: :: 392 383 393 class MyApp(wx.App): 384 """385 386 """394 395 #Test application used to invoke the ExploreDialog for testing 396 387 397 def OnInit(self): 388 398 from inversion_state import Reader … … 391 401 392 402 def call_back(state, datainfo=None): 393 """394 395 396 """403 404 #Dummy call-back method used by the P(r) 405 #file reader. 406 397 407 print state 398 408 … … 429 439 app = MyApp(0) 430 440 app.MainLoop() 431 441 442 """ -
prview/perspectives/pr/inversion_panel.py
r9bc4ed23 r7116b6e0 17 17 18 18 class InversionControl(ScrolledPanel): 19 """ 20 """ 19 21 window_name = 'pr_control' 20 22 window_caption = "P(r) control panel" … … 27 29 28 30 def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): 31 """ 32 """ 29 33 ScrolledPanel.__init__(self, parent, id = id, **kwargs) 30 34 self.SetupScrolling() … … 85 89 def __setattr__(self, name, value): 86 90 """ 87 91 Allow direct hooks to text boxes 88 92 """ 89 93 if name=='nfunc': … … 138 142 def __getattr__(self, name): 139 143 """ 140 144 Allow direct hooks to text boxes 141 145 """ 142 146 if name=='nfunc': … … 234 238 def _save_state(self, evt=None): 235 239 """ 236 240 Method used to create a memento of the current state 237 241 238 @return: state object242 :return: state object 239 243 """ 240 244 # Ask the user the location of the file to write to. … … 290 294 def set_state(self, state): 291 295 """ 292 293 294 295 296 297 @param state: InversionState object296 Set the state of the panel and inversion problem to 297 the state passed as a parameter. 298 Execute the inversion immediately after filling the 299 controls. 300 301 :param state: InversionState object 298 302 """ 299 303 if state.nfunc is not None: … … 638 642 def _on_accept_alpha(self, evt): 639 643 """ 640 641 644 User has accepted the estimated alpha, 645 set it as part of the input parameters 642 646 """ 643 647 try: … … 653 657 def _on_accept_nterms(self, evt): 654 658 """ 655 656 659 User has accepted the estimated number of terms, 660 set it as part of the input parameters 657 661 """ 658 662 try: … … 668 672 def _on_reset(self, evt): 669 673 """ 670 674 Resets inversion parameters 671 675 """ 672 676 self.nfunc = self.manager.DEFAULT_NFUNC … … 691 695 def _on_pars_changed(self, evt=None): 692 696 """ 693 694 695 697 Called when an input parameter has changed 698 We will estimate the alpha parameter behind the 699 scenes. 696 700 """ 697 701 flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() … … 711 715 width=width) 712 716 713 def _read_pars(self, evt=None): 717 def _read_pars(self, evt=None): 718 """ 719 """ 714 720 alpha = 0 715 721 nfunc = 5 … … 818 824 def _on_explore(self, evt): 819 825 """ 820 826 Invoke the d_max exploration dialog 821 827 """ 822 828 from explore_dialog import ExploreDialog … … 831 837 def _on_invert(self, evt): 832 838 """ 833 Perform inversion 834 @param silent: when True, there will be no output for the user 839 Perform inversion 840 841 :param silent: when True, there will be no output for the user 842 835 843 """ 836 844 # Get the data from the form … … 858 866 def _change_file(self, evt=None, filepath=None): 859 867 """ 860 868 Choose a new input file for I(q) 861 869 """ 862 870 import os … … 878 886 879 887 class HelpDialog(wx.Dialog): 888 """ 889 """ 880 890 def __init__(self, parent, id): 891 """ 892 """ 881 893 from sans.pr.invertor import help 882 894 wx.Dialog.__init__(self, parent, id, size=(400, 420)) … … 913 925 class PrDistDialog(wx.Dialog): 914 926 """ 915 916 927 Property dialog to let the user change the number 928 of points on the P(r) plot. 917 929 """ 918 930 def __init__(self, parent, id): … … 956 968 def _checkValues(self, event): 957 969 """ 958 970 Check the dialog content. 959 971 """ 960 972 flag = True … … 972 984 def get_content(self): 973 985 """ 974 975 976 986 Return the content of the dialog. 987 At this point the values have already been 988 checked. 977 989 """ 978 990 value = int(self.npts_ctl.GetValue()) … … 981 993 def set_content(self, npts): 982 994 """ 983 995 Initialize the content of the dialog. 984 996 """ 985 997 self.npts_ctl.SetValue("%i" % npts) 986 998 987 999 ##### testing code ############################################################ 1000 """ 1001 Example: :: 1002 988 1003 class TestPlot: 989 1004 def __init__(self, text): … … 1006 1021 app.MainLoop() 1007 1022 1023 """ 1008 1024 ##### end of testing code ##################################################### -
prview/perspectives/pr/inversion_state.py
r80d2872 r7116b6e0 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 1 2 ################################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 # 7 #See the license text in license.txt 8 # 9 #copyright 2009, University of Tennessee 10 ################################################################################ 11 12 10 13 import time, os, sys 11 14 import logging … … 22 25 # Translation of names between stored and object data 23 26 ## List of P(r) inversion inputs 24 in_list = [["nterms", "nfunc"],27 in_list = [["nterms", "nfunc"], 25 28 ["d_max", "d_max"], 26 29 ["alpha", "alpha"], … … 31 34 32 35 ## List of P(r) inversion outputs 33 out_list = [["elapsed", "elapsed"],36 out_list = [["elapsed", "elapsed"], 34 37 ["rg", "rg"], 35 38 ["iq0", "iq0"], … … 44 47 class InversionState(object): 45 48 """ 46 49 Class to hold the state information of the InversionControl panel. 47 50 """ 48 51 def __init__(self): 49 52 """ 50 53 Default values 51 54 """ 52 55 # Input … … 93 96 def __str__(self): 94 97 """ 95 Pretty print 96 97 @return: string representing the state 98 Pretty print 99 100 :return: string representing the state 101 98 102 """ 99 103 state = "File: %s\n" % self.file … … 128 132 def toXML(self, file="pr_state.prv", doc=None, entry_node=None): 129 133 """ 130 Writes the state of the InversionControl panel to file, as XML. 131 132 Compatible with standalone writing, or appending to an 133 already existing XML document. In that case, the XML document 134 is required. An optional entry node in the XML document may also be given. 135 136 @param file: file to write to 137 @param doc: XML document object [optional] 138 @param entry_node: XML node within the XML document at which we will append the data [optional] 134 Writes the state of the InversionControl panel to file, as XML. 135 136 Compatible with standalone writing, or appending to an 137 already existing XML document. In that case, the XML document 138 is required. An optional entry node in the XML document may also be given. 139 140 :param file: file to write to 141 :param doc: XML document object [optional] 142 :param entry_node: XML node within the XML document at which 143 we will append the data [optional] 144 139 145 """ 140 146 from xml.dom.minidom import getDOMImplementation … … 213 219 def fromXML(self, file=None, node=None): 214 220 """ 215 Load a P(r) inversion state from a file 216 217 @param file: .prv file 218 @param node: node of a XML document to read from 221 Load a P(r) inversion state from a file 222 223 :param file: .prv file 224 :param node: node of a XML document to read from 225 219 226 """ 220 227 if file is not None: … … 328 335 class Reader(CansasReader): 329 336 """ 330 337 Class to load a .prv P(r) inversion file 331 338 """ 332 339 ## File type … … 340 347 def __init__(self, call_back, cansas=True): 341 348 """ 342 Initialize the call-back method to be called 343 after we load a file 344 @param call_back: call-back method 345 @param cansas: True = files will be written/read in CanSAS format 346 False = write CanSAS format 349 Initialize the call-back method to be called 350 after we load a file 351 352 :param call_back: call-back method 353 :param cansas: True = files will be written/read in CanSAS format 354 False = write CanSAS format 347 355 348 356 """ … … 354 362 def read(self, path): 355 363 """ 356 Load a new P(r) inversion state from file 357 358 @param path: file path 359 @return: None 364 Load a new P(r) inversion state from file 365 366 :param path: file path 367 368 :return: None 369 360 370 """ 361 371 if self.cansas==True: … … 366 376 def _read_standalone(self, path): 367 377 """ 368 Load a new P(r) inversion state from file. 369 The P(r) node is assumed to be the top element. 370 371 @param path: file path 372 @return: None 378 Load a new P(r) inversion state from file. 379 The P(r) node is assumed to be the top element. 380 381 :param path: file path 382 383 :return: None 384 373 385 """ 374 386 # Read the new state from file … … 382 394 def _parse_prstate(self, entry): 383 395 """ 384 Read a p(r) inversion result from an XML node 385 @param entry: XML node to read from 386 @return: InversionState object 396 Read a p(r) inversion result from an XML node 397 398 :param entry: XML node to read from 399 400 :return: InversionState object 401 387 402 """ 388 403 # Create an empty state … … 400 415 def _read_cansas(self, path): 401 416 """ 402 Load data and P(r) information from a CanSAS XML file. 403 404 @param path: file path 405 @return: Data1D object if a single SASentry was found, 406 or a list of Data1D objects if multiple entries were found, 407 or None of nothing was found 408 @raise RuntimeError: when the file can't be opened 409 @raise ValueError: when the length of the data vectors are inconsistent 417 Load data and P(r) information from a CanSAS XML file. 418 419 :param path: file path 420 421 :return: Data1D object if a single SASentry was found, 422 or a list of Data1D objects if multiple entries were found, 423 or None of nothing was found 424 425 :raise RuntimeError: when the file can't be opened 426 :raise ValueError: when the length of the data vectors are inconsistent 427 410 428 """ 411 429 output = [] … … 448 466 def write(self, filename, datainfo=None, prstate=None): 449 467 """ 450 451 452 @param filename: name of the file to write453 @param datainfo: Data1D object454 @param prstate: InversionState object455 """456 468 Write the content of a Data1D as a CanSAS XML file 469 470 :param filename: name of the file to write 471 :param datainfo: Data1D object 472 :param prstate: InversionState object 473 474 """ 457 475 # Sanity check 458 476 if self.cansas == True: -
prview/perspectives/pr/pr.py
rf0ff8d65 r7116b6e0 1 """ 2 This software was developed by the University of Tennessee as part of the 3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 4 project funded by the US National Science Foundation. 5 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 1 2 ################################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 # 7 #See the license text in license.txt 8 # 9 #copyright 2009, University of Tennessee 10 ################################################################################ 11 10 12 11 13 # Make sure the option of saving each curve is available … … 39 41 40 42 class Plugin: 41 43 """ 44 """ 42 45 DEFAULT_ALPHA = 0.0001 43 46 DEFAULT_NFUNC = 10 … … 45 48 46 49 def __init__(self, standalone=True): 50 """ 51 """ 47 52 ## Plug-in name 48 53 self.sub_menu = "Pr inversion" … … 114 119 def set_state(self, state, datainfo=None): 115 120 """ 116 Call-back method for the inversion state reader. 117 This method is called when a .prv file is loaded. 118 119 @param state: InversionState object 120 @param datainfo: Data1D object [optional] 121 Call-back method for the inversion state reader. 122 This method is called when a .prv file is loaded. 123 124 :param state: InversionState object 125 :param datainfo: Data1D object [optional] 126 121 127 """ 122 128 try: … … 150 156 def populate_menu(self, id, owner): 151 157 """ 152 158 Create a menu for the plug-in 153 159 """ 154 160 return [] … … 156 162 def help(self, evt): 157 163 """ 158 Show a general help dialog. 159 TODO: replace the text with a nice image 164 Show a general help dialog. 165 166 :TODO: replace the text with a nice image 167 160 168 """ 161 169 from inversion_panel import HelpDialog … … 167 175 168 176 def _fit_pr(self, evt): 177 """ 178 """ 169 179 from sans.pr.invertor import Invertor 170 180 import numpy … … 178 188 d_max = 2*radius 179 189 180 181 190 r = pylab.arange(0.01, d_max, d_max/51.0) 182 191 M = len(r) … … 191 200 pr_err[j] = math.sqrt(y[j]) 192 201 193 194 202 y = y/sum*d_max/len(r) 195 196 197 203 198 204 # Perform fit … … 207 213 print "%g +- %g" % (out[i], math.sqrt(cov[i][i])) 208 214 209 210 215 # Show input P(r) 211 216 new_plot = Data1D(pr.x, pr.y, dy=pr.err) … … 222 227 self.show_iq(out, pr, q) 223 228 224 225 229 def show_shpere(self, x, radius=70.0, x_range=70.0): 230 """ 231 """ 226 232 import numpy 227 233 import pylab … … 251 257 def get_npts(self): 252 258 """ 253 259 Returns the number of points in the I(q) data 254 260 """ 255 261 try: … … 259 265 260 266 def show_iq(self, out, pr, q=None): 267 """ 268 """ 261 269 import numpy 262 270 import pylab … … 334 342 def _on_pr_npts(self, evt): 335 343 """ 336 344 Redisplay P(r) with a different number of points 337 345 """ 338 346 from inversion_panel import PrDistDialog … … 348 356 349 357 def show_pr(self, out, pr, cov=None): 358 """ 359 """ 350 360 import numpy 351 361 import pylab … … 402 412 def choose_file(self, path=None): 403 413 """ 404 405 414 """ 406 415 #TODO: this should be in a common module … … 410 419 def load(self, path): 411 420 """ 412 413 421 Load data. This will eventually be replaced 422 by our standard DataLoader class. 414 423 """ 415 424 class FileData: … … 458 467 def load_columns(self, path = "sphere_60_q0_2.txt"): 459 468 """ 460 469 Load 2- or 3- column ascii 461 470 """ 462 471 import numpy, math, sys … … 502 511 def load_abs(self, path): 503 512 """ 504 Load an IGOR .ABS reduced file 505 @param path: file path 506 @return: x, y, err vectors 513 Load an IGOR .ABS reduced file 514 515 :param path: file path 516 517 :return: x, y, err vectors 518 507 519 """ 508 520 import numpy, math, sys … … 551 563 return data_x, data_y, data_err 552 564 553 554 555 565 def pr_theory(self, r, R): 556 """ 557 566 """ 558 567 """ 559 568 if r<=2*R: … … 564 573 def get_context_menu(self, graph=None): 565 574 """ 566 Get the context menu items available for P(r) 567 @param graph: the Graph object to which we attach the context menu 568 @return: a list of menu items with call-back function 575 Get the context menu items available for P(r) 576 577 :param graph: the Graph object to which we attach the context menu 578 579 :return: a list of menu items with call-back function 580 569 581 """ 570 582 # Look whether this Graph contains P(r) data … … 604 616 def _on_disable_scaling(self, evt): 605 617 """ 606 Disable P(r) scaling 607 @param evt: Menu event 618 Disable P(r) scaling 619 620 :param evt: Menu event 621 608 622 """ 609 623 self._normalize_output = False … … 623 637 def _on_normalize(self, evt): 624 638 """ 625 Normalize the area under the P(r) curve to 1. 626 This operation is done for all displayed plots. 627 628 @param evt: Menu event 639 Normalize the area under the P(r) curve to 1. 640 This operation is done for all displayed plots. 641 642 :param evt: Menu event 643 629 644 """ 630 645 self._normalize_output = True … … 647 662 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True, 648 663 title=self._added_plots[plot].name)) 649 650 651 664 652 665 def _on_scale_unity(self, evt): 653 666 """ 654 Scale the maximum P(r) value on each displayed plot to 1. 655 656 @param evt: Menu event 667 Scale the maximum P(r) value on each displayed plot to 1. 668 669 :param evt: Menu event 670 657 671 """ 658 672 self._scale_output_unity = True … … 680 694 def _on_add_data(self, evt): 681 695 """ 682 Add a data curve to the plot 683 WARNING: this will be removed once guiframe.plotting has its full functionality 696 Add a data curve to the plot 697 698 :WARNING: this will be removed once guiframe.plotting has 699 its full functionality 684 700 """ 685 701 path = self.choose_file() … … 731 747 732 748 def start_thread(self): 749 """ 750 """ 733 751 from pr_thread import CalcPr 734 752 from copy import deepcopy … … 744 762 745 763 def _thread_error(self, error): 764 """ 765 """ 746 766 wx.PostEvent(self.parent, StatusEvent(status=error)) 747 767 748 768 def _estimate_completed(self, alpha, message, elapsed): 749 769 """ 750 Parameter estimation completed, 751 display the results to the user 752 @param alpha: estimated best alpha 753 @param elapsed: computation time 770 Parameter estimation completed, 771 display the results to the user 772 773 :param alpha: estimated best alpha 774 :param elapsed: computation time 775 754 776 """ 755 777 # Save useful info … … 765 787 def _estimateNT_completed(self, nterms, alpha, message, elapsed): 766 788 """ 767 Parameter estimation completed, 768 display the results to the user 769 @param alpha: estimated best alpha 770 @param nterms: estimated number of terms 771 @param elapsed: computation time 789 Parameter estimation completed, 790 display the results to the user 791 792 :param alpha: estimated best alpha 793 :param nterms: estimated number of terms 794 :param elapsed: computation time 795 772 796 """ 773 797 # Save useful info … … 780 804 def _completed(self, out, cov, pr, elapsed): 781 805 """ 782 Method called with the results when the inversion 783 is done 784 785 @param out: output coefficient for the base functions 786 @param cov: covariance matrix 787 @param pr: Invertor instance 788 @param elapsed: time spent computing 806 Method called with the results when the inversion 807 is done 808 809 :param out: output coefficient for the base functions 810 :param cov: covariance matrix 811 :param pr: Invertor instance 812 :param elapsed: time spent computing 813 789 814 """ 790 815 from copy import deepcopy … … 843 868 def show_data(self, path=None, reset=False): 844 869 """ 845 Show data read from a file 846 @param path: file path 847 @param reset: if True all other plottables will be cleared 870 Show data read from a file 871 872 :param path: file path 873 :param reset: if True all other plottables will be cleared 874 848 875 """ 849 876 if path is not None: … … 883 910 def save_data(self, filepath, prstate=None): 884 911 """ 885 Save data in provided state object. 886 TODO: move the state code away from inversion_panel and move it here. 887 Then remove the "prstate" input and make this method private. 888 889 @param filepath: path of file to write to 890 @param prstate: P(r) inversion state 912 Save data in provided state object. 913 914 :TODO: move the state code away from inversion_panel and move it here. 915 Then remove the "prstate" input and make this method private. 916 917 :param filepath: path of file to write to 918 :param prstate: P(r) inversion state 919 891 920 """ 892 921 #TODO: do we need this or can we use DataLoader.loader.save directly? … … 906 935 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 907 936 bck=False, height=0, width=0): 937 """ 938 """ 908 939 self.alpha = alpha 909 940 self.nfunc = nfunc … … 925 956 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 926 957 bck=False, height=0, width=0): 958 """ 959 """ 927 960 self.alpha = alpha 928 961 self.nfunc = nfunc … … 944 977 def _create_plot_pr(self, estimate=False): 945 978 """ 946 Create and prepare invertor instance from 947 a plottable data set. 948 @param path: path of the file to read in 979 Create and prepare invertor instance from 980 a plottable data set. 981 982 :param path: path of the file to read in 983 949 984 """ 950 985 # Sanity check … … 1000 1035 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 1001 1036 bck=False, height=0, width=0): 1037 """ 1038 """ 1002 1039 self.alpha = alpha 1003 1040 self.nfunc = nfunc … … 1019 1056 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 1020 1057 bck=False, height=0, width=0): 1058 """ 1059 """ 1021 1060 self.alpha = alpha 1022 1061 self.nfunc = nfunc … … 1039 1078 def _create_file_pr(self, path): 1040 1079 """ 1041 Create and prepare invertor instance from 1042 a file data set. 1043 @param path: path of the file to read in 1080 Create and prepare invertor instance from 1081 a file data set. 1082 1083 :param path: path of the file to read in 1084 1044 1085 """ 1045 1086 # Load data … … 1107 1148 1108 1149 def perform_estimate(self): 1150 """ 1151 """ 1109 1152 from pr_thread import EstimatePr 1110 1153 from copy import deepcopy … … 1122 1165 1123 1166 def perform_estimateNT(self): 1167 """ 1168 """ 1124 1169 from pr_thread import EstimateNT 1125 1170 from copy import deepcopy … … 1141 1186 1142 1187 def perform_inversion(self): 1143 1188 """ 1189 """ 1144 1190 # Time estimate 1145 1191 #estimated = self.elapsed*self.nfunc**2 … … 1161 1207 except: 1162 1208 print "%d: %g +- ?" % (i, out[i]) 1163 1164 1165 1209 1166 1210 # Make a plot of I(q) data -
prview/perspectives/pr/pr_thread.py
ra00ee4c r7116b6e0 4 4 class CalcPr(CalcThread): 5 5 """ 6 Compute P(r) 6 Compute P(r) 7 """ 8 9 def __init__(self, pr, nfunc=5, error_func=None, 10 completefn = None, 11 updatefn = None, 12 yieldtime = 0.01, 13 worktime = 0.01 14 ): 15 """ 16 """ 17 CalcThread.__init__(self,completefn, 18 updatefn, 19 yieldtime, 20 worktime) 21 self.pr = pr 22 self.nfunc = nfunc 23 self.error_func = error_func 24 self.starttime = 0 25 26 def compute(self): 27 """ 28 Perform P(r) inversion 29 """ 30 try: 31 self.starttime = time.time() 32 out, cov = self.pr.invert(self.nfunc) 33 #out, cov = self.pr.lstsq(self.nfunc) 34 #out, cov = self.pr.invert_optimize(self.nfunc) 35 elapsed = time.time()-self.starttime 36 self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed) 37 except KeyboardInterrupt: 38 # Thread was interrupted, just proceed 39 pass 40 except: 41 if not self.error_func==None: 42 self.error_func("CalcPr.compute: %s" % sys.exc_value) 43 44 class EstimatePr(CalcThread): 45 """ 46 Estimate P(r) 7 47 """ 8 48 … … 24 64 def compute(self): 25 65 """ 26 Perform P(r) inversion 27 """ 28 try: 29 self.starttime = time.time() 30 out, cov = self.pr.invert(self.nfunc) 31 #out, cov = self.pr.lstsq(self.nfunc) 32 #out, cov = self.pr.invert_optimize(self.nfunc) 33 elapsed = time.time()-self.starttime 34 self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed) 35 except KeyboardInterrupt: 36 # Thread was interrupted, just proceed 37 pass 38 except: 39 if not self.error_func==None: 40 self.error_func("CalcPr.compute: %s" % sys.exc_value) 41 42 class EstimatePr(CalcThread): 43 """ 44 Estimate P(r) 45 """ 46 47 def __init__(self, pr, nfunc=5, error_func=None, 48 completefn = None, 49 updatefn = None, 50 yieldtime = 0.01, 51 worktime = 0.01 52 ): 53 CalcThread.__init__(self,completefn, 54 updatefn, 55 yieldtime, 56 worktime) 57 self.pr = pr 58 self.nfunc = nfunc 59 self.error_func = error_func 60 self.starttime = 0 61 62 def compute(self): 63 """ 64 Calculates the estimate 66 Calculates the estimate 65 67 """ 66 68 try: … … 76 78 77 79 class EstimateNT(CalcThread): 78 80 """ 81 """ 79 82 def __init__(self, pr, nfunc=5, error_func=None, 80 83 completefn = None, … … 96 99 97 100 def isquit(self): 101 """ 102 """ 98 103 CalcThread.isquit(self) 99 104 if time.time()>self._time_for_sleep+self._sleep_delay: … … 103 108 def compute(self): 104 109 """ 105 110 Calculates the estimate 106 111 """ 107 112 try: -
prview/perspectives/pr/pr_widgets.py
r8eeb0b6 r7116b6e0 1 """2 This software was developed by the University of Tennessee as part of the3 Distributed Data Analysis of Neutron Scattering Experiments (DANSE)4 project funded by the US National Science Foundation.5 1 6 See the license text in license.txt 7 8 copyright 2009, University of Tennessee 9 """ 2 ################################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 # 7 #See the license text in license.txt 8 # 9 #copyright 2009, University of Tennessee 10 ################################################################################ 10 11 11 12 """ 12 13 Text controls for input/output of the main PrView panel 13 14 """ 14 15 … … 18 19 class PrTextCtrl(wx.TextCtrl): 19 20 """ 20 21 21 Text control for model and fit parameters. 22 Binds the appropriate events for user interactions. 22 23 """ 23 24 def __init__(self, *args, **kwds): … … 35 36 def _on_set_focus(self, event): 36 37 """ 37 Catch when the text control is set in focus to highlight the whole 38 text if necessary 39 @param event: mouse event 38 Catch when the text control is set in focus to highlight the whole 39 text if necessary 40 41 :param event: mouse event 42 40 43 """ 41 44 event.Skip() … … 44 47 def _highlight_text(self, event): 45 48 """ 46 Highlight text of a TextCtrl only of no text has be selected 47 @param event: mouse event 49 Highlight text of a TextCtrl only of no text has be selected 50 51 :param event: mouse event 52 48 53 """ 49 54 # Make sure the mouse event is available to other listeners … … 62 67 class OutputTextCtrl(wx.TextCtrl): 63 68 """ 64 65 66 69 Text control used to display outputs. 70 No editing allowed. The background is 71 grayed out. User can't select text. 67 72 """ 68 73 def __init__(self, *args, **kwds): 74 """ 75 """ 69 76 wx.TextCtrl.__init__(self, *args, **kwds) 70 77 self.SetEditable(False) … … 78 85 def _click(self, event): 79 86 """ 80 81 87 Prevent further handling of the mouse event 88 by not calling Skip(). 82 89 """ 83 90 pass … … 86 93 class DataFileTextCtrl(OutputTextCtrl): 87 94 """ 88 89 90 91 95 Text control used to display only the file name 96 given a full path. 97 98 :TODO: now that we no longer choose the data file from the panel, 92 99 it's no longer necessary to pass around the file path. That code 93 100 should be refactored away and simplified. 94 101 """ 95 102 def __init__(self, *args, **kwds): 103 """ 104 """ 96 105 OutputTextCtrl.__init__(self, *args, **kwds) 97 106 self._complete_path = None … … 99 108 def SetValue(self, value): 100 109 """ 101 110 Sets the file name given a path 102 111 """ 103 112 self._complete_path = str(value) … … 107 116 def GetValue(self): 108 117 """ 109 118 Return the full path 110 119 """ 111 120 return self._complete_path -
prview/sansview.py
r4d5005e r7116b6e0 13 13 14 14 class PrFrame(gui_manager.ViewerFrame): 15 """ 16 """ 15 17 def _on_open(self, event): 18 """ 19 """ 16 20 wx.PostEvent(self, NewPrFileEvent()) 17 21 18 22 class PrApp(gui_manager.ViewApp): 23 """ 24 """ 19 25 def OnInit(self): 20 26 """ 27 """ 21 28 # Check the size of the screen 22 29 # Add some padding to make sure to clear any OS tool bar … … 35 42 36 43 class SansView(): 37 44 """ 45 """ 38 46 def __init__(self): 39 47 """ 40 41 48 """ 42 49 #from gui_manager import ViewApp
Note: See TracChangeset
for help on using the changeset viewer.