Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modify run_rdf.py and improve analyze.m

run_rdf.py:
  Change the outputBaseName pattern.
  Add --controlFile option.

analyze.m:
  Change some variable names to more general terms.
  Use load() instead of fscanf() to read data from files.
  Add the ability to assign custom x-positions for drawing error bars.
  • Loading branch information...
commit fc202cf04ed7d9d258bdb666b7b82aa9000fab0a 1 parent cf7f02d
@kmtu authored
Showing with 96 additions and 5 deletions.
  1. +89 −0 src/analyze.m
  2. +7 −5 src/run_rdf.py
View
89 src/analyze.m
@@ -0,0 +1,89 @@
+#!/usr/bin/octave -qf
+
+clear all
+format long
+
+if (nargin() < 3)
+ error("Usage: $analyze.m baseFileName ibegin iend [mode errbar_pos...]")
+endif
+
+baseFileName = argv(){1}
+ibegin = str2num(argv(){2})
+iend = str2num(argv(){3})
+indexes = [ibegin:iend]
+
+if (nargin() > 3)
+ mode = argv(){4} #even or odd or custom
+ if (strcmp(mode, "custom"))
+ if (nargin() > 4)
+ errbarXPos_cell = argv()(5:end)
+ for i = [1:length(errbarXPos_cell)]
+ errbarXPos(i) = str2num(errbarXPos_cell{i})
+ endfor
+ else
+ error("When mode = custom, there should be values of errbarXPos following behind.\n\
+ Usage: $analyze.m baseFileName ibegin iend [mode errbar_pos...]")
+ endif
+ endif
+endif
+
+#k = 0;
+#for i = indexes
+# fileName = strcat(baseFileName, num2str(i, "%02d"))
+# datafid = fopen(fileName, 'r');
+# j = 0;
+# k++;
+# while(!feof(datafid))
+# j++;
+# [r(j), g(j,k)] = fscanf(datafid, "%f %f", "C");
+# endwhile
+# fclose(datafid);
+#endfor
+
+for i = indexes
+ fileName = strcat(baseFileName, num2str(i, "%02d"))
+ data = load(fileName)
+ if (!exist("xdata"))
+ xdata= data(:,1)
+ ydata = data(:,2)
+ else
+# if (size(xdata) != size(data) || xdata != data(:,1))
+# error("The xdata indexes of file %s is different", fileName)
+# endif
+ # don't check the consistency of xdata
+ # use the first xdata
+ minSize = min(size(ydata, 1), size(data, 1))
+ ydata(1:minSize, end+1) = data(1:minSize, 2)
+ endif
+endfor
+
+ydata_mean = mean(ydata, 2);
+ydata_std = std(ydata, 0, 2);
+
+if (nargin() > 3)
+ switch (mode)
+ case "even"
+ ydata_std(1:2:j) = 0
+ case "odd"
+ ydata_std(2:2:j) = 0
+ case "custom"
+ #find the closest xdata, both its value and index
+ for i = [1:length(errbarXPos)]
+ [m, mi] = min(abs(errbarXPos(i) - xdata))
+ errbarIndexes(i) = mi
+ endfor
+ #assign values of OTHER indexes as 0
+ for i = [1:length(xdata)]
+ if (all(errbarIndexes != i))
+ ydata_std(i) = 0
+ endif
+ endfor
+ otherwise
+ error("Unknown mode: %s", mode)
+ endswitch
+endif
+
+out = [xdata, ydata_mean, ydata_std]
+outFileName = strcat("rdf_std_", num2str(ibegin), "-", num2str(iend))
+save(outFileName,"out")
+
View
12 src/run_rdf.py
@@ -5,10 +5,10 @@
import math
parser = argparse.ArgumentParser(description='Process data to RDF')
-parser.add_argument('dataIndexFile', type=argparse.FileType('r'), metavar='FILE')
+parser.add_argument('dataIndexFile', type=argparse.FileType('r'))
parser.add_argument('window', type=int, help="Window size in ns")
parser.add_argument('outputBaseName',
- help = "Output file name = outputBaseName-01,-02,-03...")
+ help = "Output file name = outputBaseName01,02,03...")
parser.add_argument('-r', '--dataRange', nargs=2, type=int, metavar=('BEGIN', 'END'),
help = "The data range to be processed. ex. -r 6 10, means 6ns to 10ns.")
parser.add_argument('--correlated', action='store_true', default=False,
@@ -16,11 +16,13 @@
"Default is False, i.e. uncorrelated: 1 2 3, 4 5 6,...")
parser.add_argument('--beginIndex', type=int, default=1,
help = "Only takes effect for uncorrelated rdf.")
+parser.add_argument('-c', '--controlFile', default="rdf_control",
+ help = "rdf control file")
args = parser.parse_args()
dataIndexFile = args.dataIndexFile
window = args.window
-control = "../rdf_control"
+control = args.controlFile
outputBaseName = args.outputBaseName
isCorrelated = args.correlated
beginIndex = args.beginIndex
@@ -70,7 +72,7 @@
files += dataFileList[i+j]
# print("rdf_dlchau -c " + control + " -o " + outputBaseName+"-%02d"%i + " -f " + " ".join(files))
subprocess.check_call(["rdf_dlchau", "-c", control,
- "-o", outputBaseName + "-%02d"%(i+dataRange[0]+1),
+ "-o", outputBaseName + "%02d"%(i+dataRange[0]+1),
"-f"] + files)
else:
for i in range(int(math.floor(len(dataFileList) / window))):
@@ -79,6 +81,6 @@
files += dataFileList[window*i+j]
# print("rdf_dlchau -c " + control + " -o " + outputBaseName+"-%02d"%i + " -f " + " ".join(files))
subprocess.check_call(["rdf_dlchau", "-c", control,
- "-o", outputBaseName + "-%02d"%(i+beginIndex),
+ "-o", outputBaseName + "%02d"%(i+beginIndex),
"-f"] + files)
Please sign in to comment.
Something went wrong with that request. Please try again.