> For the complete documentation index, see [llms.txt](https://stitchit.mouse.vision/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stitchit.mouse.vision/new-users/syncandcrunch-walk-through.md).

# syncAndCrunch walkthrough

`syncAndCrunch` is the function that processes data during acquisition, sends images of the most recently completed section to the web, and stitches data automatically once acquisition is complete. This page describes in detail how to set it up and run it. Note that in day to day use, all you will need to run is:

```
syncAndCrunch('MICROSCOPE_NAME')
```

However, the details are:

1. If you are running the command on a remote server you will probably want to set up a persistent session so the analysis does not stop if you disconnect. Use the Unix [tmux](https://robots.thoughtbot.com/a-tmux-crash-course) or [screen](https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/) commands or set up `VNC` or even TeamViewer. Our favoured option is `tmux`.
2. Start MATLAB. Run `help syncAndCrunch` if you are not familiar with the command.
3. The acquisition system should be mounted on the analysis machine and at this mount point you should find your sample directory. Use the `ls` command to find your sample.
4. Create a variable containing the name of you experiment directory on the acquisition machine or server. e.g.

   ```
   S = ’/mnt/acqMachine/Data/Sample_0123’;
   ```

   (obviously substituting this with your own data directory).
5. Now you can run `syncAndCrunch`. In one of these ways:

```
syncAndCrunch('MICROSCOPE_NAME')
```

Where `MICROSCOPE_NAME` is the name of your microscope (e.g. `brainsaw`, `organator`, ... whatever). The `syncAndCrunch` command looks for files coming from this system.

You can also run:

```
syncAndCrunch(S,2)
```

This will copy the contents of `S` to the so-called "landing directory" on the analysis machine on which `syncAndCrunch` is running. The landing directory is defined in your INI file or can be manually set when you run `syncAndCrunch` with an optional input argument. The `2` indicates that the second channel will be sent to the web to monitor progress. Read the help for the command if it's not clear why it does that. You should now see stuff scrolling down the screen and it should appear to be doing things. After a bit you’ll see it say that it’s building the web images.\
You can the navigate to the URL to which the images are sent. This is set vi a the [INI file](/installation/setting-up-the-ini-file.md). It will just keep looping. If running on a remote server you can detach from your screen session or VNC connection. When all sections have been acquired, it will stop pulling in data and automatically start stitching. If you finish the acquisition early, you can manually trigger stitching by creating a file called ‘FINISHED ’ in the experiment root directory. `syncAndCrunch` will automatically start stitching when it finds the `FINISHED` file. Alternatively, you can quit with `ctrl+c` and run the stitching commands manually. It is important that you keep an eye on the progress of the experiment by looking on the web from time to time. `syncAndCrunch` will usually send messages to Slack (if you have configured this) if it crashes. You can then re-start it.

## Note

[Do not use the bidirectional scan (comb) correction at present](https://github.com/raacampbell/stitchit_docs/tree/20a8038fe376dfc0775d79973b78f5b9df27f09a/Tile-pre-processing.md)) Note that one of the options will delete the third channel from the server without confirmation!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://stitchit.mouse.vision/new-users/syncandcrunch-walk-through.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
