Created
October 10, 2016 20:31
-
-
Save grzanka/85910d851538b042d89e5fc13d261eb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import numpy as np | |
# directory with .dat files | |
dirname = '.' | |
# new location of the main peak | |
x_peak_loc = 220 | |
# normalization factor | |
y_norm = 2.0 | |
# loop through all files in a directory | |
for filename in os.listdir(dirname): | |
# select only .dat files | |
if filename.endswith(".dat"): | |
# get the filepath | |
filepath = os.path.join(dirname, filename) | |
print("analyzing " + filepath) | |
# replace , with . as decimal point | |
data = np.loadtxt(filepath, converters={0 : lambda s : s.replace(',','.'), 1 : lambda s : s.replace(',','.')}) | |
# renormalize Y axis | |
data[:1] *= y_norm | |
# get current location of maximum | |
max_loc = np.amax(data, axis=0)[0] | |
# difference between actual and desired maximum location | |
shift = max_loc - y_norm | |
# renorm. X axis | |
data[:0] -= shift | |
# save file with .new suffix | |
np.savetxt(filepath + ".new", data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment