Skip to content

Commit f239b48

Browse files
authored
Merge pull request #46 from FZJ-INM1-BDA/pr_fixNewSiibraPythonRegion
Fix new siibra-python issues
2 parents 99da527 + d0e4ee0 commit f239b48

File tree

5 files changed

+23
-39
lines changed

5 files changed

+23
-39
lines changed

.github/workflows/github-actions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
EBRAINS_IAM_CLIENT_ID: ${{ secrets.EBRAINS_IAM_CLIENT_ID }}
1414
EBRAINS_IAM_CLIENT_SECRET: ${{ secrets.EBRAINS_IAM_CLIENT_SECRET }}
1515
EBRAINS_IAM_REFRESH_TOKEN: ${{ secrets.EBRAINS_IAM_REFRESH_TOKEN }}
16-
# SIIBRA_CONFIG_GITLAB_PROJECT_TAG: develop
16+
SIIBRA_CONFIG_GITLAB_PROJECT_TAG: master
1717
steps:
1818
- name: Check out repository code
1919
uses: actions/checkout@v2

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ ARG DEV_FLAG
1616
ENV DEPLOY_ENVIRONMENT=${DEV_FLAG:+develop}
1717
# if DEPLOY_ENVIRONMENT is not yet set, set it to production
1818
ENV DEPLOY_ENVIRONMENT=${DEPLOY_ENVIRONMENT:-production}
19-
# if DEV_FLAG flag is set, set SIIBRA_CONFIG_GITLAB_PROJECT_TAG=develop
20-
#ENV SIIBRA_CONFIG_GITLAB_PROJECT_TAG=${DEV_FLAG:+develop}
19+
# if DEV_FLAG flag is set, set SIIBRA_CONFIG_GITLAB_PROJECT_TAG=master
20+
ENV SIIBRA_CONFIG_GITLAB_PROJECT_TAG=${DEV_FLAG:+master}
2121

2222
RUN if [ "$DEPLOY_ENVIRONMENT" = "production" ]; \
2323
then python -m pip install -r requirements/prod.txt; \

app/core/parcellation_api.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030

3131
preheat_flag = False
3232

33+
parcellation_json_encoder = {
34+
siibra.core.Parcellation: lambda parcellation: {
35+
'id': split_id(parcellation.id),
36+
'name': parcellation.name,
37+
'availableSpaces': get_spaces_for_parcellation(parcellation),
38+
'modality': parcellation.modality,
39+
'version': parcellation.version,
40+
'_dataset_specs': parcellation._dataset_specs,
41+
}
42+
}
3343

3444
def get_preheat_status():
3545
global preheat_flag
@@ -86,9 +96,6 @@ def __parcellation_result_info(parcellation, atlas_id=None, request=None):
8696
Create the response for a parcellation object
8797
"""
8898
result_info = {
89-
'id': split_id(parcellation.id),
90-
'name': parcellation.name,
91-
'availableSpaces': get_spaces_for_parcellation(parcellation),
9299
'links': {
93100
'self': {
94101
'href': '{}atlases/{}/parcellations/{}'.format(get_base_url_from_request(request),
@@ -109,35 +116,13 @@ def __parcellation_result_info(parcellation, atlas_id=None, request=None):
109116
atlas_id.replace('/', '%2F'),
110117
parcellation.id.replace('/', '%2F')
111118
)
112-
}
119+
},
120+
**jsonable_encoder(parcellation, custom_encoder={
121+
**siibra_custom_json_encoder,
122+
**parcellation_json_encoder
123+
})
113124
}
114125

115-
if hasattr(parcellation, 'modality') and parcellation.modality:
116-
result_info['modality'] = parcellation.modality
117-
118-
if hasattr(parcellation, 'version') and parcellation.version:
119-
result_info['version'] = parcellation.version
120-
121-
if hasattr(parcellation, 'volume_src') and parcellation.volume_src:
122-
volumeSrc = {
123-
key.id: value for key, value in parcellation.volume_src.items()
124-
}
125-
result_info['volumeSrc'] = jsonable_encoder(
126-
volumeSrc, custom_encoder=siibra_custom_json_encoder)
127-
if hasattr(parcellation, 'origin_datainfos'):
128-
original_infos = []
129-
for datainfo in parcellation.origin_datainfos:
130-
try:
131-
original_info = origin_data_decoder(datainfo)
132-
original_infos.append(original_info)
133-
except RuntimeError:
134-
continue
135-
136-
result_info['originDatainfos'] = original_infos
137-
138-
if hasattr(parcellation, 'deprecated'):
139-
result_info['deprecated'] = parcellation.deprecated
140-
141126
return result_info
142127

143128

app/service/request_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@ def _add_children_to_region(region_json, region, space_id=None, atlas=None):
4848

4949
def _create_region_json_object(region, space_id=None, atlas=None, detail=False):
5050
region_json = {'name': region.name, 'children': []}
51-
if hasattr(region, 'rgb'):
52-
region_json['rgb'] = region.rgb
5351
if hasattr(region, 'fullId'):
5452
region_json['id'] = region.fullId
55-
if hasattr(region, 'labelIndex'):
56-
region_json['labelIndex'] = region.labelIndex
53+
if len(region.labels) == 1:
54+
region_json['labelIndex'] = list(region.labels)[0]
5755
if hasattr(region, 'attrs'):
58-
region_json['volumeSrc'] = region.attrs.get('volumeSrc', {})
56+
region_json['rgb'] = region.attrs.get('rgb')
57+
region_json['id'] = region.attrs.get('fullId')
5958
if detail and hasattr(region, 'origin_datainfos'):
6059
region_json['originDatainfos'] = [origin_data_decoder(datainfo) for datainfo in region.origin_datainfos]
6160
region_json['availableIn'] = get_available_spaces_for_region(region)

test/core/test_atlas_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_get_all_atlases():
1313
response = client.get('/v1_0/atlases')
1414
assert response.status_code == 200
1515
result_content = json.loads(response.content)
16-
assert len(result_content) == 3
16+
assert len(result_content) == 4
1717

1818

1919
def test_get_singe_atlas():

0 commit comments

Comments
 (0)