Skip to content

Commit

Permalink
omero import script, updated UI
Browse files Browse the repository at this point in the history
  • Loading branch information
thejohnhoffer committed Apr 9, 2021
1 parent 6c74d69 commit 016db20
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
2 changes: 1 addition & 1 deletion minerva-story
Submodule minerva-story updated 1 files
+1 −1 index.html
1 change: 1 addition & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ def is_mask_ok(mask):


@app.route('/')
@nocache
def root():
"""
Serves the minerva-author web UI
Expand Down
101 changes: 101 additions & 0 deletions src/convert_omero_channels.py
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)
1 change: 1 addition & 0 deletions src/save_exhibit_pyramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
from distutils import file_util
from distutils.errors import DistutilsFileError
from tifffile.tifffile import TiffFileError
from json.decoder import JSONDecodeError
from render_jpg import render_color_tiles
from storyexport import deduplicate_data
Expand Down
Loading

0 comments on commit 016db20

Please sign in to comment.