Skip to content

Commit

Permalink
Merge pull request #227 from mehta-lab/rm-microscope-params
Browse files Browse the repository at this point in the history
Remove microscope parameters from calibration metadata
  • Loading branch information
talonchandler authored Oct 5, 2022
2 parents 7012084 + e9da838 commit e932954
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 44 deletions.
5 changes: 2 additions & 3 deletions recOrder/calib/Calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def calc_inst_matrix(self):

return inst_mat

def write_metadata(self, notes=None, microscope_params=None):
def write_metadata(self, notes=None):

inst_mat = self.calc_inst_matrix()
inst_mat = np.around(inst_mat, decimals=5).tolist()
Expand All @@ -794,8 +794,7 @@ def write_metadata(self, notes=None, microscope_params=None):
'Black level': np.round(self.I_Black, 2),
'Extinction ratio': self.extinction_ratio,
'ROI (x, y, width, height)': self.ROI},
'Notes': notes,
'Microscope parameters': microscope_params
'Notes': notes
}

if self.calib_scheme == '4-State':
Expand Down
11 changes: 0 additions & 11 deletions recOrder/io/metadata_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __init__(self, path: str):
self.LCB_voltage = self.get_lc_voltage('LCB')
self.Swing_measured = self.get_swing_measured()
self.Notes = self.get_notes()
self.Microscope_parameters = self.get_microscope_parameters()

def get_summary_calibration_attr(self, attr):
try:
Expand Down Expand Up @@ -162,16 +161,6 @@ def get_channel_names(self):
val = self.json_metadata['Summary']['ChNames']
return val

def get_microscope_parameters(self):
try:
val = self.json_metadata['Microscope parameters']
except KeyError:
try:
val = self.json_metadata['Microscope parameters']
except KeyError:
val = None
return val

def get_notes(self):
try:
val = self.json_metadata['Notes']
Expand Down
30 changes: 21 additions & 9 deletions recOrder/plugin/widget/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,27 @@ def calc_extinction(self):
extinction = self.calib.calculate_extinction(self.swing, self.calib.I_Black, extinction, state1)
self.ui.le_extinction.setText(str(extinction))

@property
def _microscope_params(self):
"""
A dictionary containing microscope parameters from the current GUI
Unused in 0.2.0 --- candidate for deletion
"""
def _param_value(param_name: str, ui=self.ui):
# refer to main widget class ui attribute names
ui_attr_name = "le_" + param_name
param_text = ui.__getattribute__(ui_attr_name).text()
# handle blank string
return float(param_text) if param_text != '' else None

return {
'n_objective_media': _param_value("n_media"),
'objective_NA': _param_value("obj_na"),
'condenser_NA': _param_value("cond_na"),
'magnification': _param_value("mag"),
'pixel_size': _param_value("ps")
}

@Slot(bool)
def load_calibration(self):
"""
Expand Down Expand Up @@ -2169,15 +2190,6 @@ def load_calibration(self):

self.last_calib_meta_file = metadata_path

# Update the Microscope Parameters with those from the previous calibration (if they're present)
params = metadata.Microscope_parameters
if params is not None:
self.ui.le_n_media.setText(str(params['n_objective_media']) if params['n_objective_media'] is not None else '')
self.ui.le_obj_na.setText(str(params['objective_NA']) if params['objective_NA'] is not None else '')
self.ui.le_cond_na.setText(str(params['condenser_NA']) if params['condenser_NA'] is not None else '')
self.ui.le_mag.setText(str(params['magnification']) if params['magnification'] is not None else '')
self.ui.le_ps.setText(str(params['pixel_size']) if params['pixel_size'] is not None else '')

# Move the load calibration function to a separate thread
self.worker = load_calibration(self.calib, metadata)

Expand Down
22 changes: 1 addition & 21 deletions recOrder/plugin/workers/calibration_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,9 @@ def _check_abort(self):
self.aborted.emit()
raise TimeoutError('Stop Requested.')

@property
def _microscope_params(self):
"""A dictionary containing microscope parameters from the current GUI"""
def _param_value(param_name: str, ui=self.calib_window.ui):
# refer to main widget class ui attribute names
ui_attr_name = "le_" + param_name
param_text = ui.__getattribute__(ui_attr_name).text()
# handle blank string
return float(param_text) if param_text != '' else None

return {
'n_objective_media': _param_value("n_media"),
'objective_NA': _param_value("obj_na"),
'condenser_NA': _param_value("cond_na"),
'magnification': _param_value("mag"),
'pixel_size': _param_value("ps")
}

def _write_meta_file(self, meta_file: str):
self.calib.meta_file = meta_file
self.calib.write_metadata(notes=self.calib_window.ui.le_notes_field.text(), microscope_params=self._microscope_params)
self.calib.write_metadata(notes=self.calib_window.ui.le_notes_field.text())


class CalibrationWorker(CalibrationWorkerBase, signals=CalibrationSignals):
Expand Down Expand Up @@ -383,8 +365,6 @@ def work(self):
else:
current_json['Notes'] = old_note + ', ' + note

current_json['Microscope Parameters'] = self._microscope_params

with open(self.calib_window.last_calib_meta_file, 'w') as file:
json.dump(current_json, file, indent=1)

Expand Down

0 comments on commit e932954

Please sign in to comment.