# Extending ISX Algorithms

If you want to expand the available ISX algorithms in the pipeline, you can do so by modifying the file:

ci\_pipe/\
└─ modules/\
&#x20;         └─ isx\_module.py <-- modify this file

This file defines the `ISXModule` class, which wraps each ISX processing step (e.g., preprocessing, bandpass filtering, motion correction, etc.) into a pipeline-compatible function.

Each algorithm is implemented as a method inside the `ISXModule` class and decorated with the `@step` decorator.

Each of these methods:

1. Creates a new output directory for the next step.
2. Iterates through the input list (`inputs('videos-isxd')`).
3. Calls the corresponding ISX backend function (`self._isx.preprocess`, `self._isx.spatial_filter`, etc.).
4. Returns a dictionary of outputs for the pipeline trace.

**Example: Adding a New ISX Step**

Suppose you want to add a new ISX algorithm called `denoise_videos`.\
You would edit `isx_module.py` and add the following code:

```
class ISXModule:
    # Add a constant for the step name and suffix
    DENOISE_VIDEOS_STEP = "ISX Denoise Videos"
    DENOISE_VIDEOS_SUFIX = "DN"

    ...

    @step(DENOISE_VIDEOS_STEP)
    def denoise_videos(
            self,
            inputs,
            *,
            isx_dn_method="gaussian",
            isx_dn_strength=0.5
    ):
        output = []
        output_dir = self._ci_pipe.create_output_directory_for_next_step(self.DENOISE_VIDEOS_STEP)

        for input in inputs('videos-isxd'):
            input_path = input['value']
            output_path = self._isx.make_output_file_path(input_path, output_dir, self.DENOISE_VIDEOS_SUFIX)

            # Here you call your ISX backend method or a custom function
            self._isx.denoise(
                input_movie_files=[input_path],
                output_movie_files=[output_path],
                method=isx_dn_method,
                strength=isx_dn_strength
            )

            output.append({'ids': input['ids'], 'value': output_path})

        return {
            'videos-isxd': output
        }

```

Once added, the new step becomes automatically available in the pipeline:

```
pipeline.isx.denoise_videos(isx_dn_method="median", isx_dn_strength=0.7)
```

**Best Practices**

* Use clear and consistent naming for step constants and suffixes.
* Keep all ISX-related constants at the top of the class.
* Follow the existing structure to maintain trace compatibility (`index`, `name`, `params`, `outputs`).
* Always return a dictionary of outputs (even if there’s only one key).
* If your new algorithm uses different input/output formats, ensure they are correctly handled by the pipeline’s `inputs()` and `create_output_directory_for_next_step()` methods.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cipipe.gitbook.io/cipipe-docs/expansion-guide/extending-isx-algorithms.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
