Skip to content

Commit d2851df

Browse files
adding docs and fixing bugs
1 parent ef893ef commit d2851df

7 files changed

Lines changed: 33 additions & 24 deletions

File tree

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
Rastermap is a discovry algorithm for neural data. The algorithm was written by
1717
Carsen Stringer and Marius Pachitariu. To learn about Rastermap, read the [paper]() or watch the [talk](). For support, please open an [issue](https://github.com/MouseLand/rastermap/issues). Please see install instructions [below](README.md/#Installation).
1818

19-
Rastermap runs in python 3.8+ and has a graphical user interface (GUI) for running it easily. Rastermap can also be run in a jupyter notebook locally or on google colab:
19+
Rastermap runs in python 3.8+ and has a graphical user interface (GUI) for running it easily. Rastermap can also be run in a jupyter notebook locally or on google colab, see these demos:
2020
* [rastermap_largescale.ipynb](notebooks/rastermap_largescale.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/rastermap_largescale.ipynb) shows how to use it with large-scale data from mouse cortex (> 200 neurons)
2121
* [rastermap_singleneurons.ipynb](notebooks/rastermap_singleneurons.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/rastermap_singleneurons.ipynb) shows how to use it with small to medium sized data (< 200 neurons), in this case recorded from rat hippocampus
2222
* [rastermap_zebrafish.ipynb](notebooks/rastermap_zebrafish.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/rastermap_zebrafish.ipynb) shows how to use it with large-scale data from zebrafish
2323
* [rastermap_widefield.ipynb](notebooks/rastermap_widefield.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/rastermap_widefield.ipynb) shows how to use it with widefield imaging data, or other types of datasets that are too large to fit into memory
2424
* [tutorial.ipynb](notebooks/tutorial.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/MouseLand/rastermap/blob/main/notebooks/tutorial.ipynb) is a guided tutorial for integrating rastermap and facemap to visualize behavioral representations
2525

26+
**all demo data available [here](https://osf.io/xn4cm/)**
27+
2628
Here is what the output looks like for a segment of a mesoscope recording in a mouse during spontaneous activity (3.2Hz sampling rate), compared to random neural sorting:
2729

2830
<img src="https://www.suite2p.org/static/images/rastermap_spont.png" width="800" alt="random sorting and rastermap sorting of spontaneous activity"/>
@@ -86,7 +88,7 @@ The quickest way to start is to open the GUI from a command line terminal. You m
8688
python -m rastermap
8789
~~~
8890

89-
To start using the GUI, save your data into an npy file that is just a matrix that is neurons x timepoints. Then "File > Load data matrix" and choose this file. Next click "Run > Run rastermap" and click run. See the parameters section to learn about the parameters.
91+
To start using the GUI, save your data into an npy file that is just a matrix that is neurons x timepoints. Then "File > Load data matrix" and choose this file (or drag and drop your file). Next click "Run > Run rastermap" and click run. See the parameters section to learn about the parameters.
9092

9193
The GUI will start with a highlighted region that you can drag to visualize the average activity of neurons in a given part of the plot. To draw more regions, you right-click to start a region, then right-click to end it. The neurons' activity traces then show up on the botton of the GUI, and if the neuron positions are loaded, you will see them colored by the region color. You can delete a region by holding CTRL and clicking on it. You can save the ROIs you've drawn with the "Save > Save processed data" button. They will save along with the embedding so you can reload the file with the "Load processed data" option.
9294

@@ -230,8 +232,8 @@ Here is the list of all variables assigned from `fit`:
230232

231233
* **embedding** : array, shape (n_samples, 1)
232234
embedding of each neuron / voxel
233-
* **isort** : sorting along first dimension of input matrix
234-
use this to get neuron / voxel sorting
235+
* **isort** : array, shape (n_samples,)
236+
sorting along first dimension of input matrix - use this to get neuron / voxel sorting
235237
* **igood** : array, shape (n_samples, 1)
236238
neurons/voxels which had non-zero activity and were used for sorting
237239
* **Usv** : array, shape (n_samples, n_PCs)
@@ -253,6 +255,20 @@ Here is the list of all variables assigned from `fit`:
253255
* **X_embedding** : array, shape (n_samples//bin_size, n_features)
254256
normalized data binned across samples (if compute_X_embedding is True)
255257

258+
The output from the GUI and the command line is a file that ends with `_embedding.npy`. This file contains:
259+
* **filename**: str,
260+
path to file that rastermap was run on
261+
* **save_path**: str,
262+
folder with filename
263+
* **embedding** : array, shape (n_samples, 1)
264+
embedding of each neuron / voxel
265+
* **isort** : array, shape (n_samples,)
266+
sorting along first dimension of input matrix - use this to get neuron / voxel sorting
267+
* **user_clusters**: list,
268+
list of user drawn clusters in GUI
269+
* **ops**: dict,
270+
dictionary of options used to run rastermap
271+
256272

257273
# License
258274

rastermap/__main__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@
6262
model.fit(data=X, Usv=Usv, Vsv=Vsv)
6363

6464
proc = {
65-
"embedding": model.embedding,
65+
"filename": args.S,
66+
"save_path": os.path.split(args.S)[0],
6667
"isort": model.isort,
67-
"Usv": model.Usv,
68-
"Vsv": model.Vsv,
69-
"sv": model.sv,
68+
"embedding": model.embedding,
69+
"user_clusters": None,
7070
"ops": ops,
71-
"filename": args.S,
72-
"train_time": train_time
7371
}
7472
basename, fname = os.path.split(args.S)
7573
fname = os.path.splitext(fname)[0]

rastermap/gui/gui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ def sat_changed(self):
229229
self.show()
230230

231231
def reset(self):
232-
self.run_embedding_button.setEnabled(False)
233232
self.p1.clear()
234233
self.p2.clear()
235234
self.p3.clear()
@@ -461,7 +460,7 @@ def smooth_activity(self):
461460
self.sp_smoothed = np.maximum(-2, np.minimum(5, self.sp_smoothed)) + 2
462461
self.sp_smoothed /= 7
463462
else:
464-
self.sp_smoothed = self.sp.copy()
463+
self.sp_smoothed = self.sp[self.sorting].copy()
465464
self.nsmooth = self.sp_smoothed.shape[0]
466465
yr0 = min(4, self.nsmooth // 4)
467466
ym = self.nsmooth // 2
@@ -475,6 +474,8 @@ def smooth_activity(self):
475474
self.get_behav_corr() if self.behav_data else None
476475
if self.neuron_pos is not None or self.behav_data is not None:
477476
self.update_scatter(init=True)
477+
elif self.neuron_pos is None and self.scatter_comboBox.currentIndex()==0:
478+
self.p5.clear()
478479
self.p2.show()
479480
self.p3.show()
480481

@@ -558,7 +559,6 @@ def update_scatter(self, init=False, roi_id=None):
558559
self.p5.invertY(False)
559560
request = self.scatter_comboBox.currentIndex()
560561
if request > 0:
561-
562562
self.plot_behav_corr(roi_id=roi_id, init=init)
563563
else:
564564
self.plot_neuron_pos(roi_id=roi_id, init=init)

rastermap/gui/io.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from ..io import _load_iscell, _load_stat, load_activity
1313

1414
def _load_activity_gui(parent, X, Usv, Vsv, xy):
15-
1615
igood = None
1716
if X is not None:
1817
parent.update_status_bar(
@@ -45,8 +44,7 @@ def _load_activity_gui(parent, X, Usv, Vsv, xy):
4544
else:
4645
raise ValueError("file missing keys / data")
4746

48-
if xy is not None:
49-
parent.neuron_pos = xy if igood is None else xy[igood]
47+
parent.neuron_pos = xy if igood is None else xy[igood]
5048

5149
parent.n_samples = (parent.sp.shape[0] if parent.sp is not None
5250
else parent.Usv.shape[0])
@@ -67,10 +65,8 @@ def load_mat(parent, name=None):
6765
name = QFileDialog.getOpenFileName(parent, "Open *.npy, *.npz, *.nwb or *.mat",
6866
filter="*.npy *.npz *.mat *.nwb")
6967
parent.fname = name[0]
70-
parent.filebase = name[0]
7168
else:
7269
parent.fname = name
73-
parent.filebase = name
7470

7571
X, Usv, Vsv, xy = load_activity(parent.fname)
7672
_load_activity_gui(parent, X, Usv, Vsv, xy)
@@ -416,7 +412,7 @@ def save_proc(parent): # Save embedding output
416412
parent, "Choose save folder")
417413
parent.save_path = folderName
418414
if parent.save_path:
419-
filename = parent.fname.split("/")[-1]
415+
filename = os.path.split(parent.fname)[-1]
420416
filename, ext = os.path.splitext(filename)
421417
savename = os.path.join(parent.save_path,
422418
("%s_embedding.npy" % filename))
@@ -439,7 +435,6 @@ def save_proc(parent): # Save embedding output
439435
"save_path": parent.save_path,
440436
"isort": parent.sorting,
441437
"embedding": parent.embedding,
442-
"Usv": parent.U,
443438
"user_clusters": user_clusters,
444439
"ops": ops
445440
}

rastermap/gui/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_RMAP(self, parent):
8282
ops_path = os.path.join(os.getcwd(), "rmap_ops.npy")
8383
np.save(ops_path, self.ops)
8484
print("Running rastermap with command:")
85-
cmd = f"-u -W ignore -m rastermap --ops {ops_path} --S {parent.filebase}"
85+
cmd = f"-u -W ignore -m rastermap --ops {ops_path} --S {parent.fname}"
8686
if parent.file_iscell is not None:
8787
cmd += f"--iscell {parent.file_iscell}"
8888
print("python " + cmd)

rastermap/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _load_dict(dat, keys):
6565
raise ValueError("Vsv must have 2 dimensions")
6666

6767
if xpos is not None and xy is None:
68-
xy = np.stack((xpos, ypos), axis=1)
68+
xy = np.stack((ypos, xpos), axis=1)
6969

7070
if xy is not None:
7171
if xy.ndim != 2:
@@ -76,7 +76,7 @@ def _load_dict(dat, keys):
7676
if xy is not None:
7777
if X is not None and X.shape[0]!=xy.shape[0]:
7878
xy = None
79-
elif Usv.shape[0]!=xy.shape[0]:
79+
elif Usv is not None and Usv.shape[0]!=xy.shape[0]:
8080
xy = None
8181
if xy is None:
8282
print("cannot use xy from file: x and y positions of neurons are not same size as activity")

rastermap/rastermap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def fit(self, data=None, Usv=None, Vsv=None, U_nodes=None, itrain=None,
241241
242242
"""
243243
t0 = time.time()
244-
244+
self.n_clusters = None if self.n_clusters==0 else self.n_clusters
245245

246246
# normalize data
247247
igood = ~np.isnan(data[:,0]) if data is not None else ~np.isnan(Usv[:,0])

0 commit comments

Comments
 (0)