Skip to content

Commit e5d837a

Browse files
authored
Arvedes/issue20 (#24)
1 parent a31aedc commit e5d837a

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,27 @@ Additional devices may be included in a flexible manner.
3232

3333
## Usage
3434

35-
multilog is configured using the file *config.yml* in the main directory. A template [*config_template.yml*](./config_template.yml), including all supported measurement devices, is provided in this repository; please create a copy of this file and adjust it to your needs. Further details are given below.
35+
multilog is configured by default using the file *config.yml* in the main directory. Outputs are written to the working directory. A template [*config_template.yml*](./config_template.yml), including all supported measurement devices, is provided in this repository; please create a copy of this file and adjust it to your needs. Further details are given below.
3636

3737
To run multilog execute the python file [*multilog.py*](./multilog.py):
3838

3939
```shell
4040
python3 ./multilog.py
4141
```
4242

43+
Alternatively, multilog can be started with the optional command line arguments `-c` and `-o` to give an individual config file and output directory.
44+
45+
```shell
46+
python3 ./multilog.py -c ./my_config_file.yml -o ../my_output_dir
47+
```
48+
4349
If everything is configured correctly, the GUI window opens up. Sampling is started immediately for verification purposes, but the measurements are not recorded yet. Once the *Start* button is clicked, the directory "measdata_*date*_#*XX*" is created and samplings are saved to this directory in csv format. A separate file (or folder for images) is created for each measurement device.
4450

4551
multilog is built for continuous sampling. In case of problems, check the log file for errors and warnings!
4652

4753
## Configuration
4854

49-
multilog is configured using the file *config.yml* in the main directory. A template [*config_template.yml*](./config_template.yml) including all supported measurement devices is provided in this repository; please create a copy of this file and adjust it to your needs.
55+
multilog is configured using the file *config.yml* in the main directory or a user-defined config-file provided using the `-c` argument. A template [*config_template.yml*](./config_template.yml) including all supported measurement devices is provided in this repository; please create a copy of this file and adjust it to your needs.
5056

5157
### Main settings
5258

multilog.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
"""Execute this to start multilog!"""
22

3+
from argparse import ArgumentParser
4+
35
from multilog.main import main
6+
from multilog import __version__
7+
48

59
if __name__ == "__main__":
6-
main()
10+
parser = ArgumentParser(
11+
prog="multilog",
12+
description="Measurement data recording and visualization using various devices.",
13+
)
14+
parser.add_argument(
15+
"-c",
16+
"--config",
17+
help="multilog configuration file [optional, default='./config.yml']",
18+
default="./config.yml",
19+
)
20+
parser.add_argument(
21+
"-o",
22+
"--out_dir",
23+
help="directory where to put the output [optional, default='.']",
24+
default=".",
25+
)
26+
parser.add_argument(
27+
"-v",
28+
"--version",
29+
action="version",
30+
version=f"{parser.prog} version {__version__}",
31+
)
32+
args = parser.parse_args()
33+
main(args.config, args.out_dir)

multilog/main.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,24 @@ class Controller(QObject):
8787
signal_update_camera = pyqtSignal() # sample and update view
8888
signal_sample_camera = pyqtSignal(dict) # sample, update view and save
8989

90-
def __init__(self) -> None:
91-
"""Initialize and run multilog."""
90+
def __init__(self, config, output_dir) -> None:
91+
"""Initialize and run multilog.
92+
93+
Args:
94+
config (str): File path of configuration file.
95+
output_dir (str): Directory where to put the output.
96+
"""
9297
super().__init__()
9398

9499
# load configuration, setup logging
95-
with open("./config.yml", encoding="utf-8") as f:
100+
with open(config, encoding="utf-8") as f:
96101
self.config = yaml.safe_load(f)
97102
logging.basicConfig(**self.config["logging"])
98103
logging.info("initializing multilog")
99104
logging.info(f"configuration: {self.config}")
100105

106+
self.output_dir = output_dir
107+
101108
# do that after logging has been configured to log possible errors
102109
from .devices.daq6510 import Daq6510
103110
from .devices.basler_camera import BaslerCamera
@@ -280,7 +287,7 @@ def init_output_files(self):
280287
for i in range(100):
281288
if i == 99:
282289
raise ValueError("Too high directory count.")
283-
self.directory = f"./measdata_{date}_#{i+1:02}"
290+
self.directory = f"{self.output_dir}/measdata_{date}_#{i+1:02}"
284291
if not os.path.exists(self.directory):
285292
os.makedirs(self.directory)
286293
break
@@ -358,6 +365,11 @@ def sample_camera(self):
358365
self.signal_sample_camera.emit({"time_abs": time_abs, "time_rel": time_rel})
359366

360367

361-
def main():
362-
"""Execute this function to run multilog."""
363-
ctrl = Controller()
368+
def main(config, output_dir):
369+
"""Execute this function to run multilog.
370+
371+
Args:
372+
config (str): File path of configuration file.
373+
output_dir (str): Directory where to put the output.
374+
"""
375+
ctrl = Controller(config, output_dir)

0 commit comments

Comments
 (0)