Fix imports and apply formatter
This commit is contained in:
parent
7a50f2c8d5
commit
e2f00a3bce
@ -5,3 +5,4 @@ from pyzebra.load_1D import load_1D, parse_1D
|
|||||||
from pyzebra.ccl_findpeaks import ccl_findpeaks
|
from pyzebra.ccl_findpeaks import ccl_findpeaks
|
||||||
from pyzebra.fit2 import fitccl
|
from pyzebra.fit2 import fitccl
|
||||||
from pyzebra.comm_export import export_comm
|
from pyzebra.comm_export import export_comm
|
||||||
|
import pyzebra.ccl_dict_operation
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import uncertainties as u
|
import uncertainties as u
|
||||||
from fitvol2 import create_uncertanities
|
from .fit2 import create_uncertanities
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
|
|
||||||
def add_dict(dict1, dict2):
|
def add_dict(dict1, dict2):
|
||||||
@ -13,48 +12,52 @@ def add_dict(dict1, dict2):
|
|||||||
Note: dict1 must be made from ccl, otherwise we would have to change the structure of loaded
|
Note: dict1 must be made from ccl, otherwise we would have to change the structure of loaded
|
||||||
dat file"""
|
dat file"""
|
||||||
max_measurement_dict1 = max([int(str(keys)[1:]) for keys in dict1["Measurements"]])
|
max_measurement_dict1 = max([int(str(keys)[1:]) for keys in dict1["Measurements"]])
|
||||||
if dict2['meta']['data_type'] == '.ccl':
|
if dict2["meta"]["data_type"] == ".ccl":
|
||||||
new_filenames = ['M' + str(x + max_measurement_dict1) for x in
|
new_filenames = [
|
||||||
[int(str(keys)[1:]) for keys in dict2["Measurements"]]]
|
"M" + str(x + max_measurement_dict1)
|
||||||
new_meta_name = 'meta' + str(dict2["meta"]['original_filename'])
|
for x in [int(str(keys)[1:]) for keys in dict2["Measurements"]]
|
||||||
|
]
|
||||||
|
new_meta_name = "meta" + str(dict2["meta"]["original_filename"])
|
||||||
if new_meta_name not in dict1:
|
if new_meta_name not in dict1:
|
||||||
for keys, name in zip(dict2["Measurements"], new_filenames):
|
for keys, name in zip(dict2["Measurements"], new_filenames):
|
||||||
dict2["Measurements"][keys]['file_of_origin'] = str(dict2["meta"]['original_filename'])
|
dict2["Measurements"][keys]["file_of_origin"] = str(
|
||||||
|
dict2["meta"]["original_filename"]
|
||||||
|
)
|
||||||
dict1["Measurements"][name] = dict2["Measurements"][keys]
|
dict1["Measurements"][name] = dict2["Measurements"][keys]
|
||||||
|
|
||||||
dict1[new_meta_name] = dict2["meta"]
|
dict1[new_meta_name] = dict2["meta"]
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise KeyError(str('The file %s has alredy been added to %s' % (dict2["meta"][
|
raise KeyError(
|
||||||
'original_filename'],
|
str(
|
||||||
dict1["meta"][
|
"The file %s has alredy been added to %s"
|
||||||
'original_filename'])))
|
% (dict2["meta"]["original_filename"], dict1["meta"]["original_filename"])
|
||||||
elif dict2['meta']['data_type'] == '.dat':
|
)
|
||||||
|
)
|
||||||
|
elif dict2["meta"]["data_type"] == ".dat":
|
||||||
d = {}
|
d = {}
|
||||||
new_name = 'M' + str(max_measurement_dict1+1)
|
new_name = "M" + str(max_measurement_dict1 + 1)
|
||||||
hkl = dict2['meta']['title']
|
hkl = dict2["meta"]["title"]
|
||||||
d['h_index'] = float(hkl.split()[-3])
|
d["h_index"] = float(hkl.split()[-3])
|
||||||
d['k_index'] = float(hkl.split()[-2])
|
d["k_index"] = float(hkl.split()[-2])
|
||||||
d['l_index'] = float(hkl.split()[-1])
|
d["l_index"] = float(hkl.split()[-1])
|
||||||
d['number_of_measurements'] = len(dict2['Measurements']['NP'])
|
d["number_of_measurements"] = len(dict2["Measurements"]["NP"])
|
||||||
d['om'] = dict2['Measurements']['om']
|
d["om"] = dict2["Measurements"]["om"]
|
||||||
d['Counts'] = dict2['Measurements']['Counts']
|
d["Counts"] = dict2["Measurements"]["Counts"]
|
||||||
d['monitor'] = dict2['Measurements']['Monitor1'][0]
|
d["monitor"] = dict2["Measurements"]["Monitor1"][0]
|
||||||
d['temperature'] = dict2['meta']['temp']
|
d["temperature"] = dict2["meta"]["temp"]
|
||||||
d['mag_field'] = dict2['meta']['mf']
|
d["mag_field"] = dict2["meta"]["mf"]
|
||||||
d['omega_angle'] = dict2['meta']['omega']
|
d["omega_angle"] = dict2["meta"]["omega"]
|
||||||
dict1["Measurements"][new_name] = d
|
dict1["Measurements"][new_name] = d
|
||||||
print(hkl.split())
|
print(hkl.split())
|
||||||
for keys in d:
|
for keys in d:
|
||||||
print(keys)
|
print(keys)
|
||||||
|
|
||||||
|
print("s")
|
||||||
|
|
||||||
print('s')
|
|
||||||
|
|
||||||
return dict1
|
return dict1
|
||||||
|
|
||||||
|
|
||||||
def auto(dict):
|
def auto(dict):
|
||||||
"""takes just unique tuples from all tuples in dictionary returend by scan_dict
|
"""takes just unique tuples from all tuples in dictionary returend by scan_dict
|
||||||
intendet for automatic merge if you doesent want to specify what scans to merge together
|
intendet for automatic merge if you doesent want to specify what scans to merge together
|
||||||
@ -244,8 +247,10 @@ def merge(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
if dict1 == dict2:
|
if dict1 == dict2:
|
||||||
del dict1["Measurements"][keys[1]]
|
del dict1["Measurements"][keys[1]]
|
||||||
|
|
||||||
note = f'This measurement was merged with measurement {keys[1]} from ' \
|
note = (
|
||||||
|
f"This measurement was merged with measurement {keys[1]} from "
|
||||||
f'file {dict2["meta"]["original_filename"]} \n'
|
f'file {dict2["meta"]["original_filename"]} \n'
|
||||||
|
)
|
||||||
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] = note
|
dict1["Measurements"][str(keys[0])]["notes"] = note
|
||||||
else:
|
else:
|
||||||
@ -255,7 +260,7 @@ def merge(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
dict1["Measurements"][keys[0]]["Counts"] = Counts
|
dict1["Measurements"][keys[0]]["Counts"] = Counts
|
||||||
dict1["Measurements"][keys[0]]["sigma"] = sigma
|
dict1["Measurements"][keys[0]]["sigma"] = sigma
|
||||||
dict1["Measurements"][keys[0]]["monitor"] = monitor
|
dict1["Measurements"][keys[0]]["monitor"] = monitor
|
||||||
print('merging done')
|
print("merging done")
|
||||||
return dict1
|
return dict1
|
||||||
|
|
||||||
|
|
||||||
@ -288,22 +293,20 @@ def substract_measurement(dict1, dict2, keys, auto=True, monitor=100000):
|
|||||||
for k in range(len(res)):
|
for k in range(len(res)):
|
||||||
res_nom = np.append(res_nom, res[k].n)
|
res_nom = np.append(res_nom, res[k].n)
|
||||||
res_err = np.append(res_err, res[k].s)
|
res_err = np.append(res_err, res[k].s)
|
||||||
# plt.plot(res_nom, 'r', label='final')
|
|
||||||
# plt.plot(cor_y1, 'g', label='dict1')
|
|
||||||
# plt.plot(cor_y2, 'b', label='dict2')
|
|
||||||
# plt.legend()
|
|
||||||
# plt.title(str(keys))
|
|
||||||
# plt.show()
|
|
||||||
|
|
||||||
if len([num for num in res_nom if num < 0]) >= 0.3 * len(res_nom):
|
if len([num for num in res_nom if num < 0]) >= 0.3 * len(res_nom):
|
||||||
print(f'Warning! percentage of negative numbers in measurement subsracted {keys[0]} is '
|
print(
|
||||||
f'{len([num for num in res_nom if num < 0]) / len(res_nom)}')
|
f"Warning! percentage of negative numbers in measurement subsracted {keys[0]} is "
|
||||||
|
f"{len([num for num in res_nom if num < 0]) / len(res_nom)}"
|
||||||
|
)
|
||||||
|
|
||||||
dict1["Measurements"][str(keys[0])]["Counts"] = res_nom
|
dict1["Measurements"][str(keys[0])]["Counts"] = res_nom
|
||||||
dict1["Measurements"][str(keys[0])]["sigma"] = res_err
|
dict1["Measurements"][str(keys[0])]["sigma"] = res_err
|
||||||
dict1["Measurements"][str(keys[0])]["monitor"] = monitor
|
dict1["Measurements"][str(keys[0])]["monitor"] = monitor
|
||||||
note = f'Measurement {keys[1]} from file {dict2["meta"]["original_filename"]} ' \
|
note = (
|
||||||
f'was substracted from this measurement \n'
|
f'Measurement {keys[1]} from file {dict2["meta"]["original_filename"]} '
|
||||||
|
f"was substracted from this measurement \n"
|
||||||
|
)
|
||||||
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
if "notes" not in dict1["Measurements"][str(keys[0])]:
|
||||||
dict1["Measurements"][str(keys[0])]["notes"] = note
|
dict1["Measurements"][str(keys[0])]["notes"] = note
|
||||||
else:
|
else:
|
||||||
@ -384,7 +387,7 @@ def compare_dict(dict1, dict2):
|
|||||||
)
|
)
|
||||||
S.append("Different values in Measurements:\n")
|
S.append("Different values in Measurements:\n")
|
||||||
select_set = ["om", "Counts", "sigma"]
|
select_set = ["om", "Counts", "sigma"]
|
||||||
exlude_set = ["time", "Counts", "date", 'notes']
|
exlude_set = ["time", "Counts", "date", "notes"]
|
||||||
for keys1 in comp:
|
for keys1 in comp:
|
||||||
for key2 in dict1["Measurements"][str(comp[str(keys1)][0])]:
|
for key2 in dict1["Measurements"][str(comp[str(keys1)][0])]:
|
||||||
if key2 in exlude_set:
|
if key2 in exlude_set:
|
||||||
@ -420,14 +423,14 @@ def compare_dict(dict1, dict2):
|
|||||||
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
||||||
)
|
)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print('Missing keys, some files were probably merged or substracted')
|
print("Missing keys, some files were probably merged or substracted")
|
||||||
print(e.args)
|
print(e.args)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
comparison = list(dict1["Measurements"][comp[str(keys1)][0]][str(key2)]) == list(
|
comparison = list(
|
||||||
dict2["Measurements"][comp[str(keys1)][1]][str(key2)]
|
dict1["Measurements"][comp[str(keys1)][0]][str(key2)]
|
||||||
)
|
) == list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
||||||
if len(list(dict1["Measurements"][comp[str(keys1)][0]][str(key2)])) != len(
|
if len(list(dict1["Measurements"][comp[str(keys1)][0]][str(key2)])) != len(
|
||||||
list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
list(dict2["Measurements"][comp[str(keys1)][1]][str(key2)])
|
||||||
):
|
):
|
||||||
@ -465,7 +468,7 @@ def compare_dict(dict1, dict2):
|
|||||||
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
conflicts[key2]["measurements"] + " " + (str(comp[str(keys1)]))
|
||||||
)
|
)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
print('Missing keys, some files were probably merged or substracted')
|
print("Missing keys, some files were probably merged or substracted")
|
||||||
print(e.args)
|
print(e.args)
|
||||||
|
|
||||||
for keys in conflicts:
|
for keys in conflicts:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user