Skip to content

Commit

Permalink
Merge pull request #318 from RichieHakim/dev
Browse files Browse the repository at this point in the history
v1.3
  • Loading branch information
RichieHakim authored Oct 2, 2024
2 parents b8ee25c + ddc703a commit 5727fcc
Show file tree
Hide file tree
Showing 32 changed files with 2,689 additions and 1,055 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ jobs:
run: |
# pip install tox tox-gh-actions
pip install pytest pytest-cov
python -m pytest -rP --capture=tee-sys --cov=roicat --cov-report=xml:coverage.xml --color=yes --ignore=tests/test_packages.py --ignore=tests/test_interactive.py
# python -m pytest -v -rP --capture=tee-sys --cov=roicat --cov-report=xml:coverage.xml --color=yes --ignore=tests/test_packages.py --ignore=tests/test_interactive.py
python -m pytest -v -rP --capture=tee-sys --cov=roicat --cov-report=xml:coverage.xml --color=yes
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3 ## this is a public action recognized by GitHub Actions
Expand Down
49 changes: 33 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ computer.

### TRACKING:
- [Interactive
notebook](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/tracking/tracking_interactive_notebook.ipynb)
notebook](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/tracking/1_tracking_interactive_notebook.ipynb)
- [Google
CoLab](https://githubtocolab.com/RichieHakim/ROICaT/blob/main/notebooks/colab/tracking/tracking_interactive_notebook.ipynb)
CoLab](https://githubtocolab.com/RichieHakim/ROICaT/blob/main/notebooks/colab/tracking/1_tracking_interactive_notebook.ipynb)
- [Command line interface script](https://github.com/RichieHakim/ROICaT/blob/main/scripts/demo_run_tracking_pipeline.py)

### CLASSIFICATION:
- [Interactive notebook -
Drawing](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/classify_by_drawingSelection.ipynb)
Drawing](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/A1_classify_by_drawingSelection.ipynb)
- [Google CoLab -
Drawing](https://githubtocolab.com/RichieHakim/ROICaT/blob/main/notebooks/colab/classification/classify_by_drawingSelection_colab.ipynb)
Drawing](https://githubtocolab.com/RichieHakim/ROICaT/blob/main/notebooks/colab/classification/A1_classify_by_drawingSelection_colab.ipynb)
- [Interactive notebook -
Labeling](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/labeling_interactive.ipynb)
Labeling](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/B1_labeling_interactive.ipynb)
- [Interactive notebook - Train
classifier](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/classifier_train_interactive.ipynb)
classifier](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/B2_classifier_train_interactive.ipynb)
- [Interactive notebook - Inference with
classifier](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/classifier_inference_interactive.ipynb)
classifier](https://github.com/RichieHakim/ROICaT/blob/main/notebooks/jupyter/classification/B3_classifier_inference_interactive.ipynb)

**OTHER:**
- [Custom data importing
Expand Down Expand Up @@ -236,12 +236,29 @@ intercompatible, so if you have CUDA 11.8 drivers, you can install


# TODO:
- Some more integration tests
- Switch to ONNX for ROINet
- Add more documentation / tutorials
- Make a GUI
- Finish ROIextractors integration
- Make a Docker container
- Make a standard classifier
- Write the paper
- Make tweet about it
#### algorithmic improvements:
- [ ] Add in method to use more similarity metrics for tracking
- [ ] Coordinate descent on each similarity metric
- [ ] Add F and Fneu to data_roicat, dFoF and trace quality metric functions
- [ ] Add in notebook for demonstrating using temporal similarity metrics (SWT on dFoF)
- [ ] Make a standard classifier
- [ ] Try other clustering methods
- [ ] Make image aligner based on image similarity + RANSAC of centroids or s_SF
- [ ] Better post-hoc curation metrics and visualizations
#### code improvements:
- [ ] Update automatic regression module (make new repo for it)
- [ ] Switch to ONNX for ROINet
- [ ] Some more integration tests
- [ ] Add more documentation / tutorials
- [ ] Make a GUI
- [ ] Finish ROIextractors integration
- [ ] Make a Docker container
- [ ] Make colab demo notebook not require user data
#### other:
- [ ] Write the paper
- [ ] Make tweet about it
- [ ] Make a video or two on how to use it
- [ ] Maybe use lightthetorch for torch installation
- [ ] Better Readme
- [ ] More documentation
- [ ] Make a regression model for in-plane-ness
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def download_data_test_zip(directory):
check_local_first=True,
check_hash=True,
hash_type='MD5',
hash_hex=r'aec4284b7f0a25e5e8eec85ed659d532',
hash_hex=r'2fcd64902d3c71eb0a85bbdb15a7d68e',
mkdir=True,
allow_overwrite=True,
write_mode='wb',
Expand Down
8 changes: 6 additions & 2 deletions docs/source/inputsAndOutputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ Inputs
Outputs
#######

The outputs of ROICaT are encapsulated in a ``results.pkl`` file, which is a
Python dictionary containing the following fields:
The outputs of ROICaT tracking are encapsulated in a set of files. The main file
is a ``...tracking.results_all.richfile`` directory that can be loaded using
``roicat.util.RichFile_ROICaT``. It is a python dictionary with the following
fields:

Clusters
~~~~~~~~
Expand All @@ -30,6 +32,8 @@ Clusters
- **labels_bool_bySession:** Same as ``labels_bool``, but by session.
- **labels_dict:** Dictionary mapping UCIDs to ROI indices. Keys are UCIDs,
values are lists of ROI indices.
- **quality_metrics:** Dictionary of quality metrics for each cluster. See below
section `Quality Metrics <quality-metrics>`_ for more details.

ROIs
~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"id": "aaeb2017-7988-47b1-96d6-cc9b0c68edf3",
"metadata": {},
"outputs": [],
Expand All @@ -87,7 +87,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "9904f613-2094-48bd-8265-cfd7e0aed001",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -226,7 +226,8 @@
" ROI_images=data.ROI_images, ## Input images of ROIs\n",
" um_per_pixel=data.um_per_pixel, ## Resolution of FOV\n",
" pref_plot=False, ## Whether or not to plot the ROI sizes\n",
");"
");\n",
"images = roinet.ROI_images_rs"
]
},
{
Expand All @@ -246,7 +247,7 @@
"metadata": {},
"outputs": [],
"source": [
"roicat.visualization.display_toggle_image_stack(roinet.ROI_images_rs[:1000], image_size=(200,200))"
"roicat.visualization.display_toggle_image_stack(images[:1000], image_size=(200,200))"
]
},
{
Expand Down Expand Up @@ -286,14 +287,14 @@
"metadata": {},
"outputs": [],
"source": [
"umap = UMAP(\n",
"model_umap = UMAP(\n",
" n_neighbors=25,\n",
" n_components=2,\n",
" n_epochs=400,\n",
" verbose=True,\n",
" densmap=False,\n",
")\n",
"emb = umap.fit_transform(roinet.latents)"
"emb = model_umap.fit_transform(roinet.latents)"
]
},
{
Expand All @@ -314,7 +315,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 75,
"id": "802791ab-e0fc-424a-8320-d6a1e641f61d",
"metadata": {},
"outputs": [],
Expand All @@ -326,7 +327,7 @@
"# border_frac=0.05,\n",
")\n",
"\n",
"images_overlay = roinet.ROI_images_rs[idx_images_overlay]"
"images_overlay = images[idx_images_overlay]"
]
},
{
Expand Down Expand Up @@ -374,33 +375,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 77,
"id": "9005978f-a9b4-4a56-87d1-fe6844e238b9",
"metadata": {},
"outputs": [],
"source": [
"## Save the layout to an SVG file if desired\n",
"# roicat.helpers.export_svg_hv_bokeh(layout, '/home/rich/Desktop/umap_with_labels_dotsOnly.svg')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 78,
"id": "b9b82100",
"metadata": {},
"outputs": [],
"source": [
"n_sessions = len(data.ROI_images)\n",
"idx_session_cat = np.concatenate([[ii]*data.ROI_images[ii].shape[0] for ii in range(n_sessions)])\n",
"bool_good_cat = roicat.helpers.idx2bool(fn_get_indices(), length=len(idx_session_cat))\n",
"preds_good_sessions = [np.int64((bool_good_cat * (idx_session_cat==ii))[idx_session_cat==ii]) for ii in range(data.n_sessions)]\n",
"preds_good_sessions = roicat.util.JSON_List([[int(l) for l in labels] for labels in roicat.util.labels_to_labelsBySession(bool_good_cat, data.n_roi)])\n",
"\n",
"classification_output = {\n",
" 'preds': preds_good_sessions,\n",
" 'spatialFootprints': data.spatialFootprints,\n",
" 'FOV_height': data.FOV_height,\n",
" 'FOV_width': data.FOV_width,\n",
" 'input_data': data.paths_stat,\n",
" 'um_per_pixel': data.um_per_pixel,\n",
"run_data = {\n",
" \"data\": data.__dict__,\n",
" \"roinet\": roinet.__dict__,\n",
" \"umap_embedding\": emb,\n",
" \"preds\": preds_good_sessions,\n",
"}"
]
},
Expand All @@ -420,7 +420,7 @@
"outputs": [],
"source": [
"print(f\"Number of 'good' and 'bad' ROIs from each session:\")\n",
"print([f\"good: {p.sum()} / bad: {(p!=1).sum()}\" for p in preds_good_sessions])"
"print([f\"good: {np.array(p).sum()} / bad: {(np.array(p)!=1).sum()}\" for p in preds_good_sessions])"
]
},
{
Expand Down Expand Up @@ -465,27 +465,21 @@
{
"cell_type": "code",
"execution_count": null,
"id": "fe17605e-96da-4d5d-b111-0d96bb0888b4",
"metadata": {},
"outputs": [],
"source": [
"mouse = 'mouse_0916N'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ca2f1539",
"id": "028db758",
"metadata": {},
"outputs": [],
"source": [
"dir_save = f'/media/rich/bigSSD/analysis_data/face_rhythm/{mouse}/'\n",
"filename_save = mouse\n",
"## Define the directory to save the results to\n",
"dir_save = '/media/rich/bigSSD/data_tmp/test_data/'\n",
"name_save = 'mouse_1'\n",
"\n",
"path_save = str(Path(dir_save).resolve() / (filename_save + '.ROICaT.classification_drawn.results' + '.pkl'))\n",
"print(f'path_save: {path_save}')\n",
"paths_save = {\n",
" 'preds': str(Path(dir_save) / f'{name_save}.classification_drawn.preds.json'),\n",
" 'run_data': str(Path(dir_save) / f'{name_save}.classification_drawn.run_data.richfile'),\n",
"}\n",
"\n",
"roicat.helpers.pickle_save(classification_output, path_save, mkdir=True)"
"roicat.helpers.json_save(obj=preds_good_sessions, filepath=paths_save['preds'])\n",
"roicat.util.RichFile_ROICaT(path=paths_save['run_data']).save(run_data, overwrite=True)"
]
},
{
Expand Down Expand Up @@ -522,7 +516,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 5727fcc

Please sign in to comment.