def __init__(self, fn, number): self.number = number # get the components self.light = model.getComponent(role="light") self.ccd = model.getComponent(role="ccd") # TODO: only support TIFF # prepare the data export self.exporter = dataio.find_fittest_converter(fn) # Make the name "fn" -> "~/Pictures/fn-XXXXXX.ext" path, base = os.path.split(fn) bn, ext = os.path.splitext(base) tmpl = os.path.join(path, bn + "-%06d" + ext) if path.startswith("/"): # if fn starts with / => don't add ~/Pictures self.fntmpl = tmpl else: self.fntmpl = os.path.join(get_picture_folder(), tmpl) self._acq_done = threading.Event() self._n = 0 self._startt = 0 # starting time of acquisition self._q = queue.Queue() # queue of tuples (str, DataArray) for saving data # TODO: find the right number of threads, based on CPU numbers (but with # python threading that might be a bit overkill) for i in range(4): t = threading.Thread(target=self._saving_thread, args=(i,)) t.daemon = True t.start()
def __init__(self, fn, number): self.number = number # get the components self.light = model.getComponent(role="light") self.ccd = model.getComponent(role="ccd") # TODO: only support TIFF # prepare the data export self.exporter = dataio.find_fittest_converter(fn) # Make the name "fn" -> "~/Pictures/fn-XXXXXX.ext" path, base = os.path.split(fn) bn, ext = os.path.splitext(base) tmpl = os.path.join(path, bn + "-%06d" + ext) if path.startswith("/"): # if fn starts with / => don't add ~/Pictures self.fntmpl = tmpl else: self.fntmpl = os.path.join(get_picture_folder(), tmpl) self._acq_done = threading.Event() self._n = 0 self._startt = 0 # starting time of acquisition self._q = Queue.Queue() # queue of tuples (str, DataArray) for saving data # TODO: find the right number of threads, based on CPU numbers (but with # python threading that might be a bit overkill) for i in range(4): t = threading.Thread(target=self._saving_thread, args=(i,)) t.daemon = True t.start()
def on_acquisition_done(self, future, num): """ Callback called when the one overview image acquisition is finished. """ try: da = future.result() except CancelledError: self._reset_acquisition_gui() return except Exception: # leave the gauge, to give a hint on what went wrong. logging.exception("Acquisition failed") self._reset_acquisition_gui("Acquisition failed (see log panel).", level=logging.WARNING) return # Store DataArray as TIFF in pyramidal format and reopen as static stream (to be memory-efficient) # TODO: pick a different name from previous acquisition? fn = os.path.join(get_picture_folder(), "fastem_overview_%s.ome.tiff" % num) dataio.tiff.export(fn, da, pyramid=True) da = open_acquisition(fn) s = data_to_static_streams(da)[0] s = FastEMOverviewStream(s.name.value, s.raw[0]) # Dict VA needs to be explicitly copied, otherwise it doesn't detect the change ovv_ss = self._main_data_model.overview_streams.value.copy() ovv_ss[num] = s self._main_data_model.overview_streams.value = ovv_ss
def __init__(self, tab_panel, tab_data): super(StreakCamAlignSettingsController, self).__init__(tab_data) self.panel = tab_panel main_data = tab_data.main self.streak_ccd = main_data.streak_ccd self.streak_delay = main_data.streak_delay self.streak_unit = main_data.streak_unit self.streak_lens = main_data.streak_lens self._calib_path = get_picture_folder() # path to the trigger delay calibration folder self.panel_streak = SettingsPanel(self.panel.pnl_streak) self.panel_streak.SetBackgroundColour(odemis.gui.BG_COLOUR_PANEL) self.panel.pnl_streak.GetSizer().Add(self.panel_streak, 1, border=5, flag=wx.BOTTOM | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL) entry_timeRange = create_setting_entry(self.panel_streak, "Time range", self.streak_unit.timeRange, self.streak_unit, conf={"control_type": odemis.gui.CONTROL_COMBO, "label": "Time range", "tooltip": "Time needed by the streak unit for one sweep " "from top to bottom of the readout camera chip."} ) entry_timeRange.value_ctrl.SetBackgroundColour(odemis.gui.BG_COLOUR_PANEL) self.ctrl_timeRange = entry_timeRange.value_ctrl entry_triggerDelay = create_setting_entry(self.panel_streak, "Trigger delay", self.streak_delay.triggerDelay, self.streak_delay, conf={"control_type": odemis.gui.CONTROL_FLT, "label": "Trigger delay", "tooltip": "Change the trigger delay value to " "center the image."}, change_callback=self._onUpdateTriggerDelayMD) entry_triggerDelay.value_ctrl.SetBackgroundColour(odemis.gui.BG_COLOUR_PANEL) self.ctrl_triggerDelay = entry_triggerDelay.value_ctrl entry_magnification = create_setting_entry(self.panel_streak, "Magnification", self.streak_lens.magnification, self.streak_lens, conf={"control_type": odemis.gui.CONTROL_COMBO, "label": "Magnification", "tooltip": "Change the magnification of the input" "optics for the streak camera system. \n" "Values < 1: De-magnifying \n" "Values > 1: Magnifying"}) entry_magnification.value_ctrl.SetBackgroundColour(odemis.gui.BG_COLOUR_PANEL) self.combo_magnification = entry_magnification.value_ctrl # remove border self.panel_streak.GetSizer().GetItem(0).SetBorder(0) self.panel_streak.Layout() self.panel.btn_open_streak_calib_file.Bind(wx.EVT_BUTTON, self._onOpenCalibFile) self.panel.btn_save_streak_calib_file.Bind(wx.EVT_BUTTON, self._onSaveCalibFile)
def _get_snapshot_info(self, dialog=False): config = conf.get_acqui_conf() tab, filepath, exporter = self._main_data_model.tab.value, None, None if dialog: format_info = get_available_formats() wildcards, formats = formats_to_wildcards(format_info) # The default file name should be empty because otherwise the # dialog will add an extension that won't change when the user # selects a different file type in the dialog. dlg = wx.FileDialog(self._main_frame, "Save Snapshot", config.last_path, "", wildcard=wildcards, style=wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) # Select the last format used try: idx = formats.index(config.last_format) except ValueError: idx = 0 dlg.SetFilterIndex(idx) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() fmt = formats[dlg.GetFilterIndex()] extension = format_info[fmt][0] # Prevent double extensions when an old file is selected filepath, _ = os.path.splitext(path) filepath = filepath + extension config.last_path = os.path.dirname(path) config.last_format = fmt config.last_extension = extension config.write() exporter = dataio.get_exporter(config.last_format) dlg.Destroy() else: extension = config.last_extension dirname = get_picture_folder() basename = time.strftime("%Y%m%d-%H%M%S", time.localtime()) filepath = os.path.join(dirname, basename + extension) exporter = dataio.get_exporter(config.last_format) if os.path.exists(filepath): msg = "File '%s' already exists, cancelling snapshot" logging.warning(msg, filepath) tab, filepath, exporter = None, None, None return tab, filepath, exporter
def _get_export_info(self): """ Return str, str, str: full filename, exporter name, export type Full filename is None if cancelled by user """ # Set default to the first of the list export_type = self.get_export_type(self._data_model.focussedView.value) formats = EXPORTERS[export_type] default_exporter = get_converter(formats[0][0]) extension = default_exporter.EXTENSIONS[0] # TODO: default to the same path/filename as current file (but different extension) basename = time.strftime("%Y%m%d-%H%M%S", time.localtime()) filepath = os.path.join(get_picture_folder(), basename + extension) # filepath will be None if cancelled by user filepath, export_format, export_type = self.ShowExportFileDialog(filepath, default_exporter) # get rid of the prefix before you ask for the exporter if any(prefix in export_format.split(' ') for prefix in (PR_PREFIX, PP_PREFIX)): export_format = export_format.split(' ', 1)[1] return filepath, export_format, export_type
def __init__(self, fn, number): self.number = number # get the components self.light = model.getComponent(role="light") self.ccd = model.getComponent(role="ccd") # prepare the data export self.exporter = dataio.find_fittest_converter(fn) # Make the name "fn" -> "~/Pictures + fn + fn-XXXX.ext" path, base = os.path.split(fn) bn, ext = os.path.splitext(base) tmpl = os.path.join(path, bn, bn + "-%05d." + ext) if path.startswith("/"): # if fn starts with / => don't add ~/Pictures self.fntmpl = tmpl else: self.fntmpl = os.path.join(get_picture_folder(), tmpl) self._n = 0
def _get_snapshot_info(self, dialog=False): config = conf.get_acqui_conf() tab, filepath, exporter = self._main_data_model.tab.value, None, None extension = config.last_extension basename = time.strftime("%Y%m%d-%H%M%S", time.localtime()) if dialog: filepath = os.path.join(config.last_path, basename + extension) # filepath will be None if cancelled by user filepath = ShowAcquisitionFileDialog(self._main_frame, filepath) else: dirname = get_picture_folder() filepath = os.path.join(dirname, basename + extension) if os.path.exists(filepath): msg = "File '%s' already exists, cancelling snapshot" logging.warning(msg, filepath) tab, filepath = None, None exporter = dataio.get_converter(config.last_format) return tab, filepath, exporter
from ConfigParser import NoOptionError except ImportError: # Python 3 naming import configparser as ConfigParser from configparser import NoOptionError import logging import math import os.path from odemis.dataio import tiff from odemis.acq.align import delphi from odemis.gui.util import get_picture_folder, get_home_folder import sys from past.builtins import unicode CONF_PATH = os.path.join(get_home_folder(), u".config/odemis") ACQUI_PATH = get_picture_folder() class Config(with_metaclass(ABCMeta, object)): """ Abstract configuration super class Configurations are built around the :py:class:`ConfigParser.SafeConfigParser` class. The main difference is that the filename is fixed, and changes are automatically saved. """ @abstractproperty def file_name(self): """Name of the configuration file""" pass
try: import ConfigParser from ConfigParser import NoOptionError except ImportError: # Python 3 naming import configparser as ConfigParser from configparser import NoOptionError import logging import math import os.path from odemis.dataio import tiff from odemis.acq.align import delphi from odemis.gui.util import get_picture_folder, get_home_folder CONF_PATH = os.path.join(get_home_folder(), u".config/odemis") ACQUI_PATH = get_picture_folder() class Config(object): """ Abstract configuration super class Configurations are built around the :py:class:`ConfigParser.SafeConfigParser` class. The main difference is that the filename is fixed, and changes are automatically saved. """ __metaclass__ = ABCMeta @abstractproperty def file_name(self):