def create1Log(self, wellId, session=None): logger.debug(">>create3Logs() well id: " + str(wellId)) localSession = False if session == None: session = DM.getSession() localSession = True log1 = Log() log1.name = "SWIRR" log1.log_type_name = LogType.SATURATION.name log1.z_measure_type_name = "MD" log1.z_measure_min = 0.0 log1.z_measure_max = 2000.0 log1.z_measure_step = 0.1524 log1.log_data_str = BaseDao.convertDataToJSON( [0.378425, 0.381605, 0.397528]) log1.z_measure_data_str = BaseDao.convertDataToJSON([102, 103, 104]) log1.well_id = wellId self.setPreferences(log1, session) session.add(log1) session.commit() dummyLog = session.query(Log).filter(Log.name == 'SWIRR').one() assert "SWIRR" == dummyLog.name assert wellId == dummyLog.well_id allLogs = session.query(Log).all() if localSession: session.close() return allLogs
def execute(self, session, treeview, explorer, ids, tablename, treedescription, **kargs): logger.debug("WellPlot --execute()") session = DM.getSession() selectedLogSet = None if tablename.title() == "Well": if len(ids) > 1: logger.info("Plotting first selected well") selectedWell = WellDao.getWell(ids[0], session) logs = LogDao.getWellLogs(ids[0], session) elif tablename.title() == "Log_Set": if len(ids) > 1: logger.info("Plotting first selected log set") selectedWell = WellDao.getWell(ids[0], session) selectedLogSet = LogSetDao.getLogSet(ids[0], session) logs = LogDao.getLogSetLogs(ids[0], session) session.close() if (logs != None) and (selectedWell != None): #need to connect WellPlotMPL to main application so can receive signals #centralTabWidget = CentralTabWidget() wellPlotSetupDialog = WellPlotSetupDialog(logs, well=selectedWell, logSet=selectedLogSet) wellPlotSetupDialog.exec_() ''' settings = RendererSettings() if settings.plotRenderer == PlotRenderer.pyqtgraph: wellPlotPyQtGraph = WellPlotPG(logs, well = selectedWell, logSet = selectedLogSet, parent = centralTabWidget) elif settings.plotRenderer == PlotRenderer.matplotlib: wellPlot = WellPlotMPL(logs, well = selectedWell, logSet = selectedLogSet, parent = centralTabWidget) ''' else: logger.warn("Error getting data from database, cannot plot logs") explorer.refresh()
def getZAxisPriority(self): ''' Retrieves lit of z measure track priorities from db on first call and stores them here eg MDKB highest priority followed by TVDSS etc..''' if (len(self.z_axis_track_priority) == 0): logger.debug("--getZAxisPriority() getting domain track priorities from DB") session = DM.getSession() self.z_axis_track_priority = LogTrackDataDao.convertJSONtoData(self.z_axis_priority_str) return self.z_axis_track_priority
def getZAxisDatas(self): ''' Retrieves lit of _z_axis_track_datas from db on first call and stores them here ''' if (len(self._z_axis_track_datas) == 0) and (self._z_axis_track_ids != ""): session = DM.getSession() domainDataIdList = BaseDao.convertJSONtoData(self._z_axis_track_ids) domainTrackData = ZAxisDataDao() self._z_axis_track_datas = domainTrackData.getDomainTrackDatasFromIds(domainDataIdList, session) return self._z_axis_track_datas
def getLogTrackDatas(self): ''' Retrieves lit of sub-plots from db on first call and stores them here ''' if (len(self._log_track_datas) == 0) and (self._log_track_ids != ""): logger.debug("--getLogTrackDatas() getting sub_plots from DB") session = DM.getSession() subPlotIdList = LogTrackDataDao.convertJSONtoData(self._log_track_ids) self._log_track_datas = LogTrackDataDao.getLogTrackDatasFromIds(subPlotIdList, session) return self._log_track_datas
def getLogs(self): ''' Retrieves lit of logs from db on first call and stores them here ''' if (len(self._logs) == 0) and (self.log_ids != None) and (self.log_ids != ""): session = DM.getSession() logIdList = (self.log_ids).split(",") self._logs = LogDao.getLogsFromIds(logIdList, session) session.close() return self._logs
def test_findLogWithLargestDepthRange(self): #QWidget: Must construct a QApplication before a QPaintDevice app = QApplication(sys.argv) self.dummyDbSetup = DummyDbSetup() self.dummyDbSetup.setupDatabase() session = DM.getSession() well = self.dummyDbSetup.createWell() logs = self.dummyDbSetup.create3VariableDepthLogs(well.id) log = Log() longestLog = log.findLogWithLargestDepthRange(logs) self.assertEqual("3SP", longestLog.name)
def createWell(self, mdstart, mdstop, wellName): logger.debug(">>createWell() ") session = DM.getSession() well = Well() well.name = wellName well.depth_reference = "MDKB" well.elevation_of_depth_reference = "24.0" well.mdstart = mdstart well.mdstop = mdstop session.add(well) session.commit() dummyWell = session.query(Well).filter(Well.name == wellName).one() assert wellName == dummyWell.name session.close() return dummyWell
def execute(self, session, treeview, explorer, ids, tablename, treedescription, **kargs): logger.debug("Settings --execute()") session = DM.getSession() if tablename.title() == "Well": if len(ids) > 1: logger.info("Settings for first well selected") rs = session.query(Well).filter(Well.id == ids[0]) assert rs.count() == 1 for well in rs: logger.debug("--plotLogs() well: " + str(well.name)) dialog = WellSettingsDialog(well) dialog.exec_() session.close() explorer.refresh()
def test_write(self): logger.debug("--test_write() ") DM.init_db() session = DM.getSession() well = Well() well.name = "Hampo" well.depth_reference = "MDKB" well.elevation_of_depth_reference = "24.0" session.add(well) session.commit() logger.debug("--test_write() id: " + str(well.id)) dummy = session.query(Well).filter(Well.name == 'Hampo').one() logger.debug("--test_write() dummy: " + str(dummy.name) + " object: " + str(dummy)) self.assertEqual("Hampo", dummy.name) session.close()
def setPreferences(self, log, session=None): localSession = False if session == None: session = DM.getSession() localSession = True logType = LogType.getLogType(log.log_type_name) log_type_uid = logType.getUid() logCurveDefaults = LogCurvePreferencesDao.getLogCurvePreferences( log_type_uid, session) if logCurveDefaults == None: #no preferences set yet, use defaults logCurveDefaults = LogCurvePreferencesDao.getLogCurveDefaults( log_type_uid, session) assert logCurveDefaults is not None log.log_plot_left = logCurveDefaults.log_plot_left log.log_plot_right = logCurveDefaults.log_plot_right log.log_plot_default = logCurveDefaults.log_plot_default log.log_plot_points_on = logCurveDefaults.log_plot_points_on log.histogram_left = logCurveDefaults.histogram_left log.histogram_right = logCurveDefaults.histogram_right log.histogram_default = logCurveDefaults.histogram_default log.cross_plot_left = logCurveDefaults.cross_plot_left log.cross_plot_right = logCurveDefaults.cross_plot_right log.cross_plot_default = logCurveDefaults.cross_plot_default log.line_width = logCurveDefaults.line_width log.line_style = logCurveDefaults.line_style log.point_size = logCurveDefaults.point_size log.point_style = logCurveDefaults.point_style log.rgb = logCurveDefaults.rgb log.alpha = logCurveDefaults.alpha log.is_logarithmic = logCurveDefaults.is_logarithmic if logCurveDefaults.is_logarithmic: log.log_plot_log_cycles = logCurveDefaults.log_plot_log_cycles log.z_measure_type_name = "MD" #duplication - but makes simpler if want to change log down track log.z_measure_reference = "KB" if localSession: session.close()
def test_updateWellStartStop(self, mock_class): logger.debug(">>test_updateWellStartStop()") #self.dummyDbSetup = DummyDbSetup() self.dummyDbSetup.setupDatabase() session = DM.getSession() well = self.dummyDbSetup.createWell(session) logs = self.dummyDbSetup.create3Logs(well.id, session) data = BaseDao.convertJSONtoData(logs[0].log_data_str) logData = np.empty((len(logs), len(data))) domainId = 0 for i, log in enumerate(logs): if i == 0: domainId = log.log_domain_id data = BaseDao.convertJSONtoData(log.log_data_str) for j, sample in enumerate(data): logData[i][j] = sample log.importLog = True dataTest = logData[1,:] lasPersister = LasPersister(session) lasReader = LasReader() lasReader.logList = logs lasReader._logs = logData lasPersister._logSetId = 1 lasPersister._logServiceId = 1 #TODO log domain needs to be created with dumy DB logDomain = LogDomainDao.getLogDomain( domainId, session) self.assertNotEqual(None, logDomain, "Sould not be None") lasPersister._logDomainId = logDomain.id lasReader.logDomain = logDomain logger.debug("well.mdstart:{0}, well.mdstop:{1}, logDomain.log_start:{2}, logDomain.log_stop:{3}".format(well.mdstart, well.mdstop, logDomain.log_start, logDomain.log_stop)) lasPersister._lasReader = lasReader lasPersister._wellId = well.id lasPersister.writeLogData() allLogs = session.query(Log).all() for log in allLogs: logger.debug("--test_updateWellStartStop() post write log data id:{0}, name:{1}".format(log.id, log.name)) session.close()
def __init__(self, fileName, parent=None): logger.debug("__init__() " + str(fileName)) super(ImportLasWizard, self).__init__(parent) self.setObjectName("importLasWizard") #default wizard anyway #self.setupUi(self) #holder for radio button selection state -instead of registerField self._importAllData = False self._wellExistsInDB = False #if error saving an object quit wizard self._errorOnSave = False self._reader = LasReader() self._fileName = fileName self._session = DM.getSession() self.checkIfWellExistsInDB() self.setWindowTitle("Import .las data wizard") self.resize(640, 480) #slot handling the next button, but disconnect the default slot first #see http://stackoverflow.com/questions/11155494/handling-cancellation-on-a-wizard-page #self.disconnect(self.button(QWizard.NextButton), QtCore.SIGNAL('clicked()'), self, QtCore.SLOT('next()')) if fileName is not None: #plotter=totaldepth.PlotLogs #plotter.mockPlot() self.readFile() #las_info = lasio.pylasdev.las_reader.read_las_file(str(fileName)) if len(self._reader.logList) == 0: self.NextButton.setEnabled(False) self.BackButton.setEnabled(False) logger.info("Cannot populate dialog, log list is empty") else: self.addPage(ImportLasWizardPage(self._reader.logList, self)) self.addPage(WellLasWizardPage(self._reader.well, self)) self.addPage(LogServiceWizardPage(self._reader, self)) self.addPage(ParameterLasWizardPage(self._reader, self)) else: logger.info("Cannot populate dialog, filename is empty") self.connectSlots()
def test_writeLogData(self, mock_class): logger.debug(">>test_writeLogData()") #self.dummyDbSetup = DummyDbSetup() self.dummyDbSetup.setupDatabase() session = DM.getSession() well = self.dummyDbSetup.createWell(session) logs = self.dummyDbSetup.create3Logs(well.id, session) data = BaseDao.convertJSONtoData(logs[0].log_data_str) logData = np.empty((len(logs), len(data))) for i, log in enumerate(logs): data = BaseDao.convertJSONtoData(log.log_data_str) for j, sample in enumerate(data): logData[i][j] = sample log.importLog = True dataTest = logData[1,:] lasPersister = LasPersister(session) lasReader = LasReader() lasReader.logList = logs lasReader._logs = logData lasPersister._logSetId = 1 lasPersister._logServiceId = 1 #TODO log domain needs to be created with dumy DB logDomain = LogDomainDao.getLogDomain(log.log_domain_id, session) lasPersister._logDomainId = logDomain.id lasReader.logDomain = logDomain lasPersister._lasReader = lasReader lasPersister._wellId = well.id lasPersister._lasModel = lasReader.lasModel lasRounding = 4 lasPersister._lasImportLogicModel = LasImportLogicModel() lasPersister.writeLogData(lasPersister._lasModel, lasPersister._lasImportLogicModel, lasRounding) allLogs = session.query(Log).all() for log in allLogs: logger.debug("--test_writeLogData() post write log data id:{0}, name:{1}".format(log.id, log.name)) session.close()
def createWell(self, session=None): logger.debug(">>createWell() ") localSession = False if session == None: session = DM.getSession() localSession = True wells = WellDao.getAllWells(session) if len(wells) > 0: for well in wells: logger.debug("existing wells:{0}".format(well.name)) assert 0 == len(wells) #timeStamp = TimeUtils.getTimeInMilliSecs() well = Well() well.name = "test_well" well.depth_reference = "MDKB" well.elevation_of_depth_reference = "24.0" session.add(well) session.commit() dummyWell = session.query(Well).filter(Well.name == 'test_well').one() assert "test_well" == dummyWell.name if localSession: session.close() return dummyWell
def __init__( self, parent=None, #dbinfo = None, settings=None, name=None, context_menu=context_menu, ): QWidget.__init__(self, parent) #self.dbinfo = dbinfo self._session = DM.getSession() #here is where we connect database modified signal to refresh slot DM.databaseModifiedSignal.connect(self.refresh) self.name = name self.context_menu = context_menu self.mainLayout = QVBoxLayout() self.setLayout(self.mainLayout) self.listTreeDescription = get_standard_treeview() self.settings = settings ''' if self.settings is not None and self.name is not None: self.listTreeDescription = self.settings.getValueOrDefault('/listTreeDescription'+self.name, self.listTreeDescription) for td in self.listTreeDescription: td.check_and_complete(self.dbinfo) ''' self.tabViews = QTabWidget() self.mainLayout.addWidget(self.tabViews) self.setObjectName("mainExplorer") self.createAction() self.createConfigureMenu() self.deepRefresh()
def test_getSession(self): logger.debug(">>test_getSession") DM.init_db() session = DM.getSession() session.close()
def getSession(cls): session = DM.getSession() return session
def getYData(self): ''' Retrieves lit of yData from db on first call and stores it here ''' if (len(self.y_data) == 0) and (self.y_data_string != ""): session = DM.getSession() self.y_data = BaseDao.convertJSONtoData(self.y_data_string) return self.y_data
def create3Logs(self, wellId, session=None): logger.debug(">>create3Logs() well id: " + str(wellId)) localSession = False if session == None: session = DM.getSession() localSession = True logDomain = LogDomain() logDomain.z_measure_type_name = "MD" logDomain.log_start = 0.0 logDomain.log_step = 0.1524 logDomain.log_stop = 1000.0 session.add(logDomain) session.flush() logDomainId = logDomain.id log1 = Log() log1.name = "LWD_GR" log1.log_type_name = LogType.GAMMA.name log1.z_measure_type_name = "MD" log1.z_measure_min = 0.0 log1.z_measure_max = 1000.0 log1.z_measure_step = 0.1524 log1.log_data_str = BaseDao.convertDataToJSON( [0.378425, 0.381605, 0.397528]) log1.z_measure_data_str = BaseDao.convertDataToJSON([102, 103, 104]) #log1.rgb="100,100,100" #log1.alpha="255" #log1.log_plot_points_on = False log1.well_id = wellId log1.log_domain_id = logDomainId log2 = Log() log2.name = "2DT" log2.log_type_name = LogType.DT.name log2.z_measure_type_name = "MD" log2.z_measure_min = 0.0 log2.z_measure_max = 1000.0 log2.z_measure_step = 0.1524 log2.log_data_str = BaseDao.convertDataToJSON( [0.378425, 0.381605, 0.397528]) log2.z_measure_data_str = BaseDao.convertDataToJSON([102, 103, 104]) #log2.rgb="100,100,100" #log2.alpha="255" #log2.log_plot_points_on = False log2.well_id = wellId log2.log_domain_id = logDomainId log3 = Log() log3.name = "3SP" log3.log_type_name = LogType.SP.name log3.z_measure_type_name = "MD" log3.z_measure_min = 0.0 log3.z_measure_max = 1000.0 log3.z_measure_step = 0.1524 log3.log_data_str = BaseDao.convertDataToJSON( [0.378425, 0.381605, 0.397528]) log3.z_measure_data_str = BaseDao.convertDataToJSON([102, 103, 104]) #log3.rgb="100,100,100" #log3.alpha="255" #log3.log_plot_points_on = False log3.well_id = wellId log3.log_domain_id = logDomainId self.setPreferences(log1, session) self.setPreferences(log2, session) self.setPreferences(log3, session) session.add(log1) session.add(log2) session.add(log3) session.commit() dummyLog = session.query(Log).filter(Log.name == 'LWD_GR').one() assert "LWD_GR" == dummyLog.name assert wellId == dummyLog.well_id allLogs = session.query(Log).all() if localSession: session.close() return allLogs