Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oli4 committed Oct 5, 2020
1 parent 72a6a43 commit 8935ab4
Showing 1 changed file with 49 additions and 9 deletions.
58 changes: 49 additions & 9 deletions eyepy/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def estimate_bscan_distance(self):
a = self[-1].StartY - self[0].StartY
b = self[-1].StartX - self[0].StartX
self.meta["Distance"] = np.sqrt(a ** 2 + b ** 2) / (
len(self.bscans) - 1)
len(self) - 1)
return self.Distance

@property
Expand All @@ -485,10 +485,28 @@ def eyepy_id(self):

@property
def shape(self):
return (self.SizeZ, self.SizeX, self.NumBScans)

@property
def SizeZ(self):
try:
return (self.sizeZ, self.SizeX, self.NumBScans)
except AttributeError:
return self[0].shape + (len(self),)
return self.meta["SizeZ"]
except (AttributeError, KeyError, TypeError):
return self[0].scan.shape[0]

@property
def SizeX(self):
try:
return self.meta["SizeX"]
except (AttributeError, KeyError, TypeError):
return self[0].scan.shape[1]

@property
def NumBScans(self):
try:
return self.meta["NumBScans"]
except (AttributeError, KeyError, TypeError):
return len(self)

@property
def enface(self):
Expand Down Expand Up @@ -561,7 +579,7 @@ def drusen(self):
# Try to load the drusen from the default location
try:
self._drusen = np.load(self.drusen_path)
except NotADirectoryError:
except (NotADirectoryError, FileNotFoundError):
self._drusen = self._drusenfinder.filter(self.drusen_raw)
self.drusen_path.parent.mkdir(parents=True, exist_ok=True)
np.save(self.drusen_path, self._drusen)
Expand Down Expand Up @@ -603,6 +621,13 @@ def tform_enface_to_oct(self):
@property
def tform_oct_to_enface(self):
return self.tform_enface_to_oct.inverse

@property
def enface_shape(self):
try:
return self.enface.shape
except:
return (self.SizeX, self.SizeX)

def _estimate_enface_to_oct_tform(self):
oct_projection_shape = (self.NumBScans, self.SizeX)
Expand All @@ -621,7 +646,7 @@ def _estimate_enface_to_oct_tform(self):
self[0].StartY / self.ScaleXSlo, self[0].StartX / self.ScaleYSlo,
self[0].EndY / self.ScaleXSlo, self[0].EndX / self.ScaleYSlo
]).reshape((-1, 2))
except AttributeError():
except AttributeError:
# Map the oct projection to a square area of shape (bscan_width, bscan_width)
warnings.warn(f"Bscan positions on enface image or the scale of the "
f"enface image is missing. We assume that the B-Scans cover "
Expand Down Expand Up @@ -654,7 +679,7 @@ def drusen_enface(self):
""" Drusen projection warped into the enface space """
return transform.warp(self.drusen_projection.astype(float),
self.tform_oct_to_enface,
output_shape=self.enface.shape)
output_shape=self.enface_shape)

@property
def drusenfinder(self):
Expand All @@ -670,7 +695,7 @@ def drusenfinder(self, drusenfinder):
self._drusen_raw = None
self._drusenfinder = drusenfinder

def plot(self, ax=None, slo=True, drusen=False, bscan_region=False,
def plot(self, ax=None, enface=True, drusen=False, bscan_region=False,
bscan_positions=None, masks=False, region=np.s_[...], alpha=1):
"""
Expand All @@ -693,7 +718,7 @@ def plot(self, ax=None, slo=True, drusen=False, bscan_region=False,
if ax is None:
ax = plt.gca()

if slo:
if enface:
self.plot_enface(ax=ax, region=region)
if drusen:
self.plot_drusen(ax=ax, region=region, alpha=alpha)
Expand All @@ -711,6 +736,21 @@ def plot(self, ax=None, slo=True, drusen=False, bscan_region=False,
# self.plot_quantification(space=space, region=region, ax=ax,
# q_kwargs=q_kwargs)

def plot_layer_distance(self, region=np.s_[...], ax=None, top_layer="RPE", bot_layer="BM"):
if ax is None:
ax = plt.gca()

bot = self.layers[bot_layer]
top = self.layers[top_layer]

distance = bot-top
img = transform.warp(distance.astype(float),
self.tform_oct_to_enface,
output_shape=self.enface_shape)
ax.imshow(img[region], cmap="gray")



def plot_masks(self, region=np.s_[...], ax=None, color="r", linewidth=0.5):
"""
Expand Down

0 comments on commit 8935ab4

Please sign in to comment.