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 | VAR_KEYWORD |
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(
2025-06-24 21:41:06 - log_args - INFO - running function: math
2025-06-24 21:41:06 - log_args - INFO - fetching args:
2025-06-24 21:41:06 - log_args - INFO - output = './math/c.zarr'
2025-06-24 21:41:06 - log_args - INFO - operation = 'sin(a)*exp(b)/2'
2025-06-24 21:41:06 - log_args - INFO - data = {'a': './math/a.zarr', 'b': './math/b.zarr'}
2025-06-24 21:41:06 - log_args - INFO - fetching args done.
2025-06-24 21:41:06 - zarr_info - INFO - a zarray shape, chunks, dtype: (100, 100), (10, 10), float32
2025-06-24 21:41:06 - zarr_info - INFO - b zarray shape, chunks, dtype: (100, 100), (10, 10), float32
2025-06-24 21:41:06 - math - INFO - starting dask local cluster.
2025-06-24 21:41:07 - math - INFO - dask local cluster started.
2025-06-24 21:41:07 - dask_cluster_info - INFO - dask cluster: LocalCluster(dashboard_link='http://10.211.48.18:8787/status', workers=1, threads=2, memory=1.46 TiB)
2025-06-24 21:41:07 - darr_info - INFO - a dask array shape, chunksize, dtype: (100, 100), (10, 10), float32
2025-06-24 21:41:07 - darr_info - INFO - b dask array shape, chunksize, dtype: (100, 100), (10, 10), float32
2025-06-24 21:41:07 - math - INFO - computing graph setted. doing all the computing.
2025-06-24 21:41:08 - math - INFO - computing finished.eted | 1.5s
2025-06-24 21:41:08 - 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)