-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_views.py
57 lines (45 loc) · 2.22 KB
/
fix_views.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import os
from subprocess import run
import mobie
def fix_views_ds(ds):
ds_folder = os.path.join("./data", ds)
mdata = mobie.metadata.read_dataset_metadata(ds_folder)
sources = mdata["sources"]
for name, source in sources.items():
stype = list(source.keys())[0]
menu_name = "em" if stype == "image" else "segmentation"
if stype == "segmentation":
view = mobie.metadata.get_default_view(stype, name, menu_name=menu_name,
tables=["default.tsv", "color_scheme_fibsem.tsv"],
colorByColumn="figuresColorScheme",
lut="argbColumn")
else:
view = mobie.metadata.get_default_view(stype, name, menu_name=menu_name)
mobie.metadata.add_view_to_dataset(ds_folder, name, view, overwrite=True)
if ds == "Covid19-S5-mock-Cell1-2":
url = "https://raw.githubusercontent.com/mobie/covid-em-project/master/data/Covid19-S5-mock-Cell1-2/misc/bookmarks/bookmarks.json"
elif ds == "Covid19-S4-Area2":
url = "https://raw.githubusercontent.com/mobie/covid-em-project/master/data/Covid19-S4-Area2/misc/bookmarks/bookmarks.json"
else:
url = None
if url is not None:
run(["wget", url, "-O", "bookmarks.json"])
with open("./bookmarks.json") as f:
trafos = json.load(f)
for name, trafo in trafos.items():
params = [float(tt[1:]) for tt in trafo["normView"]]
view = {
"viewerTransform": mobie.metadata.get_viewer_transform(normalized_affine=params),
"isExclusive": False,
"uiSelectionGroup": "bookmark"
}
mobie.metadata.add_view_to_dataset(ds_folder, name, view, overwrite=True)
os.remove("./bookmarks.json")
def fix_all_views():
ds_names = mobie.metadata.get_datasets("./data")
for ds in ds_names:
fix_views_ds(ds)
fix_all_views()
# https://github.com/mobie/covid-em-project/blob/master/data/Covid19-S4-Area2/misc/bookmarks/bookmarks.json
# https://github.com/mobie/covid-em-project/blob/master/data/Covid19-S5-mock-Cell1-2/misc/bookmarks/bookmarks.json