当前位置: 首页>>代码示例>>Python>>正文


Python pandas2ri.activate方法代码示例

本文整理汇总了Python中rpy2.robjects.pandas2ri.activate方法的典型用法代码示例。如果您正苦于以下问题:Python pandas2ri.activate方法的具体用法?Python pandas2ri.activate怎么用?Python pandas2ri.activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rpy2.robjects.pandas2ri的用法示例。


在下文中一共展示了pandas2ri.activate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_log_source

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def query_log_source(source, time_filter, time_column):
    from rpy2.robjects import pandas2ri

    cutoff = f"DATEADD(day, -{time_filter}, CURRENT_TIMESTAMP())"
    query = f"SELECT * FROM {source} WHERE {time_column} > {cutoff};"
    try:
        data = list(db.fetch(query))
    except Exception as e:
        log.error("Failed to query log source: ", e)
    f = pack(data)
    frame = pandas.DataFrame(f)
    pandas2ri.activate()
    r_dataframe = pandas2ri.py2rpy(frame)
    return r_dataframe 
开发者ID:snowflakedb,项目名称:SnowAlert,代码行数:16,代码来源:baseline_runner.py

示例2: _build

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def _build(self, **kwargs):
        from rpy2.robjects import numpy2ri, pandas2ri
        match_it = self.install_matchit()

        self.num_treatments = kwargs["num_treatments"]
        self.batch_size = kwargs["batch_size"]
        self.match_it = match_it
        numpy2ri.activate()
        pandas2ri.activate()

        return super(PSM, self)._build(**kwargs) 
开发者ID:d909b,项目名称:perfect_match,代码行数:13,代码来源:psm.py

示例3: _build

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def _build(self, **kwargs):
        from rpy2.robjects import numpy2ri, pandas2ri
        n_jobs = int(np.rint(kwargs["n_jobs"]))

        bart = self.install_bart()
        bart.set_bart_machine_num_cores(n_jobs)

        self.bart = bart
        numpy2ri.activate()
        pandas2ri.activate()

        return None 
开发者ID:d909b,项目名称:perfect_match,代码行数:14,代码来源:bart.py

示例4: dtwWrapper

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def dtwWrapper(data, rows, columns, k):
    '''
    wrapper function for dynamic time warping.
    includes use of exponential adaptive tuning function
    with temporal correlation if k > 0
    '''

    # not explicitly called, but needs to be in R environment
    DTW = importr("dtw")

    # create a data frame of zeros of size number of ids x number of ids
    # fill it with the calculated distance metric for each pair wise comparison

    df_ = pd.DataFrame(index=rows,
                       columns=columns)
    df_ = df_.fillna(0.0).astype(np.float64)

    # fill the array with dtw-distance values
    pandas2ri.activate()

    for i in rows:
        E.info("DTW %s" % i)
        for j in columns:
            series1 = data.loc[i].values.tolist()
            series2 = data.loc[j].values.tolist()
            DTW_value = (R.dtw(series1,
                               series2)).rx('distance')[0][0]
            cort_value = temporalCorrelate(series1, series2)
            tuned_value = adaptiveTune(cort_value, k)
            time_dist = DTW_value * tuned_value
            df_.loc[i][j] = float(time_dist)
            df_[j][i] = float(time_dist)

    return df_ 
开发者ID:CGATOxford,项目名称:CGATPipelines,代码行数:36,代码来源:PipelineTimeseries.py

示例5: testActivate

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def testActivate(self):
        #FIXME: is the following still making sense ?
        assert rpyp.py2rpy != robjects.conversion.py2rpy
        l = len(robjects.conversion.py2rpy.registry)
        k = set(robjects.conversion.py2rpy.registry.keys())
        rpyp.activate()
        assert len(conversion.py2rpy.registry) > l
        rpyp.deactivate()
        assert len(conversion.py2rpy.registry) == l
        assert set(conversion.py2rpy.registry.keys()) == k 
开发者ID:rpy2,项目名称:rpy2,代码行数:12,代码来源:test_pandas_conversions.py

示例6: testActivateTwice

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def testActivateTwice(self):
        #FIXME: is the following still making sense ?
        assert rpyp.py2rpy != robjects.conversion.py2rpy
        l = len(robjects.conversion.py2rpy.registry)
        k = set(robjects.conversion.py2rpy.registry.keys())
        rpyp.activate()
        rpyp.deactivate()
        rpyp.activate()
        assert len(conversion.py2rpy.registry) > l
        rpyp.deactivate()
        assert len(conversion.py2rpy.registry) == l
        assert set(conversion.py2rpy.registry.keys()) == k 
开发者ID:rpy2,项目名称:rpy2,代码行数:14,代码来源:test_pandas_conversions.py

示例7: Kriging_Interpolation_Array

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def Kriging_Interpolation_Array(input_array, x_vector, y_vector):
    """
    Interpolate data in an array using Ordinary Kriging

    Reference: https://cran.r-project.org/web/packages/automap/automap.pdf
    """
    # Total values in array
    n_values = np.isfinite(input_array).sum()
    # Load function
    pandas2ri.activate()
    robjects.r('''
                library(gstat)
                library(sp)
                library(automap)
                kriging_interpolation <- function(x_vec, y_vec, values_arr,
                                                  n_values){
                  # Parameters
                  shape <- dim(values_arr)
                  counter <- 1
                  df <- data.frame(X=numeric(n_values),
                                   Y=numeric(n_values),
                                   INFZ=numeric(n_values))
                  # Save values into a data frame
                  for (i in seq(shape[2])) {
                    for (j in seq(shape[1])) {
                      if (is.finite(values_arr[j, i])) {
                        df[counter,] <- c(x_vec[i], y_vec[j], values_arr[j, i])
                        counter <- counter + 1
                      }
                    }
                  }
                  # Grid
                  coordinates(df) = ~X+Y
                  int_grid <- expand.grid(x_vec, y_vec)
                  names(int_grid) <- c("X", "Y")
                  coordinates(int_grid) = ~X+Y
                  gridded(int_grid) = TRUE
                  # Kriging
                  krig_output <- autoKrige(INFZ~1, df, int_grid)
                  # Array
                  values_out <- matrix(krig_output$krige_output$var1.pred,
                                       nrow=length(y_vec),
                                       ncol=length(x_vec),
                                       byrow = TRUE)
                  return(values_out)
                }
                ''')
    kriging_interpolation = robjects.r['kriging_interpolation']
    # Execute kriging function and get array
    r_array = kriging_interpolation(x_vector, y_vector, input_array, n_values)
    array_out = np.array(r_array)
    # Return
    return array_out 
开发者ID:gespinoza,项目名称:hants,代码行数:55,代码来源:functions.py

示例8: array_interpolation

# 需要导入模块: from rpy2.robjects import pandas2ri [as 别名]
# 或者: from rpy2.robjects.pandas2ri import activate [as 别名]
def array_interpolation(lon_ls, lat_ls, infz_array_in, min_infz,
                        return_single_value):
    '''
    Interpolate missing values in an array using kriging in R
    '''
    # Replace values smaller than the minimum
    infz_array_in[infz_array_in < min_infz] = np.nan
    # Total values in array
    n_values = np.isfinite(infz_array_in).sum()
    # Load function
    pandas2ri.activate()
    robjects.r('''
                library(gstat)
                library(sp)
                library(automap)
                kriging_interpolation <- function(x_vec, y_vec, values_arr,
                                                  n_values){
                  # Parameters
                  shape <- dim(values_arr)
                  counter <- 1
                  df <- data.frame(X=numeric(n_values),
                                   Y=numeric(n_values),
                                   INFZ=numeric(n_values))
                  # Save values into a data frame
                  for (i in seq(shape[2])) {
                    for (j in seq(shape[1])) {
                      if (is.finite(values_arr[j, i])) {
                        df[counter,] <- c(x_vec[i], y_vec[j], values_arr[j, i])
                        counter <- counter + 1
                      }
                    }
                  }
                  # Grid
                  coordinates(df) = ~X+Y
                  int_grid <- expand.grid(x_vec, y_vec)
                  names(int_grid) <- c("X", "Y")
                  coordinates(int_grid) = ~X+Y
                  gridded(int_grid) = TRUE
                  # Kriging
                  krig_output <- autoKrige(INFZ~1, df, int_grid)
                  # Array
                  values_out <- matrix(krig_output$krige_output$var1.pred,
                                       nrow=length(y_vec),
                                       ncol=length(x_vec),
                                       byrow = TRUE)
                  return(values_out)
                }
                ''')
    kriging_interpolation = robjects.r['kriging_interpolation']
    # Execute kriging function and get array
    r_array = kriging_interpolation(lon_ls, lat_ls, infz_array_in, n_values)
    infz_array_out = np.array(r_array)
    # Return
    if not return_single_value:
        return infz_array_out
    else:
        x, y = return_single_value
        return infz_array_out[y, x] 
开发者ID:wateraccounting,项目名称:wa,代码行数:60,代码来源:functions.py


注:本文中的rpy2.robjects.pandas2ri.activate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。