Example #1
0
    def connect_db(self):
        """ Connect ByMur to a database containing data."""

        if self._core.db:
            msg = "Close connected database?"
            confirmation = bf.showMessage(parent=self.get_gui(),
                                          message=msg,
                                          kind="BYMUR_CONFIRM",
                                          caption="Please confirm this action")
            if confirmation:
                self.close_db()
            else:
                return

        dialogResult = self._wxframe.showModalDlg("BymurDBLoadDlg",
                                                  **self._dbDetails)
        if dialogResult:
            self._dbDetails.update(dialogResult)
            try:
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_DB_CONNECTED,
                               self._core.load_db,
                               self._dbDetails,
                               callback=self._set_ctrls_data,
                               wait_msg="Loading database...")
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               debug=self._exception_debug,
                               message=str(e),
                               kind="BYMUR_ERROR",
                               caption="Error")
Example #2
0
    def create_ensemble(self):
        """Define a new ensemble model combining available hazard models."""

        print "openEnsemble"
        dialogResult = self._wxframe.showModalDlg(
            "BymurEnsembleDlg", **{'data': self._core.ctrls_data})
        if dialogResult:
            try:
                dialogResult['ensIMLThresh'] = [
                    float(thresh)
                    for thresh in dialogResult['ensIMLThresh'].split()
                ]
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_UPDATE_DIALOG,
                               self._core.defEnsembleHaz,
                               dialogResult,
                               self._set_ctrls_data,
                               wait_msg="Creating ensemble hazard...")
                # self._core.defEnsembleHaz(**dialogResult)
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               message=str(e),
                               debug=self._exception_debug,
                               kind="BYMUR_ERROR",
                               caption="Ensemble hazard definition")

            finally:
                self.get_gui().busy = False
Example #3
0
    def update_hazard_options(self, event):
        """Update hazard options from parameters from GUI.

        :param event: wx.Event
        """

        try:
            data = self.get_gui().ctrlsPanel.hazard_options
            print "Setting hazard_options data: %s" % data
            if (data['ret_per'] is None) or (data['int_thresh'] is None) or \
                    (data['hazard_name'] is None) or (data['exp_time'] is None):
                raise StandardError("Hazard options are not complete")
            tmp = dict()
            tmp['hazard_name'] = data['hazard_name']
            tmp['risk_model_name'] = data['risk_model_name']
            tmp['ret_per'] = float(data['ret_per'])
            tmp['int_thresh'] = float(data['int_thresh'])
            tmp['exp_time'] = float(data['exp_time'])
            self._hazard_options = tmp
            bf.SpawnThread(self.get_gui(),
                           bf.wxBYMUR_UPDATE_ALL,
                           self._core.updateModel,
                           self._hazard_options,
                           callback=self._update_hazard_data,
                           wait_msg="Updating maps...")
        except Exception as e:
            bf.showMessage(parent=self.get_gui(),
                           debug=self._exception_debug,
                           message="Error setting hazard_options!\n" + str(e),
                           kind="BYMUR_ERROR",
                           caption="Error")
Example #4
0
    def drop_tables(self):
        """ Drop all tables from currently open ByMur database."""

        print "dropDBTables"
        if self._core.db:
            msg = "Are you really sure you want to delete all tables in the " \
                  "database?"
            confirmation = bf.showMessage(parent=self.get_gui(),
                                          message=msg,
                                          kind="BYMUR_CONFIRM",
                                          caption="Please confirm this action")
            if confirmation:
                try:
                    bf.SpawnThread(self.get_gui(),
                                   bf.wxBYMUR_DB_CLOSED,
                                   self._core.drop_tables,
                                   dict(),
                                   self.close_db,
                                   wait_msg="Dropping tables...")
                except Exception as e:
                    bf.showMessage(parent=self.get_gui(),
                                   message=str(e),
                                   debug=self._exception_debug,
                                   kind="BYMUR_ERROR",
                                   caption="Error")
            else:
                return
Example #5
0
    def add_data(self):
        """Add new data to currently open ByMuR database."""

        print "addDBData"
        print "_addDBDetails %s" % self._addDBDataDetails
        _localDBDataDetails = self._addDBDataDetails.copy()
        _localDBDataDetails['grid_list'] = [
            d['datagrid_name'] for d in self._core.db.get_datagrids_list()
        ]
        _localDBDataDetails['phenomena_list'] = [
            p['phenomenon_name'] for p in self._core.db.get_phenomena_list()
        ]
        dialogResult = self._wxframe.showModalDlg("BymurAddDBDataDlg",
                                                  **_localDBDataDetails)
        if dialogResult:
            _localDBDataDetails.update(dialogResult)
            try:
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_UPDATE_DIALOG,
                               self._core.add_data,
                               _localDBDataDetails,
                               self._set_ctrls_data,
                               wait_msg="Adding data to database...")
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               message=str(e),
                               debug=self._exception_debug,
                               kind="BYMUR_ERROR",
                               caption="Error")
Example #6
0
    def create_db(self):
        """Create a new ByMuR database."""

        if self._core.db:
            msg = "Close connected database?"
            confirmation = bf.showMessage(parent=self.get_gui(),
                                          message=msg,
                                          kind="BYMUR_CONFIRM",
                                          caption="Please confirm this action")
            if confirmation:
                self.close_db()
            else:
                return
        dialogResult = self._wxframe.showModalDlg("BymurDBCreateDlg",
                                                  **self._createDBDetails)
        if dialogResult:
            self._createDBDetails.update(dialogResult)
            self.get_gui().busymsg = "Creating DB..."
            self.get_gui().busy = True
            try:
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_DB_CONNECTED,
                               self._core.create_db,
                               self._createDBDetails,
                               self._set_ctrls_data,
                               wait_msg="Creating database...")
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               message=str(e),
                               debug=self._exception_debug,
                               kind="BYMUR_ERROR",
                               caption="Error")
Example #7
0
    def load_grid(self):
        """Load new grid into currently open ByMuR database."""

        print "loadGrid"
        gridData = dict(basedir=self._basedir, filepath='')
        dialogResult = self._wxframe.showModalDlg("BymurLoadGridDlg",
                                                  **gridData)
        if dialogResult:
            gridData.update(dialogResult)
            try:
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_UPDATE_DIALOG,
                               self._core.load_grid,
                               gridData,
                               self._set_ctrls_data,
                               wait_msg="Adding grid to database...")
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               message=str(e),
                               debug=self._exception_debug,
                               kind="BYMUR_ERROR",
                               caption="Error")
Example #8
0
    def export_hazard(self):
        """Export hazard model to XMLs file"""

        print "export Hazard"
        dialogResult = self._wxframe.showModalDlg(
            "BymurExportHazDlg", **{'data': self._core.ctrls_data})
        if dialogResult:
            try:
                bf.SpawnThread(self.get_gui(),
                               bf.wxBYMUR_UPDATE_DIALOG,
                               self._core.exportHaz,
                               dialogResult,
                               self._set_ctrls_data,
                               wait_msg="Exporting hazard XMLs...")
            except Exception as e:
                bf.showMessage(parent=self.get_gui(),
                               message=str(e),
                               debug=self._exception_debug,
                               kind="BYMUR_ERROR",
                               caption="Export XML files")

            finally:
                self.get_gui().busy = False