Skip to content

Commit

Permalink
Updates to tiling, protocol file save organization, protocol run fixe…
Browse files Browse the repository at this point in the history
…s, protocol defaults. (#303)
  • Loading branch information
jmcoreymv authored Nov 16, 2023
1 parent 9595fb8 commit 95e5438
Show file tree
Hide file tree
Showing 11 changed files with 712 additions and 302 deletions.
Binary file removed capture/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions data/example_protocol.tsv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
LumaViewPro Protocol
Period 0.1
Duration 1.2
Period 20.0
Duration 48.0
Labware 96 well microplate
Name X Y Z Auto_Focus Channel False_Color Illumination Gain Auto_Gain Exposure
46.5 36.999963199999996 7168.49698 1.0 0.0 1.0 100.0 10.0 0.0 100.0
46.5 37.0 7168.5 1.0 0.0 1.0 100.0 10.0 0.0 100.0
46.5 37.0 7168.5 0.0 1.0 0.0 100.0 10.0 0.0 100.0
46.5 37.0 7168.5 0.0 2.0 0.0 100.0 10.0 0.0 100.0
55.5 37.0 7168.5 0.0 0.0 1.0 100.0 10.0 0.0 100.0
Expand Down
5 changes: 5 additions & 0 deletions data/new_default_protocol.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LumaViewPro Protocol
Period 20.0
Duration 48.0
Labware 96 well microplate
Name X Y Z Auto_Focus Channel False_Color Illumination Gain Auto_Gain Exposure
14 changes: 4 additions & 10 deletions data/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"z": 4950.0
},
"BF": {
"save_folder": "./capture",
"file_root": "BF_",
"focus": 4950.0,
"autofocus": false,
Expand All @@ -41,7 +40,6 @@
"acquire": false
},
"PC": {
"save_folder": "./capture",
"file_root": "PC_",
"focus": 4950.0,
"autofocus": false,
Expand All @@ -53,10 +51,9 @@
"acquire": false
},
"EP": {
"save_folder": "./capture",
"file_root": "EP_",
"focus": 4950.0,
"autofocus": true,
"autofocus": false,
"false_color": false,
"ill": 100.0,
"gain": 1.0,
Expand All @@ -65,7 +62,6 @@
"acquire": false
},
"Blue": {
"save_folder": "./capture",
"file_root": "B_",
"focus": 4950.0,
"autofocus": false,
Expand All @@ -77,7 +73,6 @@
"acquire": false
},
"Green": {
"save_folder": "./capture",
"file_root": "G_",
"focus": 4950.0,
"autofocus": false,
Expand All @@ -89,7 +84,6 @@
"acquire": false
},
"Red": {
"save_folder": "./capture",
"file_root": "R_",
"focus": 4950.0,
"autofocus": false,
Expand All @@ -107,8 +101,8 @@
},
"protocol": {
"period": 20,
"duration": 20,
"duration": 48,
"labware": "96 well microplate",
"filepath": "./data/example_protocol.tsv"
"filepath": "./data/new_default_protocol.tsv"
}
}
}
49 changes: 49 additions & 0 deletions data/tiling.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"metadata": {
"name": "tiling",
"version": 1,
"default": "1x1"
},
"data": {
"1x1": {
"m": 1,
"n": 1
},
"2x2": {
"m": 2,
"n": 2
},
"3x3": {
"m": 3,
"n": 3
},
"4x4": {
"m": 4,
"n": 4
},
"5x5": {
"m": 5,
"n": 5
},
"6x6": {
"m": 6,
"n": 6
},
"7x7": {
"m": 7,
"n": 7
},
"8x8": {
"m": 8,
"n": 8
},
"9x9": {
"m": 9,
"n": 9
},
"10x10": {
"m": 10,
"n": 10
}
}
}
8 changes: 7 additions & 1 deletion labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def set_indices(self, stitch=1):

if stitch > 1:
for i in range(stitch):
for j in range(stich):
for j in range(stitch):
if j % 2 == 1:
i = self.plate['columns'] - i - 1
self.stitch_list.append([i,j])
Expand Down Expand Up @@ -137,6 +137,12 @@ def get_well_index(self, x, y):
return i, j


def get_well_label(self, x, y):
well_x, well_y = self.get_well_index(x=x, y=y)
letter = chr(ord('A') + well_y)
return f'{letter}{well_x + 1}'


class PitriDish(LabWare):
"""A class that stores and computes actions for petri dish labware"""

Expand Down
50 changes: 39 additions & 11 deletions lumascope_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

# Import additional libraries
from lvp_logger import logger
import pathlib
import time
import threading
import os
Expand Down Expand Up @@ -168,6 +169,10 @@ def get_next_save_path(self, path):
"""

# TODO for now converting pathlib.Path's to strings for the algorithm below
if issubclass(type(path), pathlib.Path):
path = str(path)

# Extract file extension (.tiff) and file_id (00001)
dot_idx = path.rfind('.')
under_idx = path.rfind('_')
Expand All @@ -185,7 +190,7 @@ def get_next_save_path(self, path):

return f'{path[:under_idx]}_{new_file_id}.{file_extension}'

def save_image(self, array, save_folder = './capture', file_root = 'img_', append = 'ms', color = 'BF'):
def save_image(self, array, save_folder = './capture', file_root = 'img_', append = 'ms', color = 'BF', tail_id_mode = "increment"):
"""CAMERA FUNCTIONS
save image (as array) to file
"""
Expand Down Expand Up @@ -213,29 +218,52 @@ def save_image(self, array, save_folder = './capture', file_root = 'img_', appen
# else:
# append = ''

# generate filename and save path string
initial_id = '_000001'
filename = file_root + append + initial_id + '.tiff'
path = save_folder + '/' + filename
if type(save_folder) == str:
save_folder = pathlib.Path(save_folder)

# Obtain next save path if current directory already exists
while os.path.exists(path):
path = self.get_next_save_path(path)
if file_root is None:
file_root = ""

# generate filename and save path string
if tail_id_mode == "increment":
initial_id = '_000001'
filename = file_root + append + initial_id + '.tiff'
path = save_folder / filename

# Obtain next save path if current directory already exists
while os.path.exists(path):
path = self.get_next_save_path(path)

elif tail_id_mode == None:
filename = file_root + append + '.tiff'
path = save_folder / filename

else:
raise Exception(f"tail_id_mode: {tail_id_mode} not implemented")


try:
cv2.imwrite(path, img.astype(np.uint8))
cv2.imwrite(str(path), img.astype(np.uint8))
logger.info(f'[SCOPE API ] Saving Image to {path}')
except:
logger.exception("[SCOPE API ] Error: Unable to save. Perhaps save folder does not exist?")

def save_live_image(self, save_folder = './capture', file_root = 'img_', append = 'ms', color = 'BF'):
def save_live_image(
self,
save_folder = './capture',
file_root = 'img_',
append = 'ms',
color = 'BF',
tail_id_mode = "increment"
):

"""CAMERA FUNCTIONS
Grab the current live image and save to file
"""
array = self.get_image()
if array is False:
return
self.save_image(array, save_folder, file_root, append, color)
self.save_image(array, save_folder, file_root, append, color, tail_id_mode)

def get_max_width(self):
"""CAMERA FUNCTIONS
Expand Down
52 changes: 2 additions & 50 deletions lumaviewpro.kv
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,12 @@
Spinner:
id: tiling_size_spinner
sync_height: True
text: 'New'
text: ''
font_size: '12dp'
size_hint_y: None
height: '30dp'
text_autoupdate: True
on_text: root.select_tiling_size()
values: '1x1', '2x2', '3x3', '4x4', '5x5', '6x6', '7x7', '8x8', '9x9'
values: ''


# # Z-stack
Expand Down Expand Up @@ -1528,25 +1527,6 @@
disabled: True
font_size: '12sp'

BoxLayout:
orientation: 'horizontal'
size_hint_y: None
height: '30dp'
Label:
text: 'Field of View'
size_hint_x: None
width: '120dp'
font_size: '12sp'
TextInput:
id: FOV_id
multiline: False
padding: ['5dp', (self.height-self.line_height)/2]
halign: 'center'
# input_filter: 'int'
text: 'tbd'
disabled: True
font_size: '12sp'

# Frame Size
BoxLayout:
orientation: 'horizontal'
Expand Down Expand Up @@ -1961,34 +1941,6 @@
valign: 'middle'
text_size: self.size

BoxLayout:
orientation: 'horizontal'
size_hint_y: None
height: '30dp'
spacing: '5dp'
FolderChooseBTN:
id: folder_btn
# size_hint_y: None
# height: '30dp'
# font_size: '12sp'
# text: 'Folder'
border: 0, 0, 0, 0
background_normal: './data/icons/folder.png' # Press to Select Folder
background_down: './data/icons/folder_down.png'
size_hint: None, None
size: '30dp', '30dp'
on_release: self.choose(root.layer)
TextInput:
id: root_text
# size_hint_y: None
# height: '30dp'
font_size: '12sp'
multiline: False
text: 'File Root'
padding: ['5dp', (self.height-self.line_height)/2]
on_text: root.root_text()
hint_text: 'Filename Root'

Label:

<Histogram>:
Expand Down
Loading

0 comments on commit 95e5438

Please sign in to comment.