-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c74d69
commit 016db20
Showing
6 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -659,6 +659,7 @@ def is_mask_ok(mask): | |
|
||
|
||
@app.route('/') | ||
@nocache | ||
def root(): | ||
""" | ||
Serves the minerva-author web UI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import pathlib | ||
import json | ||
import os | ||
import argparse | ||
from json.decoder import JSONDecodeError | ||
|
||
def make_channel(ch_key, ch): | ||
ch_id = 0 | ||
try: | ||
# Minerva Author uses a zero-based index | ||
ch_id = int(ch_key) - 1 | ||
except ValueError as e: | ||
print(e) | ||
print(f'Skipping channel: "{ch_key}" is not an integer') | ||
return {} | ||
return { | ||
"color": ch['color'], | ||
"label": ch['label'], | ||
"min": ch['start'] / ch['max'], | ||
"max": ch['end'] / ch['max'], | ||
"id": ch_id, | ||
} | ||
|
||
def make_group(channels): | ||
all_channels = [ | ||
make_channel(ch_key, ch) for (ch_key, ch) in channels.items() | ||
] | ||
all_channels = [ch for ch in all_channels if 'id' in ch] | ||
all_channels.sort(key= lambda ch: ch['id']) | ||
return { | ||
"channels": all_channels, | ||
"label": "imported omero channels" | ||
} | ||
|
||
def main(omero_json, author_json): | ||
|
||
story_json_checks = [ | ||
(author_json, ['.json']), | ||
(pathlib.Path(author_json.stem), ['.groups', '.story']) | ||
] | ||
test_suffix = lambda check: check[0].suffix in check[1] | ||
if not all(map(test_suffix, story_json_checks)): | ||
print(' '.join([ | ||
'Invalid output path.', | ||
'It must end in .story.json or .groups.json' | ||
])) | ||
return | ||
|
||
if os.path.exists(author_json): | ||
print(f'Overwriting existing save file {author_json}') | ||
else: | ||
print(f'Writing to new save file {author_json}') | ||
|
||
if not author_json.parent.exists(): | ||
author_json.parent.mkdir(parents=True) | ||
|
||
omero_channels = {} | ||
try: | ||
with open(omero_json) as rf: | ||
loaded = json.load(rf) | ||
omero_channels = loaded['channels'] | ||
except (FileNotFoundError, JSONDecodeError, KeyError) as e: | ||
logger.error(e) | ||
logger.error(f'Invalid input file: cannot parse {omero_json}') | ||
return | ||
|
||
with open(author_json, 'w') as wf: | ||
json.dump({ | ||
"in_file": "", | ||
"csv_file": "", | ||
"groups": [ | ||
make_group(omero_channels) | ||
], | ||
"masks": [], | ||
"waypoints": [], | ||
"sample_info": { | ||
"rotation": 0, | ||
"name": "", | ||
"text": "" | ||
} | ||
}, wf) | ||
|
||
print(f'Success! {author_json} written') | ||
|
||
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"omero_json", metavar="omero_json", type=pathlib.Path, | ||
help="Input path to exported omero channels", | ||
) | ||
parser.add_argument( | ||
"author_json", metavar="author_json", type=pathlib.Path, | ||
help="Output Minerva Author save file with channels from omero", | ||
) | ||
args = parser.parse_args() | ||
|
||
omero_json = args.omero_json | ||
author_json = args.author_json | ||
|
||
main(omero_json, author_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.