def test_lut_stretch_warning(): with warnings.catch_warnings(record=True) as w: ggf.get_ggf(model="boyde2009", semi_major=3.6e-6, semi_minor=3e-6, object_index=1.344 * 1.0178, medium_index=1.344, effective_fiber_distance=175e-6, mode_field_diameter=4.8e-6, power_per_fiber=.5, wavelength=780e-9, poisson_ratio=.4, n_poly=120, use_lut=True) assert len(w) == 1 assert "Stretching ratio is high: 0.199" in str(w[0].message)
def test_exact_fus(): """Test the exact value on a LUT grid point""" f = ggf.get_ggf(model="boyde2009", semi_major=3e-6, semi_minor=3e-6, object_index=1.344 * 1.0178, medium_index=1.344, effective_fiber_distance=175e-6, mode_field_diameter=4.8e-6, power_per_fiber=.5, wavelength=780e-9, poisson_ratio=.4, n_poly=120, use_lut=True) exact = 0.8069195712307504 # upon compression this becomes: 0.8069195747375488 assert np.allclose(exact, f, rtol=0, atol=4e-9)
def test_exact_cell(): """Test the exact value on a LUT grid point""" stretch_ratio = 0.065 semi_minor = 6.724137931034484e-06 semi_major = semi_minor * (stretch_ratio + 1) f = ggf.get_ggf(model="boyde2009", semi_major=semi_major, semi_minor=semi_minor, object_index=1.333 * 1.025, medium_index=1.333, effective_fiber_distance=175e-6, mode_field_diameter=4.8e-6, power_per_fiber=.65, wavelength=780e-9, poisson_ratio=.5, n_poly=120, use_lut=True) exact = 0.7711334992513761 assert np.allclose(exact, f, rtol=0, atol=1e-7)
def func(args, const_arg): try: result = ggf.get_ggf(*args[2:], use_lut=False) except BaseException: result = np.nan return (MYIP, USERNAME, result)
def compute_ggf(**kwargs): return ggf.get_ggf(use_lut=False, **kwargs)
stretch_ratio = kw.pop("stretch_ratio") kw["semi_major"] = stretch_ratio * kw["semi_minor"] + kw["semi_minor"] return kw # get lut paths paths = pathlib.Path(__file__).parent.glob("*.h5") paths = sorted(paths)[::-1] for path in paths: # make everything reproducible np.random.set_state(np.random.RandomState(42).get_state()) fixed, ranges = get_kwarg_ranges(path) errs = [] # dice out a few parameters for ii in range(NUM_ERRS): kwargs = fixed.copy() for rr in ranges: kwargs[rr] = np.random.uniform(low=ranges[rr][0], high=ranges[rr][1]) kw_ggf = map_lut2geom(kwargs) # get LUT value ggf1 = ggf.get_ggf(use_lut=path, **kw_ggf) # compute value (cached) ggf2 = compute_ggf(**kw_ggf) erri = (ggf2-ggf1)/ggf2 errs.append(erri) print(path, "{:03d} error: {:.1f}%".format(ii, erri*100)) np.savetxt(path.with_suffix(".errors.txt"), errs)
for ii in range(len(radius)): # determine semi-major and semi-minor axes smaj, smin = ellipse_fit(radius[ii], theta[ii]) semimaj[ii] = smaj semimin[ii] = smin # compute GGF if (time[ii] > meta["time_stretch_begin [s]"] and time[ii] < meta["time_stretch_end [s]"]): power_per_fiber = meta["power_per_fiber_stretch [W]"] f = ggf.get_ggf( model="boyde2009", semi_major=smaj, semi_minor=smin, object_index=meta["object_index"], medium_index=meta["medium_index"], effective_fiber_distance=meta["effective_fiber_distance [m]"], mode_field_diameter=meta["mode_field_diameter [m]"], power_per_fiber=power_per_fiber, wavelength=meta["wavelength [m]"], poisson_ratio=.5) else: power_per_fiber = meta["power_per_fiber_trap [W]"] f = np.nan factors[ii] = f # compute compliance strains = (semimaj - semimaj[0]) / semimaj[0] complnc = strains / factors compl_ival = (time > meta["time_stretch_begin [s]"]) * \ (time < meta["time_stretch_end [s]"])