Skip to content

Commit

Permalink
Refactor: Black-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CSSFrancis committed Nov 13, 2023
1 parent af3c108 commit c379dc4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
93 changes: 52 additions & 41 deletions rsciio/mrc/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,32 @@ def read_de_metadata_file(filename):
y = int(original_metadata["Scan - Size Y"])
pr = int(original_metadata["Scan - Point Repeat"])


shape = np.array([pr, x, y, r]) # reverse order to what they are read
shape = np.array([pr, x, y, r]) # reverse order to what they are read
axes = []
axes_names = ["repeats", "x", "y", "repeats",][::-1]
axes_names = [
"repeats",
"x",
"y",
"repeats",
][::-1]
axes_units = ["times", "nm", "nm", "s"][::-1]
axes_scales = [1,
original_metadata["Specimen Pixel Size X (nanometers)"],
original_metadata["Specimen Pixel Size Y (nanometers)"],
original_metadata["Scan - Time (seconds)"] +
original_metadata["Scan - Repeat Delay (seconds)"]][::-1]
axes_scales = [
1,
original_metadata["Specimen Pixel Size X (nanometers)"],
original_metadata["Specimen Pixel Size Y (nanometers)"],
original_metadata["Scan - Time (seconds)"]
+ original_metadata["Scan - Repeat Delay (seconds)"],
][::-1]
for i, s in enumerate(shape[::-1]):
ind = 0
if s != 1:
axes_dict = {"name": axes_names[i],
"size": s,
"units": axes_units[i],
"navigate": True,
"index_in_array": ind
}
axes_dict = {
"name": axes_names[i],
"size": s,
"units": axes_units[i],
"navigate": True,
"index_in_array": ind,
}
if axes_scales[i] != -1: # -1 means that the scale is not defined
axes_dict["scale"] = axes_scales[i]
else:
Expand All @@ -203,22 +210,20 @@ def read_de_metadata_file(filename):
timestamp = original_metadata.get("Timestamp (seconds since Epoch)", None)
fps = original_metadata.get("Frames Per Second", None)

metadata = {"Acquisition_instrument":
{"TEM":
{"magnificiation": magnification,
"detector": camera_model,
"frames_per_second": fps
}
},
"Signal":
{"Noise_properties":
{"gain_factor": 1/electron_gain},
"quantity": "$e^-$",
},
"General":
{"timestamp": timestamp}

}
metadata = {
"Acquisition_instrument": {
"TEM": {
"magnificiation": magnification,
"detector": camera_model,
"frames_per_second": fps,
}
},
"Signal": {
"Noise_properties": {"gain_factor": 1 / electron_gain},
"quantity": "$e^-$",
},
"General": {"timestamp": timestamp},
}

shape = shape[shape != 1] # removing the 1s from the dataset

Expand Down Expand Up @@ -251,13 +256,18 @@ def file_reader(
"""

if metadata_file is not None:
de_metadata, metadata, navigation_axes, _navigation_shape = read_de_metadata_file(metadata_file)
(
de_metadata,
metadata,
navigation_axes,
_navigation_shape,
) = read_de_metadata_file(metadata_file)
if navigation_shape is None:
navigation_shape = _navigation_shape
original_metadata = {"de_metadata": de_metadata}
else:
original_metadata = {}
metadata = {"General":{}, "Signal":{}}
metadata = {"General": {}, "Signal": {}}
navigation_axes = None
metadata["General"]["original_filename"] = os.path.split(filename)[1]
metadata["Signal"]["signal_type"] = ""
Expand Down Expand Up @@ -351,7 +361,6 @@ def file_reader(
] * 3

if navigation_axes is None:

units = [None, "nm", "nm"]
names = ["z", "y", "x"]
navigate = [True, False, False]
Expand Down Expand Up @@ -381,15 +390,17 @@ def file_reader(
]
else:
axes = navigation_axes
if len(axes) != len(data.shape): # Add in final two axes
if len(axes) != len(data.shape): # Add in final two axes
names = ["$k_x$", "$k_y$"]
for i,s in enumerate(data.shape[-2:]):
ax = {"size": s,
"name": names[i],
"scale": 1, # TODO: Add scale when reciporical space is added
"offset": 0,
"units": "nm$^-1$",
"navigate": False}
for i, s in enumerate(data.shape[-2:]):
ax = {
"size": s,
"name": names[i],
"scale": 1, # TODO: Add scale when reciporical space is added
"offset": 0,
"units": "nm$^-1$",
"navigate": False,
}
axes.append(ax)

dictionary = {
Expand Down
3 changes: 1 addition & 2 deletions rsciio/tests/test_mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_mrc_chunks_equal(distributed):
(256,),
)


@pytest.mark.parametrize("navigation_shape", [None, (8, 32)])
def test_mrc_metadata(navigation_shape):
s = hs.load(
Expand All @@ -119,5 +120,3 @@ def test_mrc_metadata(navigation_shape):
assert s.metadata.Acquisition_instrument.TEM.detector == "CeleritasXS"
assert s.metadata.Acquisition_instrument.TEM.magnificiation == "1000"
assert s.metadata.Acquisition_instrument.TEM.frames_per_second == "40000"


0 comments on commit c379dc4

Please sign in to comment.