Changeset b1b71ad in sasview for src


Ignore:
Timestamp:
Oct 27, 2018 7:21:44 AM (5 years ago)
Author:
Piotr Rozyczko <piotr.rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
186d678
Parents:
d00475d
Message:

Initial version of the 4.x SVS project file converter. Works for
non-disperse, non-magnetic sets

Location:
src/sas
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/MainWindow/DataExplorer.py

    rd00475d rb1b71ad  
    225225        Called when the "Open Project" menu item chosen. 
    226226        """ 
     227        # check if any items loaded and warn about data deletion 
     228        if self.model.rowCount() > 0: 
     229            msg = "This operation will set remove all data, plots and analyses from" 
     230            msg += " SasView before loading the project. Do you wish to continue?" 
     231            msgbox = QtWidgets.QMessageBox(self) 
     232            msgbox.setIcon(QtWidgets.QMessageBox.Warning) 
     233            msgbox.setText(msg) 
     234            msgbox.setWindowTitle("Project Load") 
     235            # custom buttons 
     236            button_yes = QtWidgets.QPushButton("Yes") 
     237            msgbox.addButton(button_yes, QtWidgets.QMessageBox.YesRole) 
     238            button_no = QtWidgets.QPushButton("No") 
     239            msgbox.addButton(button_no, QtWidgets.QMessageBox.RejectRole) 
     240            retval = msgbox.exec_() 
     241            if retval == QtWidgets.QMessageBox.RejectRole: 
     242                # cancel fit 
     243                return 
     244 
    227245        kwargs = { 
    228246            'parent'    : self, 
    229247            'caption'   : 'Open Project', 
    230             'filter'    : 'Project (*.json);;All files (*.*)', 
     248            'filter'    : 'Project Files (*.json);;Old Project Files (*.svs);;All files (*.*)', 
    231249            'options'   : QtWidgets.QFileDialog.DontUseNativeDialog 
    232250        } 
    233251        filename = QtWidgets.QFileDialog.getOpenFileName(**kwargs)[0] 
    234252        if filename: 
     253            self.deleteAllItems() 
    235254            self.readProject(filename) 
    236255 
     
    374393        Read out datasets and fitpages from file 
    375394        """ 
    376         with open(filename, 'r') as infile: 
    377             all_data = GuiUtils.readDataFromFile(infile) 
     395        # Find out the filetype based on extension 
     396        ext = os.path.splitext(filename)[1] 
     397        all_data = {} 
     398        if 'svs' in ext.lower(): 
     399            # backward compatibility mode. 
     400            datasets = GuiUtils.readProjectFromSVS(filename) 
     401            #[[item_1, state_1], [item_2, state_2],...] 
     402 
     403            # Convert fitpage properties and update the dict 
     404            all_data = GuiUtils.convertFromSVS(datasets) 
     405        else: 
     406            with open(filename, 'r') as infile: 
     407                all_data = GuiUtils.readDataFromFile(infile) 
    378408 
    379409        for key, value in all_data.items(): 
     
    420450            if not value: continue 
    421451            new_data = value[0] 
     452            from sas.sascalc.dataloader.data_info import Data1D as old_data1d 
     453            from sas.sascalc.dataloader.data_info import Data2D as old_data2d 
     454            if isinstance(new_data, (old_data1d, old_data2d)): 
     455                new_data = self.manager.create_gui_data(value[0], new_data.filename) 
    422456            assert isinstance(new_data, (Data1D, Data2D)) 
    423457            properties = value[1] 
     
    12021236        self.actionQuick3DPlot.triggered.connect(self.quickData3DPlot) 
    12031237        self.actionEditMask.triggered.connect(self.showEditDataMask) 
    1204         self.actionDelete.triggered.connect(self.deleteItem) 
     1238        self.actionDelete.triggered.connect(self.deleteSelectedItem) 
    12051239        self.actionFreezeResults.triggered.connect(self.freezeSelectedItems) 
    12061240 
     
    14151449                self.freezeItem(item_to_copy) 
    14161450 
    1417     def deleteItem(self): 
     1451    def deleteAllItems(self): 
     1452        """ 
     1453        Deletes all datasets from both model and theory_model 
     1454        """ 
     1455        deleted_items = [self.model.item(row) for row in range(self.model.rowCount()) 
     1456                         if self.model.item(row).isCheckable()] 
     1457        deleted_names = [item.text() for item in deleted_items] 
     1458        # Let others know we deleted data 
     1459        self.communicator.dataDeletedSignal.emit(deleted_items) 
     1460        # update stored_data 
     1461        self.manager.update_stored_data(deleted_names) 
     1462 
     1463        # Clear the model 
     1464        self.model.clear() 
     1465 
     1466    def deleteSelectedItem(self): 
    14181467        """ 
    14191468        Delete the current item 
     
    14321481            return 
    14331482 
     1483        indices = self.current_view.selectedIndexes() 
     1484        self.deleteIndices(indices) 
     1485 
     1486    def deleteIndices(self, indices): 
     1487        """ 
     1488        Delete model idices from the current view 
     1489        """ 
     1490        proxy = self.current_view.model() 
     1491        model = proxy.sourceModel() 
     1492 
     1493        deleted_items = [] 
     1494        deleted_names = [] 
     1495 
    14341496        # Every time a row is removed, the indices change, so we'll just remove 
    14351497        # rows and keep calling selectedIndexes until it returns an empty list. 
    1436         indices = self.current_view.selectedIndexes() 
    1437  
    1438         proxy = self.current_view.model() 
    1439         model = proxy.sourceModel() 
    1440  
    1441         deleted_items = [] 
    1442         deleted_names = [] 
    1443  
    14441498        while len(indices) > 0: 
    14451499            index = indices[0] 
    1446             row_index = proxy.mapToSource(index) 
    1447             item_to_delete = model.itemFromIndex(row_index) 
     1500            #row_index = proxy.mapToSource(index) 
     1501            #item_to_delete = model.itemFromIndex(row_index) 
     1502            item_to_delete = model.itemFromIndex(index) 
    14481503            if item_to_delete and item_to_delete.isCheckable(): 
    1449                 row = row_index.row() 
     1504                #row = row_index.row() 
     1505                row = index.row() 
    14501506 
    14511507                # store the deleted item details so we can pass them on later 
  • src/sas/qtgui/MainWindow/GuiManager.py

    rd00475d rb1b71ad  
    464464        self._workspace.actionOpen_Project.triggered.connect(self.actionOpen_Project) 
    465465        self._workspace.actionOpen_Analysis.triggered.connect(self.actionOpen_Analysis) 
    466         self._workspace.actionSave.triggered.connect(self.actionSave) 
     466        self._workspace.actionSave.triggered.connect(self.actionSave_Project) 
    467467        self._workspace.actionSave_Analysis.triggered.connect(self.actionSave_Analysis) 
    468468        self._workspace.actionQuit.triggered.connect(self.actionQuit) 
     
    557557        pass 
    558558 
    559     def actionSave(self): 
     559    def actionSave_Project(self): 
    560560        """ 
    561561        Menu Save Project 
  • src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py

    ra24eacf rb1b71ad  
    854854 
    855855        # Attempt at deleting 
    856         self.form.deleteItem() 
     856        self.form.deleteSelectedItem() 
    857857 
    858858        # Test the warning dialog called once 
     
    868868        self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 
    869869        # delete it. now for good 
    870         self.form.deleteItem() 
     870        self.form.deleteSelectedItem() 
    871871 
    872872        # Test the warning dialog called once 
  • src/sas/qtgui/Utilities/GuiUtils.py

    rd00475d rb1b71ad  
    295295    resultPlotUpdateSignal = QtCore.pyqtSignal(list) 
    296296 
     297def updateModelItemWithPlot(item, update_data, name="", checkbox_state=None): 
    297298    """ 
    298299    Adds a checkboxed row named "name" to QStandardItem 
     
    12871288    return new_stored_data 
    12881289 
     1290def readProjectFromSVS(filepath): 
     1291    """ 
     1292    Read old SVS file and convert to the project dictionary 
     1293    """ 
     1294    from sas.sascalc.dataloader.readers.cansas_reader import Reader as CansasReader 
     1295    from sas.sascalc.fit.pagestate import Reader 
     1296 
     1297    loader = Loader() 
     1298    loader.associate_file_reader('.svs', Reader) 
     1299    temp = loader.load(filepath) 
     1300    state_reader = Reader() 
     1301    data_svs, state_svs = state_reader.read(filepath) 
     1302 
     1303    output = [] 
     1304    if isinstance(temp, list) and isinstance(state_svs, list): 
     1305        for item, state in zip(temp, state_svs): 
     1306            output.append([item, state]) 
     1307    else: 
     1308        output[temp, state_svs] 
     1309    return output 
     1310 
     1311def convertFromSVS(datasets): 
     1312    """ 
     1313    Read in properties from SVS and convert into a simple dict 
     1314    """ 
     1315    content = {} 
     1316    for dataset in datasets: 
     1317        # we already have data - interested only in properties 
     1318        #[[item_1, state_1], [item_2, state_2],...] 
     1319        data = dataset[0] 
     1320        params = dataset[1] 
     1321        content[params.data_id] = {} 
     1322        content[params.data_id]['fit_data'] = [data, {'checked': 2}, []] 
     1323        param_dict = {} 
     1324        param_dict['fitpage_category'] = [params.categorycombobox] 
     1325        param_dict['fitpage_model'] = [params.formfactorcombobox] 
     1326        param_dict['fitpage_structure'] = [params.structurecombobox] 
     1327        param_dict['2D_params'] = [str(params.is_2D)] 
     1328        param_dict['chainfit_params'] = ["False"] 
     1329        param_dict['data_id'] = [params.data_id] 
     1330        param_dict['data_name'] = [params.data_name] 
     1331        param_dict['is_data'] = [str(params.is_data)] 
     1332        param_dict['magnetic_params'] = [str(params.magnetic_on)] 
     1333        param_dict['model_name'] = [params.formfactorcombobox] 
     1334        param_dict['polydisperse_params'] = [str(params.enable_disp)] 
     1335        param_dict['q_range_max'] = [str(params.qmax)] 
     1336        param_dict['q_range_min'] = [str(params.qmin)] 
     1337        # Smearing is a bit trickier. 4.x has multiple keywords, 
     1338        # one for each combobox option 
     1339        if params.enable_smearer: 
     1340            if params.slit_smearer: 
     1341                w = 1 
     1342            elif params.pinhole_smearer: 
     1343                w = 2 
     1344            else: 
     1345                w = 0 
     1346            param_dict['smearing'] = [str(w)] 
     1347        # weighting is a bit trickier. 4.x has multiple keywords, 
     1348        # one for each radio box. 
     1349        if params.dI_noweight: 
     1350            w = 2 
     1351        elif params.dI_didata: 
     1352            w = 3 
     1353        elif params.dI_sqrdata: 
     1354            w = 4 
     1355        elif params.dI_idata: 
     1356            w = 5 
     1357        else: 
     1358            w = 2 
     1359        param_dict['weighting'] = [str(w)] 
     1360 
     1361        # 4.x multi_factor is really the multiplicity 
     1362        if params.multi_factor is not None: 
     1363            param_dict['multiplicity'] = [str(int(params.multi_factor))] 
     1364 
     1365        # playing with titles 
     1366        data.filename = params.file 
     1367        data.title = params.data_name 
     1368        data.name = params.data_name 
     1369 
     1370        # main parameters 
     1371        for p in params.parameters: 
     1372            p_name = p[1] 
     1373            param_dict[p_name] = [str(p[0]), str(p[2]), None, str(p[5][1]), str(p[6][1])] 
     1374        # orientation parameters 
     1375        if params.is_2D: 
     1376            for p in params.orientation_params: 
     1377                p_name = p[1] 
     1378                param_dict[p_name] = [str(p[0]), str(p[2]), None, str(p[5][1]), str(p[6][1])] 
     1379 
     1380        # disperse parameters 
     1381        if params.enable_disp: 
     1382            for p in params.fittable_param: 
     1383                p_name = p[1] 
     1384                param_dict[p_name] = [str(p[0]), str(p[2]), None, str(35), str(3)] 
     1385 
     1386        # magnetic parameters 
     1387 
     1388        content[params.data_id]['fit_params'] = param_dict 
     1389    return content 
    12891390 
    12901391def enum(*sequential, **named): 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    rb8080e1 rb1b71ad  
    184184            if CANSAS_NS.get(self.cansas_version).get("ns") == value.rsplit(" ")[0]: 
    185185                return True 
    186         if ext == "svs": 
     186        if ext == ".svs": 
    187187            return True # Why is this required? 
    188188        # If we get to this point then file isn't valid CanSAS 
  • src/sas/sascalc/fit/pagestate.py

    rb8080e1 rb1b71ad  
    12491249 
    12501250            else: 
    1251                 self.call_back(format=ext) 
     1251                #self.call_back(format=ext) 
    12521252                raise RuntimeError("%s is not a file" % path) 
    12531253 
    12541254            # Return output consistent with the loader's api 
    12551255            if len(output) == 0: 
    1256                 self.call_back(state=None, datainfo=None, format=ext) 
     1256                #self.call_back(state=None, datainfo=None, format=ext) 
    12571257                return None 
    12581258            else: 
     1259                states=[] 
    12591260                for data in output: 
    12601261                    # Call back to post the new state 
     
    12811282                        if isinstance(data.run_name, dict): 
    12821283                            # Note: key order in dict is not guaranteed, so sort 
    1283                             name = data.run_name.keys()[0] 
     1284                            name = list(data.run_name.keys())[0] 
    12841285                        else: 
    12851286                            name = data.run_name 
     
    12891290                    state.version = fitstate.version 
    12901291                    # store state in fitting 
    1291                     self.call_back(state=state, datainfo=data, format=ext) 
     1292                    #self.call_back(state=state, datainfo=data, format=ext) 
    12921293                    self.state = state 
     1294                    states.append(state) 
    12931295                simfitstate = self._parse_simfit_state(entry) 
    12941296                if simfitstate is not None: 
    1295                     self.call_back(state=simfitstate) 
    1296  
    1297                 return output 
     1297                    #self.call_back(state=simfitstate) 
     1298                    states.append(simfitstate) 
     1299                return (output, states) 
    12981300        except: 
    1299             self.call_back(format=ext) 
     1301            #self.call_back(format=ext) 
    13001302            raise 
    13011303 
Note: See TracChangeset for help on using the changeset viewer.