def test_doy_window2_mean_rescale_max_min(self): with podpac.settings: podpac.settings.set_unsafe_eval(True) coords = podpac.coordinates.concat([ podpac.Coordinates( [podpac.crange("1999-12-29", "2000-01-03", "1,D", "time")]), podpac.Coordinates( [podpac.crange("2001-12-30", "2002-01-02", "1,D", "time")]), ]) node = Arange() node_max = Arithmetic(source=node, eqn="(source < 5) + source") node_min = Arithmetic(source=node, eqn="-1*(source < 5) + source") nodedoywindow_s = FM( source=node, window=2, cache_output=False, force_eval=True, scale_max=node_max, scale_min=node_min, rescale=False, ) o_s = nodedoywindow_s.eval(coords) np.testing.assert_array_almost_equal([0.5] * o_s.size, o_s)
def test_init(self): sine_node = SinCoords() with podpac.settings: podpac.settings.set_unsafe_eval(True) node = Arithmetic(A=sine_node, B=sine_node, eqn="2*abs(A) - B + {offset}", params={"offset": 1}) podpac.settings.set_unsafe_eval(False) with pytest.warns(UserWarning, match="Insecure evaluation"): node = Arithmetic(A=sine_node, B=sine_node, eqn="2*abs(A) - B + {offset}", params={"offset": 1})
def test_evaluate_not_allowed(self): with podpac.settings: podpac.settings.set_unsafe_eval(False) coords = podpac.Coordinates( [podpac.crange(-90, 90, 1.0), podpac.crange(-180, 180, 1.0)], dims=["lat", "lon"]) sine_node = SinCoords() with pytest.warns(UserWarning, match="Insecure evaluation"): node = Arithmetic(A=sine_node, B=sine_node, eqn="2*abs(A) - B + {offset}", params={"offset": 1}) with pytest.raises(PermissionError): node.eval(coords)
def test_evaluate(self): with podpac.settings: podpac.settings.set_unsafe_eval(True) coords = podpac.Coordinates( [podpac.crange(-90, 90, 1.0), podpac.crange(-180, 180, 1.0)], dims=["lat", "lon"]) sine_node = SinCoords() node = Arithmetic(A=sine_node, B=sine_node, eqn="2*abs(A) - B + {offset}", params={"offset": 1}) output = node.eval(coords) a = sine_node.eval(coords) b = sine_node.eval(coords) np.testing.assert_allclose(output, 2 * abs(a) - b + 1)
def test_multi_threading(self): coords = podpac.Coordinates([[1, 2, 3]], ["lat"]) with podpac.settings: podpac.settings.set_unsafe_eval(True) podpac.settings["CACHE_NODE_OUTPUT_DEFAULT"] = False podpac.settings["DEFAULT_CACHE"] = [] podpac.settings["RAM_CACHE_ENABLED"] = False node1 = Arithmetic(A=Arange(), B=Arange(), eqn="A+B") node2 = Arithmetic(A=node1, B=Arange(), eqn="A+B") # multithreaded podpac.settings["MULTITHREADING"] = True podpac.settings["N_THREADS"] = 8 omt = node2.eval(coords) # single threaded podpac.settings["MULTITHREADING"] = False ost = node2.eval(coords) np.testing.assert_array_equal(omt, ost)
def test_multi_threading_cache_race(self): coords = podpac.Coordinates([np.linspace(0, 1, 1024)], ["lat"]) with podpac.settings: podpac.settings["MULTITHREADING"] = True podpac.settings["N_THREADS"] = 3 podpac.settings["CACHE_NODE_OUTPUT_DEFAULT"] = True podpac.settings["DEFAULT_CACHE"] = ["ram"] podpac.settings["RAM_CACHE_ENABLED"] = True podpac.settings.set_unsafe_eval(True) A = Arithmetic(A=Arange(), eqn="A**2") B = Arithmetic(A=Arange(), eqn="A**2") C = Arithmetic(A=Arange(), eqn="A**2") D = Arithmetic(A=Arange(), eqn="A**2") E = Arithmetic(A=Arange(), eqn="A**2") F = Arithmetic(A=Arange(), eqn="A**2") node2 = Arithmetic(A=A, B=B, C=C, D=D, E=E, F=F, eqn="A+B+C+D+E+F") om = node2.eval(coords) from_cache = [n._from_cache for n in node2.inputs.values()] assert sum(from_cache) > 0
def test_multi_threading_stress_nthreads(self): coords = podpac.Coordinates([np.linspace(0, 1, 4)], ["lat"]) A = Arithmetic(A=Arange(), eqn="A**0") B = Arithmetic(A=Arange(), eqn="A**1") C = Arithmetic(A=Arange(), eqn="A**2") D = Arithmetic(A=Arange(), eqn="A**3") E = Arithmetic(A=Arange(), eqn="A**4") F = Arithmetic(A=Arange(), eqn="A**5") node2 = Arithmetic(A=A, B=B, C=C, D=D, E=E, F=F, eqn="A+B+C+D+E+F") node3 = Arithmetic(A=A, B=B, C=C, D=D, E=E, F=F, G=node2, eqn="A+B+C+D+E+F+G") with podpac.settings: podpac.settings["MULTITHREADING"] = True podpac.settings["N_THREADS"] = 8 podpac.settings["CACHE_NODE_OUTPUT_DEFAULT"] = False podpac.settings["DEFAULT_CACHE"] = [] podpac.settings["RAM_CACHE_ENABLED"] = False podpac.settings.set_unsafe_eval(True) omt = node3.eval(coords) assert node3._multi_threaded assert not node2._multi_threaded with podpac.settings: podpac.settings["MULTITHREADING"] = True podpac.settings[ "N_THREADS"] = 9 # 2 threads available after first 7 podpac.settings["CACHE_NODE_OUTPUT_DEFAULT"] = False podpac.settings["DEFAULT_CACHE"] = [] podpac.settings["RAM_CACHE_ENABLED"] = False podpac.settings.set_unsafe_eval(True) omt = node3.eval(coords) assert node3._multi_threaded assert node2._multi_threaded
def test_missing_equation(self): sine_node = SinCoords() with pytest.raises(ValueError), warnings.catch_warnings(): warnings.filterwarnings("ignore", "Insecure evaluation.*") Arithmetic(A=sine_node, B=sine_node)