import numpy as np

def get_n_from_txt(filepath, points=None, lambda_min=400, lambda_max=700, complex_n=True):
    ntxt = np.loadtxt(filepath)
    if np.min(np.abs(ntxt[:, 0] - lambda_min)) > 25 or np.min(np.abs(ntxt[:, 0] - lambda_max)) > 25:
        print('No measurement data for refractive indicies are available within 25 nm in \n' + filepath)
    if points is None:
        points = lambda_max - lambda_min + 1
    idxmin = np.argmin(np.abs(ntxt[:, 0] - lambda_min))
    idxmax = np.argmin(np.abs(ntxt[:, 0] - lambda_max))
    if idxmax == idxmin:
        if complex_n:
            indicies = np.vectorize(complex)(np.array([ntxt[idxmin, 1]]), np.array([ntxt[idxmin, 2]]))
        else:
            indicies = np.array([ntxt[idxmin, 1]])
    else:
        xp = ntxt[idxmin:idxmax, 0]
        fpn = ntxt[idxmin:idxmax, 1]
        n = np.interp(np.linspace(lambda_min, lambda_max, points), xp, fpn)
        if complex_n:
            fpk = ntxt[idxmin:idxmax, 2].squeeze()
            k = np.interp(np.linspace(lambda_min, lambda_max, points), xp, fpk)
            indicies = np.vectorize(complex)(n, k)
        else:
            indicies = n
    return indicies

def get_N(path_list, lambda_min, lambda_max, points=None, complex_n=False):
    n = []
    for path in path_list:
        n.append(get_n_from_txt(path, points, lambda_min=lambda_min, lambda_max=lambda_max, complex_n=complex_n))
    return np.vstack((n))

[((4, 11, 4, 31), 'numpy.loadtxt', 'np.loadtxt', ({(4, 22, 4, 30): 'filepath'}, {}), '(filepath)', True, 'import numpy as np\n'), ((32, 11, 32, 25), 'numpy.vstack', 'np.vstack', ({(32, 22, 32, 23): 'n'}, {}), '(n)', True, 'import numpy as np\n'), ((9, 23, 9, 54), 'numpy.abs', 'np.abs', ({(9, 30, 9, 53): 'ntxt[:, (0)] - lambda_min'}, {}), '(ntxt[:, (0)] - lambda_min)', True, 'import numpy as np\n'), ((10, 23, 10, 54), 'numpy.abs', 'np.abs', ({(10, 30, 10, 53): 'ntxt[:, (0)] - lambda_max'}, {}), '(ntxt[:, (0)] - lambda_max)', True, 'import numpy as np\n'), ((15, 23, 15, 50), 'numpy.array', 'np.array', ({(15, 32, 15, 49): '[ntxt[idxmin, 1]]'}, {}), '([ntxt[idxmin, 1]])', True, 'import numpy as np\n'), ((19, 22, 19, 65), 'numpy.linspace', 'np.linspace', ({(19, 34, 19, 44): 'lambda_min', (19, 46, 19, 56): 'lambda_max', (19, 58, 19, 64): 'points'}, {}), '(lambda_min, lambda_max, points)', True, 'import numpy as np\n'), ((5, 14, 5, 45), 'numpy.abs', 'np.abs', ({(5, 21, 5, 44): '(ntxt[:, (0)] - lambda_min)'}, {}), '(ntxt[:, (0)] - lambda_min)', True, 'import numpy as np\n'), ((5, 62, 5, 93), 'numpy.abs', 'np.abs', ({(5, 69, 5, 92): '(ntxt[:, (0)] - lambda_max)'}, {}), '(ntxt[:, (0)] - lambda_max)', True, 'import numpy as np\n'), ((13, 23, 13, 44), 'numpy.vectorize', 'np.vectorize', ({(13, 36, 13, 43): 'complex'}, {}), '(complex)', True, 'import numpy as np\n'), ((13, 45, 13, 72), 'numpy.array', 'np.array', ({(13, 54, 13, 71): '[ntxt[idxmin, 1]]'}, {}), '([ntxt[idxmin, 1]])', True, 'import numpy as np\n'), ((13, 74, 13, 101), 'numpy.array', 'np.array', ({(13, 83, 13, 100): '[ntxt[idxmin, 2]]'}, {}), '([ntxt[idxmin, 2]])', True, 'import numpy as np\n'), ((22, 26, 22, 69), 'numpy.linspace', 'np.linspace', ({(22, 38, 22, 48): 'lambda_min', (22, 50, 22, 60): 'lambda_max', (22, 62, 22, 68): 'points'}, {}), '(lambda_min, lambda_max, points)', True, 'import numpy as np\n'), ((23, 23, 23, 44), 'numpy.vectorize', 'np.vectorize', ({(23, 36, 23, 43): 'complex'}, {}), '(complex)', True, 'import numpy as np\n')]