Skip to main content

Standalone for_each batch execution utilities for data pipelines

Project description

scifor

Stop Writing Loops, Start Writing Analysis

scifor is the batch execution engine behind SciDB. It takes a function you've already written and runs it across every combination of experimental conditions — subjects, sessions, trials, whatever your data is organized by — automatically slicing your data to match each combination and collecting the results into a clean table.

It works in both Python and MATLAB, and it works standalone — no database required, just plain tables.

The Problem

Scientific data is almost always organized by conditions: subjects, sessions, trials, limbs, speeds. Processing it means writing nested loops that slice, call a function, and collect results:

for i = 1:numel(subjects)
    for j = 1:numel(sessions)
        rows = tbl(tbl.subject == subjects(i) & tbl.session == sessions(j), :);
        result = my_analysis(rows.emg);
        % ...now figure out where to put the result
    end
end

This gets worse as the number of conditions grows, and the loop logic buries the actual analysis. Every scientist writes some version of this, and it's never the interesting part.

How scifor Works

You tell scifor two things:

  1. Schema — which columns in your tables represent experimental conditions (the things you iterate over)
  2. Inputs — which tables to slice, and which values are just constants

Then scifor handles the rest: it loops over every combination, filters each table to the matching rows, calls your function, and collects the results.

MATLAB

scifor.set_schema(["subject", "session"]);

results = scifor.for_each(@my_analysis, ...
    struct('emg', data_table, 'cutoff_hz', 20), ...
    subject=[1, 2, 3], session=["pre", "post"]);

Python

from scifor import set_schema, for_each

set_schema(["subject", "session"])

results = for_each(
    my_analysis,
    inputs={"emg": data_table, "cutoff_hz": 20},
    subject=[1, 2, 3],
    session=["pre", "post"],
)

For each of the 6 combinations (3 subjects x 2 sessions), scifor filters data_table to the matching rows, passes the emg column to my_analysis along with the constant cutoff_hz=20, and collects the return value. The result is a table with subject, session, and output columns — one row per combination.

Your function doesn't need to know about looping, filtering, or metadata. It just receives data and returns a result.

What You Get Back

for_each returns a MATLAB table (or pandas DataFrame in Python) with one row per combination. Metadata columns come first, then the output:

subject session output
1 pre 0.82
1 post 1.47
2 pre 0.91
2 post 1.38
3 pre 0.76
3 post 1.22

If your function returns a table, its columns are flattened into the result alongside the metadata. If your function returns multiple outputs, you get multiple result tables.

Beyond the Basics

The examples above cover the most common case, but real pipelines have real-world complications. scifor has tools for each of them:

  • Fixed inputs — Pin one input to a specific condition while the others iterate. The classic case: comparing every session against a fixed baseline.

  • Merging tables — When your function needs columns from two separate tables (say, kinematics and force data), combine them into a single input per combination.

  • Column selection — Extract just the columns you need from a multi-column table before your function sees it.

  • File paths from metadata — When your data lives in files organized by condition (e.g., data/subject_1/trial_3.mat), generate the right file path for each combination automatically.

  • Row filtering — Apply column-based filters (like "only right-side trials" or "speed > 1.5") on top of the metadata filtering.

  • Dry run — Preview which combinations would be processed and what data would be passed, without actually running anything.

  • Distribute — When a function returns a vector of values that should each become their own row at a deeper schema level (e.g., splitting a trial into individual gait cycles), scifor can expand the output automatically.

See the API reference and batch processing guide for details on all of these.

Relationship to SciDB

scifor is the engine that powers scidb.for_each(). When used through SciDB, inputs are loaded from the database and outputs are saved back automatically. When used standalone (as scifor.for_each()), it works with plain MATLAB tables or pandas DataFrames — no database needed.

If you're already using SciDB, you're already using scifor under the hood. If you just want the loop orchestration without the database, use the scifor namespace directly.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scifor-0.1.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scifor-0.1.0-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file scifor-0.1.0.tar.gz.

File metadata

  • Download URL: scifor-0.1.0.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for scifor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 48de5873b8d756a24e54d198a8bfe3deb7efaeeadc3e7e6e0e743b58368a2f22
MD5 17a128e27a7cc50f51f5b315357fa24d
BLAKE2b-256 82c931c4dced7d8704af956cdea70cbcb2f88832d06f81a437d44878b8172992

See more details on using hashes here.

File details

Details for the file scifor-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: scifor-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for scifor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e8d8e497100c4c728322a8e7e95b843cd6eaa2c1d94e206baa28fa832aa8120
MD5 8adb26198132a5c466c1573fa38fd79f
BLAKE2b-256 8f16d9e1d1bb80f9cfd40b7e396ad36f8b76cf5ebb48f17277b3c558da56bef8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page