Skip to content

Commit

Permalink
Merge branch 'main' into scaled-reconstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
talonchandler committed Feb 20, 2025
2 parents 9028e16 + 1f84072 commit 46a4e81
Show file tree
Hide file tree
Showing 39 changed files with 458 additions and 241 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: lint, style, and tests

on:
pull_request:
branches:
- main

jobs:
style:
name: Style Check
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install black==25.1.0
- name: Check code styling with Black
run: |
black --diff -S -t py310 waveorder
black --check -S -t py310 waveorder
# lint:
# name: Lint Check
# runs-on: ubuntu-latest

# strategy:
# matrix:
# python-version: ["3.10"]

# steps:
# - uses: actions/checkout@v3
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install flake8
# - name: Check code with Flake8
# # E203 conflicts with black
# run: |
# flake8 waveorder --extend-ignore=E203

isort:
name: isort Check
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install isort
- name: Check code with isort
run: |
isort --check waveorder
tests:
needs: [style, isort] # lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ".[dev]"
- name: Test with pytest
run: |
pytest -v --cov=./ --cov-report=xml
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

repos:
# basic pre-commit
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-yaml
- id: check-toml
- id: detect-private-key
# sorting imports
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
# syntax linting and formatting
- repo: https://github.com/myint/autoflake
rev: v2.1.1
hooks:
- id: autoflake
args: [--in-place, --remove-all-unused-imports,
--ignore-init-module-imports]
# - repo: https://github.com/PyCQA/flake8
# rev: 6.0.0
# hooks:
# - id: flake8
# args: [--ignore, "E203,W503", --min-python-version, '3.10']
# additional_dependencies: [flake8-typing-imports==1.12.0]
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
62 changes: 62 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Contributing guide

Thanks for your interest in contributing to `waveorder`!

Please see the following steps for our workflow.

## Getting started

Please read the [README](./README.md) for an overview of the project,
and how you can install and use the package.

## Issues

We use [issues](https://github.com/mehta-lab/waveorder/issues) to track
bug reports, feature requests, and provide user support.

Before opening a new issue, please first search existing issues (including closed ones),
to see if there is an existing discussion about it.

### Setting up development environment

For local development, first install [Git](https://git-scm.com/)
and Python with an environment management tool
(e.g. [miniforge](https://github.com/conda-forge/miniforge), a minimal community distribution of Conda).

If you use Conda, set up an environment with:

```sh
conda create -n waveorder-dev python=3.10
conda activate waveorder-dev
```

If you have push permission to the repository,
clone the repository (the code blocks below are shell commands):

```sh
cd # to the directory you want to work in
git clone https://github.com/mehta-lab/waveorder.git
```

Otherwise, you can follow [these instructions](https://docs.github.com/en/get-started/quickstart/fork-a-repo)
to [fork](https://github.com/mehta-lab/waveorder/fork) the repository.

Then install the package in editable mode with the development dependencies:

```sh
cd waveorder/ # or the renamed project root directory
pip install -e ".[dev]"
```

Then make the changes and [track them with Git](https://docs.github.com/en/get-started/using-git/about-git#example-contribute-to-an-existing-repository).


### Code style

We use [pre-commit](https://pre-commit.com/) to sort imports with [isort](https://github.com/PyCQA/isort) and format code with [black](https://black.readthedocs.io/en/stable/) automatically prior to each commit. To minimize test errors when submitting pull requests, please install pre-commit in your environment as follows:

```bash
pre-commit install
```

When these packages are executed within the project root directory, they should automatically use the [project settings](./pyproject.toml).
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# %%
# This notebook-style script requires a ~500 MB download from https://www.ebi.ac.uk/biostudies/files/S-BIAD1063/PTI-BIA/Anisotropic_target_small.zip

import numpy as np
from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import zarr
from iohub import open_ome_zarr
from numpy.fft import fftshift

import waveorder as wo
from waveorder import optics, waveorder_reconstructor, util

import zarr
from pathlib import Path
from iohub import open_ome_zarr
from waveorder import optics, util, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

# %%
Expand Down Expand Up @@ -62,10 +62,12 @@
I_cali_mean = np.array(PTI_file.I_cali_mean)

# source polarization, instrument matrix calibration
E_in, A_matrix, I_cali_mean = (
wo.waveorder_reconstructor.instrument_matrix_and_source_calibration(
I_cali_mean, handedness="RCP"
)
(
E_in,
A_matrix,
I_cali_mean,
) = wo.waveorder_reconstructor.instrument_matrix_and_source_calibration(
I_cali_mean, handedness="RCP"
)

# %%
Expand Down Expand Up @@ -238,15 +240,18 @@
# "negative" -> only solution of negatively uniaxial material
# "unknown" -> both solutions of positively and negatively uniaxial material + optic sign estimation

differential_permittivity, azimuth, theta, mat_map = (
setup.scattering_potential_tensor_to_3D_orientation(
f_tensor,
S_image_tm,
material_type="unknown",
reg_ret_pr=reg_differential_permittivity,
itr=10,
fast_gpu_mode=True,
)
(
differential_permittivity,
azimuth,
theta,
mat_map,
) = setup.scattering_potential_tensor_to_3D_orientation(
f_tensor,
S_image_tm,
material_type="unknown",
reg_ret_pr=reg_differential_permittivity,
itr=10,
fast_gpu_mode=True,
)

# %%
Expand All @@ -264,7 +269,10 @@
[
((-1) ** i)
* util.wavelet_softThreshold(
((-1) ** i) * differential_permittivity_PT[i], "db8", 0.00303, level=1
((-1) ** i) * differential_permittivity_PT[i],
"db8",
0.00303,
level=1,
)
for i in range(2)
]
Expand Down Expand Up @@ -374,17 +382,27 @@

# compute the physical properties from the scattering potential tensor

differential_permittivity_p, azimuth_p, theta_p = (
optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor, material_type="positive", reg_ret_pr=reg_differential_permittivity
)
)
differential_permittivity_n, azimuth_n, theta_n = (
optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor, material_type="negative", reg_ret_pr=reg_differential_permittivity
)
(
differential_permittivity_p,
azimuth_p,
theta_p,
) = optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor,
material_type="positive",
reg_ret_pr=reg_differential_permittivity,
)
(
differential_permittivity_n,
azimuth_n,
theta_n,
) = optics.scattering_potential_tensor_to_3D_orientation_PN(
f_tensor,
material_type="negative",
reg_ret_pr=reg_differential_permittivity,
)
differential_permittivity = np.array(
[differential_permittivity_p, differential_permittivity_n]
)
differential_permittivity = np.array([differential_permittivity_p, differential_permittivity_n])
azimuth = np.array([azimuth_p, azimuth_n])
theta = np.array([theta_p, theta_n])

Expand All @@ -402,7 +420,10 @@
[
((-1) ** i)
* util.wavelet_softThreshold(
((-1) ** i) * differential_permittivity_PT[i], "db8", 0.00303, level=1
((-1) ** i) * differential_permittivity_PT[i],
"db8",
0.00303,
level=1,
)
for i in range(2)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################

import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift
from waveorder import (
optics,
waveorder_simulator,
util,
)

from waveorder import optics, util, waveorder_simulator
from waveorder.visuals import jupyter_visuals

#####################################################################
Expand Down
8 changes: 2 additions & 6 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################

import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift

from waveorder import (
optics,
waveorder_reconstructor,
)
from waveorder import optics, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

## Initialization
Expand Down Expand Up @@ -271,7 +268,6 @@
# in-plane orientation
from matplotlib.colors import hsv_to_rgb


ret_min_color = 0
ret_max_color = 1.5

Expand Down
8 changes: 3 additions & 5 deletions examples/maintenance/PTI_simulation/PTI_Simulation_Recon3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
# "uPTI: uniaxial permittivity tensor imaging of intrinsic #
# density and anisotropy," bioRxiv 2020.12.15.422951 (2020).``` #
####################################################################
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy.fft import fftshift
from waveorder import (
optics,
waveorder_reconstructor,
)

from waveorder import optics, waveorder_reconstructor
from waveorder.visuals import jupyter_visuals

## Initialization
Expand Down
Loading

0 comments on commit 46a4e81

Please sign in to comment.