PyTMM icon indicating copy to clipboard operation
PyTMM copied to clipboard

Mutation of input numpy array.

Open LMSC-NTappy opened this issue 3 years ago • 0 comments

Hi @kitchenknif,

thank you for the very useful project!

I just wanted to point out a behaviour that I think is problematic or at least counterintuitive. When inputing a numpy array in the getRefractiveIndex functions, the array is changed during function execution. See below

import PyTMM.refractiveIndex as RI
import numpy as np
cat = RI.RefractiveIndex()
Wmat = cat.getMaterial('main','W','Werner')

lamspace = np.linspace(200,850)
lamspace
#array([200.        , 213.26530612, 226.53061224, 239.79591837, ... ])
n = Wmat.getRefractiveIndex(lamspace)
lamspace
#array([0.2       , 0.21326531, 0.22653061, 0.23979592, ... ])

This is due to this

https://github.com/kitchenknif/PyTMM/blob/712d14c3c0c5d763e3bed8d38d43821e9d2b4309/PyTMM/refractiveIndex.py#L256

if your replace it with wavelength2 = wavelength/1000 and proceed with the new variable, or re-multiply wavelength before returning the function it should be fixed. There are also other lines of code where this is an issue (for interpolated refractive indices and the two extinction coefficient).

Just letting you know, I gladly help if needed

LMSC-NTappy avatar Oct 23 '22 10:10 LMSC-NTappy