Karathon Middlelayer API Reference
import karabo.middlelayer
The Karabo Hash Dictionary
Convert Karabo hashes to Python dictionaries and back.
Bases: OrderedDict
This is the serialization data structure of Karabo
Every data that gets transferred over the network or saved to file by Karabo is in this format.
It is mostly an extended :class:dict.
The big difference to normal Python containers is the dot-access method.
The hash has a built-in knowledge about it containing itself. Thus,
one can access sub-hashes by hash['key.subhash'].
The other speciality are attributes. In Python, these can be accessed
using a second parameter to the brackets, as in
hash['key', 'attribute'].
All attributes at the same time can be accessed by hash['key', ...].
Source code in src/pythonKarabo/karabo/native/data/hash.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
__contains__(key)
Retrieve if a key is contained in the Hash
:returns: True or False
Source code in src/pythonKarabo/karabo/native/data/hash.py
246 247 248 249 250 251 252 253 254 255 | |
__delitem__(item)
Delete an item from the Hash
Source code in src/pythonKarabo/karabo/native/data/hash.py
238 239 240 241 242 243 244 | |
__getitem__(item)
Get an item from the Hash. Specify either a single key or both
key and attribute with [key, attribute] to retrieve data.
To retrieve the full attribute dictionary for a specific key, use
the Ellipsis with [key, ...]
Source code in src/pythonKarabo/karabo/native/data/hash.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__repr__()
Return the printable representation of the Hash
the representation will contain types. please note that the types are not accurate if the data cannot be serialised.
Source code in src/pythonKarabo/karabo/native/data/hash.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
deepcopy()
This method retrieves a deepcopy of the Hash element
Source code in src/pythonKarabo/karabo/native/data/hash.py
394 395 396 | |
empty()
Check if the hash is empty or not
:returns: True or False
Source code in src/pythonKarabo/karabo/native/data/hash.py
375 376 377 378 379 380 | |
erase(key)
Erase an item associated with key from the Hash
Source code in src/pythonKarabo/karabo/native/data/hash.py
344 345 346 | |
flat_iterall(hsh, base='', empty=False)
staticmethod
Recursively iterate over all parameters in a Hash object such that a simple iterator interface is exposed.
:param empty: If set to True this will yield an empty Hash followed
by all Hash properties. Default is False
Source code in src/pythonKarabo/karabo/native/data/hash.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
fullyEqual(other)
Compare two Hash objects and check if they have equal content
Note: This function does not consider the insertion order of elements
Source code in src/pythonKarabo/karabo/native/data/hash.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
get(item, default=None)
The graceful item getter function of the Hash
:param item: The item key for the element :param default: The return value if the item is not available
Source code in src/pythonKarabo/karabo/native/data/hash.py
295 296 297 298 299 300 301 302 303 304 | |
getAttributes(item)
Retrieve all attributes related to item
Source code in src/pythonKarabo/karabo/native/data/hash.py
315 316 317 | |
getElement(path)
This is a direct way of getting value and attrs of the Hash
in a HashElement object.
:returns: A tuple of value and attributes belonging to path, e.g.
data, attrs = hash.getElement(key)
Source code in src/pythonKarabo/karabo/native/data/hash.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
getKeys(keys=None)
Retrieve a list of keys from the Hash. If the 'keys' parameter is provided, the specified keys are added to the given list.
:param keys :A list of keys to be added to the result. Example: h = Hash('a', 1, 'b', 2) assert h.getKeys() == ['a', 'b'] custom_keys = ['c', 'd'] assert h.getKeys(keys=custom_keys) == ['c', 'd', 'a', 'b']
Source code in src/pythonKarabo/karabo/native/data/hash.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
has(item)
Check if the item is contained in the Hash
Source code in src/pythonKarabo/karabo/native/data/hash.py
319 320 321 | |
hasAttribute(item, key)
Check if the attribute associated with item and key is
contained the Hash
Source code in src/pythonKarabo/karabo/native/data/hash.py
339 340 341 342 | |
items()
Iterate over key and values of the Hash container
Source code in src/pythonKarabo/karabo/native/data/hash.py
271 272 273 274 | |
iterall()
Iterate over key, value and attributes
This behaves like the :meth:~dict.items method of Python
:class:dict, except that it yields not only key and value but
also the attributes for it.
Source code in src/pythonKarabo/karabo/native/data/hash.py
257 258 259 260 261 262 263 264 265 266 267 268 269 | |
merge(other, attribute_policy='merge')
Merge the hash other into this hash.
If the attribute_policy is 'merge', the attributes from the other
hash are merged with the existing ones, otherwise they are overwritten.
Source code in src/pythonKarabo/karabo/native/data/hash.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
paths(*, intermediate=False)
Returns all root-to-leaves paths
:param intermediate: If True include all intermediate path from
roots to leafs, i.e. ['a.b.c', 'a.b', 'a']
instead of ['a.b.c'], defaults to False.
Source code in src/pythonKarabo/karabo/native/data/hash.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
pop(item, default=__marker)
Pop an item from the Hash. This method only returns the value.
Source code in src/pythonKarabo/karabo/native/data/hash.py
187 188 189 190 191 192 193 194 195 | |
setElement(key, value, attrs)
This is a direct way of setting value and attrs in the Hash
Setting both value and attrs at the same time can provide a fairly
big speedup! The attributes attrs have to be a dictionary.
Source code in src/pythonKarabo/karabo/native/data/hash.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Convert a nested Hash h into a dict
Convert a Hash h into a dict. If h is nested, the result will be as well.
Note: This is greedy as we lose all possible attributes of the Hash.
Source code in src/pythonKarabo/karabo/native/data/utils.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
Convert a nested dictionary into a Hash
Source code in src/pythonKarabo/karabo/native/data/utils.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
Accessing Remote Devices with Proxies
Core functionality for interacting with devices via proxies.
get a device proxy for the device deviceId
Request a schema of a remote device and create a proxy object which acts as if one would act on the device itself.
Note that the created device will not be connected to changes on the actual device. In order to achieve this, put the returned device in a with statement as such::
with getDevice("someDevice") as device:
# do something with device
On the command line, you might prefer using :func:connectDevice.
This is a synchronized coroutine.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
get and connect a device proxy for the device deviceId
This connects a given device proxy to the real device such that the
proxy's parameters are properly updated. If the deviceId is just
a string, :func:getDevice is called on that name, as a shortcut
especially on the command line.
If the device is needed only within a specific block, it is nicer
tu use instead a with statement as described in :func:getDevice.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | |
wait for an update of a device
request new properties and wait until they arrive. This is the only way to receive changes on a device while the device is not connected.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1110 1111 1112 1113 1114 1115 1116 1117 | |
Check whether a device represented by a proxy is still running
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1154 1155 1156 1157 | |
Accessing Remote Devices Directly
A low-overhead API for short-lived interactions (no proxy). Note: state inspection still requires proxies for efficiency.
Set properties of a device
device may either be a device proxy as returned by :func:getDevice, or
simply the deviceId as a string. Add the properties to be set as keyword
arguments, as in::
setWait("someDevice", speed=3, position=5)
setWait("someDevice", "speed", 3, "position", 5)
Note that for proxy devices this method is normally not necessary, you may just write::
someDevice.speed = 3
someDevice.position = 5
the function waits until the device has acknowledged that the values have been set.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | |
Same as :func:setWait, but don't wait for acknowledgement
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 | |
execute a slot and wait until it finishes
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1101 1102 1103 1104 1105 1106 1107 | |
execute a slot without waiting for it to be finished
device may be a device proxy returned by getDevice, or simply a string with the device id, as in::
executeNoWait("someDevice", "start")
Normally you would call a slot simply using its proxy devive, as in::
someDevice.start()
but then we wait until the device has finished with the operation. If this is not desired, use executeNoWait.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 | |
Running Devices on Servers
Instantiate or shut down devices remotely, with optional fire‑and‑forget.
Instantiate and configure a device on a running server
:param serverId: The serverId of the server on which the device should be started. :param classId: The classId of the device (the corresponding plugin must already be loaded on the server) :param deviceId: The future name of the device in the Karabo installation (will fail if not unique) :param configuration: the configuration of the device (optional)
The keyword arguments are used to further configure the device.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | |
Instantiate and configure a device on a running server
Non-waiting version of :func:instantiate
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
993 994 995 996 997 998 999 1000 1001 1002 1003 | |
shut down the given device
:param deviceId: may be a device proxy, or just the id of a device
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 | |
shut down the given device
not waiting version of :func:shutdown
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
1017 1018 1019 1020 1021 1022 1023 | |
Inspecting Device Servers
Discover running devices and servers from the command line or within
DeviceClientBase.
Return a list of found deviceId's.
This function is a shortcut to find deviceIds with getDevices
:param matchPattern: String pattern, to find the deviceId's containing the matchPattern.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
889 890 891 892 893 894 895 896 897 | |
Return a list of found serverId's
This function is a shortcut to find serverId's with getServers
:param matchPattern: String pattern, to find the serverId's containing the matchPattern.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
936 937 938 939 940 941 942 943 944 | |
Return a list of currently running external clients
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
920 921 922 923 924 | |
Return a list of currently running devices
:param serverId: Optional serverId, so that only devices are returned running on device server. :param matchPattern: Optional string pattern, to find deviceId's containing the matchPattern.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | |
Return a list of currently running servers
:param matchPattern: Optional string pattern, to find serverId's containing the matchPattern.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
947 948 949 950 951 952 953 954 955 956 957 958 | |
Return a list of device classes (plugins) available on a server
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
961 962 963 964 965 | |
Return the full topology Hash of the DeviceClient
NOTE: We provide a copy here as the topology might change while working with it.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
927 928 929 930 931 932 933 | |
Working with Devices
Retrieve current configuration, schema, or instance info.
Get a configuration from a target device
:param device: deviceId or proxy
NOTE: When passing a proxy, the proxy is updated and the configuration
if extracted from the proxy. In this case, ChoiceOfNodes and
ListOfNodes (mostly) properties will be omitted in the configuration.
:returns: Configuration Hash
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
Get a schema from a target device
:param device: deviceId or proxy
:param onlyCurrentState: Boolean for the state dependent schema
The default is False.
:returns: Full Schema object
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
Get the instanceInfo Hash of a device
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
60 61 62 63 64 65 66 | |
Configurations and Timestamps
Historic Configuration
Retrieve past configurations or schemas by timestamp.
Get the configuration of a deviceId or proxy at a given time::
getConfigurationFromPast(device, "12:30")
:returns: A karabo configuration hash of the device at the specified time.
The date of the time point is parsed using :func:dateutil.parser.parse,
allowing many ways to write the date.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
466 467 468 469 470 471 472 473 474 475 476 477 478 | |
Get the schema of a deviceId or proxy at a given time::
getSchemaFromPast(deviceId, "12:30")
Returns a karabo schema object of the device at the specified time.
The date of the time point is parsed using :func:dateutil.parser.parse,
allowing many ways to write the date.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
481 482 483 484 485 486 487 488 489 490 491 492 493 | |
Named Configurations
Manage configurations by name:
Get the configuration of a deviceId or proxy with a given name::
getConfigurationFromName(device, "run2012")
:returns: A karabo configuration hash of the device saved under the name.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | |
Get a configuration from a target device
:param device: deviceId or proxy
NOTE: When passing a proxy, the proxy is updated and the configuration
if extracted from the proxy. In this case, ChoiceOfNodes and
ListOfNodes (mostly) properties will be omitted in the configuration.
:returns: Configuration Hash
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
List the list of configurations of a deviceId with given name_part::
listConfigurationFromName(device, '')
Returns a list of configuration items of the device. Optionally, a name
part can be provided to filter the configurations on manager side.
Each configuration item is a Hash containing:
- name: the configuration name
- timepoint: the timepoint the configuration of the device was taken
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
Return the list of devices which have a configuration::
listDevicesWithConfiguration()
:returns: List of deviceIds, e.g. ["deviceA", "deviceB"].
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
540 541 542 543 544 545 546 547 548 549 550 551 552 | |
Instantiate a device from name via the ConfigurationManager::
instantiateFromName(device, name='run2015')
- device: Mandatory parameter, either deviceId or proxy
- name: Mandatory parameter, name of configuration
- classId: Optional parameter for validation of classId
- serverId: Optional parameter
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
Save configuration(s) in the KaraboConfigurationManager::
- The parameter
devicescan be a Karaboproxy, a list of deviceIds, a list of proxies or a mixture of them. It can be as well a single deviceId string.
saveConfigurationFromName(devices, name="proposal2020")
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
Comparing Configurations
Utilities for comparing device configurations:
Compare device configuration (key, values) between present and past
The changes are provided in a list for comparison::
changes = [PRESENT | PAST]
>>> h = compareDeviceWithPast(device, minutesAgo(2))
>>> h
<disableEpsilonFeedback{}: [True, False]>
:param timepoint: The timepoint to compare
:returns: changes Hash
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
Compare device configurations (key, values) of two devices
The changes are provided in a list for comparison::
>>> h = compareDeviceConfiguration(device_a, device_b)
>>> h
<disableEpsilonFeedback{}: [True, False]>
:returns: changes Hash
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
Return a timestamp from n minutes ago
:param n: minutes, defaults to 1
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
158 159 160 161 162 163 | |
Return a timestamp from n hours ago
:param n: hours, defaults to 1
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
166 167 168 169 170 171 | |
Return a timestamp from n days ago
:param n: days, defaults to 1
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
174 175 176 177 178 179 | |
Utility Functions
Convenience helpers:
Return the property value from a proxy or device
:param device: The device instance or proxy object :param path: The full path of the property as string
This function is similar to python's builtin getattr and used with::
prop = get_property(proxy, 'node.subnode.property')
which is equivalent to::
prop = proxy.node.subnode.property
Source code in src/pythonKarabo/karabo/middlelayer/utils.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
Set a property value on a proxy or device
This function has been added in Karabo >= 2.14.
:param device: The device instance or proxy object :param path: The full path of the property as string :param value: The value to be set
This function is similar to python's builtin setattr and used with::
set_property(proxy, 'node.subnode.property', 5)
which is equivalent to::
proxy.node.subnode.property = 5
Source code in src/pythonKarabo/karabo/middlelayer/utils.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
Method to extract an ndarray from a raw Hash
:param data: A hash containing the data hash
:param path: The path of the NDArray. If None (default) the
input Hash is taken.
:param squeeze: If the array should be squeezed if the
latest dimension is 1. Default is True.
:returns: A numpy array containing the extracted data
Source code in src/pythonKarabo/karabo/native/data/utils.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
Method to extract an image from a Hash into a numpy array
This is a common use case when processing pipeline data (receiving from an output channel)
:param data: A hash containing the image data hash
:param path: optional path of the image data. If no path is provided,
the default checks if the data hash contains paths with
data.image or image and get the image data.
:returns: A numpy array containing the extracted pixel data
Source code in src/pythonKarabo/karabo/native/data/utils.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
Return the maximum value of the iterable
This function takes into account KaraboValues for newest timestamp generation.
Source code in src/pythonKarabo/karabo/middlelayer/unitutil.py
25 26 27 28 29 30 31 32 33 34 35 36 37 | |
Return the minimum value of the iterable
This function takes into account KaraboValues for newest timestamp generation.
Source code in src/pythonKarabo/karabo/middlelayer/unitutil.py
40 41 42 43 44 45 46 47 48 49 50 51 52 | |
Decorate a function to remove QuantityValue/KaraboValue input
This function works as well with async declarations and can be used as::
@removeQuantity def calculate(x, y): assert not isinstance(x, KaraboValue) assert not isinstance(y, KaraboValue) return x, y
This decorator does not cast to base units! In case of booleans,
they can be compared by identity.
Source code in src/pythonKarabo/karabo/middlelayer/unitutil.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
A versatile profiling class
Use this class either as a context manager or as decorator::
with profiler():
# classic context manager
with profiler("Long computation 1"):
# do something but provide a name for the context
The class can also be used for decoration of functions (async works)
@profiler()
async def do_something()
# do something
async with profiler("Async with statement"):
# do something with name in context
Source code in src/pythonKarabo/karabo/middlelayer/utils.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
__call__(func)
Decorate a function to profile the execution time
Source code in src/pythonKarabo/karabo/middlelayer/utils.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
A decorator to be used to validate arguments with their annotations
Usage examples::
@validate_args
def my_func(param1: str, param2: (float, int)):
pass
The decorator will raise if the function is called with wrong type input.
Note: Booleans are also valid for integers!
Source code in src/pythonKarabo/karabo/common/decorators.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
Derive and return an associated descriptor from data
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 | |
Get a HashType enum corresponding to data
:param data: Any kind of data typically used in the control network :returns: HashType Enum
Source code in src/pythonKarabo/karabo/native/data/hash.py
572 573 574 575 576 577 578 | |
A compare function deals with element-wise comparison
Source code in src/pythonKarabo/karabo/native/data/hash.py
634 635 636 637 638 639 640 641 642 643 644 645 | |
Compare old/new values to determine if there is a real difference
This function has been added in Karabo >= 2.14.
Source code in src/pythonKarabo/karabo/native/data/compare.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
Deprecated function to deepcopy simple data structures
Source code in src/pythonKarabo/karabo/native/data/hash.py
648 649 650 651 652 653 654 655 656 657 | |
Writing a Device
Base classes and exceptions for device authors:
The base class for everything that has Karabo attributes.
A class with Karabo attributes inherits from this class. The attributes are then defined as follows::
from karabo.native import Configurable, Int32, String
class Spam(Configurable):
ham = Int32()
eggs = String()
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
__dir__()
Return all attributes of this object.
This is mostly for tab-expansion in IPython.
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
171 172 173 174 175 | |
__init__(configuration={})
Initialize this object with the configuration
:param configuration: a :class:dict or a
:class:~karabo.middlelayer.Hash which contains the
initial values to be used for the Karabo attributes.
Default values of attributes are handled here.
:param parent: the :class:Configurable object this object
belongs to
:param key: the name of the attribute used in this object.
Top-layer objects like devices are always called with one
parameter (configuration) only, so if you are inheriting from
this class you only need to have parent and key as a
parameter if your class should be usable as a component in
another class.
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
get_root()
Return the root instance of this Configurable
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
145 146 147 148 149 150 151 152 153 154 | |
set(config, only_changes=False, strict=True)
Internal handler to set a Hash on the Configurable
:param only_changes: Boolean to check if only changed values should
be set, the default is False.
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
223 224 225 226 227 228 229 230 231 232 233 | |
setChildValue(key, value, desc)
Set all values in Nodes
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
192 193 194 195 | |
set_setter(config, only_changes=False)
async
Internal handler to set a Hash on the Configurable via the setter functions
:param only_changes: Boolean to check if only changed values should
be set, the default is False.
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
210 211 212 213 214 215 216 217 218 219 220 221 | |
Bases: InjectMixin, SignalSlotable
This is the base class for all devices.
It inherits from :class:~karabo.middlelayer.Configurable and thus
you can define expected parameters for it.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
globalAlarmCondition
property
writable
Backward compatible property for the legacy alarm implementation
is_initialized
property
Check if the device is online and has passed onInitialization
__get_time_info()
Internal method to get the time information
Source code in src/pythonKarabo/karabo/middlelayer/device.py
270 271 272 273 274 275 276 277 | |
getLocalDevice(instanceId)
Returns the instance of a device if present in the local server
This device instance can be used to shortcut broker communication.
This returns a strong reference::
async def onInitialization(self):
device = self.getLocalDevice(instanceId)
:returns: Device instance or None if not found.
Note: Added in Karabo 2.15.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
setOutputSchema(*args)
async
This is a wrapper function to change the schema of existing output channels.
For each output channel that is to be changed its key name and the new Schema have to be provided, e.g.
await self.setOutputSchema("output1", schema1,
"output2", schema2,
...)
Note: The existing output channel is closed while changing the schema.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
slotClearLock()
async
Clear the lock on this device
Source code in src/pythonKarabo/karabo/middlelayer/device.py
144 145 146 147 148 | |
slotGetConfigurationSlice(info)
Public slot to retrieve the values of a list of paths
:param info: Hash with {key: paths, value: list of strings}
returns: A Hash with the values and attributes for each requested property key.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
259 260 261 262 263 264 265 266 267 268 | |
slotGetSystemInfo(info=None)
Return the actual system information of this device
Source code in src/pythonKarabo/karabo/middlelayer/device.py
293 294 295 296 297 298 299 300 | |
slotGetTime(info=None)
Return the actual time information of this device
This slot call return a Hash with key time and the attributes
provide an actual timestamp with train Id information.
The slot call further provides a reference time information via key
reference and the attributes provide the train id.
This method has an empty input argument to allow a generic protocol.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
279 280 281 282 283 284 285 286 287 288 289 290 291 | |
update()
Update the instanceInfo Hash according to the status info
Source code in src/pythonKarabo/karabo/middlelayer/device.py
326 327 328 329 330 331 332 333 | |
Bases: Device
Keep track of other devices
A :class:~karabo.middlelayer.Device which also inherits from this class
keeps track of all the other devices in this Karabo installation. Without
inheriting from this class, listing other devices is impossible.
Source code in src/pythonKarabo/karabo/middlelayer/device.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
removeServerChildren(instanceId, info)
Cleanup the device children from the server
Source code in src/pythonKarabo/karabo/middlelayer/device.py
441 442 443 444 445 446 447 448 | |
updateSystemTopology(instanceId, info)
Update the systemTopology Hash with new information from info
Source code in src/pythonKarabo/karabo/middlelayer/device.py
450 451 452 453 454 455 456 | |
Bases: Exception
A :class:KaraboError is raised if an error occurs which is
specific to Karabo. This is mostly because things went wrong on
the other end of a network connection.
Source code in src/pythonKarabo/karabo/native/exceptions.py
19 20 21 22 23 24 25 26 27 | |
Synchronization
Asynchronous helpers and primitives:
execute a task in the background
run the task in the background. This returns a :class:KaraboFuture,
which may be cancelled or waited for as needed.
A timeout may be given after which the function in the background will be cancelled.
Example::
def do_something_in_background(some_value):
# so something here
task = background(do_something_in_background, "some value")
task.cancel()
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
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 | |
wait until all KaraboFutures given are done
This function waits until all :class:KaraboFutures passed as
arguments are done. The function returns a list of the return value
of all functions.
If one of the futures raises an exception, gather also immediately raises that exception, unless return_exceptions indicates that all futures should be waited for, and the exception returned instead.
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
wait for the first of coroutines or futures to return
Wait for the first future given as keyword argument to return. It returns three dicts: one with the names of the done futures and their results, one mapping the name of the pending futures to them, and a third one mapping the names of failed futures to their exceptions, as an example::
work = background(do_some_work)
party = background(partey)
sleep = background(zzz)
done, pending, error = firstCompleted(
work=work, party=party, sleep=sleep)
the result will then be something like {"work": 5},
{"party": Future()} and {"sleep": RuntimeError()}.
You may also give futures as positional parameters, they will be returned by their number::
done, pending, error = firstCompleted(work, party, sleep)
will return something like {0: 5}, {1: Future()} and
{2: RuntimeError()}.
Cancelled futures will be listed in the error dict, mapped to None.
You may also give a timemout.
Futures still pending will be cancelled before return, unless you
set cancel_pending to False.
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
wait until all futures are done
This function is an improved version of :func:asyncio.gather,
which also works if a future fails, and a timeout can be set.
For the returned dicts, see :func:firstCompleted.
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
186 187 188 189 190 191 192 193 194 195 | |
wait until a future raises an exception
If no future raises an exception, this is the same as
:func:allCompleted.
This function is an improved version of :func:asyncio.gather,
which also works if a future fails, and a timeout can be set.
For the returned dicts, see :func:firstCompleted.
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
198 199 200 201 202 203 204 205 206 207 208 209 210 | |
do nothing for delay seconds
if delay is a :class:~karabo.middlelayer.KaraboValue, its unit is
respected.
This method should be preferred over :func:time.sleep, as it is
interruptable.
Source code in src/pythonKarabo/karabo/middlelayer/synchronization.py
103 104 105 106 107 108 109 110 111 112 113 114 | |
A handle for a result that will be available in the future
This will be returned by many Karabo methods, if a callback has been set to a function or None. It is possible to add more callbacks, to wait for completion, or cancel the operation in question.
Source code in src/pythonKarabo/karabo/middlelayer/eventloop.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
add_done_callback(fn)
Add another callback to the future
Source code in src/pythonKarabo/karabo/middlelayer/eventloop.py
99 100 101 102 103 104 105 106 107 108 109 | |
wait()
async
Wait for the result to be available, and return the result
Source code in src/pythonKarabo/karabo/middlelayer/eventloop.py
111 112 113 114 | |
return a context manager to lock a device
This allows to lock another devices for exclusive use::
with (await lock(proxy)):
#do stuff
In a synchronous context, this function waits at the end of the block until the lock is released, unless wait_for_release is False. In an asynchronous context, we cannot wait for release, so we don't.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
Synchronization Primitives
Blocking until conditions are met:
Wait until the condition is True
The condition is typically a lambda function, as in::
waitUntil(lambda: device.speed > 3)
The condition will be evaluated each time something changes. Note that for this to work, it is necessary that all the devices used in the condition are connected while we are waiting (so typically they appear in a with statement)
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
Wait until new futures provide a result
The futures can be provided as in::
waitUntilNew(device.speed, device.targetPosition)
where device is a proxy. The first completed future will return the function. This function can be used to wait for a global property event on a device as well::
waitUntilNew(device)
Note that for this to work, it is necessary that all the devices used in the future parameters are connected while we are waiting.
For the asynchronous case a :func:asyncio.wait_for should be combined
if a timeout is desired.
Source code in src/pythonKarabo/karabo/middlelayer/device_client.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
Karabo Descriptors
Descriptor Categories
Abstract base classes for Karabo types:
Bases: Descriptor
A Type is a descriptor that does not contain other descriptors.
All basic Karabo types are described by a Type.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
toKaraboValue(data, strict=True)
Convert data into a KaraboValue
in strict mode, the default, we only allow values which have the correct unit set or are of the correct enum. In non-strict mode, we simply add our unit if none is given, or convert to our enum. This is important for data coming from the network, as that has no notion about units or enums.
Note that for critical applications, it is advisable to do unit conversions and timestamp handling by hand.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
699 700 701 702 703 704 705 706 707 708 709 710 711 | |
Bases: Type
This is the base class for all vectors of data
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
Bases: Vector
The base class for all vectors which can be represented as numpy vectors
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | |
This is the base for all numeric types
It features the minimum and maximum for its values given
in minExc, maxExc, minInc, and maxInc, where
min and max stand for miniumum and maximum, while Exc
and Inc stand for exclusive and inclusive, respectively.
Do not use inclusive and exclusive for the same limit at the same time.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
getMinMax()
Return a tuple (minimum, maximum) for this value
This are the minimum and maximum value this type can take.
This is based both on the definition of the type, as well as
on the attributes minInc, maxInc, minExc,
maxExc. All information can be condensed in just two
values as it is futile to specify both inclusive and exclusive
values for the same limit.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
234 235 236 237 238 239 240 241 242 243 244 | |
Bases: Simple
The base class for all floating-point types
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
The base class for all integers
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
The base class for all descriptors which can be an enumeration
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
Atomic Descriptors
Primitive data types:
This is the type corresponding to unicode strings, which are supposed to be used for all human-readable strings, so for everything except binary data.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
Bases: Vector
A VectorChar is simply some binary data in memory. The corresponding
Python data type is :class:python:bytes.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |
Bases: Type
This describes a boolean: True or False
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
822 823 824 825 826 827 828 829 830 831 832 | |
Bases: NumpyVector
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
835 836 837 838 839 840 841 842 | |
Bases: Vector
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | |
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
Compound Descriptors
Structured types:
Bases: Type
The Image class is a helper class to provide ImageData
Along the raw pixel values it also stores useful metadata like encoding, bit depth or binning and basic transformations like flip, rotation, ROI.
This special hash Type contains an NDArray element and is constructed::
class Device(Configurable):
data = ImageData(np.zeros(shape=(10, 10), dtype=np.uint64),
encoding=ENCODING.GRAY)
image = Image(
data=data,
displayedName="Image")
Hence, the Image element can be initialized with an ImageData
KaraboValue.
Alternatively, the Image element can be initialized by providing shape
and dtype and the encoding::
image = Image(
displayedName="Image"
shape=(2600, 2000),
dtype=UInt8,
encoding=EncodingType.GRAY)
The dtype can be provided with a simple Karabo descriptor or the numpy
dtype, e.g. numpy.uint8.
Source code in src/pythonKarabo/karabo/native/schema/image_data.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
Bases: Descriptor
Compose configurable classes into each other
with a Node you can use a Configurable object in another one as an attribute::
from karabo import Configurable, Node
class Outer(Configurable):
inner = Node(Inner)
Source code in src/pythonKarabo/karabo/native/schema/configurable.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
Bases: Vector
A VectorHash is a table
The VectorHash value setting can be for example done via:
- list of tuples: [(value1, value2), ...]
- list of Hashes: [Hash('key1', value1, 'key2', value2), ...]
A VectorHash can be initialized via::
class RowSchema(Configurable):
deviceId = String()
classId = String()
table = VectorHash(
displayedName="Table",
rows=RowSchema)
:param row: The structure of each row. This is a :class:Configurable
class.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 | |
Special Descriptors
Advanced or regex‑based types:
Bases: String
Copy a remote device into the local's namespace
A device that controls another device may add a device node such that it has a proxy to that device while both are running. The controlled device may be configured at initialization time.
As an example, a stage controlling some motor::
class Stage(Device):
motor = DeviceNode()
Then the motor can be acessed under self.motor. Before
instantiation, a device node just looks like a string, where the
id of the target device can be entered.
Source code in src/pythonKarabo/karabo/middlelayer/devicenode.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | |
checkedInit(instance, value=None)
Device Nodes cannot have an empty string
Source code in src/pythonKarabo/karabo/middlelayer/devicenode.py
72 73 74 75 76 77 78 79 80 | |
finalize_init(instance)
async
Sets a real proxy to the MetaProxy
Source code in src/pythonKarabo/karabo/middlelayer/devicenode.py
82 83 84 85 86 87 88 89 90 91 92 93 | |
Bases: VectorString
The VectorRegexString descriptor is used as follows::
data = VectorRegexString(regex="0|1")
A corresponding displayType is automatically set. The descriptor validates value input on set.
The regex is validated with each single value of the vector (list).
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | |
Bases: String
The RegexString descriptor is used as follows::
data = RegexString(regex="0|1")
A corresponding displayType is automatically set. The descriptor validates value input on set.
Source code in src/pythonKarabo/karabo/native/schema/descriptors.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
Karabo Data Types
Values and quantifiable types:
This is the base class for all Karabo values.
All attributes of a Karabo device contain objects of these types, as they are the only ones we know how to transport over the network.
A :class:KaraboValue contains attributes that describe the value
further:
.. attribute:: descriptor
This contains all the details of the datatype we have. It
is an object of :class:~karabo.middlelayer.Descriptor, look there for
what it contains.
The descriptor is only available when accessing the device attributes
directly. Values calulated from a :class:KaraboValue lose their
descriptor, as it does not apply to them anymore.
.. attribute:: timestamp
This is the time a value has been acquired by the underlying hardware
devices. It is an object of :class:~karabo.middlelayer.Timestamp.
When doing operations on :class:KaraboValue, the result takes the
newest timestamp of the values operated on. So for the example
2 * x + y, the newest timestamp of x and y is taken,
if both have a timestamp.
.. attribute:: tid
This is the macro id number attached to the timestamp.
.. attribute:: value
This is the bare value, without any special Karabo things or units attached.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
has_tid
property
Property to indicate whether our KaraboValue has a valid trainId
tid
property
Property to directly provide the trainId of the KaraboValue
getdoc()
This is called by iPython/iKarabo to get the documentation
See :func:IPython.core.oinspect.getdoc
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
166 167 168 169 170 171 | |
Test whether value actually has a value
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
256 257 258 | |
Bases: KaraboValue, Quantity
The base class for all Karabo numerical values, including vectors.
It has a unit (by virtue of inheriting a :ref:pint <pint:tutorial>
Quantity). Vectors are represented by numpy arrays.
In addition to the timestamp processing common to any :class:KaraboValue,
a :class:QuantityValue also has a unit.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
Bases: StringlikeValue, str
A StringValue is a Python :class:str.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
343 344 345 346 347 348 349 | |
Bases: KaraboValue, list
A Karabo VectorStringValue corresponds to a Python list.
We check that only strings are entered
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | |
Bases: KaraboValue
This wraps numpy structured arrays. Pint cannot deal with them.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | |
append(value)
Append value to the TableValue
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
553 554 555 | |
clear()
Clear the table element with a single message
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
604 605 606 607 | |
default_row()
Return a row Hash with default values of the TableValue
Added in 2.16.X: This method safely returns a quick deepcopy!
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
597 598 599 600 601 602 | |
extend(value)
Extend the TableValue by a value
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
549 550 551 | |
insert(index, value)
Insert a value into the TableValue at index
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
545 546 547 | |
iter_hashes()
Iterate over the table by providing the Hash elements
This method does NOT provide a copy!
Note: Added in Karabo 2.16.X
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
626 627 628 629 630 631 632 633 634 635 636 | |
pop(index=-1)
Pops a single TableValue from the table
NOTE: This method can only be used with a descriptor!
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
557 558 559 560 561 562 563 564 565 | |
to_hashlist()
Convert the TableValue as Hashlist but lose the attributes
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
609 610 611 612 613 614 | |
where(field, value, op=operator.eq)
Return indexes of the table where a condition for a column is met
:param field: The field of the row schema, e.g. string key :param value: The value for the condition :param op: Operator condition
:returns: list of indexes
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
570 571 572 573 574 575 576 577 578 579 580 581 582 | |
where_value(field, value, op=operator.eq)
Filter the table with a condition for a column
:param field: The field of the row schema, e.g. string key :param value: The value for the condition :param op: Instance of operator condition
:returns: Filtered TableValue
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
584 585 586 587 588 589 590 591 592 593 594 595 | |
Bases: KaraboValue
This contains an enum.
We can define enums in the expected parameters. This contains a value of
them. Unfortunately, it is impossible to use the is operator as with
bare enums, one has to use == instead.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
Bases: _Singleton
This contains bools.
Objects of this class behave effectively like normal bools, just with a timestamp and a descriptor added.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Bases: KaraboValue
The Karabo ImageData is supposed to provide an encapsulated NDArray
This KaraboValue can estimate from the input array the associated
attributes of the ImageData, such as binning, encoding, etc.
Every attribute can be provided as well on initialization of the object.
:param binning: The binning of the image, e.g. [0, 0]
:param encoding: The encoding of the image, e.g. EncodingType.GRAY (enum)
:param rotation: The rotation of the image, either 0, 90, 180 or 270
:param roiOffsets: The roiOffset, e.g. [0, 0]
:param dimScales: Description of the dim scales
:param dimTypes: The dimension types
:param bitsPerPixel: The bits per pixel
:param flipX: Image horizontal flip, either True or False
:param flipY: Image vertical flip, either True or False
:type binning: array with dtype uint64 :type encoding: integer with dtype int32 :type rotation: integer with dtype int32 :type roiOffsets: array with dtype uint64 :type dimScales: str :type dimTypes: array with dtype int32 :type flipX: bool :type flipY: bool
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
toDict()
Provide the attributes of the ImageData in a dictionary form
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
Bases: _Singleton
This represents a value which is not set.
This is mostly the Karabo equivalent of None.
Source code in src/pythonKarabo/karabo/native/schema/basetypes.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
This is a time stamp
:param date: is either another timestamp (then we copy), None
(we return now), a float (from time.time()), an integer
(raw timestamp) or a string that will be parsed
with :mod:dateutil
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
tid
property
writable
The train Id associated with this Timestamp
time_frac
property
The fractional seconds of the timestamp in attoseconds
time_sec
property
The seconds of the timestamp from epoch
__add__(other)
Add operator for the time in seconds since 1970-01-01 00:00 UTC
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
139 140 141 142 143 144 145 146 | |
__repr__()
Return the time as an ISO 8601 string in UTC
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
133 134 135 136 137 | |
__str__()
See toLocal()
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
129 130 131 | |
__sub__(other)
Sub operator for the time in seconds since 1970-01-01 00:00 UTC
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
148 149 150 151 152 153 154 155 | |
toLocal(sep='T', timespec='auto')
Return the time as an ISO 8601 string in the local timezone
:param sep: unicode character to separate date and time, default is 'T' :param timespec: specifies the number of additional components of the time to include, defaults to 'auto'. Further options are 'hours', 'minutes', 'seconds', 'milliseconds' and 'microseconds'
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
106 107 108 109 110 111 112 113 114 115 116 117 | |
toTimestamp()
Return the time as seconds since 1970-01-01 00:00 UTC
Source code in src/pythonKarabo/karabo/native/data/timestamp.py
102 103 104 | |