math

Basic math routine
import zarr
import numpy as np
import moraine.cli as mc

source

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:

a = np.random.rand(100,100).astype(np.float32)
b = np.random.rand(100,100).astype(np.float32)
a_zarr = zarr.open('./math/a.zarr','w',shape=a.shape,dtype=a.dtype,chunks=(10,10))
b_zarr = zarr.open('./math/b.zarr','w',shape=b.shape,dtype=b.dtype,chunks=(10,10))
a_zarr[:] = a; b_zarr[:] = b
logger = mc.get_logger()
math('./math/c.zarr','sin(a)*exp(b)/2',a='./math/a.zarr',b = './math/b.zarr')
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.
c = zarr.open('./math/c.zarr','r')[:]
np.testing.assert_array_almost_equal(c,np.sin(a)*np.exp(b)/2)