Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12", "3.13"]
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6.0.2
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
uses: astral-sh/setup-uv@v8.0.0
with:
version: "0.5.16"
python-version: ${{ matrix.python-version }}
- name: Install the project
run: uv sync
cache-dependency-glob: "pyproject.toml"
- name: Install the project with `dev`
run: uv sync --extra dev
- name: Run tests
run: uv run pytest tests
2 changes: 1 addition & 1 deletion PtyLab/io/readHdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def getOrientation(filename):
with h5py.File(str(filename), "r") as archive:
if "orientation" in archive.keys():
orientation = np.array(archive["orientation"]).ravel()[0].astype(int)
return int(orientation)
return int(orientation) if orientation is not None else None


def checkDataFields(filename, requiredFields):
Expand Down
2 changes: 1 addition & 1 deletion PtyLab/utils/visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def complexPlot(rgb, ax=None, pixelSize=1, axisUnit="pixel"):
scalar_mappable = mpl.cm.ScalarMappable(norm=norm, cmap=mpl.cm.hsv)
scalar_mappable.set_array([])
cbar = plt.colorbar(scalar_mappable, ax=ax, cax=cax, ticks=[-np.pi, 0, np.pi])
cbar.ax.set_yticklabels(["$-\pi$", "0", "$\pi$"])
cbar.ax.set_yticklabels([r"$-\pi$", "0", r"$\pi$"])
return im


Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PtyLab.py: Unified Ptychography Toolbox
![Python 3.10+](https://img.shields.io/badge/python-3.10+-green.svg)
![Tests](https://github.com/ShantanuKodgirwar/PtyLabX/actions/workflows/test.yml/badge.svg)
![Version](https://img.shields.io/badge/version-0.2.3-blue.svg)
![Tests](https://github.com/PtyLab/PtyLab.py/actions/workflows/test.yml/badge.svg)

PtyLab is an inverse modeling toolbox for Conventional (CP) and Fourier (FP) ptychography in a unified framework. For more information please check the [paper](https://opg.optica.org/oe/fulltext.cfm?uri=oe-31-9-13763&id=529026).

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ptylab"
version = "0.2.3"
version = "0.2.4"
description = "A cross-platform, open-source inverse modeling toolbox for conventional and Fourier ptychography"
authors = [
{ name = "Lars Loetgering", email = "lars.loetgering@fulbrightmail.org" },
Expand Down
38 changes: 38 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np
import h5py
import pytest
from pathlib import Path


@pytest.fixture(scope="session", autouse=True)
def generate_simu_hdf5():
"""Generate a minimal simu.hdf5 if it doesn't exist (CI-friendly).

Tests that call easyInitialize("example:simulation_cpm") resolve to
example_data/simu.hdf5. This fixture ensures that file exists before
any test runs, so no real dataset needs to be committed to the repo.
If the file already exists (e.g. locally), it is left untouched.
"""
example_data_dir = Path(__file__).parent.parent / "example_data"
example_data_dir.mkdir(exist_ok=True)
hdf5_path = example_data_dir / "simu.hdf5"

if hdf5_path.exists():
yield hdf5_path
return

rng = np.random.default_rng(42)
Nd, N_frames = 64, 20

ptychogram = rng.random((N_frames, Nd, Nd)).astype(np.float32)
encoder = rng.uniform(-1e-3, 1e-3, (N_frames, 2))

with h5py.File(hdf5_path, "w") as hf:
hf.create_dataset("ptychogram", data=ptychogram, dtype="f")
hf.create_dataset("encoder", data=encoder, dtype="f")
hf.create_dataset("dxd", data=np.array(75e-6))
hf.create_dataset("zo", data=np.array(0.1))
hf.create_dataset("wavelength", data=np.array(632e-9))
hf.create_dataset("entrancePupilDiameter", data=np.array(170e-6))

yield hdf5_path