import zarr
import numpy as np
import moraine.cli as mc
math
Basic math routine
math
math (output:str, operation:str, **data)
Basic math manipulation. Only elementwise operations are supported. Only one output is supported.
Type | Details | |
---|---|---|
output | str | path to output |
operation | str | operation |
data |
This function is based on Numexpr. All operators and functions supported inNumexpr
are supported except reduction operations.
Usage:
= np.random.rand(100,100).astype(np.float32)
a = np.random.rand(100,100).astype(np.float32)
b = zarr.open('./math/a.zarr','w',shape=a.shape,dtype=a.dtype,chunks=(10,10))
a_zarr = zarr.open('./math/b.zarr','w',shape=b.shape,dtype=b.dtype,chunks=(10,10))
b_zarr = a; b_zarr[:] = b a_zarr[:]
= mc.get_logger() logger
'./math/c.zarr','sin(a)*exp(b)/2',a='./math/a.zarr',b = './math/b.zarr') math(
2024-07-17 20:58:13 - log_args - INFO - running function: math
2024-07-17 20:58:13 - log_args - INFO - fetching args:
2024-07-17 20:58:13 - log_args - INFO - output = './math/c.zarr'
2024-07-17 20:58:13 - log_args - INFO - operation = 'sin(a)*exp(b)/2'
2024-07-17 20:58:13 - log_args - INFO - data = {'a': './math/a.zarr', 'b': './math/b.zarr'}
2024-07-17 20:58:13 - log_args - INFO - fetching args done.
2024-07-17 20:58:13 - zarr_info - INFO - a zarray shape, chunks, dtype: (100, 100), (10, 10), float32
2024-07-17 20:58:13 - zarr_info - INFO - b zarray shape, chunks, dtype: (100, 100), (10, 10), float32
2024-07-17 20:58:13 - math - INFO - starting dask local cluster.
2024-07-17 20:58:13 - math - INFO - dask local cluster started.
2024-07-17 20:58:13 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.7:8787/status', workers=1, threads=2, memory=256.00 GiB)
2024-07-17 20:58:13 - darr_info - INFO - a dask array shape, chunksize, dtype: (100, 100), (10, 10), float32
2024-07-17 20:58:13 - darr_info - INFO - b dask array shape, chunksize, dtype: (100, 100), (10, 10), float32
2024-07-17 20:58:13 - math - INFO - computing graph setted. doing all the computing.
2024-07-17 20:58:15 - math - INFO - computing finished.eted | 1.4s
2024-07-17 20:58:15 - math - INFO - dask cluster closed.
= zarr.open('./math/c.zarr','r')[:]
c *np.exp(b)/2) np.testing.assert_array_almost_equal(c,np.sin(a)