forked from Tevemadar/LocaliZoom
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
207 lines (207 loc) · 11.5 KB
/
index.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Setup</title>
<style>
input{
width:80%;
}
</style>
<script>
let lock;
async function check(){
let stamp=Date.now();
lock=stamp;
let jsonurl=document.getElementById("json").value;
let pyramids=document.getElementById("pyramids").value;
let log=document.getElementById("log");
function setlog(msg){
if(lock===stamp)
log.innerText=msg;
}
document.getElementById("trfbox").hidden=true;
setlog("");
if(pyramids.startsWith("img-"))
setlog("Shouldn't it be buckets/"+pyramids+"?\n\n");
if(!jsonurl.length)return;
let json=await fetch(jsonurl).then(response=>response.status===200?response.json():new Error(response.status+" "+response.statusText)).catch(exception=>exception);
if(json instanceof Error){
setlog(`Can't access JSON descriptor at ${jsonurl}. Please verify that the link is correct and that it's available for cross-site access ("CORS").\n${json.message}`);
return;
}
document.getElementById("pyrs").hidden=!!json.bucket;
if(json.bucket) {
let slices=json.sections;
let length=slices.length;
if(!length){
setlog(`${jsonurl} contains no images.`);
return;
}
if(!slices[0].filename.endsWith(".dzip")){
setlog(`${jsonurl} contains non-dzip images. Please contact developer.`);
return;
}
let baselink=`${location.href.match(/(.*\/)[^/]*/)[1]}filmstripzoom.html?atlas=${atlas.value}&series=${jsonurl}`;
let antools=`${baselink}&tools`;
let nltools=`${antools}&nl`;
log.innerHTML=`Viewer: <a target="_blank" href="${baselink}">${baselink}</a><br>`+
`Annotation tools: <a target="_blank" href="${antools}">${antools}</a><br>`+
`Nonlinear tools: <a target="_blank" href="${nltools}">${nltools}</a>`;
return;
}
if(pyramids.endsWith(".dzip")) {
// let dziproot=pyramids.match(/(.*\/)/)[1];
const [dziproot,bucket,path]=pyramids.match(/(.*?\/buckets\/.+?)\/(.*\/)?/);
const dzips=await fetch((path?bucket+"?prefix="+path:bucket)+"&limit=10000")
.then(response=>response.json())
.then(json=>json.objects.map(obj=>obj.name.substring(path?path.length:0)).filter(name=>name.endsWith(".dzip")));
let baselink=`${location.href.match(/(.*\/)[^/]*/)[1]}filmstripzoom.html?atlas=${atlas.value}&series=${jsonurl}&dziproot=${dziproot}`;
// let antools=`${baselink}&tools`;
// let nltools=`${antools}&nl`;
// log.innerHTML=`Viewer: <a target="_blank" href="${baselink}">${baselink}</a><br>`+
// `Annotation tools: <a target="_blank" href="${antools}">${antools}</a><br>`+
// `Nonlinear tools: <a target="_blank" href="${nltools}">${nltools}</a>`;
trfparams={baselink,dzips,sections:json.slices.map(slice=>slice.filename)};
transform();
return;
}
let slices=json.slices;
let length=slices.length;
if(!pyramids.length){
setlog(`${jsonurl} contains ${length} images. Please provide location of pyramids.`);
return;
}
let pyramidbase=(pyramids.startsWith("buckets/")?
"https://data-proxy.ebrains.eu/api/v1/public/":
"https://object.cscs.ch/v1/AUTH_08c08f9f119744cbbf77e216988da3eb/")+pyramids;
let fail=false;
let nontiff=false;
for(let i=0;i<length;i++){
let slice=slices[i];
let old=log.innerText;
let temp=old+`${i+1}/${length}, ${slice.filename}`;
setlog(temp);
let name=slice.filename;
name=name.substring(0,name.lastIndexOf("."));
let descriptor=await fetch(`${pyramidbase}/${name}.tif/${name}.dzi`).then(response=>response.status===200?response.text():new Error(response.status+" "+response.statusText)).catch(exception=>exception);
if(descriptor instanceof Error){
let second=await fetch(`${pyramidbase}/${slice.filename}/${name}.dzi`).then(response=>response.status===200?response.text():new Error(response.status+" "+response.statusText)).catch(exception=>exception);
if(second instanceof Error){
if(descriptor.message.length)
setlog(temp+" - can't access DZI descriptor "+descriptor.message+"\n");
else
setlog(temp+" - can't access DZI descriptor\n");
fail=true;
if(lock!==stamp)
return;
}else{
setlog(old);
nontiff=true;
}
}else
setlog(old);
}
if(fail || lock!==stamp)
setlog(log.innerText+"Check failed.");
else{
// let baselink=`https://localizoom.apps.hbp.eu/filmstripzoom.html?atlas=${atlas.value}&series=${jsonurl}&pyramids=${pyramids}`;
let baselink=`${location.href.match(/(.*\/)[^/]*/)[1]}filmstripzoom.html?atlas=${atlas.value}&series=${jsonurl}&pyramids=${pyramids}`;
if(nontiff)
baselink+="&nontiff";
let antools=`${baselink}&tools`;
let nltools=`${antools}&nl`;
log.innerHTML=`Viewer: <a target="_blank" href="${baselink}">${baselink}</a><br>
Annotation tools: <a target="_blank" href="${antools}">${antools}</a><br>
Nonlinear tools: <a target="_blank" href="${nltools}">${nltools}</a>`;
}
}
function E15(){
atlas.selectedIndex=3;
json.value="Test/E15.json";
pyramids.value="imgsvc-7e9a11b7-b27f-67d7-95c8-3b72bb5086e9";
check();
}
function bucket(){
atlas.selectedIndex=0;
json.value="https://data-proxy.ebrains.eu/api/v1/public/buckets/img-46e866da-c645-11ec-aa7f-00090faa0001/H441a_Timm_dark_horizontal.json";
pyramids.value="buckets/img-46e866da-c645-11ec-aa7f-00090faa0001";
check();
}
function dzip(){
atlas.selectedIndex=0;
json.value="https://data-proxy.ebrains.eu/api/v1/buckets/img-8992ccf2-e993-4fb3-996a-f5ba4780856f/.nesysWorkflowFiles/zippedPyramids/AdenosineA1/dpmg_col_all_LZ.json";
pyramids.value="https://data-proxy.ebrains.eu/api/v1/buckets/img-8992ccf2-e993-4fb3-996a-f5ba4780856f/.nesysWorkflowFiles/zippedPyramids/AdenosineA1/wt272_dpmg_col_s020.dzip";
check();
}
let trfparams;
function transform(){
let {baselink,dzips,sections}=trfparams;
const trf=document.getElementById("trf").value;
if(trf)baselink+="&transform="+trf;
let antools=`${baselink}&tools`;
let nltools=`${antools}&nl`;
log.innerHTML=`Viewer: <a target="_blank" href="${baselink}">${baselink}</a><br>`+
`Annotation tools: <a target="_blank" href="${antools}">${antools}</a><br>`+
`Nonlinear tools: <a target="_blank" href="${nltools}">${nltools}</a>`;
document.getElementById("trfbox").hidden=false;
const parts=trf.split(",").map(part=>part.split("="));
let rows="";
for(let name of sections){
if(parts)
for (const part of parts)
name=name.replaceAll(part[0],part.length>1?part[1]: "");
const _s=name.match(/(_s\d+)/);
let pair="?";
if(_s){
for(const dzip of dzips)
if(dzip.includes(_s[0]))
pair=dzip;
}
let match=0;
while(match<name.length && match<pair.length && name[match]===pair[match])
match++;
rows+=`<tr><td>${name.substring(0,match)}<span style="font-weight:bold;color:red">${name.substring(match)}</span></td>
<td>${pair.substring(0,match)}<span style="font-weight:bold;color:red">${pair.substring(match)}</span></td></tr>`;
}
document.getElementById("pairs").innerHTML=rows;
}
</script>
</head>
<body>
LocaliZoom link configurator<br><br>
Dataset descriptor, complete URL of QuickNII/VisuAlign (.json), WebAlign (.waln), WebWarp (.wwrp), or LocaliZoom (.lz) file:<br>
<input type="text" id="json" oninput="check()"><br>
<br>
<div id="pyrs">
Pyramids
<ul>
<li>CSCS container ID, old ones, usually starting with "<b>imgsvc-</b>". <button onclick="E15()">Example</button></li>
<li>Collab-slug prefixed with "<b>buckets/</b>". <button onclick="bucket()">Example</button></li>
<li>Complete link to any .dzip file from the series ("Get API Url", after "Open in Bucket"). <button onclick="dzip()">Example</button></li>
</ul>
<input type="text" id="pyramids" placeholder="Container ID only, like , or a collab-slug prefixed with "buckets/"" oninput="check()"><br>
<br>
</div>
<select id="atlas" oninput="check()">
<option value="WHS_SD_Rat_v4_39um">WHS SD Rat v4 39um</option>
<option value="WHS_SD_Rat_v3_39um">WHS SD Rat v3 39um</option>
<option value="WHS_SD_Rat_v2_39um">WHS SD Rat v2 39um</option>
<option value="ABA_Mouse_CCFv3_2017_25um">AMBA CCFv3 2017 25um</option>
<option value="ABA_Mouse_CCFv3_2015_25um">AMBA CCFv3 2015 25um</option>
<option value="ABA_Mouse_CCFv2_25um">AMBA CCFv2 25um</option>
</select>
<hr>
<div id="warn" hidden style="font-weight:bold;color:red">Pyramids of non TIFF images detected. </div>
<div id="log"></div>
<div id="trfbox" hidden>
<input type="text" id="trf" placeholder="Comma separated list of replacements and deletions, like .png=.dzip,_thumbnail" oninput="transform()"><br>
<table border="1">
<thead>
<th>Transformed JSON</th><th>Actual file</th>
</thead>
<tbody id="pairs"></tbody>
</table>
</div>
</body>
</html>