Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds demo for plotting sensors #79

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 98 additions & 19 deletions demos/demo_plotting.ipynb

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion kymata/datasets/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional
from urllib import request

from kymata.entities.expression import HexelExpressionSet
from kymata.entities.expression import HexelExpressionSet, SensorExpressionSet
from kymata.io.file import path_type
from kymata.io.nkg import load_expression_set

Expand Down Expand Up @@ -121,6 +121,24 @@ def to_expressionset(self) -> HexelExpressionSet:
assert isinstance(es, HexelExpressionSet)
return es

class TVLDeltaInsTC1LoudnessOnlySensorsDataset(SampleDataset):
def __init__(self, data_root: Optional[path_type] = None, download: bool = True):
name = "TVL_2020_delta_ins_tontop_chan1_loudness_only_sensors"
super().__init__(
name=name,
filenames=[
"TVL_2020_delta_ins_tontop_chan1_loudness_only_sensors.nkg"
],
data_root=data_root,
remote_root="https://kymata.org/assets_kymata_toolbox_tutorial_data/gridsearch-result-data/",
download=download,
)

def to_expressionset(self) -> SensorExpressionSet:
es = load_expression_set(from_path_or_file=Path(self.path, self.filenames[0]))
assert isinstance(es, SensorExpressionSet)
return es


def data_root_path(data_root: Optional[path_type] = None) -> Path:

Expand Down
5 changes: 4 additions & 1 deletion kymata/plot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def expression_plot(
custom_handles.extend([Line2D([], [], marker='.', color=color[function], linestyle='None')])
custom_labels.append(function)

if not paired_axes and isinstance(expression_set, SensorExpressionSet):
# We have a special case with paired sensor data, in that some sensors need to appear
# on both sides of the midline.
if paired_axes and isinstance(expression_set, SensorExpressionSet):
assign_left_right_channels = _left_right_sensors
# Some points will be plotted on one axis, filled, some on both, empty
top_chans = set(assign_left_right_channels[0].axis_channels)
Expand Down Expand Up @@ -189,6 +191,7 @@ def expression_plot(
data_x_max = max(data_x_max, x_max)
data_y_min = min(data_y_min, y_min)

# With non-sensor data, or non-paired axes, we can treat these cases together
else:
# As normal, plot appropriate filled points in each axis
for ax, best_funs_this_ax in zip(axes, best_functions):
Expand Down