MLResearchAtOSRAM / tmm_fast

tmm_fast is a lightweight package to speed up optical planar multilayer thin-film device computation. Developed by Alexander Luce (@Nerrror) in cooperation with Heribert Wankerl (@HarryTheBird).
MIT License
53 stars 22 forks source link

error when running Appendix A.1 #26

Open Jasonwi opened 1 month ago

Jasonwi commented 1 month ago

when running Appendix A.1 code

import tmm_fast as tmmf
import numpy as np
L = 12
d = np.random.uniform(20, 150, L)*1e-9 # thicknesses of the layers
d[0] = d[-1] = np.inf # set first and last layer as injection layer
n = np.random.uniform(1.2, 5, L) # random constant refractive index
n[-1] = 1 # outcoupling into air
wl = np.linspace(500, 900, 301)*1e-9
theta = np.deg2rad(np.linspace(0, 90, 301))
result = (tmmf.coh_tmm('s', n, d, theta, wl)['R']+ tmmf.coh_tmm('p', n, d, theta, wl)['R'])/2

get error

Traceback (most recent call last):
  File "d:\project\tmm_fast\appendix_01.py", line 10, in <module>
    result = (tmmf.coh_tmm('s', n, d, theta, wl)['R']+ tmmf.coh_tmm('p', n, d, theta, wl)['R'])/2
  File "d:\project\tmm_fast\tmm_fast\vectorized_tmm_dispersive_multistack.py", line 125, in coh_vec_tmm_disp_mstack
    check_inputs(N, T, lambda_vacuum, Theta)
  File "d:\project\tmm_fast\tmm_fast\vectorized_tmm_dispersive_multistack.py", line 498, in check_inputs
    assert N.ndim == 3, 'N is not of shape [S x L x W] (3d), as it is of dimension ' + str(N.ndim)
AssertionError: N is not of shape [S x L x W] (3d), as it is of dimension 2

tmm-fast version 0.2.1 os Windows 11 torch 2.4.0 numpy 2.0.1

Nerrror commented 3 weeks ago

Hey, I think this is a problem with some api changes that we have done with the package. In the old version, if you would specifiy a range of wavelengths but a single value for the refractive index n, we automatically assume a dispersionless material and would tile the refractive index value to the same shape as the wavelength. Since most realistic materials have dispersion, we changed this and ask the user to specify the refractive index over wavelenght by himself - however, I agree that we should make this more clear in the error message.