Commit 37c53192 authored by Stelios Karozis's avatar Stelios Karozis

Debugging - Real case use

parent 87b2b8d9
...@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
## [0.2.0] - 2021-06-04
### Added
- None
### Changed
- Use pickle5 to save data
### Removed
- None
## [0.1.2] - 2020-10-29 ## [0.1.2] - 2020-10-29
### Added ### Added
- add OrderedDict() function to keep input ordered independent to Python version - add OrderedDict() function to keep input ordered independent to Python version
...@@ -149,4 +159,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -149,4 +159,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- None - None
### Removed ### Removed
- None - None
\ No newline at end of file
This diff is collapsed.
...@@ -3,11 +3,12 @@ import numpy as np ...@@ -3,11 +3,12 @@ import numpy as np
#from mpl_toolkits.mplot3d import Axes3D #from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import scipy.optimize import scipy.optimize
import pickle as pkl import pickle5 as pkl
import json import json
import re import re
import pandas as pd import pandas as pd
from progress.bar import Bar from progress.bar import Bar
import joblib
from pytrr import ( from pytrr import (
read_trr_header, read_trr_header,
...@@ -66,15 +67,47 @@ def center_gravity(a): ...@@ -66,15 +67,47 @@ def center_gravity(a):
cg = np.sum(a)/m cg = np.sum(a)/m
return cg return cg
class StreamFile(object):
def __init__(self, f):
self.f = f
def __getattr__(self, item):
return getattr(self.f, item)
def read(self, n):
# print("reading total_bytes=%s" % n, flush=True)
if n >= (1 << 31):
buffer = bytearray(n)
idx = 0
while idx < n:
batch_size = min(n - idx, 1 << 31 - 1)
# print("reading bytes [%s,%s)..." % (idx, idx + batch_size), end="", flush=True)
buffer[idx:idx + batch_size] = self.f.read(batch_size)
# print("done.", flush=True)
idx += batch_size
return buffer
return self.f.read(n)
def write(self, buffer):
n = len(buffer)
print("writing total_bytes=%s..." % n, flush=True)
idx = 0
while idx < n:
batch_size = min(n - idx, 1 << 31 - 1)
print("writing bytes [%s, %s)... " % (idx, idx + batch_size), end="", flush=True)
self.f.write(buffer[idx:idx + batch_size])
print("done.", flush=True)
idx += batch_size
def topickle(fl, sv_name): def topickle(fl, sv_name):
print(' ') print(' ')
print('Save to pickle |################################| 1/1') print('Save to pickle |################################| 1/1')
with open(sv_name+'.pkl', 'wb') as handle: with open(sv_name+'.pkl', 'wb') as handle:
pkl.dump(fl, handle, protocol=pkl.HIGHEST_PROTOCOL) pkl.dump(fl, handle, protocol=pkl.HIGHEST_PROTOCOL)
#joblib.dump(fl, handle)
def frompickle(fl): def frompickle(fl):
with open(fl, 'rb') as handle: with open(fl, 'rb') as handle:
b = pkl.load(handle) b = pkl.load(handle)
#b = joblib.load(handle)
return b return b
...@@ -83,6 +116,14 @@ def tojson(fl, sv_name): ...@@ -83,6 +116,14 @@ def tojson(fl, sv_name):
print('Save to json |################################| 1/1') print('Save to json |################################| 1/1')
with open(sv_name+'.json', 'w') as file: with open(sv_name+'.json', 'w') as file:
file.write(json.dumps(str(fl))) file.write(json.dumps(str(fl)))
#file.write(json.dumps(fl))
def fromjson(fl):
print(' ')
print('Load to json |################################| 1/1')
with open(fl, 'r') as file:
data = file.read()
b = json.dumps(data)
return b
def plot_surf(data, normal, c, save_name): def plot_surf(data, normal, c, save_name):
#Plot surface #Plot surface
...@@ -866,4 +907,4 @@ def togmxndx(box_res, fld, sv_name): ...@@ -866,4 +907,4 @@ def togmxndx(box_res, fld, sv_name):
bar.finish() bar.finish()
def dict2pd(d, col=[]): def dict2pd(d, col=[]):
return pd.DataFrame.from_dict(d, orient='index', columns=col) return pd.DataFrame.from_dict(d, orient='index', columns=col)
\ No newline at end of file
...@@ -97,13 +97,18 @@ def rdf_peaks(TRR,TPR,IND,ST,EN,fld,arg1,arg2,dist_pk): ...@@ -97,13 +97,18 @@ def rdf_peaks(TRR,TPR,IND,ST,EN,fld,arg1,arg2,dist_pk):
p.communicate(cmd.encode('UTF-8')) p.communicate(cmd.encode('UTF-8'))
p.send_signal('<Ctrl>-D') p.send_signal('<Ctrl>-D')
p.wait() p.wait()
try:
x,y=read_xvg(XVG=fld+'/tmp.xvg') f = open(fld+'/tmp.xvg')
yhat = savgol_filter(y, 15, 4) # window size 15, polynomial order 4 f.close()
peaks, _ = find_peaks(yhat, distance=dist_pk) # Do something with the file
x,y=read_xvg(XVG=fld+'/tmp.xvg')
pathname = os.path.abspath(os.path.join(fld, 'tmp.xvg')) yhat = savgol_filter(y, 15, 4) # window size 15, polynomial order 4
os.remove(pathname) peaks, _ = find_peaks(yhat, distance=dist_pk)
pathname = os.path.abspath(os.path.join(fld, 'tmp.xvg'))
os.remove(pathname)
except IOError:
peaks=np.ndarray((0))
return peaks return peaks
...@@ -190,4 +195,4 @@ def order(TRR,TPR,IND,ST,EN,normal,fld,dist_pk=1): ...@@ -190,4 +195,4 @@ def order(TRR,TPR,IND,ST,EN,normal,fld,dist_pk=1):
pathname = os.path.abspath(os.path.join(fld, 'tmp2.xvg')) pathname = os.path.abspath(os.path.join(fld, 'tmp2.xvg'))
os.remove(pathname) os.remove(pathname)
return y return y
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment