Skip to content

Commit 1db8c88

Browse files
committed
Add getting started / io chapter
1 parent a3534ef commit 1db8c88

1 file changed

Lines changed: 43 additions & 10 deletions

File tree

src/getting_started/io.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,55 @@
1-
# I/O: Runner file handling
1+
# I/O: Runner File Handling
22

3-
TODO:
3+
When you're using Styx wrapper functions with the default runners, you won't have to worry too much about I/O since a lot of it gets handled automatically for you.
44

5-
- Explain output tuple, root attribute.
5+
## Basic File Access
66

7-
## _Default_ runner behaviour
7+
Take this example:
88

9-
While custom Styx runners allow users to implement file I/O handling any way they want, the 'default' runners (`LocalRunner` as well as `DockerRunner` and `SingularityRunner`) work very similarly by default.
9+
```python
10+
outputs = fsl.bet(infile="brain.nii", fractional_intensity=0.5)
1011

11-
They create a directory (default path `styx_temp/` in the current working directory) in which a folder gets created for every Styx function call. These will look like this:
12+
outputs.mask_file # File path to an individual output
13+
```
14+
15+
The `outputs` object gives you structured access to generated files through properties that support autocompletion and include helpful documentation.
16+
17+
## Dynamic File Access
18+
19+
Sometimes though, either when a descriptor hasn't been fully implemented or if the output structure is more complex, there may not be an output property available. For these cases, you can use the `outputs.root` property, which always points to the output directory:
20+
21+
```python
22+
outputs.root / "my_special_file.ext"
23+
24+
# Dynamic file access
25+
for number in [1, 2, 3]:
26+
f = outputs.root / f"my_file_with_a_{number}.ext"
27+
```
28+
29+
## Default Runner Behavior
30+
31+
While custom Styx runners let you implement file I/O handling however you want, the default runners (`LocalRunner`, `DockerRunner`, and `SingularityRunner`) all work pretty similarly by default. They create a working directory (defaults to `styx_temp/` in your current working directory) with individual folders for each Styx function call you make.
32+
33+
### Directory Structure
1234

1335
```
1436
79474bd248c4b2f1_5_bet/
1537
^^^^^^^^^^^^^^^^ ^ ^^^
1638
| | |
17-
| | `-- interface name (FSL BET)
18-
| `---- number of execution (5th)
19-
`--------------------- unique random hash
39+
| | `-- Interface name (FSL BET)
40+
| `---- Execution number (5th call)
41+
`--------------------- Unique session hash
2042
```
2143

22-
Every time you create a new runner a new random hash will be generated. This ensures paths created are unique and avoid conflict with previous executions of your pipeline. The hash is followed by a counting number which chronologically will count up by one for every Styx function call. This makes the folder sortable. Lastly they contain the Styx function name to be human readable.
44+
**Components:**
45+
- **Session hash**: A unique random identifier generated per runner instance, preventing conflicts between pipeline executions
46+
- **Execution number**: Sequential counter for chronological ordering of function calls
47+
- **Interface name**: Human-readable identifier for the Styx function
48+
49+
This naming convention ensures unique, sortable, and identifiable output directories.
50+
51+
> [!WARNING]
52+
> You can clean up outputs using `shutil.rmtree(outputs.root)` for individual function outputs, or `shutil.rmtree(get_global_runner().data_dir)` to remove all outputs from the current session. **Be careful** - make sure you're not deleting any important data this way!
53+
54+
> [!NOTE]
55+
> For advanced runner configuration and custom I/O behavior, see [Subcommands](./runners.md) and [Writing Custom Runners](../advanced_concepts/custom_runners.md).

0 commit comments

Comments
 (0)