Changeset 54557b5 in sasview


Ignore:
Timestamp:
Apr 6, 2017 11:04:29 AM (7 years ago)
Author:
krzywon
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
2df1bd1
Parents:
3444492
git-author:
Jeff Krzywon <krzywon@…> (04/06/17 11:04:29)
git-committer:
krzywon <krzywon@…> (04/06/17 11:04:29)
Message:

Integer params in manipulations to comply with numpy v1.12. Nearly completed saving 1D plots generated by slicers.

Location:
src/sas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/manipulations.py

    rdd11014 r54557b5  
    430430            z_max = max(data2D.q_data) 
    431431            z_min = min(data2D.q_data) 
    432             x_max = data2D.dqx_data[data2D.q_data[z_max]] 
    433             x_min = data2D.dqx_data[data2D.q_data[z_min]] 
    434             y_max = data2D.dqy_data[data2D.q_data[z_max]] 
    435             y_min = data2D.dqy_data[data2D.q_data[z_min]] 
     432            x_max = data2D.dqx_data[numpy.where(data2D.q_data == z_max)] 
     433            x_min = data2D.dqx_data[numpy.where(data2D.q_data == z_min)] 
     434            y_max = data2D.dqy_data[numpy.where(data2D.q_data == z_max)] 
     435            y_min = data2D.dqy_data[numpy.where(data2D.q_data == z_min)] 
    436436            # Find qdx at q = 0 
    437437            dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 
     
    785785            z_max = max(data2D.q_data) 
    786786            z_min = min(data2D.q_data) 
    787             x_max = data2D.dqx_data[data2D.q_data[z_max]] 
    788             x_min = data2D.dqx_data[data2D.q_data[z_min]] 
    789             y_max = data2D.dqy_data[data2D.q_data[z_max]] 
    790             y_min = data2D.dqy_data[data2D.q_data[z_min]] 
     787            x_max = data2D.dqx_data[numpy.where(data2D.q_data == z_max)] 
     788            x_min = data2D.dqx_data[numpy.where(data2D.q_data == z_min)] 
     789            y_max = data2D.dqy_data[numpy.where(data2D.q_data == z_max)] 
     790            y_min = data2D.dqy_data[numpy.where(data2D.q_data == z_min)] 
    791791            # Find qdx at q = 0 
    792792            dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 
  • src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py

    rb697396b r54557b5  
    44import wx.lib.newevent 
    55import time 
     6from sas.sascalc.dataloader.readers.cansas_reader import Reader 
    67from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    78from sas.sasgui.guiframe.utils import format_number 
    89from sas.sasgui.guiframe.events import EVT_SLICER 
    910from sas.sasgui.guiframe.events import SlicerParameterEvent, SlicerEvent 
     11from Plotter1D import ModelPanel1D 
    1012from Plotter2D import ModelPanel2D 
    1113from sas.sascalc.dataloader.data_info import Data1D, Data2D 
    12 ApplyParams, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 
     14apply_params, EVT_APPLY_PARAMS = wx.lib.newevent.NewEvent() 
     15auto_save, EVT_AUTO_SAVE = wx.lib.newevent.NewEvent() 
     16auto_close, EVT_ON_CLOSE = wx.lib.newevent.NewEvent() 
    1317 
    1418 
     
    3337        self.bck = wx.GridBagSizer(5, 5) 
    3438        self.SetSizer(self.bck) 
     39        self.auto_save = None 
     40        self.path = None 
     41        self.type_list = ["SectorInteractor", "AnnulusInteractor", 
     42                          "BoxInteractorX", "BoxInteractorY"] 
     43        self.type_select = wx.ComboBox(parent=self, choices=self.type_list) 
     44        self.append_name = wx.TextCtrl(parent=self, id=wx.NewId(), 
     45                                       name="Append to file name:") 
     46        self.data_list = None 
    3547        label = "Right-click on 2D plot for slicer options" 
    3648        title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 
     
    4052        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) 
    4153        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange) 
    42         self.Bind(EVT_APPLY_PARAMS, self.apply_params_list) 
     54        self.Bind(EVT_APPLY_PARAMS, self.apply_params_list_and_process) 
     55        self.Bind(EVT_AUTO_SAVE, self.save_files) 
     56        self.Bind(EVT_ON_CLOSE, self.on_close) 
    4357 
    4458    def onEVT_SLICER(self, event): 
     
    109123                    self.bck.Add(ctl, (iy, ix), (1, 1), 
    110124                                 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
     125 
     126            # Change slicer within the window 
    111127            ix = 0 
    112128            iy += 1 
    113  
    114             # Change slicer within the window 
    115             txt = "Slicer" 
     129            txt = "Slicer type:" 
    116130            text = wx.StaticText(self, -1, txt, style=wx.ALIGN_LEFT) 
    117131            self.bck.Add(text, (iy, ix), (1, 1), 
    118132                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    119             type_list = ["SectorInteractor", "AnnulusInteractor", 
    120                          "BoxInteractorX", "BoxInteractorY"] 
    121             self.type_select = wx.ComboBox(parent=self, choices=type_list) 
    122133            self.Bind(wx.EVT_COMBOBOX, self.onChangeSlicer) 
    123             index = self.type_select.FindString(self.type) 
     134            index = self.type_select.FindString(type) 
    124135            self.type_select.SetSelection(index) 
    125136            self.bck.Add(self.type_select, (iy, 1), (1, 1), 
     
    130141            title = wx.StaticText(self, -1, title_text, style=wx.ALIGN_LEFT) 
    131142            iy += 1 
    132             ln = wx.StaticLine(self, -1, style=wx.LI_VERTICAL) 
    133             ln.SetSize((60,60)) 
    134             self.bck.Add(ln, (iy, ix), (1, 2), 
     143            line = wx.StaticLine(self, -1, style=wx.LI_VERTICAL) 
     144            line.SetSize((60, 60)) 
     145            self.bck.Add(line, (iy, ix), (1, 2), 
    135146                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    136147            iy += 1 
    137148            self.bck.Add(title, (iy, ix), (1, 1), 
    138149                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    139             iy += 1 
     150 
    140151            # Create a list box with all of the 2D plots 
     152            iy += 1 
    141153            self.process_list() 
    142154            self.bck.Add(self.data_list, (iy, ix), (1, 1), 
    143155                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    144             iy += 1 
     156 
     157            # Checkbox for autosaving data 
     158            iy += 1 
     159 
     160            self.auto_save = wx.CheckBox(parent=self, id=wx.NewId(), 
     161                                         label="Auto save generated 1D:") 
     162            self.Bind(wx.EVT_CHECKBOX, self.on_auto_save_checked) 
     163            self.bck.Add(self.auto_save, (iy, ix), (1, 1), 
     164                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     165            iy += 1 
     166            # File browser 
     167            save_to = "Save files to:" 
     168            save = wx.StaticText(self, -1, save_to, style=wx.ALIGN_LEFT) 
     169            self.path = wx.DirPickerCtrl(self, id=wx.NewId(), path="", 
     170                                         message=save_to) 
     171            self.path.Enable(False) 
     172            self.bck.Add(save, (iy, ix), (1, 1), 
     173                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     174            self.bck.Add(self.path, (iy, 1), (1, 1), 
     175                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     176            # Append to file 
     177            iy += 1 
     178            default_value = "_{0}".format(self.type) 
     179            for key in params: 
     180                default_value += "_%d.2" % params[key] 
     181            append_text = "Append to file name:" 
     182            append = wx.StaticText(self, -1, append_text, style=wx.ALIGN_LEFT) 
     183            self.append_name.SetValue(default_value) 
     184            self.append_name.Enable(False) 
     185            self.bck.Add(append, (iy, ix), (1, 1), 
     186                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     187            self.bck.Add(self.append_name, (iy, 1), (1, 1), 
     188                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     189 
     190            # TODO: Fix fitting options combobox/radiobox 
     191            # Combobox for selecting fitting options 
     192            # iy += 1 
     193            # self.fitting_radio = wx.RadioBox(parent=self, id=wx.NewId(), 
     194            #                                  size=(4,1)) 
     195            # self.fitting_radio.SetString(0, "No fitting") 
     196            # self.fitting_radio.SetString(1, "Batch Fitting") 
     197            # self.fitting_radio.SetString(2, "Fitting") 
     198            # self.fitting_radio.SetString(3, "Simultaneous and Constrained Fit") 
     199            # self.fitting_radio.SetValue(0) 
     200            # self.bck.Add(self.fitting_radio, (iy, ix), (1, 1), 
     201            #              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     202 
    145203            # Button to start batch slicing 
     204            iy += 1 
    146205            button_label = "Apply Slicer to Selected Plots" 
    147206            self.batch_slicer_button = wx.Button(parent=self, 
    148207                                                 label=button_label) 
    149             self.Bind(wx.EVT_BUTTON, self.onBatchSlice) 
     208            self.Bind(wx.EVT_BUTTON, self.on_batch_slicer) 
    150209            self.bck.Add(self.batch_slicer_button, (iy, ix), (1, 1), 
    151                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    152             # TODO: Check box for saving file 
    153             # TODO: append to file information and file type 
    154             # TODO: Send to fitting options 
    155  
     210                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    156211            iy += 1 
    157212            self.bck.Add((5, 5), (iy, ix), (1, 1), 
     
    196251            wx.PostEvent(self.parent, event) 
    197252 
    198     def onBatchSlice(self, evt=None): 
     253    def on_batch_slicer(self, evt=None): 
    199254        """ 
    200255        Method invoked with batch slicing button is pressed 
     
    205260        params = self.parent.slicer.get_params() 
    206261        type = self.type_select.GetStringSelection() 
     262        save = self.auto_save.IsChecked() 
     263        append = self.append_name.GetValue() 
     264        path = self.path.GetPath() 
    207265 
    208266        # Find desired 2D data panels 
     
    217275        # Post an event to apply appropriate slicer params to each slicer 
    218276        # Event needed due to how apply_slicer_to_plot works 
    219         event = ApplyParams(params=params, plot_list=apply_to_list) 
     277        event = apply_params(params=params, plot_list=apply_to_list, 
     278                             auto_save=save, append=append, 
     279                             path=path) 
    220280        wx.PostEvent(self, event) 
    221         # TODO: save file (if desired) 
    222         # TODO: send to fitting (if desired) 
     281        event = auto_close() 
     282        wx.PostEvent(self, event) 
    223283 
    224284    def onChangeSlicer(self, evt): 
     
    264324                                         choices=self.loaded_data, 
    265325                                         name="Apply Slicer to 2D Plots:") 
    266         # Check all items bty default 
     326        # Check all items by default 
    267327        for item in range(len(self.data_list.Items)): 
    268328            self.data_list.Check(item) 
    269         self.data_list.Bind(wx.EVT_CHECKLISTBOX, self.onCheckBoxList) 
    270  
    271     def onCheckBoxList(self, e): 
     329        self.data_list.Bind(wx.EVT_CHECKLISTBOX, self.on_check_box_list) 
     330 
     331    def on_check_box_list(self, evt=None): 
    272332        """ 
    273333        Prevent a checkbox item from being unchecked 
    274334        :param e: Event triggered when a checkbox list item is checked 
    275335        """ 
    276         index = e.GetSelection() 
     336        if evt is None: 
     337            return 
     338        index = evt.GetSelection() 
    277339        if index == self.checkme: 
    278340            self.data_list.Check(index) 
    279341 
    280     def apply_params_list(self, evt=None): 
     342    def apply_params_list_and_process(self, evt=None): 
    281343        """ 
    282344        Event based parameter setting. 
     
    288350            item.slicer.set_params(evt.params) 
    289351            item.slicer.base.update() 
    290         # Close the slicer window 
     352        # Post an event to save each data set to file 
     353        if evt.auto_save: 
     354            event = auto_save(append_to_name=evt.append, 
     355                              file_list=evt.plot_list, 
     356                              path=evt.path) 
     357            wx.PostEvent(self, event) 
     358 
     359    def save_files(self, evt=None): 
     360        """ 
     361        Automatically save the sliced data to file. 
     362        :param evt: Event that triggered the call to the method 
     363        """ 
     364        if evt is None: 
     365            return 
     366        writer = Reader() 
     367        main_window = self.parent.parent 
     368        data_list = [] 
     369        append = evt.append_to_name 
     370        for key, plot in main_window.plot_panels.iteritems(): 
     371            if not hasattr(plot, "data2D"): 
     372                for item in plot.plots: 
     373                    data_list.append(item) 
     374        for item in data_list: 
     375            data1d = item.plots 
     376            base = item.name.split(".")[0] 
     377            save_to = evt.path + base + ".xml" 
     378            writer.write(path, data1d) 
     379 
     380        # TODO: determine data sets 
     381        # TODO: generate file names 
     382        # TODO: link one to the other 
     383        # TODO: save all files 
     384 
     385    def on_auto_save_checked(self, evt=None): 
     386        """ 
     387        Enable/Disable auto append when checkbox is checked 
     388        :param evt: Event 
     389        """ 
     390        self.append_name.Enable(self.auto_save.IsChecked()) 
     391        self.path.Enable(self.auto_save.IsChecked()) 
     392     
     393    def on_close(self, evt=None): 
     394        """ 
     395        Auto close the panel 
     396        """ 
    291397        self.Destroy() 
Note: See TracChangeset for help on using the changeset viewer.