Metadata-Version: 2.4
Name: fibsem
Version: 0.6.0rc1
Summary: a universal api for fibsem control
Author-email: Patrick Cleeve <patrick@openfibsem.org>
License: MIT License
Project-URL: Homepage, https://github.com/fibsem-os/fibsem-os
Project-URL: Bug Tracker, https://github.com/fibsem-os/fibsem-os/issues
Classifier: Programming Language :: Python :: 3.11
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: napari
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: tifffile>=2021.7.2
Requires-Dist: numpy>=1.26
Requires-Dist: scipy>=1.10.0
Requires-Dist: opencv-python-headless>=4.7.0.72
Requires-Dist: scikit-image>=0.19.3
Requires-Dist: matplotlib>=3.7.0
Requires-Dist: matplotlib_scalebar>=0.8.1
Requires-Dist: petname>=2.6
Requires-Dist: pandas>=2.0.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: psygnal
Requires-Dist: ome_types
Requires-Dist: pillow>=9.0
Requires-Dist: lxml[html_clean]
Requires-Dist: imagecodecs
Requires-Dist: pydantic>=2.12
Requires-Dist: pypdf>=4.0
Requires-Dist: httpx>=0.27.0
Requires-Dist: fastapi>=0.121.0
Requires-Dist: uvicorn>=0.35.0
Requires-Dist: websockets>=15.0
Requires-Dist: packaging
Requires-Dist: keyring>=24; sys_platform == "win32" or sys_platform == "darwin"
Provides-Extra: ml
Requires-Dist: torch>=2.0.0; extra == "ml"
Requires-Dist: segmentation-models-pytorch>=0.3.2; extra == "ml"
Requires-Dist: transformers>=4.36.2; extra == "ml"
Requires-Dist: onnx; extra == "ml"
Requires-Dist: onnxruntime; extra == "ml"
Provides-Extra: ui
Requires-Dist: pyqt5>=5.15.9; extra == "ui"
Requires-Dist: superqt>=0.6.0; extra == "ui"
Requires-Dist: pyqt5-qt5==5.15.2; platform_system == "Windows" and extra == "ui"
Requires-Dist: qtawesome>=1.4.0; extra == "ui"
Provides-Extra: odemis
Requires-Dist: pylibtiff; extra == "odemis"
Requires-Dist: shapely; extra == "odemis"
Provides-Extra: labelling
Requires-Dist: fibsem[ml,ui]; extra == "labelling"
Requires-Dist: napari<0.10,>=0.5.1; extra == "labelling"
Provides-Extra: server
Provides-Extra: mcp
Requires-Dist: mcp<3,>=2; extra == "mcp"
Provides-Extra: agent
Requires-Dist: fibsem[mcp]; extra == "agent"
Requires-Dist: claude-agent-sdk>=0.2.168; extra == "agent"
Provides-Extra: all
Requires-Dist: fibsem[agent,labelling]; extra == "all"
Provides-Extra: test
Requires-Dist: pytest>=7.2.2; extra == "test"
Requires-Dist: pytest-xdist>=3.0; extra == "test"
Requires-Dist: pytest-timeout>=2.1; extra == "test"
Requires-Dist: jsonschema>=4; extra == "test"
Requires-Dist: httpx2; extra == "test"
Provides-Extra: dev
Requires-Dist: ruff==0.16.3; extra == "dev"
Dynamic: license-file

[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/fibsem-os/fibsem-os) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)

# fibsemOS

A universal API for FIBSEM Control, Development and Automation

## Overview

fibsemOS is a Python package for controlling and automating FIB/SEM microscopes. It provides a universal API for FIBSEM control, development and automation, abstracting away the details of the microscope hardware to provide a simple, intuitive interface. The package includes reusable modules for common workflows and operations, and is extensible to support new microscopes.

We currently aim to support  [ThermoFisher AutoScript](https://www.thermofisher.com/at/en/home/electron-microscopy/products/software-em-3d-vis/autoscript-4-software.html), [TESCAN Automation SDK](https://tescan.com/product-portfolio/fib-sem), and Delmic Odemis (for the METEOR). A [Zeiss Python API](https://www.zeiss.com/metrology/en/software/zeiss-inspect/features/python-interface.html) driver is planned, as is support for other FIBSEM systems.

For more information see the [website](https://www.fibsemos.org).

## Installation

There are several ways to install fibsemOS depending on your application and needs. Requires Python 3.10+.

#### PyPI (For Users)

Create a virtual environment (see [Installation Guide](INSTALLATION.md) for
alternatives to conda), then install with the `[ui]` extra to get the GUI:

```bash
conda create -n fibsem python=3.11 pip
conda activate fibsem
pip install "fibsem[ui]"
```

#### Github (For Development)

Clone this repository:

```bash
git clone https://github.com/fibsem-os/fibsem-os.git
cd fibsem-os
```

Install dependencies and package:

```bash
conda create -n fibsem python=3.11 pip
conda activate fibsem
pip install -e ".[ui]"
```

Image labelling (`fibsem_label`) draws in napari, which is not part of `[ui]`; add
the `[labelling]` extra for it:

```bash
pip install -e ".[ui,labelling]"
```

To run:
```bash
fibsem-autolamella-ui
```

Two flags skip the clicks that start every session, for development against a
simulator or an instrument you reconnect to all day. `--quickstart` connects with the
default microscope configuration as soon as the window is up; `--quickload` does that
and then reopens the most recent experiment:
```bash
fibsem-autolamella-ui --quickload
```

### Offline Installation
For computers with no internet connection, you can download the dependencies on a separate internet connected computer and transfer it to the Support PC (e.g. via USB).

On internet connected PC (Environment should match python version): 
```bash
mkdir pkg
cd pkg
pip download "fibsem[ui]"
```
On Support PC:
Transfer the pkg directory to the support pc, and then change to the pkg directory
```bash
cd pkg
pip install --no-index --find-links . "fibsem[ui]"
```

#### Additional Installation Information

For detailed instructions on installation, and installing the commercial microscope APIs, see [Installation Guide](INSTALLATION.md).

## Getting Started

For a complete walkthrough of the AutoLamella workflow, see the [user guide](https://www.fibsemos.org/docs/), starting with [Your first lamella](https://www.fibsemos.org/docs/first-lamella/).

### Getting Started with the API

To get started with the fibsemOS API, see the example/example.py:

You can start an offline demo microscope by setting `info.manufacturer: Demo` in the configuration yaml file (fibsem/config/microscope-configuration.yaml), as the shipped file does. The file's `hardware.devices` list says which devices the microscope builds and how; see [Configuring devices](docs/developers/devices.md#configuring-devices). This will start a demo microscope that you can use to test the API without connecting to a real microscope. To connect to a real microscope, set the ip_address and manufacturer of your microscope in the configuration file or alternatively, you can pass these arguments to utils.setup_session() directly. The simulator can also image a synthetic cryo-grid instead of noise; see [docs/simulator.md](docs/simulator.md).

### Where fibsemOS keeps your files

Everything fibsemOS writes goes under `~/.fibsem` (on Windows `C:\Users\<account>\.fibsem`); set `FIBSEM_HOME` to put it somewhere else, for example a folder shared by every account on a microscope PC. The installed package is never written, so upgrading or reinstalling does not touch your files.

| Folder | Holds |
|---|---|
| `config/` | preferences, the list of microscope configurations, the configurations you made, and `session/` (saved positions, holder occupancy, FM settings, one file per configuration) |
| `experiments/` | new experiments when no default folder is set in preferences |
| `log/` | logs and data captured outside an experiment |
| `autolamella/protocols/`, `autolamella/scripts/` | your AutoLamella protocols and scripts |

The App Server's discovery file, pairing tokens and the agent's files stay in `~/.fibsem` even when `FIBSEM_HOME` is set. A release before this layout kept these files inside the package; the first start copies the settings out (leaving the originals) and moves the logs, experiments, protocols and scripts, logging each one and listing them in `~/.fibsem/MOVED-FROM.txt`.

This example shows you how to connect to the microscope, take an image with both beams, and plot the results.

```python
from fibsem import utils, acquire
import matplotlib.pyplot as plt

def main():

    # connect to microscope
    microscope, settings = utils.setup_session(ip_address="localhost", manufacturer="Demo")

    # take image with both beams
    sem_image, fib_image = acquire.take_reference_images(microscope, settings.image)

    # show images
    fig, ax = plt.subplots(1, 2, figsize=(7, 5))
    ax[0].imshow(sem_image.data, cmap="gray")
    ax[1].imshow(fib_image.data, cmap="gray")
    plt.show()


if __name__ == "__main__":
    main()

```

This example is available as a script in example/example.py.
For more detailed examples, see the Examples section below.

The microscope's beams, stage and other hardware are also available as devices, whose parameters describe their own units, limits and choices:

```python
from fibsem.structures.settings import BeamType

sem = microscope.beams[BeamType.ELECTRON]   # or microscope.devices["electron"]
sem.hfw.set_value(150e-6)
print(sem.current.get_value(), sem.current.choices)
```

See the [device guide](docs/developers/devices.md). The string-key `microscope.get("key")` and `microscope.set(...)` were removed in 0.6.0.

## Examples

### Core Functionality

For examples of core functionality please see:

- example/example_imaging.py: image acquisition
- example/example_movement.py: stage movement
- example/example_milling.py: drawing patterns and beam milling
- example/autolamella.py: recreation of [AutoLamella V1](https://github.com/DeMarcoLab/autolamella) (automated cryo-lamella preparation) in ~150 lines of code

Additional example scripts and notebooks are available.

### Working with experiment data

To read or modify a saved AutoLamella experiment from a plain Python script — no microscope or GUI needed — see the [Scripting Guide](SCRIPTING.md).

## Contributing

Contributions are welcome! Please open a pull request or issue.

## Docs

fibsemOS is a large package with many features. For more detailed documentation, please see the [Documentation Website](https://www.fibsemos.org).

Developer documentation, for changing or extending fibsemOS, is in [docs/developers/](docs/developers/README.md).

## Related Projects and Publications

| Name | Full Title | Date |
|------|------------|------|
| 3DCT | [Site-Specific Cryo-focused Ion Beam Sample Preparation Guided by 3D Correlative Microscopy](https://doi.org/10.1016/j.bpj.2015.10.053) | 2016 |
| AutoLamella | [Automated cryo-lamella preparation for high-throughput in-situ structural biology](https://doi.org/10.1016/j.jsb.2020.107488) | 2020 |
| SerialFIB | [A modular platform for automated cryo-FIB workflows](https://elifesciences.org/articles/70506) | 2021 |
| PFIB-SEM | [Cryo-plasma FIB/SEM volume imaging of biological specimens](https://doi.org/10.7554/eLife.83623) | 2023 |
| OpenFIBSEM | [OpenFIBSEM: A universal API for FIBSEM control](https://doi.org/10.1016/j.jsb.2023.107967) | 2023 |
| SEM Charging | [Reduction of SEM charging artefacts in native cryogenic biological samples](https://www.nature.com/articles/s41467-025-60545-3) | 2025 |
| Fillets | [Mind the corner: Fillets in cryo-FIB lamella preparation to minimise sample loss](https://doi.org/10.1016/j.jsb.2025.108249) | 2025 |
