Fix KeyError if 'mf' or 'temp' not in data

This commit is contained in:
usov_i 2024-06-04 14:13:37 +02:00
parent 144b37ba09
commit 58a704764a

View File

@ -147,6 +147,8 @@ def read_detector_data(filepath, cami_meta=None):
# optional parameters # optional parameters
if "/entry1/sample/magnetic_field" in h5f: if "/entry1/sample/magnetic_field" in h5f:
scan["mf"] = h5f["/entry1/sample/magnetic_field"][:] scan["mf"] = h5f["/entry1/sample/magnetic_field"][:]
if "mf" in scan:
# TODO: NaNs are not JSON compliant, so replace them with None # TODO: NaNs are not JSON compliant, so replace them with None
# this is not a great solution, but makes it safe to use the array in bokeh # this is not a great solution, but makes it safe to use the array in bokeh
scan["mf"] = np.where(np.isnan(scan["mf"]), None, scan["mf"]) scan["mf"] = np.where(np.isnan(scan["mf"]), None, scan["mf"])
@ -155,6 +157,8 @@ def read_detector_data(filepath, cami_meta=None):
scan["temp"] = h5f["/entry1/sample/temperature"][:] scan["temp"] = h5f["/entry1/sample/temperature"][:]
elif "/entry1/sample/Ts/value" in h5f: elif "/entry1/sample/Ts/value" in h5f:
scan["temp"] = h5f["/entry1/sample/Ts/value"][:] scan["temp"] = h5f["/entry1/sample/Ts/value"][:]
if "temp" in scan:
# TODO: NaNs are not JSON compliant, so replace them with None # TODO: NaNs are not JSON compliant, so replace them with None
# this is not a great solution, but makes it safe to use the array in bokeh # this is not a great solution, but makes it safe to use the array in bokeh
scan["temp"] = np.where(np.isnan(scan["temp"]), None, scan["temp"]) scan["temp"] = np.where(np.isnan(scan["temp"]), None, scan["temp"])