コード例 #1
0
 def test_stringToInt1(self):
     stringForTest = "34"
     value = NumberUtils.stringToInt(stringForTest)
     self.assertTrue(34 == value,
                     'expected {0} actual {1}'.format(34, value))
コード例 #2
0
 def test_stringToInt0(self):
     stringForTest = "100.w"
     value = NumberUtils.stringToInt(stringForTest)
     self.assertTrue(0 == value, 'expected {0} actual {1}'.format(0, value))
コード例 #3
0
 def test_parseStringToFloat1(self):
     stringToStrip = "w34"
     value = NumberUtils.parseStringToFloat(stringToStrip)
     self.assertTrue(0.0 == value,
                     'expected {0} actual {1}'.format(0.0, value))
コード例 #4
0
 def test_parseStringToRoundedFloat(self):
     stringToStrip = "9.333333333meters"
     value = NumberUtils.parseStringToRoundedFloat(stringToStrip, 3)
     self.assertTrue(9.333 == value,
                     'expected {0} actual {1}'.format(9.333, value))
コード例 #5
0
 def test_parseStringToFloat0(self):
     stringToStrip = "-0.01.2"
     value = NumberUtils.parseStringToFloat(stringToStrip)
     self.assertTrue(-0.01 == value,
                     'expected {0} actual {1}'.format(-0.01, value))
コード例 #6
0
    def computeStepNp(self, depthData, readerStep, rounding):
        """ check if las data has a consistent step value between all samples """
        #use depthData parameter so can unit test easily
        if len(depthData) > 1:
            try:
                depthDiff = []
                for i, item in enumerate(depthData):
                    if i > 0:
                        depthDiff.append(abs(item - depthData[i - 1]))

                roundedDepthDiff = np.around(depthDiff, decimals=rounding)

                #twice as fast as itemfreq
                uniqueDiffs, indexes, counts = np.unique(roundedDepthDiff,
                                                         return_index=True,
                                                         return_counts=True)

                if readerStep in uniqueDiffs:
                    readerStepInDiffs = True
                self._meanStepValue = NumberUtils.roundToDecimal(
                    np.mean(roundedDepthDiff), rounding)

                if len(uniqueDiffs) == 1:
                    self._consistentStep = True
                else:
                    self._consistentStep = False
                    numberDiffSteps = len(counts.tolist())
                    nonReaderStepLocations = {}
                    #are we going to use these or not?
                    for i, item in enumerate(roundedDepthDiff.tolist()):
                        for dstep in uniqueDiffs:
                            if dstep == item and dstep != readerStep:
                                if dstep in nonReaderStepLocations:
                                    # append the new number to the existing array at this slot
                                    nonReaderStepLocations[dstep].append(i)
                                else:
                                    # create a new array in this slot
                                    nonReaderStepLocations[dstep] = [i]
                    joinedStr = ', '.join(str(s) for s in indexes.tolist())
                    diffSteps = []
                    for s in uniqueDiffs:
                        if s != readerStep:
                            diffSteps.append(str(s))
                    joinedNonReaderSteps = ', '.join(diffSteps)
                    logger.info(
                        str(numberDiffSteps) + " different steps detected.")
                    if readerStepInDiffs:
                        logger.info("Non .las header specified steps (" +
                                    str(readerStep) + ") are: " +
                                    str(joinedNonReaderSteps))
                        logger.debug(
                            "Non .las header specified step line indexes in file: "
                            + str(nonReaderStepLocations.values()))

            except Exception as ex:
                template = "An exception of type {0} occured. Arguments:\n{1!r}"
                message = template.format(type(ex).__name__, ex.args)
                logger.debug(message)
        else:
            #  one or less data values
            self.consistentStep == True
コード例 #7
0
    def writeLogData(self):
        logger.debug(">>writeLogData()")
        logList = self._lasReader.logList
        assert len(self._lasReader.logList) == len(self._lasReader._logs)
        depthType = self._lasReader.well.z_measure_type_name
        for i, log in enumerate(logList):
            logger.debug("--writeLogData() log: " + str(log.name) +
                         " import: " + str(log.importLog))
            if log.importLog:
                log.log_set_id = self._logSetId
                log.log_service_id = self._logServiceId
                log.log_domain_id = self._logDomainId
                log.well_id = self._wellId

                if ImportExportPreferences.HONOUR_LAS_DEPTH_VALUES:
                    depthList = self._lasReader._depthData
                    honour_las_depth_values = True
                else:
                    depthList = self.calcSteppedDepth(
                        self._lasReader.logDomain, self._las_rounding,
                        self._lasReader._logs[0, :])
                    honour_las_depth_values = False
                jsonStr = BaseDao.convertDataToJSON(depthList)
                log.z_measure_data_str = jsonStr
                logDomain = self._lasReader.logDomain
                log.z_measure_min = logDomain.log_start
                log.z_measure_max = logDomain.log_stop
                log.consistent_step = self._consistentStep
                #store the mean step anyway
                log.z_measure_step = self._meanStepValue

                log.null = self._lasReader.null_value

                logTypeUid = LogType.getUidFromName(log.log_type_name)
                logCurveDefaults = LogCurvePreferencesDao.getLogCurvePreferences(
                    logTypeUid, self._session)
                if logCurveDefaults == None:
                    #no preferences set yet, use defaults
                    logCurveDefaults = LogCurvePreferencesDao.getLogCurveDefaults(
                        logTypeUid, self._session)

                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 log.is_logarithmic:
                    log.log_plot_log_cycles = logCurveDefaults.log_plot_log_cycles

                log.z_measure_type_name = depthType
                #duplication - but makes simpler if want to change log down track
                log.z_measure_reference = self._lasReader.logService.z_measure_reference
                try:
                    #see http://stackoverflow.com/questions/4455076/numpy-access-an-array-by-column
                    data = self._lasReader._logs[i, :]
                    log.honour_las_depth_values = honour_las_depth_values
                    log.value_min = NumberUtils.minimumExcludingNulls(
                        data, log.null)
                    log.value_max = NumberUtils.maximumExcludingNulls(
                        data, log.null)
                    jsonStr = BaseDao.convertDataToJSON(data.tolist())
                    log.log_data_str = jsonStr
                    #statistics
                    log.mean = statistics.mean(data)
                    log.median = statistics.median(data)
                    #standard deviation
                    log.stdev = statistics.pstdev(data)

                except IndexError as ie:
                    logger.error("Error saving log data " + str(ie))
                    return
                if self._allDataFlag:
                    log.parameter_set_id = self._parameterSetId

                log.source = self._lasReader.fullFilePathName
                logger.debug("--writeLogData() pre flush log.id: " +
                             str(log.id) + " log_set_id " +
                             str(log.log_set_id) + " log_service_id " +
                             str(log.log_service_id) + " log_domain_id " +
                             str(log.log_domain_id) +
                             " log.parameter_set_id " +
                             str(log.parameter_set_id))
                logger.debug(
                    "--writeLogData() name: " + str(log.name) + " type: " +
                    str(log.log_type_name))  #+" datas: "+str(log.log_datas))

                log.history_set_id = self._historySetId

                self._session.add(log)
                self._session.flush()
                logger.debug("--writeLogData() post flush log.id: " +
                             str(log.id))
コード例 #8
0
    def saveDataState(self, wellPlotData, curveStyleWidget):
        '''called from apply/OK button, saves all data to log objects '''
        #assert twItem.data != None
        #assert isinstance(twItem.data(Qt.UserRole), tuple)
        #assert isinstance(twItem.data(Qt.UserRole)[0], LogTrackData)
        #assert isinstance(twItem.data(Qt.UserRole)[1], Log)
        allRows = curveStyleWidget.curveTableWidget.rowCount()
        for row in range(0, allRows):
            twItemName = curveStyleWidget.curveTableWidget.item(row, 0)
            trackData = twItemName.data(Qt.UserRole)[0]
            tableLog = twItemName.data(Qt.UserRole)[1]
            for track in wellPlotData.getLogTrackDatas():
                for log in track.getLogs():
                    if track.plot_index == trackData.plot_index:
                        if log.id == tableLog.id:
                            logger.debug(
                                "track.plot_index :{0}, trackData.plot_index: {1}, log.id: {2}, tableLog.id: {3}, log.name: {4}"
                                .format(track.plot_index, trackData.plot_index,
                                        log.id, tableLog.id, log.name))

                            twItemLeftScale = curveStyleWidget.curveTableWidget.item(
                                row, 4)
                            log.left_scale = NumberUtils.straightStringToFloat(
                                twItemLeftScale.text())
                            twItemRightScale = curveStyleWidget.curveTableWidget.item(
                                row, 5)
                            log.right_scale = NumberUtils.straightStringToFloat(
                                twItemRightScale.text())
                            twItemLogarithmic = curveStyleWidget.curveTableWidget.item(
                                row, 6)
                            log.logarithmic = WidgetUtils.getBoolFromQtCheck(
                                twItemLogarithmic.checkState())

                            twItemCurveColour = curveStyleWidget.curveTableWidget.cellWidget(
                                row, 7)
                            r, g, b, a = QColor(
                                twItemCurveColour.color()).getRgb()
                            rgbStr = ImageUtils.rgbToString(r, g, b)
                            log.rgb = rgbStr

                            twItemOpacity = curveStyleWidget.curveTableWidget.item(
                                row, 8)
                            log.alpha = NumberUtils.straightStringToFloat(
                                twItemOpacity.text())
                            twItemLineWidth = curveStyleWidget.curveTableWidget.item(
                                row, 9)
                            log.line_width = NumberUtils.straightStringToFloat(
                                twItemLineWidth.text())

                            twItemLineStyle = curveStyleWidget.curveTableWidget.cellWidget(
                                row, 10)
                            log.line_style = twItemLineStyle.currentText()

                            twItemPointSize = curveStyleWidget.curveTableWidget.item(
                                row, 11)
                            log.point_size = NumberUtils.straightStringToFloat(
                                twItemPointSize.text())

                            twItemPointStyle = curveStyleWidget.curveTableWidget.cellWidget(
                                row, 12)
                            log.point_style = twItemPointStyle.currentText()

                            twItemPointsOn = curveStyleWidget.curveTableWidget.item(
                                row, 13)
                            log.log_plot_points_on = WidgetUtils.getBoolFromQtCheck(
                                twItemPointsOn.checkState())
コード例 #9
0
    def populateData(self):
        logger.debug(">>populateData()")

        titleOnCheckState = WidgetUtils.getQtCheckObject(
            self._wellPlotData.title_on)
        self.plotTitleOnCheckBox.setCheckState(titleOnCheckState)
        self.plotTitleOnCheckBox.stateChanged.connect(self.styleChanged)
        self.plotTitleLineEdit.setText(self._wellPlotData.title)
        self.plotTitleLineEdit.textChanged.connect(self.styleChanged)

        #not enabled for this version
        self.plotTitleOnCheckBox.setEnabled(False)
        self.plotTitleLineEdit.setEnabled(False)
        #track background button
        trackBackButtonQColor = ImageUtils.rgbToQColor(
            self._wellPlotData.plot_background_rgb)
        hBox1 = QHBoxLayout()
        self.trackBGColourBtnHolderWidget.setLayout(hBox1)
        self.trackBackgroundColorPushButton = QColorButton()
        self.trackBackgroundColorPushButton.setColor(trackBackButtonQColor)
        hBox1.addWidget(self.trackBackgroundColorPushButton)
        self.trackBackgroundColorPushButton.clicked.connect(self.styleChanged)

        plotBackgroundAlpha = NumberUtils.stringToInt(
            self._wellPlotData.plot_background_alpha)
        self.trackBackgroundOpacitySpinBox.setValue(plotBackgroundAlpha)
        self.trackBackgroundOpacitySpinBox.valueChanged.connect(
            self.styleChanged)

        singleRowCheckState = WidgetUtils.getQtCheckObject(
            self._wellPlotData.single_row_header_labels)
        self.singleRowLabelsCheckBox.setCheckState(singleRowCheckState)
        self.singleRowLabelsCheckBox.stateChanged.connect(self.styleChanged)
        #header label background button
        labelBackButtonQColor = ImageUtils.rgbToQColor(
            self._wellPlotData.label_background_rgb)
        hBox2 = QHBoxLayout()
        self.headerLabelBGColourBtnHolderWidget.setLayout(hBox2)
        self.labelBackgroundColorPushButton = QColorButton()
        self.labelBackgroundColorPushButton.setColor(labelBackButtonQColor)
        hBox2.addWidget(self.labelBackgroundColorPushButton)
        self.labelBackgroundColorPushButton.clicked.connect(self.styleChanged)

        labelBackgroundAlpha = NumberUtils.stringToInt(
            self._wellPlotData.label_background_alpha)
        self.labelBackgroundOpacitySpinBox.setValue(labelBackgroundAlpha)
        self.labelBackgroundOpacitySpinBox.valueChanged.connect(
            self.styleChanged)

        #label foreground button

        #labelForegroundRGB = NumberUtils.stringToInt(self._wellPlotData.label_foreground_rgb)
        labelForeButtonQColor = ImageUtils.rgbToQColor(
            self._wellPlotData.label_foreground_rgb)
        hBox3 = QHBoxLayout()
        self.headerLabelTextColourBtnHolderWidget.setLayout(hBox3)
        self.labelForegroundColorPushButton = QColorButton()
        self.labelForegroundColorPushButton.setColor(labelForeButtonQColor)
        hBox3.addWidget(self.labelForegroundColorPushButton)
        self.labelForegroundColorPushButton.clicked.connect(self.styleChanged)

        labelForegroundAlpha = NumberUtils.stringToInt(
            self._wellPlotData.label_foreground_alpha)
        self.labelForegroundOpacitySpinBox.setValue(labelForegroundAlpha)
        self.labelForegroundOpacitySpinBox.valueChanged.connect(
            self.styleChanged)