diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ae87c82..94c6463 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,7 @@ on: branches: [main] pull_request: branches: [main] + workflow_dispatch: jobs: build: @@ -12,16 +13,16 @@ jobs: 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 \ No newline at end of file diff --git a/PtyLab/io/readHdf5.py b/PtyLab/io/readHdf5.py index 5facfbf..d097730 100644 --- a/PtyLab/io/readHdf5.py +++ b/PtyLab/io/readHdf5.py @@ -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): diff --git a/PtyLab/utils/visualisation.py b/PtyLab/utils/visualisation.py index 022f4c7..4b954c9 100644 --- a/PtyLab/utils/visualisation.py +++ b/PtyLab/utils/visualisation.py @@ -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 diff --git a/README.md b/README.md index 6523393..68d7651 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/pyproject.toml b/pyproject.toml index 708ede8..13dadb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }, diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..da238a2 --- /dev/null +++ b/tests/conftest.py @@ -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