-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
71 lines (63 loc) · 2.96 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from qtpy.QtWidgets import QApplication
import sys
from logging import FileHandler
from pathlib import Path, WindowsPath
import logging
import os
import numpy as np
from ruamel.yaml import YAML
from exaspim_control.metadata_launch import MetadataLaunch
from exaspim_control.exa_spim_view import ExASPIMInstrumentView, ExASPIMAcquisitionView
from exaspim_control.exa_spim_instrument import ExASPIM
from exaspim_control.exa_spim_acquisition import ExASPIMAcquisition
from datetime import datetime
RESOURCES_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
ACQUISITION_YAML = RESOURCES_DIR / "acquisition.yaml"
INSTRUMENT_YAML = RESOURCES_DIR / "instrument.yaml"
GUI_YAML = RESOURCES_DIR / "gui_config.yaml"
if __name__ == "__main__":
# Setup logging.
# Create log handlers to dispatch:
# - User-specified level and above to print to console if specified.
logger = logging.getLogger() # get the root logger.
# Remove any handlers already attached to the root logger.
logging.getLogger().handlers.clear()
# logger level must be set to the lowest level of any handler.
logger.setLevel(logging.DEBUG)
fmt = "%(asctime)s.%(msecs)03d %(levelname)s %(name)s: %(message)s"
datefmt = "%Y-%m-%d,%H:%M:%S"
log_formatter = logging.Formatter(fmt=fmt, datefmt=datefmt)
log_filename = f'output_{datetime.now().strftime("%Y-%m-%d_%H-%M-%S")}.log'
file_handler = FileHandler(log_filename, "w")
file_handler.setLevel("INFO")
file_handler.setFormatter(log_formatter)
log_handler = logging.StreamHandler(sys.stdout)
log_handler.setLevel("INFO")
log_handler.setFormatter(log_formatter)
logger.addHandler(file_handler)
logger.addHandler(log_handler)
app = QApplication(sys.argv)
# create yaml handler
yaml = YAML()
yaml.representer.add_representer(np.int64, lambda obj, val: obj.represent_int(int(val)))
yaml.representer.add_representer(np.int32, lambda obj, val: obj.represent_int(int(val)))
yaml.representer.add_representer(np.str_, lambda obj, val: obj.represent_str(str(val)))
yaml.representer.add_representer(np.float64, lambda obj, val: obj.represent_float(float(val)))
yaml.representer.add_representer(Path, lambda obj, val: obj.represent_str(str(val)))
yaml.representer.add_representer(WindowsPath, lambda obj, val: obj.represent_str(str(val)))
# instrument
instrument = ExASPIM(config_filename=INSTRUMENT_YAML, yaml_handler=yaml, log_level="INFO")
# acquisition
acquisition = ExASPIMAcquisition(
instrument=instrument, config_filename=ACQUISITION_YAML, yaml_handler=yaml, log_level="INFO"
)
instrument_view = ExASPIMInstrumentView(instrument, GUI_YAML, log_level="INFO")
acquisition_view = ExASPIMAcquisitionView(acquisition, instrument_view)
MetadataLaunch(
instrument=instrument,
acquisition=acquisition,
instrument_view=instrument_view,
acquisition_view=acquisition_view,
log_filename=log_filename,
)
sys.exit(app.exec_())