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')
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.
c = zarr.open('./math/c.zarr','r')[:]
np.testing.assert_array_almost_equal(c,np.sin(a)*np.exp(b)/2)