Exemplo n.º 1
0
    def on_calcAll_requested(self):
        '''
            Calculation of gradient for all timesteps has been requested
        '''
        try:
            info = self.ctrlWidget().selectedWellsInfo()
            if len(info.keys()) < 3:
                raise ValueError('Select at least 3 wells to calculate gradient')
            
            datetimeColName = self.ctrlWidget().comboBox_Datetime.currentText()
            if not datetimeColName:
                return
            
            # now generate long dataframe
            df    = self.inputValues()['data']  #pd.DataFrame in the input terminal `data`
            All_df = pd.DataFrame({datetimeColName: df[datetimeColName], 'gradient': np.zeros(len(df.index)), 'direction(degrees North)': np.zeros(len(df.index))}  )
            

            # then get the information
            dictForDf = {'well': [], 'x': [], 'y': []}  # dictionary that will be used for a convinient creation of the DataFrame that is requered for calculations
            for wellName, wellInfo in info.iteritems():
                dictForDf['well'].append(wellName)
                dictForDf['x'].append(wellInfo['x'])
                dictForDf['y'].append(wellInfo['y'])


            with pg.ProgressDialog("Calculating gradient for All timesteps {0}".format(len(All_df.index)), 0, len(All_df.index)) as dlg:
                for row_i in df.index:
                    row = df.loc[row_i]
                    z = np.zeros(len(dictForDf['well']))
                    for i, well_n in enumerate(dictForDf['well']):
                        z[i] = float(row[info[well_n]['z']])
                    x = np.array(dictForDf['x'])
                    y = np.array(dictForDf['y'])
                    _, gradient, angle = devlin2003(np.matrix([x, y, z]).T)
                    All_df.loc[row_i, 'gradient'] = gradient
                    All_df.loc[row_i, 'direction(degrees North)'] = angle2bearing(angle, origin='N')[0]
                    dlg += 1
                    del z
                    
                    if dlg.wasCanceled():
                        del All_df
                        All_df = None
                        break
                dlg += 1
            self.setOutput(All=All_df)
            self.clearException()
        except:
            self.setOutput(All=None)
            self.ctrlWidget().clear(clearTable=False)
            self.setException(sys.exc_info())
            
            self.sigOutputChanged.emit(self)  ## triggers flowchart to propagate new data
Exemplo n.º 2
0
    def on_calcAll_requested(self):
        '''
            Calculation of gradient for all timesteps has been requested
        '''
        try:
            info = self.ctrlWidget().selectedWellsInfo()
            if len(info.keys()) < 3:
                raise ValueError(
                    'Select at least 3 wells to calculate gradient')

            datetimeColName = self.ctrlWidget().comboBox_Datetime.currentText()
            if not datetimeColName:
                return

            # now generate long dataframe
            df = self.inputValues()[
                'data']  #pd.DataFrame in the input terminal `data`
            All_df = pd.DataFrame({
                datetimeColName:
                df[datetimeColName],
                'gradient':
                np.zeros(len(df.index)),
                'direction(degrees North)':
                np.zeros(len(df.index))
            })

            # then get the information
            dictForDf = {
                'well': [],
                'x': [],
                'y': []
            }  # dictionary that will be used for a convinient creation of the DataFrame that is requered for calculations
            for wellName, wellInfo in info.iteritems():
                dictForDf['well'].append(wellName)
                dictForDf['x'].append(wellInfo['x'])
                dictForDf['y'].append(wellInfo['y'])

            with pg.ProgressDialog(
                    "Calculating gradient for All timesteps {0}".format(
                        len(All_df.index)), 0, len(All_df.index)) as dlg:
                for row_i in df.index:
                    row = df.loc[row_i]
                    z = np.zeros(len(dictForDf['well']))
                    for i, well_n in enumerate(dictForDf['well']):
                        z[i] = float(row[info[well_n]['z']])
                    x = np.array(dictForDf['x'])
                    y = np.array(dictForDf['y'])
                    _, gradient, angle = devlin2003(np.matrix([x, y, z]).T)
                    All_df.loc[row_i, 'gradient'] = gradient
                    All_df.loc[row_i,
                               'direction(degrees North)'] = angle2bearing(
                                   angle, origin='N')[0]
                    dlg += 1
                    del z

                    if dlg.wasCanceled():
                        del All_df
                        All_df = None
                        break
                dlg += 1
            self.setOutput(All=All_df)
            self.clearException()
        except:
            self.setOutput(All=None)
            self.ctrlWidget().clear(clearTable=False)
            self.setException(sys.exc_info())

            self.sigOutputChanged.emit(
                self)  ## triggers flowchart to propagate new data
Exemplo n.º 3
0
    def process(self, coord, data):
        if data is not None:
            colname = [col for col in data.columns if isNumpyDatetime(data[col].dtype)]
            self._ctrlWidget.param('Datetime').setLimits(colname)
            self.data = data
        else:
            self.data = None
            return dict(this=None, All=self.All_out)
        
        if coord is not None:
            colname = [col for col in coord.columns if isNumpyNumeric(coord[col].dtype)]
            self._ctrlWidget.param('coords_grp', 'x').setLimits(colname)
            self._ctrlWidget.param('coords_grp', 'y').setLimits(colname)
            self.CW().disconnect_valueChanged2upd(self.CW().param('coords_grp', 'x'))
            self.CW().disconnect_valueChanged2upd(self.CW().param('coords_grp', 'y'))

            self.CW().param('coords_grp', 'x').setValue(colname[0])
            self.CW().param('coords_grp', 'y').setValue(colname[1])
            self.CW().connect_valueChanged2upd(self.CW().param('coords_grp', 'x'))
            self.CW().connect_valueChanged2upd(self.CW().param('coords_grp', 'y'))
        else:
            return dict(this=None, All=self.All_out)


        # now make sure All well specified in `coord` dataframe are found in `data`
        well_names = coord.index.values
        for well_n in well_names:
                if well_n not in data.columns:
                    raise ValueError('Well named `{0}` not found in `data` but is declared in `coords`'.format(well_n))


        kwargs = self.ctrlWidget().prepareInputArguments()

        # select row whith user-specified datetime `timestep`
        row = data.loc[data[kwargs['datetime']] == kwargs['t']]
        if row.empty:
            raise IndexError('Selected timestep `{0}` not found in `data`s column {1}. Select correct one'.format(kwargs['t'], kwargs['datetime']))

        # now prepare dataframe for devlin calculations
        df = coord.copy()
        df['z'] = np.zeros(len(df.index))
        for well_n in well_names:
            df.loc[well_n, 'z'] = float(row[well_n])
        gradient, direction = devlin2003pandas(df, kwargs['x'], kwargs['y'], 'z')

        self.CW().param('grad').setValue(gradient)
        self.CW().param('angle').setValue(direction)


        # here we will generate large dataset of all timesteps
        if self.CW().CALCULATE_ALL:
            # now generate long dataframe
            All = pd.DataFrame({kwargs['datetime']: data[kwargs['datetime']], 'gradient': np.zeros(len(data.index)), 'direction(degrees North)': np.zeros(len(data.index))}  )
            self.All_out = All  # pointer
            with pg.ProgressDialog("Calculating gradient for All timesteps {0}".format(len(All.index)), 0, len(All.index)) as dlg:
                for row_i in data.index:
                    row = data.loc[row_i]
                    z = np.zeros(len(coord.index))
                    for i, well_n in enumerate(well_names):
                        z[i] = float(row[well_n])
                    x = coord[kwargs['x']].values
                    y = coord[kwargs['y']].values
                    _, gradient, angle = devlin2003(np.matrix([x, y, z]).T)
                    All.loc[row_i, 'gradient'] = gradient
                    All.loc[row_i, 'direction(degrees North)'] = angle2bearing(angle, origin='N')[0]
                    dlg += 1
                    del z
                    
                    if dlg.wasCanceled():
                        del All
                        self.All_out = None
                        break
                        #return dict(df=df, All=self.All_out)
                dlg += 1

        return dict(this=df, All=self.All_out)
Exemplo n.º 4
0
    def process(self, coord, data):
        if data is not None:
            colname = [
                col for col in data.columns if isNumpyDatetime(data[col].dtype)
            ]
            self._ctrlWidget.param('Datetime').setLimits(colname)
            self.data = data
        else:
            self.data = None
            return dict(this=None, All=self.All_out)

        if coord is not None:
            colname = [
                col for col in coord.columns
                if isNumpyNumeric(coord[col].dtype)
            ]
            self._ctrlWidget.param('coords_grp', 'x').setLimits(colname)
            self._ctrlWidget.param('coords_grp', 'y').setLimits(colname)
            self.CW().disconnect_valueChanged2upd(self.CW().param(
                'coords_grp', 'x'))
            self.CW().disconnect_valueChanged2upd(self.CW().param(
                'coords_grp', 'y'))

            self.CW().param('coords_grp', 'x').setValue(colname[0])
            self.CW().param('coords_grp', 'y').setValue(colname[1])
            self.CW().connect_valueChanged2upd(self.CW().param(
                'coords_grp', 'x'))
            self.CW().connect_valueChanged2upd(self.CW().param(
                'coords_grp', 'y'))
        else:
            return dict(this=None, All=self.All_out)

        # now make sure All well specified in `coord` dataframe are found in `data`
        well_names = coord.index.values
        for well_n in well_names:
            if well_n not in data.columns:
                raise ValueError(
                    'Well named `{0}` not found in `data` but is declared in `coords`'
                    .format(well_n))

        kwargs = self.ctrlWidget().prepareInputArguments()

        # select row whith user-specified datetime `timestep`
        row = data.loc[data[kwargs['datetime']] == kwargs['t']]
        if row.empty:
            raise IndexError(
                'Selected timestep `{0}` not found in `data`s column {1}. Select correct one'
                .format(kwargs['t'], kwargs['datetime']))

        # now prepare dataframe for devlin calculations
        df = coord.copy()
        df['z'] = np.zeros(len(df.index))
        for well_n in well_names:
            df.loc[well_n, 'z'] = float(row[well_n])
        gradient, direction = devlin2003pandas(df, kwargs['x'], kwargs['y'],
                                               'z')

        self.CW().param('grad').setValue(gradient)
        self.CW().param('angle').setValue(direction)

        # here we will generate large dataset of all timesteps
        if self.CW().CALCULATE_ALL:
            # now generate long dataframe
            All = pd.DataFrame({
                kwargs['datetime']:
                data[kwargs['datetime']],
                'gradient':
                np.zeros(len(data.index)),
                'direction(degrees North)':
                np.zeros(len(data.index))
            })
            self.All_out = All  # pointer
            with pg.ProgressDialog(
                    "Calculating gradient for All timesteps {0}".format(
                        len(All.index)), 0, len(All.index)) as dlg:
                for row_i in data.index:
                    row = data.loc[row_i]
                    z = np.zeros(len(coord.index))
                    for i, well_n in enumerate(well_names):
                        z[i] = float(row[well_n])
                    x = coord[kwargs['x']].values
                    y = coord[kwargs['y']].values
                    _, gradient, angle = devlin2003(np.matrix([x, y, z]).T)
                    All.loc[row_i, 'gradient'] = gradient
                    All.loc[row_i, 'direction(degrees North)'] = angle2bearing(
                        angle, origin='N')[0]
                    dlg += 1
                    del z

                    if dlg.wasCanceled():
                        del All
                        self.All_out = None
                        break
                        #return dict(df=df, All=self.All_out)
                dlg += 1

        return dict(this=df, All=self.All_out)