Skip to content

Commit

Permalink
Bugs fix (#88)
Browse files Browse the repository at this point in the history
* Change importing format to comply with develop mode

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Solve that curtain could not dynamically render

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Select box correctly when not inverting y-axis

* local testing

* y-axis testing

* Y-axis testing

* add options for echogram

* del testing files

* add options

* set y-axis inversion

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* 06/06/2023 - testing

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ldr426 and pre-commit-ci[bot] authored Jun 7, 2023
1 parent 3031dcd commit 55e46f0
Show file tree
Hide file tree
Showing 7 changed files with 1,270 additions and 26 deletions.
20 changes: 13 additions & 7 deletions echoshader/echogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def __init__(self, MVBS_ds):
self.upper_time = pandas.to_datetime(self.MVBS_ds.ping_time.data[-1])

# http://holoviews.org/user_guide/Applying_Customizations.html
self.gram_opts = holoviews.opts(invert_yaxis=True)
self.gram_opts = holoviews.opts(
invert_yaxis=False, tools=["hover", "box_select"]
)

self.bound_opts = holoviews.opts(line_width=1.5, line_color="white")

Expand Down Expand Up @@ -301,9 +303,9 @@ def view_gram(self):
source=self.gram,
bounds=(
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[0],
self.MVBS_ds.echo_range.values[-1],
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[-1],
self.MVBS_ds.echo_range.values[0],
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[-1],
self.MVBS_ds.echo_range.values[-1],
),
)

Expand Down Expand Up @@ -394,9 +396,9 @@ def view_all_gram(self):
source=self.all_gram[0],
bounds=(
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[0],
self.MVBS_ds.echo_range.values[-1],
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[-1],
self.MVBS_ds.echo_range.values[0],
self.MVBS_ds.sel(ping_time=time_range).ping_time.values[-1],
self.MVBS_ds.echo_range.values[-1],
),
)

Expand All @@ -419,7 +421,9 @@ def get_box_data(self):
return self.MVBS_ds.sel(
channel=self.channel_select.value,
ping_time=slice(self.box.bounds[0], self.box.bounds[2]),
echo_range=slice(self.box.bounds[3], self.box.bounds[1]),
echo_range=slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1]),
)

def get_all_box_data(self):
Expand All @@ -432,7 +436,9 @@ def get_all_box_data(self):
"""
return self.MVBS_ds.sel(
ping_time=slice(self.box.bounds[0], self.box.bounds[2]),
echo_range=slice(self.box.bounds[3], self.box.bounds[1]),
echo_range=slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1]),
)


Expand Down
23 changes: 12 additions & 11 deletions echoshader/echomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import pandas
import panel
import param

from .curtain import plot_curtain
from .echogram import Echogram
from curtain import plot_curtain
from echogram import Echogram


def plot_track(
Expand Down Expand Up @@ -402,7 +401,11 @@ def view_curtain(self):

time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

channel = self.channel_select.value

Expand All @@ -421,13 +424,11 @@ def view_curtain(self):
ratio=ratio,
)

curtain_panel = panel.Row(
panel.panel(
self.curtain.ren_win,
height=self.curtain_height,
width=self.curtain_width,
orientation_widget=True,
)
curtain_panel = panel.panel(
self.curtain.ren_win,
height=self.curtain_height,
width=self.curtain_width,
orientation_widget=True,
)

return curtain_panel
39 changes: 31 additions & 8 deletions echoshader/echostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pandas
import panel
import param

from .echogram import Echogram
from echogram import Echogram


def simple_hist(echogram):
Expand Down Expand Up @@ -254,7 +253,11 @@ def view_table(self):
"""
time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

channel = self.channel_select.value

Expand Down Expand Up @@ -287,7 +290,11 @@ def view_hist(self):

time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

channel = self.channel_select.value

Expand All @@ -312,7 +319,11 @@ def view_all_table(self):
"""
time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

# Apply current ranges
obj_df = self.MVBS_ds.sel(
Expand Down Expand Up @@ -366,7 +377,11 @@ def view_sum_hist(self):

time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

# Apply current ranges
obj_df = self.MVBS_ds.sel(
Expand All @@ -389,7 +404,11 @@ def view_overlay_hist(self):
"""
time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

return (
self.MVBS_ds.sel(ping_time=time_range, echo_range=echo_range)
Expand All @@ -416,7 +435,11 @@ def view_layout_hist(self):
"""
time_range = slice(self.box.bounds[0], self.box.bounds[2])

echo_range = slice(self.box.bounds[3], self.box.bounds[1])
echo_range = (
slice(self.box.bounds[1], self.box.bounds[3])
if self.box.bounds[3] > self.box.bounds[1]
else slice(self.box.bounds[3], self.box.bounds[1])
)

return (
self.MVBS_ds.sel(ping_time=time_range, echo_range=echo_range)
Expand Down
14 changes: 14 additions & 0 deletions echoshader/new_version/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pkg_resources import DistributionNotFound, get_distribution

try:
VERSION = get_distribution(__name__).version
except DistributionNotFound: # pragma: no cover
try:
from .version import version as VERSION # noqa
except ImportError: # pragma: no cover
raise ImportError(
"Failed to find (autogenerated) version.py. "
"This might be because you are installing from GitHub's tarballs, "
"use the PyPI ones."
)
__version__ = VERSION
Binary file added echoshader/new_version/concatenated_MVBS.nc
Binary file not shown.
83 changes: 83 additions & 0 deletions echoshader/new_version/echogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Dict, Union

import holoviews
import panel
import param
import xarray


@xarray.register_dataset_accessor("eshader")
class Echogram(param.Parameterized):
def __init__(self, MVBS_ds):
super().__init__()

self.MVBS_ds = MVBS_ds

self.gram_opts = {
"Image": {
"cmap": "jet",
"colorbar": True,
"cmap": "jet",
"tools": ["box_select", "lasso_select", "hover"],
"invert_yaxis": False,
"width": 600,
}
}

def echogram(
self,
cmap: str = "jet",
layout: Union[
str("single_frequency"), str("multiple_frequency"), str("composite")
] = "single_frequency",
vmin: float = None,
vmax: float = None,
rgb_map: Dict[str, str] = None,
*args,
**kwargs
):
if vmin == None:
vmin = self.MVBS_ds.Sv.actual_range[0]

if vmax == None:
vmax = self.MVBS_ds.Sv.actual_range[-1]

self.gram_opts["Image"]["clim"] = (vmin, vmax)
self.gram_opts["Image"]["cmap"] = cmap

if layout == "single_frequency":
tabs = panel.Tabs()

for index, channel in enumerate(self.MVBS_ds.channel.values):
plot = (
holoviews.Dataset(self.MVBS_ds.sel(channel=channel))
.to(
holoviews.Image, vdims=["Sv"], kdims=["ping_time", "echo_range"]
)
.opts(self.gram_opts)
)
tab = panel.Column(panel.pane.Markdown("## " + channel), plot)
tabs.append(("channel" + " " + str(index + 1), tab))

return tabs

elif layout == "multiple_frequency":
col = panel.Column()

for index, channel in enumerate(self.MVBS_ds.channel.values):
plot = (
holoviews.Dataset(self.MVBS_ds.sel(channel=channel))
.to(
holoviews.Image, vdims=["Sv"], kdims=["ping_time", "echo_range"]
)
.opts(self.gram_opts)
)

col.append(panel.pane.Markdown("## " + channel))
col.append(plot)

return col

elif layout == "composite":
if rgb_map == None:
pass
1,117 changes: 1,117 additions & 0 deletions echoshader/new_version/test.ipynb

Large diffs are not rendered by default.

0 comments on commit 55e46f0

Please sign in to comment.