2
2
Input/Ouput module for data generated using the network_watchdog approach for adaptive temporal
3
3
sampling on the iSIM
4
4
'''
5
+ # There are mixed naming styles here unfortunately
6
+ # pylint: disable=C0103
5
7
6
8
import contextlib
7
9
import glob
@@ -37,7 +39,6 @@ def loadiSIMmetadata(folder):
37
39
new_name = file .split ("Timing_" )[0 ] + "Timing_z" + file .split ("Timing_" )[1 ]
38
40
os .rename (file , new_name )
39
41
40
-
41
42
delay = []
42
43
fileList = sorted (glob .glob (folder + '/iSIMmetadata*.txt' ))
43
44
for name in fileList :
@@ -54,13 +55,15 @@ def loadiSIMmetadata(folder):
54
55
except ValueError :
55
56
# This means that delay was > 240 and an empty frame was added
56
57
delay [- 1 ] = delay [- 1 ] + 240
58
+
57
59
return delay
58
60
59
61
60
62
def loadElapsedTime (folder , progress = None , app = None ):
61
63
""" get the Elapsed time for all .tif files in folder or from a stack """
62
64
63
65
elapsed = []
66
+ step = None
64
67
# Check for folder or stack mode
65
68
# if not re.match(r'*.tif*', folder) is None:
66
69
# # get microManager elapsed times if available
@@ -72,9 +75,11 @@ def loadElapsedTime(folder, progress=None, app=None):
72
75
if os .path .isfile (folder + '/img_channel001_position000_time000000000_z000.tif' ):
73
76
fileList = sorted (glob .glob (folder + '/img_channel001*' ))
74
77
numFrames = len (fileList )
78
+ step = 1
75
79
else :
76
- fileList = glob .glob (folder + '/img_*[0-9].tif' )
80
+ fileList = sorted ( glob .glob (folder + '/img_*[0-9].tif' ) )
77
81
numFrames = int (len (fileList )/ 2 )
82
+ step = 2
78
83
79
84
if progress is not None :
80
85
progress .setRange (0 , numFrames * 2 )
@@ -99,7 +104,7 @@ def loadElapsedTime(folder, progress=None, app=None):
99
104
progress .setValue (i )
100
105
i = i + 1
101
106
102
- return elapsed
107
+ return elapsed [ 0 :: step ]
103
108
104
109
105
110
def loadNNData (folder ):
@@ -468,13 +473,13 @@ def calculateNNforStack(file, model=None, nnPath=None, img_range=None):
468
473
""" calculate neural network output for all frames in a stack and write to new stack """
469
474
# dataOrder = 1 # 0 for drp/foci first, 1 for mito/structure first
470
475
if model is None :
471
- from tensorflow import keras
476
+ from tensorflow import keras # pylint: disable=C0415
472
477
modelPath = '//lebnas1.epfl.ch/microsc125/Watchdog/GUI/model_Dora.h5'
473
478
modelPath = '//lebnas1.epfl.ch/microsc125/Watchdog/Model/paramSweep5/f32_c07_b08.h5'
474
479
model = keras .models .load_model (modelPath , compile = True )
475
480
elif isinstance (model , str ):
476
481
if os .path .isfile (model ):
477
- from tensorflow import keras
482
+ from tensorflow import keras # pylint: disable=C0415
478
483
model = keras .models .load_model (model , compile = True )
479
484
else :
480
485
raise FileNotFoundError
@@ -489,7 +494,8 @@ def calculateNNforStack(file, model=None, nnPath=None, img_range=None):
489
494
mdInfo = tif .ome_metadata .encode (encoding = 'UTF-8' , errors = 'strict' )
490
495
# extract only the planes that was written to
491
496
mdInfoDict = xmltodict .parse (mdInfo )
492
- mdInfoDict ['OME' ]['Image' ]['Pixels' ]['Plane' ] = mdInfoDict ['OME' ]['Image' ]['Pixels' ]['Plane' ][0 ::2 ]
497
+ intermediateInfo = mdInfoDict ['OME' ]['Image' ]['Pixels' ]['Plane' ][0 ::2 ]
498
+ mdInfoDict ['OME' ]['Image' ]['Pixels' ]['Plane' ] = intermediateInfo
493
499
494
500
dataOrder = int (mdInfoDict ['OME' ]['Image' ]['Description' ]['@dataOrder' ])
495
501
mdInfo = xmltodict .unparse (mdInfoDict ).encode (encoding = 'UTF-8' , errors = 'strict' )
@@ -526,14 +532,15 @@ def calculateNNforStack(file, model=None, nnPath=None, img_range=None):
526
532
527
533
528
534
def calculateNNforFolder (folder , model = None ):
535
+ """ Recalculate all the neural network frames for a folder with peak/structure frames """
529
536
if model is None :
530
- from tensorflow import keras
537
+ from tensorflow import keras # pylint: disable=C0415
531
538
modelPath = '//lebnas1.epfl.ch/microsc125/Watchdog/GUI/model_Dora.h5'
532
539
# modelPath = '//lebnas1.epfl.ch/microsc125/Watchdog/Model/paramSweep5/f32_c07_b08.h5'
533
540
model = keras .models .load_model (modelPath , compile = True )
534
541
elif isinstance (model , str ):
535
542
if os .path .isfile (model ):
536
- from tensorflow import keras
543
+ from tensorflow import keras # pylint: disable=C0415
537
544
model = keras .models .load_model (model , compile = True )
538
545
else :
539
546
raise FileNotFoundError
@@ -546,7 +553,7 @@ def calculateNNforFolder(folder, model=None):
546
553
filelist = sorted (glob .glob (folder + '/img_*.tif' ))
547
554
re_odd = re .compile (r'.*time\d*[13579]_.*' )
548
555
bact_filelist = [file for file in filelist if re_odd .match (file )]
549
- re_even = re .compile (" .*time\d*[02468]_.*" )
556
+ re_even = re .compile (r' .*time\d*[02468]_.*' )
550
557
ftsz_filelist = [file for file in filelist if re_even .match (file )]
551
558
552
559
for index , bact_file in tqdm (enumerate (bact_filelist )):
@@ -707,13 +714,14 @@ def on_select(*_):
707
714
minspanx = 5 , minspany = 5 , spancoords = 'pixels' , rectprops = rectprops ,
708
715
interactive = True , state_modifier_keys = {'square' : 'shift' })
709
716
plt .show ()
710
- rectProp = rectHandle ._rect_bbox
717
+ # There might be different properties there that could give the same information
718
+ # https://matplotlib.org/stable/api/widgets_api.html#matplotlib.widgets.RectangleSelector
719
+ rectProp = rectHandle ._rect_bbox # pylint: disable=W0212
711
720
rectProp = tuple (int (x ) for x in rectProp )
712
721
print (rectProp )
713
722
return rectProp
714
723
715
724
716
-
717
725
def main ():
718
726
""" Main method calculating a nn stack for a set of old Mito/drp stacks """
719
727
@@ -735,7 +743,6 @@ def main():
735
743
# makePrepImages(folder, model)
736
744
# loadiSIMmetadata(folder)
737
745
738
-
739
746
# allFiles = glob.glob('//lebnas1.epfl.ch/microsc125/iSIMstorage/Users/Willi/'
740
747
# '180420_DRP_mito_Dora/**/*MMStack*lzw.ome.tif', recursive=True)
741
748
# mainPath = 'W:/iSIMstorage/Users/Willi/160622_caulobacter/160622_CB15N_WT/SIM images'
0 commit comments