Skip to content

Commit

Permalink
Merge pull request #635 from arayabrain/develop-main
Browse files Browse the repository at this point in the history
fix for 1.2.1
  • Loading branch information
ReiHashimoto authored Apr 15, 2024
2 parents 70ab0c1 + 82c7a08 commit 26ef6df
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 27 deletions.
9 changes: 0 additions & 9 deletions studio/app/optinist/wrappers/caiman/README.md

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

48 changes: 40 additions & 8 deletions studio/app/optinist/wrappers/caiman/cnmf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import gc
import os
import shutil

import numpy as np
import requests

from studio.app.common.core.logger import AppLogger
from studio.app.common.core.utils.filepath_creater import join_filepath
from studio.app.common.core.utils.filepath_creater import (
create_directory,
join_filepath,
)
from studio.app.common.dataclass import ImageData
from studio.app.dir_path import DIRPATH
from studio.app.optinist.core.nwb.nwb import NWBDATASET
from studio.app.optinist.dataclass import EditRoiData, FluoData, IscellData, RoiData

Expand Down Expand Up @@ -114,6 +116,40 @@ def util_recursive_flatten_params(params, result_params: dict, nest_counter=0):
result_params[key] = nested_param


def util_download_model_files():
"""
download model files for component evaluation
"""
# NOTE: We specify the version of the CaImAn to download.
base_url = "https://github.com/flatironinstitute/CaImAn/raw/v1.9.12/model"
model_files = [
"cnn_model.h5",
"cnn_model.h5.pb",
"cnn_model.json",
"cnn_model_online.h5",
"cnn_model_online.h5.pb",
"cnn_model_online.json",
]

caiman_data_dir = os.path.join(os.path.expanduser("~"), "caiman_data")
if not os.path.exists(caiman_data_dir):
create_directory(caiman_data_dir)

model_dir = join_filepath([caiman_data_dir, "model"])
if not os.path.exists(model_dir):
create_directory(join_filepath(model_dir))

if len(os.listdir(model_dir)) < len(model_files):
for model in model_files:
url = f"{base_url}/{model}"
file_path = join_filepath([model_dir, model])
if not os.path.exists(file_path):
logger.info(f"Downloading {model}")
response = requests.get(url)
with open(file_path, "wb") as f:
f.write(response.content)


def caiman_cnmf(
images: ImageData, output_dir: str, params: dict = None, **kwargs
) -> dict(fluorescence=FluoData, iscell=IscellData):
Expand All @@ -126,11 +162,7 @@ def caiman_cnmf(
logger.info(f"start caiman_cnmf: {function_id}")

# NOTE: evaluate_components requires cnn_model files in caiman_data directory.
caiman_data_dir = os.path.join(os.path.expanduser("~"), "caiman_data")
if not os.path.exists(caiman_data_dir):
shutil.copytree(
f"{DIRPATH.APP_DIR}/optinist/wrappers/caiman/caiman_data", caiman_data_dir
)
util_download_model_files()

# flatten cmnf params segments.
reshaped_params = {}
Expand Down
10 changes: 2 additions & 8 deletions studio/app/optinist/wrappers/caiman/cnmf_multisession.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import gc
import os
import shutil

import imageio
import numpy as np

from studio.app.common.core.logger import AppLogger
from studio.app.common.dataclass import ImageData
from studio.app.dir_path import DIRPATH
from studio.app.optinist.core.nwb.nwb import NWBDATASET
from studio.app.optinist.dataclass import EditRoiData, FluoData, IscellData, RoiData
from studio.app.optinist.wrappers.caiman.cnmf import (
get_roi,
util_download_model_files,
util_get_memmap,
util_recursive_flatten_params,
)
Expand All @@ -32,11 +30,7 @@ def caiman_cnmf_multisession(
logger.info(f"start caiman_cnmf_multisession: {function_id}")

# NOTE: evaluate_components requires cnn_model files in caiman_data directory.
caiman_data_dir = os.path.join(os.path.expanduser("~"), "caiman_data")
if not os.path.exists(caiman_data_dir):
shutil.copytree(
f"{DIRPATH.APP_DIR}/optinist/wrappers/caiman/caiman_data", caiman_data_dir
)
util_download_model_files()

# flatten cmnf params segments.
reshaped_params = {}
Expand Down
12 changes: 12 additions & 0 deletions studio/app/optinist/wrappers/caiman/params/caiman_cnmfe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,15 @@ advanced:
do_merge: True
merge_parallel: False
max_merge_area: null

quality_evaluation_params:
SNR_lowest: 0.5
cnn_lowest: 0.1
gSig_range: null
min_SNR: 2.5
min_cnn_thr: 0.9
rval_lowest: -1
rval_thr: 0.8
use_cnn: True
use_ecc: False
max_ecc: 3

0 comments on commit 26ef6df

Please sign in to comment.