vvmtools.analyze.DataRetriever.func_time_parallel#
- DataRetriever.func_time_parallel(func, time_steps=None, func_config=None, cores=5)[source]#
Applies a time-dependent function func in parallel over a list of time steps. The result is returned as a NumPy array.
- Parameters:
func (callable) – The time-dependent function to be parallelized. It should accept two arguments: the time step t and a config object (containing any additional parameters).
time_steps (list or array-like, optional) – List or array of time steps over which to apply the function. Defaults to np.arange(0, 721, 1).
func_config (dict or object, optional) – A dictionary or object containing additional parameters for the function.
cores (int, optional) – The number of CPU cores to use for parallel processing, defaults to 20.
- Returns:
The combined result of applying the function to all time steps.
- Return type:
numpy.ndarray
- Raises:
TypeError – If time_steps is not a list or array-like of integers.
- Example:
>>> import numpy as np >>> import vvmtools >>> def cal_TKE_land(t, func_config): >>> u = np.squeeze(my_vvmtool.get_var("u", t, numpy=True, domain_range=func_config["domain_range"])) >>> v = np.squeeze(my_vvmtool.get_var("v", t, numpy=True, domain_range=func_config["domain_range"])) >>> w = np.squeeze(my_vvmtool.get_var("w", t, numpy=True, domain_range=func_config["domain_range"])) >>> u_inter = (u[:, :, 1:] + u[:, :, :-1])[1:, 1:] / 2 >>> v_inter = (v[:, 1:] + v[:, :-1])[1:, :, 1:] / 2 >>> w_inter = (w[1:] + w[:-1])[:, 1:, 1:] / 2 >>> TKE = np.mean(u_inter ** 2 + v_inter ** 2 + w_inter ** 2, axis=(1, 2)) >>> return TKE >>> my_vvmtool = vvmtools.analyze.DataRetriever(case_path="path/to/case") >>> func_config = {"domain_range": (None, None, None, None, 64, 128)} >>> TKE_land = my_vvmtool.func_time_parallel(func=cal_TKE_land, time_steps=list(range(0, 721, 1)), func_config=func_config)