mippy 2.15.5__py3.7.egg → 2.16.0__py3.7.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
EGG-INFO/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mippy
3
- Version: 2.15.5
3
+ Version: 2.16.0
4
4
  Summary: Modular Image Processing in Python
5
5
  Home-page: https://tree.taiga.io/project/robflintham-mippy/
6
6
  Author: Robert Flintham
EGG-INFO/requires.txt CHANGED
@@ -12,3 +12,5 @@ markdown2
12
12
  matplotlib
13
13
  scikit-image
14
14
  pyperclip
15
+ colorama
16
+ termcolor
mippy/application.py CHANGED
@@ -35,6 +35,7 @@ import pydicom
35
35
  import gc
36
36
  import requests
37
37
  import csv
38
+ import math
38
39
  #~ from multiprocessing import freeze_support
39
40
  #~ print "Imports finished!"
40
41
 
@@ -52,6 +53,7 @@ from .threading import multithread
52
53
  import imp
53
54
  #~ print "Done!"
54
55
  from zipfile import ZipFile
56
+ from .misc import cprint
55
57
 
56
58
  # WEB LINKS
57
59
  MIPPYDOCS = r'http://mippy.readthedocs.io'
@@ -144,7 +146,11 @@ class MIPPYMain(Frame):
144
146
 
145
147
  # Use parallel processing?
146
148
  if not self.frozen:
147
- self.multiprocess = True
149
+ if len(sys.argv)>1:
150
+ if sys.argv[1]=='multiprocess_off':
151
+ self.multiprocess=False
152
+ else:
153
+ self.multiprocess = True
148
154
  else:
149
155
  self.multiprocess = False
150
156
 
@@ -404,6 +410,11 @@ class MIPPYMain(Frame):
404
410
  # Add progressbar
405
411
  self.master.progressbar = Progressbar(self.master, mode='determinate')
406
412
 
413
+ # Add progress number to use when loading a folder
414
+ self.master.statusmsg = StringVar()
415
+ self.master.statusmsg.set('')
416
+ self.master.statuslabel = Label(self.master,textvariable=self.master.statusmsg)
417
+
407
418
  # Use "grid" to position objects within "master"
408
419
  self.dirframe.grid(row=0,column=0,columnspan=2,rowspan=1,sticky='nsew')
409
420
  self.imcanvas.grid(row=1,column=0,sticky='nsew')
@@ -411,7 +422,8 @@ class MIPPYMain(Frame):
411
422
  self.loadmodulebutton.grid(row=2,column=1,sticky='nsew')
412
423
  #~ self.scrollbutton.grid(row=2,column=0,sticky='nsew')
413
424
  self.imcanvas.img_scrollbar.grid(row=2,column=0,sticky='ew')
414
- self.master.progressbar.grid(row=3,column=0,rowspan=1,columnspan=2,sticky='nsew')
425
+ self.master.progressbar.grid(row=3,column=0,rowspan=1,columnspan=1,sticky='nsew')
426
+ self.master.statuslabel.grid(row=3,column=1,rowspan=1,columnspan=1,sticky='w')
415
427
 
416
428
  # Set row and column weights to handle resizing
417
429
  self.master.rowconfigure(0,weight=1)
@@ -494,6 +506,10 @@ class MIPPYMain(Frame):
494
506
  def progress(self,percentage):
495
507
  self.master.progressbar['value']=percentage
496
508
  self.master.progressbar.update()
509
+
510
+ def status(self,message):
511
+ self.master.statusmsg.set(message)
512
+ self.master.statuslabel.update()
497
513
 
498
514
  def load_preview_images(self, uid_array):
499
515
  """
@@ -565,7 +581,7 @@ class MIPPYMain(Frame):
565
581
  if self.multiprocess and not (('win' in sys.platform and not 'darwin' in sys.platform)
566
582
  and len(self.path_list)<20):
567
583
  f = partial(collect_dicomdir_info,tempdir=self.tempdir)
568
- self.tag_list = multithread(f,self.path_list,progressbar=self.progress)
584
+ self.tag_list = multithread(f,self.path_list,progressbar=self.progress,status=self.status)
569
585
 
570
586
  self.tag_list = [item for sublist in self.tag_list for item in sublist]
571
587
  self.tag_list = [value for value in self.tag_list if value != []]
@@ -583,8 +599,10 @@ class MIPPYMain(Frame):
583
599
  else:
584
600
  errors.append(row)
585
601
  self.progress(0.)
602
+ self.status('')
586
603
  # This should sort the list into your initial order for the tree - maybe implement a more customised sort if necessary?
587
604
  from operator import itemgetter
605
+ self.status("Sorting DICOM files")
588
606
  self.sorted_list = sorted(self.tag_list, key=itemgetter('name','date','time','studyuid','series','seriesuid','instance','instanceuid'))
589
607
 
590
608
  if len(errors)>0:
@@ -622,7 +640,16 @@ class MIPPYMain(Frame):
622
640
  n_repeats = 0
623
641
  uid_list = []
624
642
  to_remove = []
643
+ self.status("Building DICOM tree")
644
+ progress_update = 0
645
+ i = 0
646
+ # for i in range(len(self.sorted_list)):
625
647
  for scan in self.sorted_list:
648
+ i+=1
649
+ current_progress=math.floor(float(i)/float(len(self.sorted_list))*100.)
650
+ if current_progress>progress_update:
651
+ progress_update=current_progress
652
+ self.progress(float(progress_update))
626
653
  #~ print "Adding to tree: "+scan['path']
627
654
  if not self.dirframe.dicomtree.exists(scan['studyuid']):
628
655
  #~ i+=1
@@ -646,9 +673,11 @@ class MIPPYMain(Frame):
646
673
  # EXPERIMENTAL - Remove repeated instance from list
647
674
  # print("REMOVED: {}".format(scan['seriesdesc']))
648
675
  self.sorted_list.remove(scan)
676
+ self.progress(0.)
649
677
 
650
678
  if repeats_found:
651
679
  tkinter.messagebox.showwarning("WARNING",str(n_repeats)+" repeat image UID's found and ignored.")
680
+ self.status(f"{len(self.sorted_list)} DICOM instances loaded")
652
681
  self.dirframe.dicomtree.update()
653
682
  # print("UIDS: {}".format(len(uid_list)))
654
683
  # print("IMS: {}".format(len(self.sorted_list)))
@@ -663,7 +692,7 @@ class MIPPYMain(Frame):
663
692
  return
664
693
 
665
694
  def select_modules_directory(self):
666
- print("Load module directory")
695
+ # print("Load module directory")
667
696
 
668
697
 
669
698
  # for line in sys.path:
@@ -820,7 +849,7 @@ class MIPPYMain(Frame):
820
849
  print("Local version is newer! Weird...")
821
850
 
822
851
  except requests.exceptions.ConnectionError:
823
- print("Unable to connect to repository for version check")
852
+ cprint("ERROR: Unable to connect to repository for version check")
824
853
 
825
854
 
826
855
 
@@ -858,7 +887,7 @@ class MIPPYMain(Frame):
858
887
  for mod in self.module_list:
859
888
  if (module_info['dirname']==mod['dirname'] and
860
889
  module_info['version']==mod['version']):
861
- print("MODULE CLASH: {} {}".format(module_info['dirname'],module_info['version']))
890
+ cprint("ERROR: MODULE CLASH: {} {}".format(module_info['dirname'],module_info['version']))
862
891
  self.module_info = []
863
892
  return
864
893
 
@@ -899,7 +928,7 @@ class MIPPYMain(Frame):
899
928
  for mod in self.module_list:
900
929
  if (module_info['dirname']==mod['dirname'] and
901
930
  module_info['version']==mod['version']):
902
- print("MODULE CLASH: {} {}".format(module_info['dirname'],module_info['version']))
931
+ cprint("ERROR: MODULE CLASH: {} {}".format(module_info['dirname'],module_info['version']))
903
932
  self.module_list = []
904
933
  return
905
934
 
@@ -983,7 +1012,7 @@ class MIPPYMain(Frame):
983
1012
  """
984
1013
  This has been removed for the time being.
985
1014
  """
986
- print("Display changelog")
1015
+ # print("Display changelog")
987
1016
  info = ""
988
1017
  with open('docs/changelog.info','rb') as infofile:
989
1018
  info = infofile.read()
@@ -1016,7 +1045,7 @@ class MIPPYMain(Frame):
1016
1045
  moduledir = selected_module.split('^')[0]
1017
1046
  name = self.moduleframe.moduletree.item(selected_module)['text']
1018
1047
  version = self.moduleframe.moduletree.item(selected_module)['values'][2]
1019
- print(name,version)
1048
+ # print(name,version)
1020
1049
  module_name = moduledir+'.module_main'
1021
1050
  for mod in self.module_list:
1022
1051
  if moduledir==mod['dirname'] and version==mod['version']:
@@ -1078,7 +1107,7 @@ class MIPPYMain(Frame):
1078
1107
  "or return True if you require all\n"+
1079
1108
  "images in a single 1D list.\n"+
1080
1109
  "======================================\n\n")
1081
- print(message)
1110
+ cprint(message)
1082
1111
  flatten_list = True
1083
1112
  if preload_dicom:
1084
1113
  # Attempted to make this section discrete function for use in modules etc
@@ -1152,8 +1181,7 @@ class MIPPYMain(Frame):
1152
1181
  active_module.execute(self.master,instance_info,self.datasets_to_pass)
1153
1182
  except:
1154
1183
  raise
1155
- print("Did you select a module?")
1156
- print("Bet you didn't.")
1184
+ cprint("ERROR: No module selected")
1157
1185
  return
1158
1186
 
1159
1187
 
mippy/mdicom/reading.py CHANGED
@@ -17,6 +17,11 @@ from ..threading import multithread
17
17
  from functools import partial
18
18
  from .mrenhanced import get_frame_ds
19
19
  import itertools
20
+ from ..misc import cprint
21
+
22
+ from multiprocessing import Lock
23
+
24
+ print_lock = Lock()
20
25
 
21
26
  def recursive_file_finder(path):
22
27
  pathlist = []
@@ -67,14 +72,14 @@ def get_dataset(info,tempdir=None):
67
72
  if not uid is None:
68
73
  temppath = os.path.join(tempdir,str(uid)+'.mds')
69
74
  if os.path.exists(temppath):
70
- print("TEMP FILE FOUND: "+str(uid))
75
+ # print("TEMP FILE FOUND: "+str(uid))
71
76
  with open(temppath,'rb') as tempfile:
72
77
  ds = pickle.load(tempfile)
73
78
  return ds
74
79
  elif not filepath is None:
75
80
  ds = pydicom.dcmread(filepath)
76
81
  if not 'ENHANCED' in ds.SOPClassUID.name.upper():
77
- print("SINGLE DICOM FILE FOUND")
82
+ # print("SINGLE DICOM FILE FOUND")
78
83
  io.save_temp_ds(ds,tempdir,str(ds.SOPInstanceUID)+'.mds')
79
84
  return ds
80
85
  else:
@@ -86,7 +91,7 @@ def get_dataset(info,tempdir=None):
86
91
  return ds_split
87
92
 
88
93
  # If it's got this far, cannot find file or not enough info
89
- print("CANNOT FIND FILE")
94
+ cprint(f"ERROR: Cannot find image file - {uid}\n\tPlease reload the image directory.")
90
95
  return None
91
96
 
92
97
 
@@ -112,8 +117,9 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
112
117
  # Removed this garbage collection call to try speed up directory reading
113
118
  #~ gc.collect()
114
119
  except Exception:
115
- print(path+'\n...is not a valid DICOM file and is being ignored.')
120
+ # cprint(f"INFO: {path}\n\t...is not a valid DICOM file and is being ignored.")
116
121
  return tags
122
+ raise #temp debugging
117
123
  if ds and not ds is None:
118
124
  #~ print path
119
125
 
@@ -199,8 +205,7 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
199
205
  try:
200
206
  instance = [ds.InstanceNumber]
201
207
  except AttributeError:
202
- print("INSTANCE NUMBER TAG DOESN'T EXIST")
203
- print(path)
208
+ cprint(f"ERROR: InstanceNumber tag doesn't exist\n\t{path}")
204
209
  raise
205
210
 
206
211
  instance_uid = 'UNKNOWN'
@@ -256,10 +261,11 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
256
261
  # Check if temp file already exists for that InstanceUID. If so, read that file. If not,
257
262
  # uncompress the file and replace ds. Dataset will get saved as temp file at the end of this
258
263
  # function.
264
+ cprint(f"WARNING: Compressed DICOM - {path}")
259
265
  temppath = os.path.join(tempdir,instance_uid+'.mds')
260
266
  if os.path.exists(temppath):
261
- print(seriesdesc+' '+str(i).zfill(3))
262
- print(" COMPRESSED DICOM - Temp file found")
267
+ # print(seriesdesc+' '+str(i).zfill(3))
268
+ # print(" COMPRESSED DICOM - Temp file found")
263
269
  with open(temppath,'rb') as tempfile:
264
270
  ds = pickle.load(tempfile)
265
271
  tempfile.close()
@@ -272,12 +278,11 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
272
278
  elif 'win' in sys.platform:
273
279
  dcmdjpeg = os.path.join(tempdir,"dcmdjpeg_win.exe")
274
280
  else:
275
- print("UNSUPPORTED OPERATING SYSTEM")
276
- print(str(sys.platform))
281
+ cprint(f"ERROR: UNSUPPORTED OPERATING SYSTEM - {sys.platform}")
277
282
  # Uncompress the file
278
283
  outpath=os.path.join(tempdir,'UNCOMP_'+instance_uid+'.DCM')
279
- print(seriesdesc+' '+str(i).zfill(3))
280
- print(" COMPRESSED DICOM - Uncompressing")
284
+ # print(seriesdesc+' '+str(i).zfill(3))
285
+ # print(" COMPRESSED DICOM - Uncompressing")
281
286
  command = [dcmdjpeg,'-v',path,outpath]
282
287
  call(command, shell=False)
283
288
  del(ds)
@@ -288,12 +293,12 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
288
293
  ds.is_little_endian = True
289
294
  ds.is_implicit_VR = False
290
295
 
291
- print(name,"/",date,"/",seriesdesc,"/",i)
296
+ # cprint(name,"/",date,"/",seriesdesc,"/",i)
292
297
  # print(mode.upper())
293
298
  if not ("SPECTROSCOPY" in mode.upper() or ima_mrs_uid in mode.upper()):
294
299
  pxfloat=pixel.get_px_array(ds,enhanced,i,bitdepth=8)
295
300
  if pxfloat is None:
296
- print("ERROR: Couldn't read pixel data")
301
+ # print("ERROR: Couldn't read pixel data")
297
302
  continue
298
303
  try:
299
304
  overlay = get_overlay(ds)
@@ -328,6 +333,7 @@ def collect_dicomdir_info(path,tempdir=None,force_read=False):
328
333
  return tags
329
334
  except Exception as e:
330
335
  return [{'state':'ERROR','path':path,'exception':e}]
336
+ raise
331
337
 
332
338
  def compare_dicom(ds1,ds2,diffs=None,num=None,name=''):
333
339
  if diffs is None:
mippy/misc.py CHANGED
@@ -1,5 +1,10 @@
1
1
  # Generic functions for MIPPY windows that don't fit anywhere else
2
2
 
3
+ import multiprocessing
4
+ from colorama import init
5
+ from termcolor import colored
6
+ init() # Using colorama to make termcolor work on Windows
7
+
3
8
  def optionmenu_patch(om, var):
4
9
  menu = om['menu']
5
10
  last = menu.index("end")
@@ -9,6 +14,9 @@ def optionmenu_patch(om, var):
9
14
  from collections import Mapping, Container
10
15
  from sys import getsizeof
11
16
 
17
+ # Generate threading lock for critical print code
18
+ lock = multiprocessing.Lock()
19
+
12
20
  def deep_getsizeof(o, ids):
13
21
  # From https://code.tutsplus.com/tutorials/understand-how-much-memory-your-python-objects-use--cms-25609
14
22
  """Find the memory footprint of a Python object
@@ -45,4 +53,23 @@ def deep_getsizeof(o, ids):
45
53
 
46
54
  def getsizeof(an_object):
47
55
  from pympler import asizeof
48
- return asizeof.asizeof(an_object)
56
+ return asizeof.asizeof(an_object)
57
+
58
+ def cprint(*strings,**keyargs):
59
+ # Automatically prints coloured strings for errors and warnings
60
+ strings = list(map(str,strings))
61
+ with lock:
62
+ if str(strings[0]).startswith("INFO:"):
63
+ print(colored(' '.join(strings),'cyan'),flush=True)
64
+ elif str(strings[0]).startswith("WARNING:"):
65
+ print(colored(' '.join(strings),'yellow'),flush=True)
66
+ elif str(strings[0]).startswith("ERROR:"):
67
+ print(colored(' '.join(strings),'white','on_red'),flush=True)
68
+ elif str(strings[0]).startswith("DONE:"):
69
+ print(colored(' '.join(strings),'green'),flush=True)
70
+ elif str(strings[0]).startswith("==:"):
71
+ print(colored(' '.join(strings),'black','on_magenta'),flush=True)
72
+ else:
73
+ print(' '.join(strings),'white',flush=True)
74
+ # print(colored('','white','on_black'),end='')
75
+ return
mippy/threading.py CHANGED
@@ -1,9 +1,9 @@
1
- from multiprocessing import Pool, cpu_count, freeze_support
1
+ from multiprocessing import Pool, cpu_count, freeze_support, Lock
2
2
  import time
3
3
  from contextlib import closing
4
4
  import sys
5
5
 
6
- def multithread(func,input,progressbar=None,threads=None):
6
+ def multithread(func,input,progressbar=None,threads=None,status=None):
7
7
  #~ freeze_support()
8
8
  if threads is None:
9
9
  threads=int(cpu_count())+1
@@ -15,10 +15,15 @@ def multithread(func,input,progressbar=None,threads=None):
15
15
  progress = (float(len(input))-float(result._number_left))/float(len(input))*100.
16
16
  #~ print "PROGRESS", progress
17
17
  progressbar(progress)
18
+ if not status is None:
19
+ jobnumber = len(input)-result._number_left + 1
20
+ status('Reading file: '+'/'.join([str(jobnumber),str(len(input))]))
18
21
  #~ print("num left: {}".format(result._number_left))
19
- time.sleep(0.1)
22
+ # time.sleep(0.1)
20
23
  if not progressbar is None:
21
24
  progressbar(0.)
25
+ if not status is None:
26
+ status('')
22
27
  print("Closing multiprocessing pool")
23
28
  pool.close()
24
29
  print("Joining pool")