Skip to content

Commit 9688951

Browse files
committed
modified the package conforming to python style. version 0.2.1 used for the paper
1 parent 27603f1 commit 9688951

File tree

13 files changed

+101
-46
lines changed

13 files changed

+101
-46
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Ignore compiled files
2+
*.class
3+
*.jar
4+
*.pyc
5+
*.DS_Store
6+
7+
# Ignore folders
8+
logs/
9+
correlationHistogramAnalysis.egg-info/
10+
dist/
11+
12+
# Ignore IDE-specific files
13+
.idea/
14+
.vscode/
15+
Shape_analysis.ipynb

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

correlationHistogramAnalysis/__init__.py

Whitespace-only changes.

correlationHistogramAnalysis/correlation_histogram.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def read_epos(f):
4040
~ Appendix A of 'Atom Probe tomography: A Users Guide',
4141
notes on ePOS format."""
4242
# read in the data
43-
with open(f, 'rb') as file:
43+
with open(f, "rb") as file:
4444
n = len(file.read()) / 4
4545
rs = n / 11
46-
with open(f, 'rb') as file:
47-
d = struct.unpack('>' + 'fffffffffII' * int(rs), file.read(4 * int(n)))
46+
with open(f, "rb") as file:
47+
d = struct.unpack(">" + "fffffffffII" * int(rs), file.read(4 * int(n)))
4848
epos = np.array(d)
4949
epos = epos.reshape([int(rs), 11])
5050
return epos
@@ -85,7 +85,7 @@ def get_pairs(epos):
8585
m2 : float-array
8686
second of the mass-to-charge pairs,
8787
with multiplicity>1.
88-
dx,dy: x y detector coordinates
88+
dx,dy: x y detector coordinates
8989
9090
9191
"""
@@ -112,7 +112,7 @@ def get_pairs(epos):
112112

113113
def corr_his(m1, m2, nbins):
114114
"""
115-
creates a histogram based on the mass-to-charge values m1 and m2, and number of bins
115+
creates a histogram based on the mass-to-charge values m1 and m2, and number of bins
116116
Parameters
117117
----------
118118
m1 : float

data/final_energy.csv renamed to correlationHistogramAnalysis/data/final_energy.csv

File renamed without changes.

data/final_energy_new.csv renamed to correlationHistogramAnalysis/data/final_energy_new.csv

File renamed without changes.

correlationHistogramAnalysis/dissociation_tracks.py

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
def parse_formula(formula):
1212
"""Works for formulas of form AxBy where x,y=1 do not have to be mentioned otherwise x,y <=9"""
1313
elements = {}
14-
for char, nxtchar, nxt2char in zip(formula, formula[1:] + formula[:1], formula[2:] + formula[:2]):
14+
for char, nxtchar, nxt2char in zip(
15+
formula, formula[1:] + formula[:1], formula[2:] + formula[:2]
16+
):
1517
if char.isalpha() & char.isupper():
1618
if nxtchar.isalpha() & nxtchar.islower():
1719
if nxt2char.isnumeric():
@@ -25,7 +27,9 @@ def parse_formula(formula):
2527
else:
2628
elements[char] = int(nxtchar)
2729
prime_list = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 31, 37, 41, 43, 47]
28-
elements_prime = dict([(y, prime_list[x]) for x, y in enumerate(sorted(set(elements)))])
30+
elements_prime = dict(
31+
[(y, prime_list[x]) for x, y in enumerate(sorted(set(elements)))]
32+
)
2933
return elements, elements_prime
3034

3135

@@ -59,7 +63,11 @@ def generate_triple_products(elements):
5963
for j in range(1, len(temp)):
6064
second_product = temp[:j]
6165
third_product = temp[j:]
62-
trip = (tuple(sorted(first_product)), tuple(sorted(second_product)), tuple(sorted(third_product)))
66+
trip = (
67+
tuple(sorted(first_product)),
68+
tuple(sorted(second_product)),
69+
tuple(sorted(third_product)),
70+
)
6371
triplet = tuple(sorted(trip)) # Sort the elements to ensure uniqueness
6472
if triplet not in triplets:
6573
triplets.add(triplet)
@@ -76,12 +84,12 @@ def product_reparser(p1):
7684
else:
7785
product.append(key + str(p1[key]))
7886

79-
product = ''.join(product)
87+
product = "".join(product)
8088
return product
8189

8290

8391
def possible_product_pairs(complex_formula, charge):
84-
""" Based on the chemical formula, product pairs are generated efficiently."""
92+
"""Based on the chemical formula, product pairs are generated efficiently."""
8593
original_dict, _ = parse_formula(complex_formula)
8694

8795
def szudzik_pairing(a, b):
@@ -106,28 +114,45 @@ def generate_recursive_pairs(current_pair, remaining_values, remaining_keys):
106114
pair1 = {key: i}
107115
pair2 = {key: value - i}
108116
new_pair = {**current_pair, **pair1}
109-
pairs.extend(generate_recursive_pairs(new_pair, remaining_values, remaining_keys))
117+
pairs.extend(
118+
generate_recursive_pairs(new_pair, remaining_values, remaining_keys)
119+
)
110120
new_pair = {**current_pair, **pair2}
111-
pairs.extend(generate_recursive_pairs(new_pair, remaining_values, remaining_keys))
121+
pairs.extend(
122+
generate_recursive_pairs(new_pair, remaining_values, remaining_keys)
123+
)
112124

113125
return pairs
114126

115127
all_pairs = generate_recursive_pairs({}, values, keys)
116-
unique_permutations = [dict(y) for y in set(tuple(x.items()) for x in all_pairs)]
128+
unique_permutations = [
129+
dict(y) for y in set(tuple(x.items()) for x in all_pairs)
130+
]
117131
return unique_permutations
118132

119133
unique_perms = generate_pairs(original_dict)
120134
daughter_1 = {}
121135
daughter_2 = {}
122136
count = 0
123137
prime_list = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 31, 37, 41, 43, 47]
124-
elements_prime = dict([(y, prime_list[x]) for x, y in enumerate(sorted(set(list(original_dict.keys()))))])
138+
elements_prime = dict(
139+
[
140+
(y, prime_list[x])
141+
for x, y in enumerate(sorted(set(list(original_dict.keys()))))
142+
]
143+
)
125144

126145
for i in range(len(unique_perms)):
127-
if all(value == 0 for value in unique_perms[i].values()) or unique_perms[i] == original_dict:
146+
if (
147+
all(value == 0 for value in unique_perms[i].values())
148+
or unique_perms[i] == original_dict
149+
):
128150
continue
129151
daughter_1[count] = unique_perms[i]
130-
daughter_2[count] = {key: original_dict[key] - unique_perms[i][key] for key in original_dict.keys()}
152+
daughter_2[count] = {
153+
key: original_dict[key] - unique_perms[i][key]
154+
for key in original_dict.keys()
155+
}
131156
count += 1
132157

133158
sp = []
@@ -186,14 +211,21 @@ def possible_product_triplets(complex_formula, charge):
186211
return product_trip_1, product_trip_2, product_trip_3, ccp
187212

188213

189-
def associate_mass(elements_mass, complex_formula=None, parent_charge=None, product_1=None, product_2=None,
190-
charge_states=None, react_dict=None):
214+
def associate_mass(
215+
elements_mass,
216+
complex_formula=None,
217+
parent_charge=None,
218+
product_1=None,
219+
product_2=None,
220+
charge_states=None,
221+
react_dict=None,
222+
):
191223
if react_dict is not None:
192-
complex_formula = react_dict['parent']
193-
parent_charge = react_dict['cp']
194-
product_1, _ = parse_formula(react_dict['daughter_1'])
195-
product_2, _ = parse_formula(react_dict['daughter_2'])
196-
charge_states = [react_dict['cd1'], react_dict['cd2']]
224+
complex_formula = react_dict["parent"]
225+
parent_charge = react_dict["cp"]
226+
product_1, _ = parse_formula(react_dict["daughter_1"])
227+
product_2, _ = parse_formula(react_dict["daughter_2"])
228+
charge_states = [react_dict["cd1"], react_dict["cd2"]]
197229
mp = 0
198230
ss, _ = parse_formula(complex_formula)
199231
for key, value in ss.items():
@@ -221,8 +253,14 @@ def digitize_track(m1e, m2e, m1d, m2d, h):
221253
def index_values_in_bin(m1, m2, ind, m1e, m2e, bins_along_track):
222254
indices_in_bin = []
223255
for i in range(len(bins_along_track)):
224-
indices_m1 = np.where((m1[ind] >= m1e[bins_along_track[i, 0]]) & (m1[ind] < m1e[bins_along_track[i, 0] + 1]))[0]
225-
indices_m2 = np.where((m2[ind] >= m2e[bins_along_track[i, 1]]) & (m2[ind] < m2e[bins_along_track[i, 1] + 1]))[0]
256+
indices_m1 = np.where(
257+
(m1[ind] >= m1e[bins_along_track[i, 0]])
258+
& (m1[ind] < m1e[bins_along_track[i, 0] + 1])
259+
)[0]
260+
indices_m2 = np.where(
261+
(m2[ind] >= m2e[bins_along_track[i, 1]])
262+
& (m2[ind] < m2e[bins_along_track[i, 1] + 1])
263+
)[0]
226264
if len(np.intersect1d(indices_m1, indices_m2)) != 0:
227265
indices_in_bin.append(np.intersect1d(indices_m1, indices_m2))
228266
indices_in_bin = np.concatenate(indices_in_bin)

notebooks/Fe2O3_possible_reactions.ipynb renamed to correlationHistogramAnalysis/notebooks/Fe2O3_possible_reactions.ipynb

File renamed without changes.

notebooks/Fe3O4_possible_reactions.ipynb renamed to correlationHistogramAnalysis/notebooks/Fe3O4_possible_reactions.ipynb

File renamed without changes.

notebooks/FeO_possible_reactions.ipynb renamed to correlationHistogramAnalysis/notebooks/FeO_possible_reactions.ipynb

File renamed without changes.

0 commit comments

Comments
 (0)