# ISX Algorithms

The library includes an `ISXModule` that allows running the main algorithms for calcium imaging video analysis.\
Each function in the module represents a **step** that can be added to the pipeline and executed in order.

***

#### Available Functions

Each ISX function receives the pipeline inputs and has specific parameters, which can be overwritten for each step call.

**Main functions and their purpose:**

* `preprocess_videos()`: Preprocesses videos applying temporal and spatial downsampling, cropping, and defective pixel correction.
* `bandpass_filter_videos()`: Applies a spatial bandpass filter to the videos.
* `motion_correction_videos()`: Corrects motion in the videos and generates auxiliary outputs (translations, crop rects, mean images).
* `normalize_dff_videos()`: Normalizes fluorescence data for each cell (dF/F).
* `extract_neurons_pca_ica()`: Extracts neuronal signals using PCA and ICA.
* `detect_events_in_cells()`: Detects neuronal events in the extracted cells.
* `auto_accept_reject_cells()`: Automatically filters cells based on detected events.
* `export_movie_to_tiff()`: Exports processed videos to TIFF.
* `export_movie_to_nwb()`: Exports processed videos to NWB.

***

#### Example of Overwriting Parameters

```python
pipeline.set_defaults(
    isx_bp_subtract_global_minimum=False,
    isx_mc_max_translation=25,
    isx_acr_filters=[('SNR', '>', 3), ('Event Rate', '>', 0), ('# Comps', '=', 1)]
)

pipeline.isx.motion_correction_videos(isx_mc_series_name="series1")
```

In this example, the `isx_mc_series_name` parameter is overwritten for this step only, while the other values are taken from the pipeline defaults.

***

#### Executing Multiple Steps

Steps can be chained to run the full ISX analysis sequence cumulatively:

```
pipeline
    .set_defaults(isx_bp_subtract_global_minimum=False, isx_mc_max_translation=25, isx_acr_filters=[('SNR', '>', 3), ('Event Rate', '>', 0), ('# Comps', '=', 1)])
    .isx.preprocess_videos()
    .isx.bandpass_filter_videos()
    .isx.motion_correction_videos(isx_mc_series_name="series1")
    .isx.normalize_dff_videos()
    .isx.extract_neurons_pca_ica()
    .isx.detect_events_in_cells()
    .isx.auto_accept_reject_cells()

```

Each function generates its outputs, which are stored in folders inside the pipeline `output_directory` (as described in the **Step Execution and Structure** section) with the following naming convention:\
`<branch_name> - Step <number> - <function_name>`

Inside each folder, the files produced by the corresponding step are stored (one or multiple, depending on the function).


---

# 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/creating-a-pipeline/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.
