Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
siibra-explorer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiao Gui
siibra-explorer
Commits
a114d5be
Unverified
Commit
a114d5be
authored
5 years ago
by
xgui3783
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #213 from HumanBrainProject/dev_spatial_search2
test query KG spatial search backend
parents
2fb8a94c
795764ad
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
deploy/datasets/query.js
+84
-33
84 additions, 33 deletions
deploy/datasets/query.js
deploy/datasets/spatialRouter.js
+4
-2
4 additions, 2 deletions
deploy/datasets/spatialRouter.js
with
88 additions
and
35 deletions
deploy/datasets/query.js
+
84
−
33
View file @
a114d5be
...
...
@@ -15,21 +15,10 @@ const STORAGE_PATH = process.env.STORAGE_PATH || path.join(__dirname, 'data')
let
getPublicAccessToken
const
fetchDatasetFromKg
=
async
(
arg
)
=>
{
const
fetchDatasetFromKg
=
async
({
user
}
=
{})
=>
{
const
{
releasedOnly
,
option
}
=
await
getUserKGRequestInfo
({
user
})
const
accessToken
=
arg
&&
arg
.
user
&&
arg
.
user
.
tokenset
&&
arg
.
user
.
tokenset
.
access_token
const
releasedOnly
=
!
accessToken
let
publicAccessToken
if
(
!
accessToken
&&
getPublicAccessToken
)
{
publicAccessToken
=
await
getPublicAccessToken
()
}
const
option
=
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
?
{
auth
:
{
'
bearer
'
:
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
}
}
:
{}
return
await
new
Promise
((
resolve
,
reject
)
=>
{
request
(
`
${
queryUrl
}${
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
option
,
(
err
,
resp
,
body
)
=>
{
if
(
err
)
...
...
@@ -196,36 +185,39 @@ exports.getPreview = ({ datasetName, templateSelected }) => getPreviewFile({ dat
* change to real spatial query
*/
const
cachedMap
=
new
Map
()
const
fetchSpatialDataFromKg
=
async
({
templateName
,
queryArg
})
=>
{
// const cachedResult = cachedMap.get(templateName)
// if (cachedResult)
// return cachedResult
try
{
const
fetchSpatialDataFromKg
=
async
({
templateName
,
queryArg
,
user
})
=>
{
try
{
const
filename
=
path
.
join
(
STORAGE_PATH
,
templateName
+
'
.json
'
)
const
exists
=
fs
.
existsSync
(
filename
)
if
(
!
exists
)
return
[]
const
data
=
fs
.
readFileSync
(
filename
,
'
utf-8
'
)
const
json
=
JSON
.
parse
(
data
)
var
splitQueryArg
=
queryArg
.
split
(
'
__
'
);
const
cubeDots
=
[]
splitQueryArg
.
forEach
(
element
=>
{
cubeDots
.
push
(
element
.
split
(
'
_
'
))
});
// cachedMap.set(templateName, json.filter(filterByqueryArg(cubeDots)))
return
json
.
filter
(
filterByqueryArg
(
cubeDots
))
}
catch
(
e
)
{
const
coordsString
=
queryArg
.
split
(
'
__
'
);
const
boundingBoxCorners
=
coordsString
.
map
(
coordString
=>
coordString
.
split
(
'
_
'
))
if
(
templateName
!==
'
Waxholm Space rat brain atlas v.2.0
'
)
{
return
json
.
filter
(
filterByqueryArg
(
boundingBoxCorners
))
}
else
{
const
boundingBoxInWaxhomV2VoxelSpace
=
boundingBoxCorners
.
map
(
transformWaxholmV2NmToVoxel
)
const
{
total
=
0
}
=
await
getSpatialSearchOk
({
boundingBoxInWaxhomV2VoxelSpace
,
user
})
if
(
total
>
0
)
{
return
json
.
filter
(
filterByqueryArg
(
boundingBoxCorners
))
}
else
{
return
[]
}
}
}
catch
(
e
)
{
console
.
log
(
'
datasets#query.js#fetchSpatialDataFromKg
'
,
'
read file and parse json failed
'
,
e
)
return
[]
}
}
exports
.
getSpatialDatasets
=
async
({
templateName
,
queryGeometry
,
queryArg
})
=>
{
return
await
fetchSpatialDataFromKg
({
templateName
,
queryArg
})
exports
.
getSpatialDatasets
=
async
({
templateName
,
queryGeometry
,
queryArg
,
user
})
=>
{
return
await
fetchSpatialDataFromKg
({
templateName
,
queryArg
,
user
})
}
...
...
@@ -237,9 +229,68 @@ function filterByqueryArg(cubeDots) {
if
(
cubeDots
[
0
][
0
]
<=
px
&&
px
<=
cubeDots
[
1
][
0
]
&&
cubeDots
[
0
][
1
]
<=
py
&&
py
<=
cubeDots
[
1
][
1
]
&&
cubeDots
[
0
][
2
]
<=
pz
&&
pz
<=
cubeDots
[
1
][
2
])
{
return
true
;
return
true
}
return
false
}
return
false
;
}
async
function
getSpatialSearchOk
({
user
,
boundingBoxInWaxhomV2VoxelSpace
})
{
const
{
releasedOnly
,
option
}
=
await
getUserKGRequestInfo
({
user
})
const
spatialQuery
=
'
https://kg.humanbrainproject.org/query/minds/core/dataset/v1.0.0/spatialSimple/instances?size=10
'
return
await
new
Promise
((
resolve
,
reject
)
=>
{
request
(
`
${
spatialQuery
}
&boundingBox=waxholmV2:
${
boundingBoxInWaxhomV2VoxelSpace
.
map
(
cornerCoord
=>
cornerCoord
.
join
(
'
,
'
)).
join
(
'
,
'
)}${
releasedOnly
?
'
&databaseScope=RELEASED
'
:
''
}
`
,
option
,
(
err
,
resp
,
body
)
=>
{
if
(
err
)
return
reject
(
err
)
if
(
resp
.
statusCode
>=
400
)
return
reject
(
resp
.
statusCode
)
const
json
=
JSON
.
parse
(
body
)
return
resolve
(
json
)
})
})
}
async
function
getUserKGRequestInfo
({
user
})
{
const
accessToken
=
user
&&
user
.
tokenset
&&
user
.
tokenset
.
access_token
const
releasedOnly
=
!
accessToken
let
publicAccessToken
if
(
!
accessToken
&&
getPublicAccessToken
)
{
publicAccessToken
=
await
getPublicAccessToken
()
}
const
option
=
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
?
{
auth
:
{
'
bearer
'
:
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
}
}
:
{}
return
{
option
,
releasedOnly
,
token
:
accessToken
||
publicAccessToken
||
process
.
env
.
ACCESS_TOKEN
}
}
/**
*
*/
const
transformWaxholmV2NmToVoxel
=
(
coord
)
=>
{
/**
* as waxholm is already in RAS, does not need to swap axis
*/
/**
* atlas viewer applies translation (below in nm) in order to center the brain
* query already translates nm to mm, so the unit of transl should be [mm, mm, mm]
*/
const
transl
=
[
-
9550781
,
-
24355468
,
-
9707031
].
map
(
v
=>
v
/
1
e6
)
/**
* mm/voxel
*/
const
voxelDim
=
[
0.0390625
,
0.0390625
,
0.0390625
]
return
coord
.
map
((
v
,
idx
)
=>
(
v
-
transl
[
idx
])
/
voxelDim
[
idx
]
)
}
This diff is collapsed.
Click to expand it.
deploy/datasets/spatialRouter.js
+
4
−
2
View file @
a114d5be
...
...
@@ -24,8 +24,10 @@ router.get('/templateName/:templateName/:queryGeometry/:queryArg', (req, res, ne
error
:
errorString
,
trace
:
'
dataset#spatialRouter
'
})
getSpatialDatasets
({
templateName
,
queryGeometry
,
queryArg
})
const
{
user
}
=
req
getSpatialDatasets
({
templateName
,
queryGeometry
,
queryArg
,
user
})
.
then
(
arr
=>
res
.
status
(
200
).
json
(
arr
))
.
catch
(
error
=>
{
next
({
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment