Skip to content

Commit

Permalink
Merge pull request #60 from camicroscope/develop
Browse files Browse the repository at this point in the history
For 3.10.0
  • Loading branch information
birm authored Oct 25, 2022
2 parents f61ebb7 + 253c5d3 commit 2cf9e9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions NCISlideUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dev_utils import file_md5
from dev_utils import postslide
from dev_utils import post_url
from make_thumbs import make_thumbnails

# GLOBALS (for now)
# config = {'thumbnail_size': 100, 'thread_limit': 20}
Expand Down Expand Up @@ -174,3 +175,4 @@ def addSpecialty(data):
# run process on each image
res = ThreadPool(thread_limit).imap_unordered(process, manifest)
print([r for r in res])
make_thumbnails()
34 changes: 22 additions & 12 deletions make_thumbs.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import requests
import openslide
import pycurl
from multiprocessing.pool import ThreadPool
import os

SLIDE_LIST_URL = "http://ca-back:4010/data/Slide/find"
IIP_BASE = "http://ca-back:4010/img/IIP/raw/?FIF="
UPDATE_URL = "http://ca-back:4010/data/Slide/update"
# TODO -- token input?
IM_SIZE = 256
THREADS = 5
REGNERATE = False
REGNERATE = True
SAVE_DIR = "/images/thumbnails/"

# make this SAVE_DIR if it does not exist
try:
os.mkdir(SAVE_DIR)
print("created thumbnail SAVE_DIR at", SAVE_DIR)
except FileExistsError:
pass


def setThumb(id, val):
requests.post(UPDATE_URL + "?_id=" + id, json={'thumbnail': val})

Expand All @@ -26,10 +33,11 @@ def process(record):
# skip ones which already have a thumbnail, unless otherwise specified
if REGNERATE or not record.get("thumbnail", False):
try:
slide = openslide.OpenSlide(file)
gen_thumbnail(name, slide, IM_SIZE, imgtype="png")
setThumb(record['_id']["$oid"], name+".png")
return ""
with openslide.OpenSlide(file) as slide:
gen_thumbnail(name, slide, IM_SIZE, imgtype="png")
setThumb(record['_id']["$oid"], name+".png")
# return empty to denote no issue.
return ""
except BaseException as e:
try:
url = IIP_BASE + file + "&WID=200&CVT=png"
Expand All @@ -42,9 +50,11 @@ def process(record):
except BaseException as y:
return [name, y]

# do it
manifest = requests.get(SLIDE_LIST_URL).json()
print(manifest[0])
def make_thumbnails():
manifest = requests.get(SLIDE_LIST_URL).json()
print(manifest[0])
res = [process(x) for x in manifest]
print([x for x in filter(None,[r for r in res])])

res = ThreadPool(THREADS).imap_unordered(process, manifest)
print([x for x in filter(None,[r for r in res])])
if __name__ == "__main__":
make_thumbnails()

0 comments on commit 2cf9e9a

Please sign in to comment.