From 1b1a7f934a87fb6c2b1e3eeec00ea0c7fafc9763 Mon Sep 17 00:00:00 2001 From: Koushik Naskar Date: Wed, 16 Mar 2022 10:57:43 +0530 Subject: [PATCH] update --- kfutils/__init__.py | 1 + kfutils/cli.py | 2 ++ kfutils/funcs.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 kfutils/funcs.py diff --git a/kfutils/__init__.py b/kfutils/__init__.py index e69de29..c3e0d44 100644 --- a/kfutils/__init__.py +++ b/kfutils/__init__.py @@ -0,0 +1 @@ +from .funcs import * \ No newline at end of file diff --git a/kfutils/cli.py b/kfutils/cli.py index 2424ff0..db2d6b6 100644 --- a/kfutils/cli.py +++ b/kfutils/cli.py @@ -10,6 +10,8 @@ import glob import numpy as np +__all__ = [] + class CustomParser(argparse.ArgumentParser): diff --git a/kfutils/funcs.py b/kfutils/funcs.py new file mode 100644 index 0000000..ec2262a --- /dev/null +++ b/kfutils/funcs.py @@ -0,0 +1,48 @@ +__all__ = ['smoothen', 'getShape', 'writeShapedFile', 'writeFile'] + + + +import numpy as np +from scipy.interpolate import RectBivariateSpline +import os,shutil,subprocess,sys +from csaps import csaps + + + + + +def smoothen(data, shape, tc, pc, cols, sm=0.95): + data.shape = shape + + grid = [data[:,0,tc], data[0,:, pc]] + + res = np.copy(data) + + for c in cols: + res[...,c] = csaps(grid, data[...,c], grid, smooth=sm) + return res + + + + +def getShape(data): + for i in range(data.shape[1]): + print(np.unique(data[:,i]).shape) + + + +def writeShapedFile(file,data,fmt='%.8f'): + assert len(data.shape)==3, "A 3D data is required for this function" + with open(file, 'w') as f: + for i in data: + np.savetxt(f,i,delimiter='\t', fmt=fmt) + f.write('\n') + + + +def writeFile(file,dat,tc=0,fmt='%.8f'): + with open(file,'w') as f: + for i in np.unique(dat[:,tc]): + np.savetxt(f,dat[dat[:,tc]==i],delimiter='\t', fmt=fmt) + f.write('\n') + diff --git a/setup.py b/setup.py index 0f54db1..2a8e523 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ txt = f.read() setup(name='kfutils', - version='0.0.7', + version='0.0.8', description='A common file operation utility', long_description=txt, author='Koushik Naskar',