data.append([])
    params.append([])
    for s in series[-1]:
        data[-1].append(np.loadtxt(file[-1](s, "Results.txt")))
        params[-1].append(vs.retrieve_footer(file[-1](s, "Results.txt")))
    header.append(vs.retrieve_header(file[-1](s, "Results.txt")))

    for i in range(len(params[-1])):
        if not isinstance(params[-1][i], dict):
            params[-1][i] = vu.fix_params_dict(params[-1][i])

    # r = [p["r"] for p in params]
    # from_um_factor = [p["from_um_factor"] for p in params]

wlens = data[0][0][:, 0]
resolution = [vu.find_numbers(s)[-1] for s in series[0]]
enlapsed = [p["enlapsed"] for p in params[0]]


def special_label(s):
    if str(resolution[-1]) in s:
        return "Mie Theory"
    else:
        return ""


series_label[-1] = special_label

#%% GET MAX WAVELENGTH

max_wlen = []
sysname = []
for p in params:
    r.append([pi["r"] for pi in p])
    from_um_factor.append([pi["from_um_factor"] for pi in p])
    resolution.append([pi["resolution"] for pi in p])
    index.append([pi["submerged_index"] for pi in p])
    sysname.append([pi["sysname"] for pi in p])
    try:
        paper.append([pi["paper"] for pi in p])
    except:
        paper.append(["R" for pi in p])

if test_param_in_params:
    test_param = [[p[test_param_string] for p in par] for par in params]
else:
    test_param = [[vu.find_numbers(s)[test_param_position] for s in ser]
                  for ser in series]

minor_division = [[fum * 1e3 / res for fum, res in zip(frum, reso)]
                  for frum, reso in zip(from_um_factor, resolution)]
width_points = [[int(p["cell_width"] * p["resolution"]) for p in par]
                for par in params]
grid_points = [[wp**3 for wp in wpoints] for wpoints in width_points]
memory_B = [[2 * 12 * gp * 32 for p, gp in zip(par, gpoints)]
            for par, gpoints in zip(params, grid_points)]  # in bytes

#%% LOAD MIE DATA

theory = []  # Scattering effiency
for di, ri, fi, resi, ppi, ii in zip(data, r, from_um_factor, resolution,
                                     paper, index):
Esempio n. 3
0
max_wlen = []
for d, sc in zip(data, series_column):
    max_wlen.append([d[i][np.argmax(d[i][:, sc]), 0] for i in range(len(d))])

max_wlen_theory = []
for t, d in zip(theory, data):
    max_wlen_theory.append([d[i][np.argmax(t[i]), 0] for i in range(len(t))])

max_wlen_diff = []
for md, mt in zip(max_wlen, max_wlen_theory):
    max_wlen_diff.append([d - t for d, t in zip(md, mt)])

#%% WAVELENGTH MAXIMUM DIFFERENCE VS COURANT

courant = [[vu.find_numbers(s)[0] for s in ser] for ser in series]
colors = ["darkgrey", "k"]

plt.figure()
plt.title("Difference in scattering maximum for " + plot_title)
for c, mwl, col in zip(courant, max_wlen_diff, colors):
    plt.plot(c, mwl, '.', color=col, markersize=12)
plt.grid(True)
plt.legend(series_legend)
plt.xlabel("Courant Factor")
plt.ylabel(
    "Difference in wavelength $\lambda_{max}^{MEEP}-\lambda_{max}^{MIE}$ [nm]")
vs.saveplot(plot_file("WLenDiff.png"), overwrite=True)

#%% MEAN RESIDUAL VS COURANT
Esempio n. 4
0
max_wlen = []
for d, sc in zip(data, series_column):
    max_wlen.append([d[i][np.argmax(d[i][:, sc]), 0] for i in range(len(d))])

max_wlen_theory = []
for t, d in zip(theory, data):
    max_wlen_theory.append([d[i][np.argmax(t[i]), 0] for i in range(len(t))])

max_wlen_diff = []
for md, mt in zip(max_wlen, max_wlen_theory):
    max_wlen_diff.append([d - t for d, t in zip(md, mt)])

#%% WAVELENGTH MAXIMUM DIFFERENCE VS FLUX R FACTOR COMPARED

flux_r_factor = [[vu.find_numbers(s)[0] for s in ser] for ser in series]
air_width_factor = [[p["air_width"] for p in par] for par in params]
flux_box_padding = [[p["flux_box_size"] / 2 - p["r"] for p in par]
                    for par in params]
flux_air_relation = [[f / a for f, a in zip(flux, air)]
                     for flux, air in zip(flux_box_padding, air_width_factor)]
colors = [
    sc(np.linspace(0, 1,
                   len(s) + 3))[3:] for sc, s in zip(series_colors, series)
]

plt.figure()
plt.title("Difference in scattering maximum for " + plot_title)
for f, d, c in zip(flux_air_relation, max_wlen_diff, colors):
    plt.plot(f, d, '.', markersize=12, color=c[3])
plt.grid(True)
Esempio n. 5
0
max_wlen = []
for d, sc in zip(data, series_column):
    max_wlen.append([d[i][np.argmax(d[i][:, sc]), 0] for i in range(len(d))])

max_wlen_theory = []
for t, d in zip(theory, data):
    max_wlen_theory.append([d[i][np.argmax(t[i]), 0] for i in range(len(t))])

max_wlen_diff = []
for md, mt in zip(max_wlen, max_wlen_theory):
    max_wlen_diff.append([d - t for d, t in zip(md, mt)])

#%% WAVELENGTH MAXIMUM DIFFERENCE VS WAVELENGTH MAXIMUM

wlen_range_max = [[vu.find_numbers(s)[0] for s in ser] for ser in series]

plt.figure()
plt.title("Difference in scattering maximum for " + plot_title)
plt.plot(wlen_range_max[0], max_wlen_diff[0], '.', markersize=12)
plt.grid(True)
plt.legend(["Data", r"Fit $f(r)=a_0 e^{-a_1 r} + a_2$"])
plt.xlabel("Wavelength range maximum [nm]")
plt.ylabel(
    "Difference in wavelength $\lambda_{max}^{MEEP}-\lambda_{max}^{MIE}$ [nm]")
vs.saveplot(plot_file("WLenDiff.png"), overwrite=True)

#%% GET ENLAPSED TIME COMPARED

wlen_range_max = [[vu.find_numbers(s)[0] for s in ser] for ser in series]
enlapsed_time = [[p["enlapsed"] for p in par] for par in params]
Esempio n. 6
0
            asDict=True)['Qsca'] for f in freqs
]
scatt_eff_theory = np.array(scatt_eff_theory)

#%% GET MAX WAVELENGTH

max_wlen = []
for d, sc in zip(data, series_column):
    max_wlen.append([d[i][np.argmax(d[i][:, sc]), 0] for i in range(len(d))])
max_wlen_theory = wlens[np.argmax(scatt_eff_theory)]

dif_max_wlen = [ml - max_wlen_theory for ml in max_wlen[0]]

#%% WAVELENGTH MAXIMUM DIFFERENCE VS WAVELENGTH RANGE MAXIMUM

wlen_maximum = [vu.find_numbers(s)[-2] for s in series[0]]

plt.title("Difference in scattering maximum for Au 103 nm sphere in water")
plt.plot(wlen_maximum, dif_max_wlen, '.k', markersize=12)
plt.grid(True)
plt.legend(["Data", r"Fit $f(r)=a_0 e^{-a_1 r} + a_2$"])
plt.xlabel("Wavelength Range Maximum [nm]")
plt.ylabel(
    "Difference in wavelength $\lambda_{max}^{MEEP}-\lambda_{max}^{MIE}$ [nm]")
vs.saveplot(plot_file("WLenDiff.png"), overwrite=True)

#%% AVERAGE RESIDUUM VS WAVELENGTH RANGE MAXIMUM

residuums = [[scatt_eff_theory - d[:, 1] for d in dat] for dat in data]

plt.figure()
Esempio n. 7
0
def error_value_latex(X, dX, error_digits=2, symbol='$\pm$', units='',
                      string_scale=True, one_point_scale=False):
    
    """Rounds up value and error of a measure. Also makes a latex string.
    
    This function takes a measure and its error as input. Then, it 
    rounds up both of them in order to share the same amount of decimal 
    places.
    
    After that, it generates a latex string containing the rounded up 
    measure. For that, it can rewrite both value and error so that the 
    classical prefix scale of units can be applied.
    
    Parameters
    ----------
    X : float
        Measurement's value.
    dX : float
        Measurement's associated error.
    error_digits=2 : int, optional.
        Desired number of error digits.
    units='' : str, optional.
        Measurement's units.
    string_scale=True : bool, optional.
        Whether to apply the classical prefix scale or not.        
    one_point_scale=False : bool, optional.
        Applies prefix with one order less.
    
    Returns
    -------
    latex_string : str
        Latex string containing value and error.
    
    Examples
    --------
    >> errorValueLatex(1.325412, 0.2343413)
    '(1.33$\\pm$0.23)'
    >> errorValueLatex(1.325412, 0.2343413, error_digits=3)
    '(1.325$\\pm$0.234)'
    >> errorValueLatex(.133432, .00332, units='V')
    '(133.4$\\pm$3.3) mV'
    >> errorValueLatex(.133432, .00332, one_point_scale=True, units='V')
    '(0.1334$\\pm$0.0033) V'
    >> errorValueLatex(.133432, .00332, string_scale=False, units='V')
    '(1.334$\\pm$0.033)$10^{-1}$ V'
    
    See Also
    --------
    copy
    errorValue
    
    """

    string = error_value(X, dX, error_digits, units,
                         string_scale, one_point_scale)

    try:
        measure = string[0].split(' ')[0].split("E")[0]
        error = string[1].split(' ')[0].split("E")[0]            
    except:
        measure = string[0].split("E")[0]
        error = string[1].split("E")[0]
        
    string_format = string[0].split(measure)[1].split(' ')

    if len(string_format)==2:
        if string_format[0]!='':
            order = vut.find_numbers(string_format[0])[0]
        else:
            order = 0
        unit = ' ' + string_format[1]
    elif string_format[0]=='':
        order = 0
        unit = ''
    elif units!='':
        order = 0
        unit = ' ' + string_format[0]
    else:
        order = vut.find_numbers(string_format[0])[0]
        unit = ''
    
    latex_string = r'({}{}{})'.format(measure, symbol, error)
    if order!=0:
        latex_string = latex_string + r'$10^{' + str(order) + r'}$' + unit
    else:
        latex_string = latex_string + unit
    
    return latex_string
            asDict=True)['Qsca'] for f in freqs
]
scatt_eff_theory = np.array(scatt_eff_theory)

#%% GET MAX WAVELENGTH

max_wlen = []
for d, sc in zip(data, series_column):
    max_wlen.append([d[i][np.argmax(d[i][:, sc]), 0] for i in range(len(d))])
max_wlen_theory = wlens[np.argmax(scatt_eff_theory)]

dif_max_wlen = [ml - max_wlen_theory for ml in max_wlen[0]]

#%% WAVELENGTH MAXIMUM DIFFERENCE VS WAVELENGTH MAXIMUM

pml_wlen_factor = [vu.find_numbers(s)[0] for s in series[0]]
pml_width_nm = [p["pml_width"] * p["from_um_factor"] * 1e3 for p in params[0]]

fig = plt.figure()
plt.title("Difference in scattering maximum for " + plot_title)
plt.plot(pml_wlen_factor, dif_max_wlen, '.', markersize=12)
plt.xlabel("PML width as multiples of maximum of $\lambda$ range")
plt.grid(True)
ax2 = plt.twiny()
ax2.plot(pml_width_nm, dif_max_wlen, '.', markersize=12)
# ax2.set_xlim(np.array( fig.axes[0].get_xlim() ) * params[0][0]["from_um_factor"] * 1e3 )
plt.xlabel("PML width [nm]")
plt.ylabel(
    "Difference in wavelength $\lambda_{max}^{MEEP}-\lambda_{max}^{MIE}$ [nm]")
vs.saveplot(plot_file("WLenDiff.png"), overwrite=True)