-
Notifications
You must be signed in to change notification settings - Fork 1
/
speis_data.py
33 lines (28 loc) · 1.25 KB
/
speis_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import matplotlib.pyplot as plt
# The following helper functions simplify the SPEIS data import from MPT files
def get_boundaries(highest_freq, lowest_freq, f):
if (np.count_nonzero(f[0] >= highest_freq) > 0):
cutoff_start = np.where(f[0] >= highest_freq)[0][-1]
else:
cutoff_start = 0
if (np.count_nonzero(f[0] <= lowest_freq) > 0):
cutoff_end = np.where(f[0] <= lowest_freq)[0][0]
else:
cutoff_end = len(f[0])-1
return cutoff_start, cutoff_end
def read_mpt_parameters(filename):
with open(filename, 'r', encoding="latin-1") as input_file:
lines = input_file.readlines()
header_line = lines[1]
header_lines_number = int(header_line.split(":")[1])
# Iterate over headline section containing relevant information
for i in range(header_lines_number):
if lines[i].startswith("Ei (V)"):
pot_start = float(lines[i].split("(V)")[1])*1E+3
if lines[i].startswith("Ef (V)"):
pot_end = float(lines[i].split("(V)")[1])*1E+3
if lines[i].startswith("N"):
potstepnumber = int(lines[i].strip().split(" ")[-1])+1
pot_step = int(abs(pot_start-pot_end)/(potstepnumber-1))
return pot_start, pot_step, potstepnumber