Skip to content

Instantly share code, notes, and snippets.

@kagaya
Last active December 10, 2022 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagaya/32706c38404c99431669ba34b8bccbac to your computer and use it in GitHub Desktop.
Save kagaya/32706c38404c99431669ba34b8bccbac to your computer and use it in GitHub Desktop.
read raw.pkl file from soft_skeleton_solver (https://github.com/katsuma-inoue/soft_skeleton_solver)
library(tidyverse)
library(reticulate)
read_raw_pkl <- function(file_path="/path/to/raw.pkl"){
# https://gist.github.com/kagaya/32706c38404c99431669ba34b8bccbac
j <- import("joblib") # python package joblib is loaded via {reticulate}
arm_xy <- j$load(file_path)
tibble(t=1:length(arm_xy$path), path=arm_xy$path) %>%
group_by(t) %>%
mutate(x=list(path[[1]][[1]][[2]][,1]),
y=list(path[[1]][[1]][[2]][,2])) %>%
select(t, x, y) %>%
unnest(cols=c(x,y)) %>%
ungroup() %>%
group_by(t) %>%
mutate(node=1:length(x)) %>%
ungroup()
}
txy <- read_raw_pkl("path/to/raw.pkl") # this will load the data as tibble
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment