### Installing OM from PyPI using pip (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command installs the OndaMonitor (OM) package directly from the Python Package Index (PyPI) using the `pip` package installer. It's the simplest way to get OM if you have Python and pip set up. ```bash pip install ondamonitor ``` -------------------------------- ### Running OM Source Installation Script (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command executes the provided installation script for OndaMonitor (OM) from its source directory. This script automates the installation process, offering options for custom paths and editable installations. ```bash sh tools/scripts/installation/install.sh ``` -------------------------------- ### Displaying OM Installation Script Help (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command runs the OndaMonitor (OM) installation script with the `-h` (help) flag, which displays all available options and their usage. This is useful for understanding how to customize the script's behavior. ```bash sh tools/scripts/installation/install.sh -h ``` -------------------------------- ### Activating OM Installation via Script-Generated File (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command sources an activation script generated by the `install.sh` script. Sourcing this file sets up the necessary environment variables to use a specific OndaMonitor (OM) installation, particularly when installed to a custom path. ```bash source /bin/activate-om ``` -------------------------------- ### Installing OM from Source to a Custom Path (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command installs OndaMonitor (OM) from its source code using `pip`, specifying a custom installation path. The `.` indicates the current directory (the root of the source code) as the source. ```bash pip install --prefix= . ``` -------------------------------- ### Cloning OM Source Code from GitHub (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command uses `git` to clone the entire OndaMonitor (OM) source code repository from GitHub. This is the first step when installing OM directly from its source. ```bash git clone https://github.com/omdevteam/om ``` -------------------------------- ### Setting Environment Variables for OM Installation (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md These commands set the `PATH` and `PYTHONPATH` environment variables. This is crucial for the operating system to locate the OM executables and Python modules after a custom source installation. `` and `` must be replaced with actual values. ```bash export PATH=/bin:$PATH export PYTHONPATH=/lib/python/site-packages:$PYTHONPATH ``` -------------------------------- ### Installing OM from Source in Editable Mode (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command performs an 'editable' installation of OndaMonitor (OM) from source using `pip`. This is useful for development, as changes to the source code are immediately reflected without reinstallation. ```bash pip install --editable --prefix= . ``` -------------------------------- ### Running OM Monitor with Custom Config and Source - Bash Source: https://github.com/omdevteam/om/blob/master/docs/docs/configuring_om.md This command shows how to start the `om_monitor.py` script while specifying a custom path for the configuration file using the `--config` option, in addition to providing the data source string. This allows for flexible deployment and management of monitor configurations. ```bash om_monitor.py --config ``` -------------------------------- ### Running OM Monitor with Source String - Bash Source: https://github.com/omdevteam/om/blob/master/docs/docs/configuring_om.md This snippet demonstrates the basic command-line syntax for starting the `om_monitor.py` script, where `` specifies the origin of data events. The format of the source string depends on the Data Retrieval Layer and Data Event Handler being used. ```bash om_monitor.py ``` -------------------------------- ### Installing OM from CondaForge using conda (Bash) Source: https://github.com/omdevteam/om/blob/master/docs/docs/installing_om.md This command installs the OndaMonitor (OM) package from the CondaForge channel using the `conda` package manager. Conda is often used in scientific computing environments for managing packages and environments. ```bash conda install -c conda-forge ondamonitor ``` -------------------------------- ### Example Crystallography Configuration Group - YAML Source: https://github.com/omdevteam/om/blob/master/docs/docs/configuring_om.md This YAML snippet illustrates a typical parameter group within an OM configuration file. The `crystallography` group contains parameters like `broadcast_ip`, `broadcast_port`, and `speed_report_interval`, which are related to crystallography-specific features or algorithms within OM. ```yaml crystallography: broadcast_ip: 127.0.0.1 broadcast_port: 12321 speed_report_interval: 1000 ``` -------------------------------- ### Initializing Cython Module __test__ Dictionary (C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This C code snippet, generated by Cython, initializes the __test__ dictionary for the Python module. It creates a new presized Python dictionary, increments its reference count, sets it as the __test__ attribute of the module's dictionary (__pyx_d), and then decrements its reference count. This is a standard part of Cython module setup. ```C __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; ``` -------------------------------- ### Defining Python Wrapper `bin_detector_data` (Cython & Generated C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This snippet defines the start of a Cython function `bin_detector_data`, which serves as a Python-callable wrapper for an underlying C function. It utilizes Cython's typed memoryviews (`[:,::1]`) for efficient handling of array-like data. The accompanying C code is the prototype for the Python wrapper function generated by Cython, responsible for converting Python arguments to C types before invoking the core C logic. ```Cython def bin_detector_data(double[:,::1] data, double[:,::1] binned_data, char[:,::1] mask, ``` ```C /* Python wrapper */ static PyObject *__pyx_pw_2om_10algorithms_8_generic_1bin_detector_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ ``` -------------------------------- ### Initializing Cython Module Dictionary (Python & Generated C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This snippet illustrates the module initialization process. The Python comment indicates the file's origin, while the accompanying C code, generated by Cython, creates and sets a new Python dictionary (likely for internal module state or `__test__`) within the module's global dictionary. This is a standard procedure for Cython modules to prepare their environment. ```Python # This file is part of OM. ``` ```C __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; ``` -------------------------------- ### Cython Wrapper for bin_detector_data Function (Entry) Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This snippet shows the generated C wrapper code for the `bin_detector_data` function, handling argument unpacking, error tracing, and context management before calling the core implementation. It sets up the necessary Cython runtime environment and error handling for Python-C interaction. ```C __Pyx_AddTraceback("om.algorithms._generic.bin_detector_data", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_2om_10algorithms_8_generic_bin_detector_data(__pyx_self, __pyx_v_data, __pyx_v_binned_data, __pyx_v_mask, __pyx_v_bin_size, __pyx_v_min_good_pixel_count, __pyx_v_bad_pixel_value, __pyx_v_saturation_value, __pyx_v_asic_size_fs, __pyx_v_asic_size_ss, __pyx_v_num_asics_fs, __pyx_v_num_asics_ss); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; ``` -------------------------------- ### Cython Wrapper for `peakfinder_8` Argument Parsing (C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This C function, generated by Cython, acts as the entry point for the `peakfinder_8` Python function. It is responsible for parsing and validating the Python arguments (`__pyx_args`, `__pyx_kwds`) and converting them into appropriate C types (e.g., `int`, `float`, `__Pyx_memviewslice`). It initializes variables for all expected parameters, including `max_num_peaks`, `data`, `mask`, `adc_thresh`, and various hitfinder thresholds, as detailed in the function's Python docstring. ```C static PyObject *__pyx_pw_2om_10algorithms_16_crystallography_1peakfinder_8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_v_max_num_peaks; __Pyx_memviewslice __pyx_v_data = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_mask = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_pix_r = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_rstats_num_pix; __Pyx_memviewslice __pyx_v_rstats_pidx = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_rstats_radius = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_fast; long __pyx_v_asic_nx; long __pyx_v_asic_ny; long __pyx_v_nasics_x; long __pyx_v_nasics_y; float __pyx_v_adc_thresh; float __pyx_v_hitfinder_min_snr; long __pyx_v_hitfinder_min_pix_count; long __pyx_v_hitfinder_max_pix_count; long __pyx_v_hitfinder_local_bg_radius; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("peakfinder_8 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_max_num_peaks,& __pyx_n_s_data,& __pyx_n_s_mask,& __pyx_n_s_pix_r,& __pyx_n_s_rstats_num_pix,& __pyx_n_s_rstats_pidx,& __pyx_n_s_rstats_radius,& __pyx_n_s_fast,& __pyx_n_s_asic_nx,& __pyx_n_s_asic_ny,& __pyx_n_s_nasics_x,& __pyx_n_s_nasics_y,& __pyx_n_s_adc_thresh,& __pyx_n_s_hitfinder_min_snr,& __pyx_n_s_hitfinder_min_pix_count,& __pyx_n_s_hitfinder_max_pix_count,& __pyx_n_s_hitfinder_local_bg_radius,0}; PyObject* values[17] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 17: values[16] = PyTuple_GET_ITEM(__pyx_args, 16); CYTHON_FALLTHROUGH; case 16: values[15] = PyTuple_GET_ITEM(__pyx_args, 15); CYTHON_FALLTHROUGH; case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14); CYTHON_FALLTHROUGH; case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13); CYTHON_FALLTHROUGH; case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12); CYTHON_FALLTHROUGH; case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11); CYTHON_FALLTHROUGH; case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); CYTHON_FALLTHROUGH; case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); CYTHON_FALLTHROUGH; case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); CYTHON_FALLTHROUGH; case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); CYTHON_FALLTHROUGH; case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; ``` -------------------------------- ### Defining and Parsing Arguments for bin_detector_data in Cython/C Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This snippet defines the `bin_detector_data` function, a Cython-generated C function, including its method definition and argument parsing logic. It handles multiple input parameters such as data memory views, binning parameters, pixel counts, and ASIC dimensions. The function uses `PyObject` for arguments and `__Pyx_memviewslice` for data, ensuring proper handling of Python objects and C memory views. ```C static char __pyx_doc_2om_10algorithms_8_generic_bin_detector_data[] = "\n Docstring here\n "; static PyMethodDef __pyx_mdef_2om_10algorithms_8_generic_1bin_detector_data = {"bin_detector_data", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2om_10algorithms_8_generic_1bin_detector_data, METH_VARARGS|METH_KEYWORDS, __pyx_doc_2om_10algorithms_8_generic_bin_detector_data}; static PyObject *__pyx_pw_2om_10algorithms_8_generic_1bin_detector_data(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __Pyx_memviewslice __pyx_v_data = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_binned_data = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_mask = { 0, 0, { 0 }, { 0 }, { 0 } }; int __pyx_v_bin_size; int __pyx_v_min_good_pixel_count; double __pyx_v_bad_pixel_value; double __pyx_v_saturation_value; int __pyx_v_asic_size_fs; int __pyx_v_asic_size_ss; int __pyx_v_num_asics_fs; int __pyx_v_num_asics_ss; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("bin_detector_data (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_binned_data,&__pyx_n_s_mask,&__pyx_n_s_bin_size,&__pyx_n_s_min_good_pixel_count,&__pyx_n_s_bad_pixel_value,&__pyx_n_s_saturation_value,&__pyx_n_s_asic_size_fs,&__pyx_n_s_asic_size_ss,&__pyx_n_s_num_asics_fs,&__pyx_n_s_num_asics_ss,0}; PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10); CYTHON_FALLTHROUGH; case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9); CYTHON_FALLTHROUGH; case 9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8); CYTHON_FALLTHROUGH; case 8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7); CYTHON_FALLTHROUGH; case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_binned_data)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("bin_detector_data", 1, 11, 11, 1); __PYX_ERR(0, 32, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("bin_detector_data", 1, 11, 11, 2); __PYX_ERR(0, 32, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bin_size)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("bin_detector_data", 1, 11, 11, 3); __PYX_ERR(0, 32, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_min_good_pixel_count)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("bin_detector_data", 1, 11, 11, 4); __PYX_ERR(0, 32, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bad_pixel_value)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("bin_detector_data", 1, 11, 11, 5); __PYX_ERR(0, 32, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: ``` -------------------------------- ### Defining Module Docstring (Python) Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This Python docstring provides a high-level description of the `_generic` module, indicating its purpose as an extension for 'Peakfinder8' and its implementation of Cheetah's 'peakfinder8' peak detection algorithm. Docstrings are crucial for documenting Python modules and functions. ```Python """ Peakfinder8 extension. This extension contains an implementation of Cheetah's 'peakfinder8' peak detection algorithm. """ ``` -------------------------------- ### Cython Python API Integration for bin_detector_data Source: https://github.com/omdevteam/om/blob/master/src/cython/_generic.html This snippet demonstrates how the `bin_detector_data` function is exposed to Python. It involves packing function arguments into a Python tuple, creating a Python C function object, and associating it with a code object, making the underlying C function callable from Python. ```C __pyx_tuple__20 = PyTuple_Pack(11, __pyx_n_s_data, __pyx_n_s_binned_data, __pyx_n_s_mask, __pyx_n_s_bin_size, __pyx_n_s_min_good_pixel_count, __pyx_n_s_bad_pixel_value, __pyx_n_s_saturation_value, __pyx_n_s_asic_size_fs, __pyx_n_s_asic_size_ss, __pyx_n_s_num_asics_fs, __pyx_n_s_num_asics_ss); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__20); __Pyx_GIVEREF(__pyx_tuple__20); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2om_10algorithms_8_generic_1bin_detector_data, NULL, __pyx_n_s_om_algorithms__generic); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_bin_detector_data, __pyx_t_1) < 0) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(11, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_cython__generic_pyx, __pyx_n_s_bin_detector_data, 32, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 32, __pyx_L1_error) ``` -------------------------------- ### Parsing Function Arguments in Cython-Generated C Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This C code snippet, generated by Cython, demonstrates the robust argument parsing logic for a function named 'peakfinder_8'. It handles both positional arguments (extracted from `__pyx_args` tuple) and keyword arguments (extracted from `__pyx_kwds` dictionary). The `CYTHON_FALLTHROUGH` macro is used to process arguments sequentially, and extensive error checking (`__Pyx_RaiseArgtupleInvalid`) ensures all required parameters are provided, raising an error if any are missing. ```C case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_max_num_peaks)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_data)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 1); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mask)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 2); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_pix_r)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 3); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rstats_num_pix)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 4); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rstats_pidx)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 5); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rstats_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 6); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 7: if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_fast)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 7); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 8: if (likely((values[8] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_asic_nx)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 8); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 9: if (likely((values[9] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_asic_ny)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 9); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 10: if (likely((values[10] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nasics_x)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 10); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 11: if (likely((values[11] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nasics_y)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 11); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 12: if (likely((values[12] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_adc_thresh)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 12); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 13: if (likely((values[13] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hitfinder_min_snr)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 13); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 14: if (likely((values[14] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hitfinder_min_pix_count)) != 0)) kw_args--; else { ``` -------------------------------- ### Error Handling and Resource Cleanup in peakfinder_8 (Cython/C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This snippet illustrates the error handling and resource cleanup mechanism within the `peakfinder_8` function. It includes `__Pyx_XDECREF` calls to decrement reference counts for Python objects and `__PYX_XDEC_MEMVIEW` for memory views, ensuring proper memory management and preventing leaks before the function returns. ```C /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_16); __Pyx_XDECREF(__pyx_t_17); __Pyx_XDECREF(__pyx_t_18); __Pyx_XDECREF(__pyx_t_19); __Pyx_XDECREF(__pyx_t_20); __Pyx_XDECREF(__pyx_t_21); __Pyx_XDECREF(__pyx_t_22); __Pyx_XDECREF(__pyx_t_2 ``` -------------------------------- ### Populating C++ Vectors with Peak Data in Cython Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This section shows the C++ `push_back` operations used to populate various `peak_list_` vectors (x, y, index, value, npix, maxi, sigma, snr) with corresponding peak data. The code includes error handling for C++ exceptions and type conversions from Python objects to C++ doubles where necessary. ```C++ try { __pyx_v_peak_list_x.push_back(__pyx_v_peak_x); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 212, __pyx_L1_error) } try { __pyx_v_peak_list_y.push_back(__pyx_v_peak_y); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 213, __pyx_L1_error) } try { __pyx_v_peak_list_index.push_back(__pyx_v_peak_index); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 214, __pyx_L1_error) } try { __pyx_v_peak_list_value.push_back(__pyx_v_peak_value); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 215, __pyx_L1_error) } __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_peak_npix); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 216, __pyx_L1_error) try { __pyx_v_peak_list_npix.push_back(__pyx_t_15); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 216, __pyx_L1_error) } __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_peak_maxi); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 217, __pyx_L1_error) try { __pyx_v_peak_list_maxi.push_back(__pyx_t_15); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 217, __pyx_L1_error) } __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_peak_sigma); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 218, __pyx_L1_error) try { __pyx_v_peak_list_sigma.push_back(__pyx_t_15); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 218, __pyx_L1_error) } __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_peak_snr); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 219, __pyx_L1_error) try { __pyx_v_peak_list_snr.push_back(__pyx_t_15); } catch(...) { __Pyx_CppExn2PyErr(); __PYX_ERR(0, 219, __pyx_L1_error) } ``` -------------------------------- ### Parsing and Type Conversion for peakfinder_8 Arguments Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This snippet manages the parsing of 17 arguments for the `peakfinder_8` function, supporting both keyword and positional inputs. It includes error checks for missing or incorrect arguments and performs type conversions from Python objects to specific C types such as `int`, `long`, `float`, and `MemoryviewSlice` for numerical data and masks, ensuring data readiness for the function's core logic. ```C __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 14); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 15: if (likely((values[15] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hitfinder_max_pix_count)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 15); __PYX_ERR(0, 70, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 16: if (likely((values[16] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hitfinder_local_bg_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("peakfinder_8", 1, 17, 17, 16); __PYX_ERR(0, 70, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "peakfinder_8") < 0)) __PYX_ERR(0, 70, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 17) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); values[7] = PyTuple_GET_ITEM(__pyx_args, 7); values[8] = PyTuple_GET_ITEM(__pyx_args, 8); values[9] = PyTuple_GET_ITEM(__pyx_args, 9); values[10] = PyTuple_GET_ITEM(__pyx_args, 10); values[11] = PyTuple_GET_ITEM(__pyx_args, 11); values[12] = PyTuple_GET_ITEM(__pyx_args, 12); values[13] = PyTuple_GET_ITEM(__pyx_args, 13); values[14] = PyTuple_GET_ITEM(__pyx_args, 14); values[15] = PyTuple_GET_ITEM(__pyx_args, 15); values[16] = PyTuple_GET_ITEM(__pyx_args, 16); } __pyx_v_max_num_peaks = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_max_num_peaks == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L3_error) __pyx_v_data = __Pyx_PyObject_to_MemoryviewSlice_d_dc_float(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_data.memview)) __PYX_ERR(0, 70, __pyx_L3_error) __pyx_v_mask = __Pyx_PyObject_to_MemoryviewSlice_d_dc_char(values[2], PyBUF_WRITABLE); if (unlikely(!__pyx_v_mask.memview)) __PYX_ERR(0, 70, __pyx_L3_error) __pyx_v_pix_r = __Pyx_PyObject_to_MemoryviewSlice_d_dc_float(values[3], PyBUF_WRITABLE); if (unlikely(!__pyx_v_pix_r.memview)) __PYX_ERR(0, 71, __pyx_L3_error) __pyx_v_rstats_num_pix = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_rstats_num_pix == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 71, __pyx_L3_error) __pyx_v_rstats_pidx = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[5], PyBUF_WRITABLE); if (unlikely(!__pyx_v_rstats_pidx.memview)) __PYX_ERR(0, 71, __pyx_L3_error) __pyx_v_rstats_radius = __Pyx_PyObject_to_MemoryviewSlice_ds_int(values[6], PyBUF_WRITABLE); if (unlikely(!__pyx_v_rstats_radius.memview)) __PYX_ERR(0, 72, __pyx_L3_error) __pyx_v_fast = __Pyx_PyInt_As_int(values[7]); if (unlikely((__pyx_v_fast == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L3_error) __pyx_v_asic_nx = __Pyx_PyInt_As_long(values[8]); if (unlikely((__pyx_v_asic_nx == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L3_error) __pyx_v_asic_ny = __Pyx_PyInt_As_long(values[9]); if (unlikely((__pyx_v_asic_ny == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L3_error) __pyx_v_nasics_x = __Pyx_PyInt_As_long(values[10]); if (unlikely((__pyx_v_nasics_x == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) __pyx_v_nasics_y = __Pyx_PyInt_As_long(values[11]); if (unlikely((__pyx_v_nasics_y == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) __pyx_v_adc_thresh = __pyx_PyFloat_AsFloat(values[12]); if (unlikely((__pyx_v_adc_thresh == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) __pyx_v_hitfinder_min_snr = __pyx_PyFloat_AsFloat(values[13]); if (unlikely((__pyx_v_hitfinder_min_snr == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 74, __pyx_L3_error) __pyx_v_hitfinder_min_pix_count = __Pyx_PyInt_As_long(values[14]); if (unlikely((__pyx_v_hitfinder_min_pix_count == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 74, __pyx_L3_error) ``` -------------------------------- ### Defining peakfinder_8 Function and Variables (Cython/C) Source: https://github.com/omdevteam/om/blob/master/src/cython/_crystallography.html This snippet defines the `peakfinder_8` function, which serves as the core peak detection routine. It declares numerous local variables, including a `tPeakList` structure for peak data and `std::vector` instances for storing various peak properties, preparing the environment for the main peak-finding logic. ```C static PyObject *__pyx_pf_2om_10algorithms_16_crystallography_peakfinder_8(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_max_num_peaks, __Pyx_memviewslice __pyx_v_data, __Pyx_memviewslice __pyx_v_mask, __Pyx_memviewslice __pyx_v_pix_r, int __pyx_v_rstats_num_pix, __Pyx_memviewslice __pyx_v_rstats_pidx, __Pyx_memviewslice __pyx_v_rstats_radius, int __pyx_v_fast, long __pyx_v_asic_nx, long __pyx_v_asic_ny, long __pyx_v_nasics_x, long __pyx_v_nasics_y, float __pyx_v_adc_thresh, float __pyx_v_hitfinder_min_snr, long __pyx_v_hitfinder_min_pix_count, long __pyx_v_hitfinder_max_pix_count, long __pyx_v_hitfinder_local_bg_radius) { tPeakList __pyx_v_peak_list; int __pyx_v_i; float __pyx_v_peak_x; float __pyx_v_peak_y; float __pyx_v_peak_value; std::vector __pyx_v_peak_list_x; std::vector __pyx_v_peak_list_y; std::vector __pyx_v_peak_list_index; std::vector __pyx_v_peak_list_value; std::vector __pyx_v_peak_list_npix; std::vector __pyx_v_peak_list_maxi; std::vector __pyx_v_peak_list_sigma; std::vector __pyx_v_peak_list_snr; long __pyx_v_num_peaks; long __pyx_v_peak_index; PyObject *__pyx_v_peak_npix = NULL; PyObject *__pyx_v_peak_maxi = NULL; PyObject *__pyx_v_peak_sigma = NULL; PyObject *__pyx_v_peak_snr = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("peakfinder_8", 0); ```