Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from setup.py to pyproject.toml #73

Merged
merged 19 commits into from
Aug 23, 2024
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
31 changes: 16 additions & 15 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ on:

pull_request:

# everyday at 3 am UTC
# schedule:
# - cron: '0 3 * * *'
# weekly
schedule:
- cron: '3 7 * * 4'

jobs:
testing:
Expand Down Expand Up @@ -42,8 +42,9 @@ jobs:

- name: Install python dependencies
run: |
python -m pip install --upgrade setuptools wheel pip
pip install .
python -m pip install uv
uv pip install --system .
uv pip install --system numpy wheel setuptools

- name: Install S4 in Linux
if: matrix.os == 'ubuntu-latest'
Expand All @@ -64,25 +65,25 @@ jobs:
cd ..
rm -rf S4

- name: Install on Linux and MacOS
if: matrix.os != 'windows-latest'
run: pip install .
# - name: Install on Linux and MacOS
# if: matrix.os != 'windows-latest'
# run: pip install .

- name: Install on Windows
if: matrix.os == 'windows-latest'
run: |
pip install .
shell: powershell
# - name: Install on Windows
# if: matrix.os == 'windows-latest'
# run: |
# pip install .
# shell: powershell

- name: Test with pytest
run: |
pip install pytest-cov pytest-rerunfailures
uv pip install --system pytest-cov pytest-rerunfailures
pytest --cov-report= --cov=rayflare tests/ --reruns 5

- name: Codecov
if: matrix.os == 'ubuntu-latest'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
pip install codecov
uv pip install --system codecov
codecov
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ matplotlib==3.7.2
scipy==1.11.2
solcore==5.10.0
nbsphinx==0.9.3
inkstone==0.3.12
inkstone==0.3.12
numba==0.58.1
6 changes: 3 additions & 3 deletions examples/analytical_rt_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

options.wavelength = wl

options.nx = 50
options.ny = 50
options.nx = 100
options.ny = 100
options.n_rays = 1 * options.nx ** 2
# options.x_limits = [2.5, 7.5]
# options.y_limits = [2.5, 7.5]
Expand Down Expand Up @@ -51,7 +51,7 @@
overwrite=True,
)

angle_in = np.linspace(0, 70, 10)
angle_in = np.linspace(0, 70, 6)

n_int_R_a = np.zeros((len(angle_in), len(wl)))
n_int_T_a = np.zeros((len(angle_in), len(wl)))
Expand Down
19 changes: 10 additions & 9 deletions examples/phong_scattering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from rayflare.ray_tracing.rt import rt_structure
from rayflare.ray_tracing import rt_structure
from rayflare.textures import regular_pyramids, planar_surface
from rayflare.options import default_options

Expand All @@ -15,7 +15,6 @@
# setting up some colours for plotting
pal = sns.color_palette("husl", 4)


# setting up Solcore materials
Air = material("Air")()

Expand Down Expand Up @@ -146,15 +145,17 @@
scaled_intensity = n/np.sin(mean_theta_bin)

fig, ax1 = plt.subplots()
plt.plot(mean_theta_bin, scaled_intensity/np.max(scaled_intensity))
plt.plot(x, power_law)
plt.bar(mean_theta_bin*180/np.pi, scaled_intensity/np.max(scaled_intensity), width=180*np.diff(bins)[0]/np.pi,
alpha=0.5, label='probability density/area')
plt.plot(x*180/np.pi, power_law, '-k', label=r'cos$^\alpha(\theta)$')
plt.legend()
plt.show()

fig, ax1 = plt.subplots()
n, _, _ = ax1.hist(thetas, color=pal[2], alpha=0.5, label="Phong 100 % transmission",
bins=70, density=True)
plt.plot((x+1), power_law)
plt.show()
# fig, ax1 = plt.subplots()
# n, _, _ = ax1.hist(thetas, color=pal[2], alpha=0.5, label="Phong 100 % transmission",
# bins=70, density=True)
# plt.plot((x+1), power_law)
# plt.show()

x2 = np.linspace(0, 1, 100)

Expand Down
87 changes: 46 additions & 41 deletions examples/phong_scattering_2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from rayflare.ray_tracing.rt import rt_structure
from rayflare.ray_tracing import rt_structure
from rayflare.textures import regular_pyramids, planar_surface
from rayflare.options import default_options

Expand All @@ -27,7 +27,7 @@
SiN = material("Si3N4")()

# number of x and y points to scan across
nxy = 30
nxy = 50

# setting options
options = default_options()
Expand All @@ -36,10 +36,12 @@
options.ny = nxy
options.n_rays = 2 * nxy**2
options.depth_spacing = si("0.1um")
options.parallel = False
options.parallel = True
options.analytical_ray_tracing = 0
options.I_thresh = 0.005
options.randomize_surface = True
options.project_name = "phong_scattering"
options.lookuptable_angles = 200

# analytical: phong and regular pyramids 15 degree rear look the same
front_opening_deg = 50
Expand All @@ -58,7 +60,10 @@
args_same = { "materials": [Si],
"widths": [d],
"incidence": Air,
"transmission": Air}
"transmission": Air,
"use_TMM": False,
"options": options,
"overwrite": True}

# set up ray-tracing options
rtstr_planar = rt_structure(
Expand All @@ -79,44 +84,44 @@
result_list_phong = []

start = time()
#
# for alpha in alpha_values:
# flat_phong[0].phong_options[0] = alpha
# rtstr_phong = rt_structure(
# textures=[triangle_surf, flat_phong],
# **args_same
# )
# result_list_phong.append(rtstr_phong.calculate(options))

# result_planar = rtstr_planar.calculate(options)
for alpha in alpha_values:
flat_phong[0].phong_options[0] = alpha
rtstr_phong = rt_structure(
textures=[triangle_surf, flat_phong],
**args_same
)
result_list_phong.append(rtstr_phong.calculate(options))

result_planar = rtstr_planar.calculate(options)

result_flat_tri = rtstr_flat_tri.calculate(options)
#
# result_same_tri = rtstr_same_tri.calculate(options)
#

result_same_tri = rtstr_same_tri.calculate(options)

print("total time:", time() - start)
#
# R0 = result_planar['R0']
# A_lambertian = (1-R0)*4*Si.n(options.wavelength)**2*Si.alpha(options.wavelength)*d/(1+4*Si.n(options.wavelength)**2*Si.alpha(options.wavelength)*d)
#
#
# plt.figure()
#
# for i1, alpha in enumerate(alpha_values):
# plt.plot(options.wavelength*1e9, result_list_phong[i1]["A_per_layer"], '-', color=pal[i1],
# label=r"phong, $\alpha$ = " + str(alpha))
#
#
# plt.plot(options.wavelength * 1e9, result_planar["A_per_layer"], '-.k',
# label="planar", alpha=0.6)
# plt.plot(options.wavelength * 1e9, result_flat_tri["A_per_layer"], '-k',
# label="15 degree pyramid", alpha=0.6)
# plt.plot(options.wavelength * 1e9, result_same_tri["A_per_layer"], '--k',
# label="same angle pyramid", alpha=0.6)
#
# plt.ylim(0, 1)
# plt.xlim(np.min(options.wavelength * 1e9), np.max(options.wavelength * 1e9))
# plt.legend(title='Rear surface:')
# plt.xlabel("Wavelength (nm)")
# plt.ylabel("Absorption")
# plt.show()

R0 = result_planar['R0']
A_lambertian = (1-R0)*4*Si.n(options.wavelength)**2*Si.alpha(options.wavelength)*d/(1+4*Si.n(options.wavelength)**2*Si.alpha(options.wavelength)*d)


plt.figure()

for i1, alpha in enumerate(alpha_values):
plt.plot(options.wavelength*1e9, result_list_phong[i1]["A_per_layer"], '-', color=pal[i1],
label=r"phong, $\alpha$ = " + str(alpha))


plt.plot(options.wavelength * 1e9, result_planar["A_per_layer"], '-.k',
label="planar", alpha=0.6)
plt.plot(options.wavelength * 1e9, result_flat_tri["A_per_layer"], '-k',
label="15 degree pyramid", alpha=0.6)
plt.plot(options.wavelength * 1e9, result_same_tri["A_per_layer"], '--k',
label="same angle pyramid", alpha=0.6)

plt.ylim(0, 1)
plt.xlim(np.min(options.wavelength * 1e9), np.max(options.wavelength * 1e9))
plt.legend(title='Rear surface:')
plt.xlabel("Wavelength (nm)")
plt.ylabel("Absorption")
plt.show()
68 changes: 68 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[build-system]
requires = ["hatchling>=1.24.2", "hatch-vcs>=0.3.0"]
build-backend = "hatchling.build"

[project]
name = "rayflare"
version = "1.3.0"
description = "Python-based integrated optical modelling"
readme = "README.md"
requires-python = ">=3.7"
# "LICENSE" is name of the license file, which must be in root of project folder
license = {file = "LICENSE.txt"}
authors = [
{name = "Phoebe Pearce", email = "p.m.pearce@gmail.com"},
]
keywords = [
"photovoltaics", "physics", "optics", "ray tracing", " ray optics",
"wave optics", "transfer matrix", "rcwa", "tmm", "rigorous coupled wave analysis",
"thin film", "thin film optics", "scattering", "light scattering", "light trapping",
"ellipsometry", "diffraction", "lens", "lens design", "lens simulation",
]

# https://pypi.org/classifiers/
# Add PyPI classifiers here
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
]

# Required dependencies for install/usage of your package or application
# If you don't have any dependencies, leave this section empty
# Format for dependency strings: https://peps.python.org/pep-0508/
dependencies = [
"matplotlib",
"scipy",
"numpy<2.0.0",
"solcore",
"xarray",
"sparse",
"joblib",
"seaborn",
"inkstone",
"numba",
]

test = [
"pytest",
"pytest-cov",
]

[project.urls]
Homepage = "https://github.com/qpv-research-group/rayflare"
Documentation = "https://rayflare.readthedocs.io"
Changelog = "https://rayflare.readthedocs.io/en/latest/news.html"

[tool.hatch.build.targets.sdist]
include = ["/rayflare"]

[tool.pytest.ini_options]
testpaths = "tests" # directory containing your tests
12 changes: 7 additions & 5 deletions rayflare/matrix_formalism/multiply_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Contact: p.pearce@unsw.edu.au

import numpy as np
from sparse import load_npz, dot, COO, stack, einsum
from sparse import load_npz, COO, stack, einsum
from rayflare.angles import make_angle_vector, fold_phi, overall_bin
import os
import xarray as xr
Expand Down Expand Up @@ -161,18 +161,20 @@ def make_D(alphas, thick, thetas):
# faster than the previous for loop implementation. Thanks to Johnson Wong
# (GitHub: arsonwong)
def dot_wl(mat, vec):

# note: sometimes get nans here in result, even when there are no nans
# in mat or vec.
if len(mat.shape) == 3:
result = einsum('ijk,ik->ij', mat, vec).todense()
result = einsum('ijk,ik->ij', mat, COO(vec)).todense()

if len(mat.shape) == 2:
result = einsum('jk,ik->ij', mat, vec).todense()
result = einsum('jk,ik->ij', mat, COO(vec)).todense()

return result


def dot_wl_u2d(mat, vec):
result = einsum('jk,ik->ij', mat, vec).todense()

result = einsum('jk,ik->ij', mat, COO(vec)).todense()
return result


Expand Down
2 changes: 1 addition & 1 deletion rayflare/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ def __init__(self):
self.analytical_threshold = 0.99

# TMM options
self.lookuptable_angles = 300
self.lookuptable_angles = 100
self.coherent = True
self.coherency_list = None
3 changes: 2 additions & 1 deletion rayflare/ray_tracing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .rt import RT, rt_structure
from .rt_matrix import RT
from .rt_structure import rt_structure
Loading
Loading