Added method LeftRightBottomTop to ROI

This commit is contained in:
2022-08-27 21:23:57 +02:00
parent 3de4db9415
commit a75fba93fd
2 changed files with 20 additions and 10 deletions

View File

@@ -188,20 +188,23 @@ def plot_image_channel(data, channel_name, pulse=0, ax=None, rois=None, norms=No
axis_styling(ax, channel_name, description)
plt.legend(loc=4)
def plot_spectrum_channel(data, channel_name_x, channel_name_y, ax=None):
def plot_spectrum_channel(data, channel_name_x, channel_name_y, average=True, frame=0, ax=None):
"""
Plots channel data for two channels where the first is taken as the (constant) x-axis
and the second as the y-axis (here we take the mean over the individual pulses).
and the second as the y-axis (here we take by default the mean over the individual pulses).
"""
try:
mean, std = np.mean(data[channel_name_y].data), np.std(data[channel_name_y].data)
# data[channel_name].data
mean_over_frames = np.mean(data[channel_name_y].data, axis=0)
except TypeError:
print(f"Unknown data in channel {channel_name_y}.")
return
y_data = mean_over_frames
if average:
y_data = mean_over_frames
else:
y_data = data[channel_name_y].data[frame]
if ax is None:
fig, ax = plt.subplots(constrained_layout=True)

View File

@@ -92,6 +92,9 @@ class ROI:
@property
def rows(self):
return slice(self.bottom, self.top)
@property
def LeftRightBottomTop(self):
return [self.left, self.right, self.bottom, self.top]
@property
def cols(self):
@@ -106,7 +109,7 @@ class ROI:
return self.top - self.bottom
def __repr__(self):
return f"ROI(bottom={self.bottom}, top={self.top}, left={self.left}, right={self.right})"
return f"ROI(bottom={self.bottom},top={self.top},left={self.left},right={self.right})"
def __eq__(self, other):
# we disregard the name
@@ -118,12 +121,16 @@ class ROI:
######################## Setting up paths ########################
def heuristic_extract_pgroup():
""" The function tries to guess the current p-group from the directory name."""
cwd = os.getcwd()
if "/p" in cwd:
def heuristic_extract_pgroup(path=None):
""" The function tries to guess the current p-group from the
current working directory (default) or the contents of
the given path.
"""
path = path or os.getcwd()
if "/p" in path:
# Cut the string and look at the next five letters after /p
p_number = cwd.partition("/p")[2][:5]
p_number = path.partition("/p")[2][:5]
if not p_number.isdigit():
raise KeyError("Automatic p-group extraction from the current working directory didn't work.")