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
## [Unreleased]
## [0.2.0] - 2021-06-04
### Added
- None
### Changed
- Use pickle5 to save data
### Removed
- None
## [0.1.2] - 2020-10-29
### Added
- 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
- None
### Removed
- None
\ No newline at end of file
- None
This diff is collapsed.
......@@ -3,11 +3,12 @@ import numpy as np
#from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import scipy.optimize
import pickle as pkl
import pickle5 as pkl
import json
import re
import pandas as pd
from progress.bar import Bar
import joblib
from pytrr import (
read_trr_header,
......@@ -66,15 +67,47 @@ def center_gravity(a):
cg = np.sum(a)/m
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):
print(' ')
print('Save to pickle |################################| 1/1')
with open(sv_name+'.pkl', 'wb') as handle:
pkl.dump(fl, handle, protocol=pkl.HIGHEST_PROTOCOL)
#joblib.dump(fl, handle)
def frompickle(fl):
with open(fl, 'rb') as handle:
b = pkl.load(handle)
#b = joblib.load(handle)
return b
......@@ -83,6 +116,14 @@ def tojson(fl, sv_name):
print('Save to json |################################| 1/1')
with open(sv_name+'.json', 'w') as file:
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):
#Plot surface
......@@ -866,4 +907,4 @@ def togmxndx(box_res, fld, sv_name):
bar.finish()
def dict2pd(d, col=[]):
return pd.DataFrame.from_dict(d, orient='index', columns=col)
\ No newline at end of file
return pd.DataFrame.from_dict(d, orient='index', columns=col)
......@@ -97,13 +97,18 @@ def rdf_peaks(TRR,TPR,IND,ST,EN,fld,arg1,arg2,dist_pk):
p.communicate(cmd.encode('UTF-8'))
p.send_signal('<Ctrl>-D')
p.wait()
x,y=read_xvg(XVG=fld+'/tmp.xvg')
yhat = savgol_filter(y, 15, 4) # window size 15, polynomial order 4
peaks, _ = find_peaks(yhat, distance=dist_pk)
pathname = os.path.abspath(os.path.join(fld, 'tmp.xvg'))
os.remove(pathname)
try:
f = open(fld+'/tmp.xvg')
f.close()
# Do something with the file
x,y=read_xvg(XVG=fld+'/tmp.xvg')
yhat = savgol_filter(y, 15, 4) # window size 15, polynomial order 4
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
......@@ -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'))
os.remove(pathname)
return y
\ No newline at end of file
return y
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