Skip to content

Commit

Permalink
Deploying to gh-pages from @ c23264b 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin committed Apr 25, 2024
1 parent 09b53cf commit be19681
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 0 deletions.
15 changes: 15 additions & 0 deletions asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files": {
"main.css": "/static/css/main.64a8db64.css",
"main.js": "/static/js/main.e51fcf55.js",
"static/js/453.97f7d3b1.chunk.js": "/static/js/453.97f7d3b1.chunk.js",
"index.html": "/index.html",
"main.64a8db64.css.map": "/static/css/main.64a8db64.css.map",
"main.e51fcf55.js.map": "/static/js/main.e51fcf55.js.map",
"453.97f7d3b1.chunk.js.map": "/static/js/453.97f7d3b1.chunk.js.map"
},
"entrypoints": [
"static/css/main.64a8db64.css",
"static/js/main.e51fcf55.js"
]
}
184 changes: 184 additions & 0 deletions basic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Interactive Template Visualization</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
#loader {
text-align: center;
padding: 20px;
display: none;
}
</style>
</head>
<body>
<div id="plots-container"></div>
<div id="loader">Loading...</div>

<script type="module">
import * as zarr from "https://cdn.skypack.dev/[email protected]";

let unit_index = 0; // Keep track of the current template index
let isLoading = false; // Flag to prevent multiple simultaneous loads
const templatesToLoad = 5; // Number of templates to load per batch
let selectedUnitIndices = []; // Initialize outside of loadData function

async function loadData() {
if (isLoading) return;
isLoading = true;
document.getElementById("loader").style.display = "block";

const s3Url = "https://spikeinterface-template-database.s3.us-east-2.amazonaws.com/test_templates";
const fetchOptions = { redirect: "follow" };
const store = new zarr.HTTPStore(s3Url, fetchOptions);

try {
const zarr_group = await zarr.openGroup(store);
const probe_group = await zarr.openGroup(store, "probe", "r");
const template_array = await zarr_group.getItem("templates_array");
const attributes = await zarr_group.attrs.asObject();
const samplingFrequency = attributes["sampling_frequency"];

for (let i = 0; i < templatesToLoad; i++, unit_index++) {
const single_template = await template_array.get([unit_index, null, null]);
const bestChannel = calculateBestChannel(single_template);
// get x and y
const x = await probe_group.getItem("x");
const y = await probe_group.getItem("y");
const xData = await x.get(null);
const yData = await y.get(null);

const single_template_best_channel = await single_template.get([null, bestChannel]);
renderPlot(single_template_best_channel, unit_index, bestChannel, xData, yData);
}
} catch (error) {
console.error("Error loading data:", error);
} finally {
isLoading = false;
document.getElementById("loader").style.display = "none";
}
}

function calculateBestChannel(single_template) {
// Placeholder for your logic to calculate the best channel
// This function needs to be implemented based on your existing logic
const numberOfChannels = single_template.shape[1];
const peak_to_peak_values = new Array(numberOfChannels).fill(0).map((_, channelIndex) => {
let channelMax = -Infinity;
let channelMin = Infinity;
single_template.data.forEach((sample) => {
const value = sample[channelIndex];
if (value > channelMax) channelMax = value;
if (value < channelMin) channelMin = value;
});
return channelMax - channelMin;
});
return peak_to_peak_values.indexOf(Math.max(...peak_to_peak_values));
}

function renderPlot(single_template_best_channel, templateIndex, bestChannel, xData, yData) {
const plotDiv = document.createElement("div");
const plotId = `plot-${templateIndex}`;
plotDiv.id = plotId;
document.getElementById("plots-container").appendChild(plotDiv);

// Get the location for the best channel
const locationX = xData.data[bestChannel];
const locationY = yData.data[bestChannel];

const figure = {
data: [
{
x: Array.from({ length: single_template_best_channel.shape[0] }, (_, i) => i),
y: single_template_best_channel.data,
type: "scatter",
xaxis: "x1",
yaxis: "y1",
name: "Template Data", // Optional, but useful for clarity
showlegend: false, // Optionally remove legend for individual traces
},
{
x: xData.data,
y: yData.data,
mode: "markers",
type: "scatter",
marker: { color: "orange" },
xaxis: "x2",
yaxis: "y2",
name: "XY Data", // Optional
showlegend: false,
},
{
x: [locationX],
y: [locationY],
mode: "markers",
type: "scatter",
marker: { color: "red", size: 25 },
xaxis: "x2",
yaxis: "y2",
name: "Best Channel", // Optional
showlegend: false,
},
],
layout: {
title: `Template for unit index: ${unit_index} - on channel with index: ${bestChannel} - at location: (${locationX}, ${locationY})`,
grid: { rows: 1, columns: 2, pattern: "independent" },
xaxis1: { title: "Time (samples)" },
yaxis1: { title: "Amplitude (uV)" },
xaxis2: {
title: "X Location",
range: [Math.min(...xData.data) - 5, Math.max(...xData.data) + 5],
},
yaxis2: {
title: "Y Location",
anchor: "x2",
scale: 1.0,
},
annotations: [
{
x: locationX,
y: locationY,
xref: "x2",
yref: "y2",
text: "Unit Location",
showarrow: true,
arrowhead: 2,
ax: 30,
ay: 30,
},
],
showlegend: false, // This will apply globally to all traces
},
};

Plotly.newPlot(plotId, figure.data, figure.layout);
// Create and append the checkbox for selecting the unit
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.id = `checkbox-${templateIndex}`;
checkbox.className = "plot-selection-checkbox";
checkbox.onchange = function () {
if (this.checked) {
selectedUnitIndices.push(templateIndex);
} else {
const index = selectedUnitIndices.indexOf(templateIndex);
if (index > -1) {
selectedUnitIndices.splice(index, 1);
}
}
console.log("Selected templates:", selectedUnitIndices);
};
plotDiv.appendChild(checkbox);
}

window.onscroll = function () {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 100) {
loadData();
}
};

loadData(); // Initial load
</script>
</body>
</html>
Binary file added favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,initial-scale=1"><title>Visualization of Templates Data Base</title><script defer="defer" src="/static/js/main.e51fcf55.js"></script><link href="/static/css/main.64a8db64.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
Binary file added logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
2 changes: 2 additions & 0 deletions static/css/main.64a8db64.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/css/main.64a8db64.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions static/js/453.97f7d3b1.chunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit be19681

Please sign in to comment.