-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathread.py
35 lines (25 loc) · 1.04 KB
/
read.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
from scipy.stats import rankdata
def read_data(data, t_min = None, t_max = None):
path = data + '/' + data + '-'
# read in the data
nverts = np.array([int(f.rstrip('\n')) for f in open(path + 'nverts.txt')])
times = np.array([float(f.rstrip('\n')) for f in open(path + 'times.txt')])
simplices = np.array([int(f.rstrip('\n')) for f in open(path + 'simplices.txt')])
times_ex = np.repeat(times, nverts)
# time filtering
t_ix = np.repeat(True, len(times))
if t_min is not None:
simplices = simplices[times_ex >= t_min]
nverts = nverts[times >= t_min]
if t_max is not None:
simplices = simplices[times_ex <= t_max]
nverts = nverts[times <= t_max]
# relabel nodes: consecutive integers from 0 to n-1
unique = np.unique(simplices)
mapper = {unique[i] : i for i in range(len(unique))}
simplices = np.array([mapper[s] for s in simplices])
# format as list of lists
l = np.split(simplices, np.cumsum(nverts))
C = [list(c) for c in l]
return(C)