-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenpmd_ccd_labview.py
executable file
·79 lines (62 loc) · 2.99 KB
/
openpmd_ccd_labview.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
72
73
74
75
76
77
78
79
#!/usr/bin/env python
#
from openpmd_ccd import CCD
import os
# Start Configuration #########################################################
config_allow_overwrite = True # Overwrite scan data if filename exists?
config_create_directory = True # Create directory if it does not exist yet?
# End Configuration ###########################################################
# scan series per camera name (global state per LavView Python session)
scan = dict()
# cluster
# Ref.:
# https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/using_standard_error_in/
# https://zone.ni.com/reference/en-XX/help/371361R-01/lvconcepts/using_standard_error_out/
# https://zone.ni.com/reference/en-XX/help/371361R-01/glang/python_node/
# https://forums.ni.com/t5/LabVIEW/LabVIEW-cluster-and-python-node/td-p/3846386
# "cluster[0] -> Integer, cluster[1] -> String, cluster[2] -> Integer"
# success: (False, 0, "source name")
# warning: (False, 42, "source name")
# error: (True, 42, "source name")
def open_write(directory_path, ccd_name, scan_number=None, ccd_model=None,
ccd_serial=None, ccd_operator=None, ccd_resolution=None,
ccd_roi=None, ccd_exposure_time=None):
""" FIXME: doc strings """
assert not ccd_name in scan, "[openPMD-CCD] You cannot define the same CCD name twice."
if scan_number is not None:
file_name = "{0}_scan-{0}_ccd.h5".format(ccd_name, scan_number)
else:
file_name = "{0}_ccd.h5".format(ccd_name)
file_path = os.path.join(directory_path, file_name)
#... dir name ...
#if config_create_directory:
# ...
scan[ccd_name] = CCD(
file_path,
config_allow_overwrite, config_create_directory,
ccd_name, ccd_model, ccd_serial, ccd_operator,
ccd_resolution, ccd_roi, ccd_exposure_time)
# FIXME: try-catch and return status "cluster" (tuple)
# return (False, 42, "this is a warning")
def add(ccd_name, image_number, image_data=None, image_path=None):
""" FIXME: doc strings """
assert ccd_name in scan, "[openPMD-CCD] CCD name not known (open_write called?)."
scan[ccd_name].add(image_number, image_data=image_data, image_path=image_path)
# FIXME: try-catch and return status "cluster" (tuple)
def recalibrate(ccd_name, resolution=None, roi=None, exposure_time=None):
""" FIXME: doc strings """
assert ccd_name in scan, "[openPMD-CCD] CCD name not known (open_write called?)."
scan[ccd_name].recalibrate(resolution, roi, exposure_time)
# FIXME: try-catch and return status "cluster" (tuple)
def close(ccd_name):
""" FIXME: doc strings """
assert ccd_name in scan, "[openPMD-CCD] CCD name not known (open_write called?)."
scan[ccd_name].close()
del scan[ccd_name]
# FIXME: try-catch and return status "cluster" (tuple)
if __name__ == "__main__":
open_write("./", "defaultCam")
add("defaultCam", 0, [[1, 2, 3], [4, 5, 6]])
add("defaultCam", 1, [[3, 4, 5], [6, 7, 8]])
add("defaultCam", 2, [[6, 7, 8], [9, 0, 1]])
close("defaultCam")