Skip to content

Commit

Permalink
Update binning size values to string format (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcoreymv authored Oct 22, 2024
1 parent 0abb4a0 commit 5909d35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion data/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
}
},
"binning": {
"size": 1
"size": "1x1"
},
"logging": {
"default": {
Expand Down
24 changes: 10 additions & 14 deletions lumaviewpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
import labware
from modules.autofocus_executor import AutofocusExecutor
from modules.stitcher import Stitcher
import modules.binning as binning
from modules.composite_generation import CompositeGeneration
from modules.contrast_stretcher import ContrastStretcher
import modules.coord_transformations as coord_transformations
Expand Down Expand Up @@ -4727,16 +4728,16 @@ def load_settings(self, filename="./data/current.json"):
# Multiplying frame size by the binning size to account for the select_binning_size() call
# Effectively sets the frame size to the size it was prior to pixel binning, then bins

binning_size = int(settings['binning']['size'])
binning_size_str = settings['binning']['size']
binning_size = binning.binning_size_str_to_int(text=binning_size_str)

self.ids['frame_width_id'].text = str(settings['frame']['width'] * binning_size)
self.ids['frame_height_id'].text = str(settings['frame']['height'] * binning_size)
lumaview.scope.set_frame_size(settings['frame']['width'] * binning_size,
settings['frame']['height'] * binning_size)

# Pixel Binning

self.ids['binning_spinner'].text = str(settings['binning']['size'])
self.ids['binning_spinner'].text = binning_size_str
self.select_binning_size()
lumaview.scope.set_stage_offset(stage_offset=settings['stage_offset'])

Expand Down Expand Up @@ -4874,13 +4875,6 @@ def select_video_recording_format(self):
else:
settings['video_as_frames'] = True


def update_binning_size(self, size: int):
global settings
# size = int(self.ids['binning_spinner'].text)
lumaview.scope.set_binning_size(size=size)
settings['binning']['size'] = size


def update_scale_bar_state(self):
if self.ids['enable_scale_bar_btn'].state == 'down':
Expand Down Expand Up @@ -4923,8 +4917,7 @@ def save_settings(self, file="./data/current.json"):

def load_binning_sizes(self):
spinner = self.ids['binning_spinner']
sizes = (1,2,4)
spinner.values = list(map(str,sizes))
spinner.values = ['1x1','2x2','4x4']


def select_binning_size(self):
Expand All @@ -4933,8 +4926,11 @@ def select_binning_size(self):
orig_binning_size = lumaview.scope.get_binning_size()
orig_frame_size = get_current_frame_dimensions()

new_binning_size = int(self.ids['binning_spinner'].text)
self.update_binning_size(size=new_binning_size)
new_binning_size_str = self.ids['binning_spinner'].text

new_binning_size = binning.binning_size_str_to_int(new_binning_size_str)
lumaview.scope.set_binning_size(size=new_binning_size)
settings['binning']['size'] = new_binning_size_str
ratio = new_binning_size / orig_binning_size
new_frame_size = {
'width': math.floor(orig_frame_size['width'] / ratio),
Expand Down
19 changes: 19 additions & 0 deletions modules/binning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


BINNING_SIZE_MAP = {
'1x1': 1,
'2x2': 2,
'4x4': 4,
}


def binning_size_str_to_int(text: str) -> int:
return BINNING_SIZE_MAP.get(text, 1)


def binning_size_int_to_str(val: int):
for k, v in BINNING_SIZE_MAP.items():
if v == val:
return k

return '1x1'

0 comments on commit 5909d35

Please sign in to comment.