|
1 | 1 | """This module contains the controller-part of multilog. It sets up the |
2 | 2 | communication between device and visualization and manages the sampling |
3 | 3 | loop.""" |
| 4 | +from copy import deepcopy |
4 | 5 | import shutil |
5 | 6 | from PyQt5.QtWidgets import QApplication |
6 | 7 | from PyQt5.QtCore import QTimer, QThread, QObject, pyqtSignal |
@@ -293,13 +294,73 @@ def init_output_files(self): |
293 | 294 | break |
294 | 295 | for device in self.devices: |
295 | 296 | self.devices[device].init_output(self.directory) |
| 297 | + self.write_nomad_file() |
296 | 298 | self.write_metadata() |
297 | 299 | shutil.copy( |
298 | 300 | "./multilog/nomad/base_classes.schema.archive.yaml", |
299 | 301 | f"{self.directory}/base_classes.schema.archive.yaml", |
300 | 302 | ) |
301 | 303 | self.main_window.set_output_directory(self.directory) |
302 | 304 |
|
| 305 | + def write_nomad_file(self): |
| 306 | + """Write main multilog.archive.yaml including an overview of all devices.""" |
| 307 | + with open("./multilog/nomad/archive_template_main.yml") as f: |
| 308 | + nomad_dict = yaml.safe_load(f) |
| 309 | + data = nomad_dict.pop("data") |
| 310 | + multilog_version = ( |
| 311 | + subprocess.check_output( |
| 312 | + ["git", "describe", "--tags", "--dirty", "--always"] |
| 313 | + ) |
| 314 | + .strip() |
| 315 | + .decode("utf-8") |
| 316 | + ) |
| 317 | + data["process"]["start_time"] = datetime.datetime.now(datetime.timezone.utc).astimezone().isoformat(timespec='milliseconds').replace('T', ' ') |
| 318 | + data["data_processing"].update( |
| 319 | + { |
| 320 | + "software": f"multilog {multilog_version}", |
| 321 | + "sampling_time": self.config["settings"]["dt-main"], |
| 322 | + "image_time": self.config["settings"]["dt-camera"], |
| 323 | + } |
| 324 | + ) |
| 325 | + |
| 326 | + template_ir_cam = nomad_dict.pop("instrumentation_IR-camera_template") |
| 327 | + template_camera = nomad_dict.pop("instrumentation_camera_template") |
| 328 | + template_sensor = nomad_dict.pop("instrumentation_sensors_template") |
| 329 | + for device_name in self.devices: |
| 330 | + nomad_name = device_name.replace(" ", "_").replace("-", "_") |
| 331 | + if "Optris-IP-640" in device_name: |
| 332 | + instrument = deepcopy(template_ir_cam) |
| 333 | + instrument["section"]["quantities"]["ir_camera"]["type"] = f"../upload/raw/{device_name}.archive.yaml#IR_camera" |
| 334 | + nomad_dict["definitions"]["sections"]["MeltCzochralski"]["sub_sections"]["instrumentation"]["section"]["sub_sections"].update( |
| 335 | + {nomad_name: instrument} |
| 336 | + ) |
| 337 | + data["instrumentation"][nomad_name] = { |
| 338 | + "ir_camera": f"../upload/raw/{device_name}.archive.yaml#data" |
| 339 | + } |
| 340 | + elif "Basler" in device_name: |
| 341 | + instrument = deepcopy(template_camera) |
| 342 | + instrument["section"]["quantities"]["camera"]["type"] = f"../upload/raw/{device_name}.archive.yaml#camera" |
| 343 | + nomad_dict["definitions"]["sections"]["MeltCzochralski"]["sub_sections"]["instrumentation"]["section"]["sub_sections"].update( |
| 344 | + {nomad_name: instrument} |
| 345 | + ) |
| 346 | + data["instrumentation"][nomad_name] = { |
| 347 | + "camera": f"../upload/raw/{device_name}.archive.yaml#data" |
| 348 | + } |
| 349 | + else: |
| 350 | + instrument = deepcopy(template_sensor) |
| 351 | + instrument["section"]["quantities"]["sensors_list"]["type"] = f"../upload/raw/{device_name}.archive.yaml#Sensors_list" |
| 352 | + nomad_dict["definitions"]["sections"]["MeltCzochralski"]["sub_sections"]["instrumentation"]["section"]["sub_sections"].update( |
| 353 | + {nomad_name: instrument} |
| 354 | + ) |
| 355 | + data["instrumentation"][nomad_name] = { |
| 356 | + "sensors_list": f"../upload/raw/{device_name}.archive.yaml#data" |
| 357 | + } |
| 358 | + |
| 359 | + nomad_dict.update({"data": data}) |
| 360 | + with open(f"{self.directory}/multilog_eln.archive.yaml", "w", encoding="utf-8") as f: |
| 361 | + yaml.safe_dump(nomad_dict, f, sort_keys=False) |
| 362 | + |
| 363 | + |
303 | 364 | def write_metadata(self): |
304 | 365 | """Write a csv file with information about multilog version, |
305 | 366 | python version and operating system. |
|
0 commit comments