# Custom DAP Scripts The DAP allows custom scripts to be uploaded and run on the streamed detector data. Libraries like numpy and scipy are available, further can be added. ## Structure `myalgo.py`: ```python def proc(meta, image, mask): ... return result ``` or ```python def myalgo(meta, image, mask): ... return result ``` Both function names, i.e., either the same as the script name or `proc`, are allowed. `meta` is a dict containing all results that have been calculated for this image by other configured algorithms already. Modifications of this dict inside the function are ignored. Instead, all new results should be returned from the function. `result` may be either a single value or a dict. A single value will be turned into the channel name `detector_name:script_name`, e.g. `JF01T02V03:myalgo`. For a dict, each entry will be turned into a channel of the pattern `detector_name:key`. ## Uploading For uploading a custom script from slic, use: ```python daq = SFAcquisition(...) daq.client.upload_custom_dap_script("myalgo.py") ``` Alternatively, the "slow broker" endpoint `upload_custom_dap_script` may be used directly. It expects `"name"` and `"code"`, which are the script's name and function code as strings, respectively. The scripts will be stored per beamline. This allows two beamlines to have a script each with the same name. The beamline is determined by the subnet from which the script is uploaded and cannot be manually changed. ## Enabling For enabling a custom script from slic, use: ```python daq = SFAcquisition(...) parameters = { "custom_script": "beamline:script_name" } daq.client.restapi.set_dap_settings(detector, parameters) ``` Here, beamline can be any beamline, meaning it is possible to use a script from another beamline. Alternatively, the "slow broker" endpoint `set_dap_settings` may be used directly. It expects `"detector_name"` and `"parameters"` (see example above).