Changeset edcbd467 in sasview
- Timestamp:
- Apr 8, 2010 4:48:01 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:
- 8e87ece
- Parents:
- 0a7c2f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitting.py
ra704bb5 redcbd467 8 8 copyright 2009, University of Tennessee 9 9 """ 10 import re ,copy10 import re 11 11 import sys, wx, logging 12 12 import string, numpy, math 13 13 import time 14 14 import thread 15 #from danse.common.plottools.plottables import Theory1D 15 16 from copy import deepcopy 17 from DataLoader.data_info import Data1D as LoaderData1D 16 18 from danse.common.plottools.PlotPanel import PlotPanel 17 19 … … 230 232 self.index_theory= 0 231 233 self.parent.Bind(EVT_SLICER_PANEL, self._on_slicer_event) 232 self.parent.Bind( 234 self.parent.Bind(ERR_DATA, self._on_data_error) 233 235 self.parent.Bind(EVT_REMOVE_DATA, self._closed_fitpage) 234 236 self.parent.Bind(EVT_SLICER_PARS_UPDATE, self._onEVT_SLICER_PANEL) … … 284 286 id = None 285 287 if hasattr(item,"id"): 286 id = copy.deepcopy(item.id)288 id = item.id 287 289 288 290 data= Data1D(x=item.x, y=item.y,dx=None, dy=None) … … 292 294 data.name = item.name 293 295 ## allow to highlight data when plotted 294 data.interactive = copy.deepcopy(item.interactive)296 data.interactive = deepcopy(item.interactive) 295 297 ## when 2 data have the same id override the 1 st plotted 296 298 data.id = id … … 377 379 self.page_finder[self.current_pg].set_smearer(smearer) 378 380 ## draw model 1D with smeared data 379 data = self.page_finder[self.current_pg].get_ plotted_data()381 data = self.page_finder[self.current_pg].get_fit_data() 380 382 model = self.page_finder[self.current_pg].get_model() 381 383 ## if user has already selected a model to plot … … 536 538 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot_data, 537 539 title=data.name)) 538 540 def create_fittable_data2D(self, data): 541 """ 542 check if the current data is a data 2d and add dy to that data 543 @return Data2D 544 """ 545 if data.__class__.__name__ != "Data2D": 546 raise Valueerror, " create_fittable_data2D expects a Data2D" 547 ## Data2D case 548 new_data = deepcopy(data) 549 if not hasattr(data, "is_data"): 550 new_data.group_id += "data2D" 551 new_data.id +="data2D" 552 new_data.is_data = False 553 title = new_data.name 554 title += " Fit" 555 wx.PostEvent(self.parent, NewPlotEvent(plot=new_data, 556 title=str(title))) 557 else: 558 new_data.is_data = True 559 return new_data 560 561 def create_fittable_data1D(self, data): 562 """ 563 check if the current data is a theory 1d and add dy to that data 564 @return Data1D 565 """ 566 if not issubclass(data.__class__, LoaderData1D): 567 raise ValueError, "create_fittable_data1D expects Data1D" 568 #get the appropriate dy 569 dy = deepcopy(data.dy) 570 if len(self.err_dy) > 0: 571 if data.name in self.err_dy.iterkeys(): 572 dy = self.err_dy[data.name] 573 print "err_dy ====", dy 574 if data.dy is None or data.dy == []: 575 dy = numpy.zeros(len(data.y)) 576 print "dy ====", dy 577 if data.__class__.__name__ == "Theory1D": 578 579 new_data = self.copy_data(data, dy) 580 new_data.group_id += "data1D" 581 new_data.id +="data1D" 582 new_data.is_data = False 583 title = new_data.name 584 title = 'Data created from Theory' 585 wx.PostEvent(self.parent, NewPlotEvent(plot=new_data, 586 title=str(title), 587 reset=True)) 588 else: 589 new_data = self.copy_data(data, dy) 590 new_data.is_data = True 591 return new_data 592 593 def add_fit_page(self, data): 594 """ 595 given a data, ask to the fitting panel to create a new fitting page, 596 get this page and store it into the page_finder of this plug-in 597 """ 598 try: 599 page = self.fit_panel.add_fit_page(data) 600 # add data associated to the page created 601 if page != None: 602 page.set_data(data) 603 #create a fitproblem storing all link to data,model,page creation 604 if not page in self.page_finder.keys(): 605 self.page_finder[page]= FitProblem() 606 ## item is almost the same as data but contains 607 ## axis info for plotting 608 #self.page_finder[page].add_plotted_data(item) 609 self.page_finder[page].add_fit_data(data) 610 611 wx.PostEvent(self.parent, StatusEvent(status="Page Created")) 612 else: 613 wx.PostEvent(self.parent, StatusEvent(status="Page was already Created")) 614 except: 615 raise 616 #wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 617 #%sys.exc_value)) 618 return 619 539 620 def _onEVT_SLICER_PANEL(self, event): 540 621 """ … … 650 731 Plugin.on_perspective(self,event=event) 651 732 for plottable in self.panel.graph.plottables: 652 if plottable.name == self.panel.graph.selected_plottable: 653 if plottable.__class__.__name__=="Theory1D": 654 dy=numpy.zeros(len(plottable.y)) 655 if hasattr(plottable, "dy"): 656 dy= copy.deepcopy(plottable.dy) 657 658 item = self.copy_data(plottable, dy) 659 item.group_id += "data1D" 660 item.id +="data1D" 661 item.is_data = False 662 title = item.name 663 title = 'Data created from Theory' 664 wx.PostEvent(self.parent, NewPlotEvent(plot=item, 665 title=str(title), 666 reset=True)) 667 else: 668 item= self.copy_data(plottable, plottable.dy) 669 item.is_data=True 670 671 ## put the errors values back to the model if the errors were hiden 672 ## before sending them to the fit engine 673 if len(self.err_dy)>0: 674 dy = item.dy 675 if item.name in self.err_dy.iterkeys(): 676 dy = self.err_dy[item.name] 677 data = self.copy_data(item, dy) 678 data.is_data= item.is_data 679 680 else: 681 if item.dy==None: 682 dy= numpy.zeros(len(item.y)) 683 data= self.copy_data(item, dy) 684 data.is_data=item.is_data 685 else: 686 data= self.copy_data(item,item.dy) 687 data.is_data=item.is_data 733 if issubclass(plottable.__class__, LoaderData1D): 734 if plottable.name == self.panel.graph.selected_plottable: 735 data = self.create_fittable_data1D(data=plottable) 736 self.add_fit_page(data=data) 737 return 688 738 else: 689 ## Data2D case 690 if not hasattr(plottable, "is_data"): 691 item= copy.deepcopy(plottable) 692 item.group_id += "data2D" 693 item.id +="data2D" 694 item.is_data= False 695 title = item.name 696 title += " Fit" 697 data = item 698 wx.PostEvent(self.parent, NewPlotEvent(plot=item, title=str(title))) 699 else: 700 item= copy.deepcopy(plottable) 701 data= copy.deepcopy(plottable) 702 item.is_data=True 703 data.is_data=True 704 705 706 ## create anew page 707 if item.name == self.panel.graph.selected_plottable or\ 708 item.__class__.__name__ is "Data2D": 709 try: 710 page = self.fit_panel.add_fit_page(data) 711 # add data associated to the page created 712 if page != None: 713 page.set_data(data) 714 #create a fitproblem storing all link to data,model,page creation 715 if not page in self.page_finder.keys(): 716 self.page_finder[page]= FitProblem() 717 ## item is almost the same as data but contains 718 ## axis info for plotting 719 self.page_finder[page].add_plotted_data(item) 720 self.page_finder[page].add_fit_data(data) 721 722 wx.PostEvent(self.parent, StatusEvent(status="Page Created")) 723 else: 724 wx.PostEvent(self.parent, StatusEvent(status="Page was already Created")) 725 except: 726 raise 727 #wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 728 #%sys.exc_value)) 729 return 730 731 739 data = self.create_fittable_data2D(data=plottable) 740 self.add_fit_page(data=data) 741 732 742 def _updateFit(self): 733 743 """ … … 801 811 if value.get_scheduled()==1: 802 812 model = value.get_model() 803 metadata = value.get_plotted_data()813 data = value.get_fit_data() 804 814 small_param_name = [] 805 815 small_out = [] … … 935 945 if self.page_finder[self.current_pg].get_model()== None : 936 946 937 model.name ="M"+str(self.index_model)947 model.name = "M"+str(self.index_model) 938 948 self.index_model += 1 939 949 else: 940 950 model.name= self.page_finder[self.current_pg].get_model().name 941 951 942 metadata = self.page_finder[self.current_pg].get_plotted_data()952 data = self.page_finder[self.current_pg].get_fit_data() 943 953 944 954 # save the name containing the data name with the appropriate model … … 948 958 smearer= self.page_finder[self.current_pg].get_smearer() 949 959 # save model name 950 self.draw_model( model=model, smearer=smearer,951 data= metadata, qmin=qmin, qmax=qmax)960 self.draw_model( model=model, smearer=smearer, 961 data=data, qmin=qmin, qmax=qmax) 952 962 953 963 if self.sim_page!=None: 954 964 self.sim_page.draw_page() 955 965 956 957 958 966 def _on_model_menu(self, evt): 959 967 """ … … 1183 1191 """ 1184 1192 self.err_dy = event.err_dy 1185 1193 print "receiving error dy",self.err_dy 1186 1194 1187 1195 def _draw_model2D(self,model,data=None,description=None, enable2D=False,
Note: See TracChangeset
for help on using the changeset viewer.