Skip to content
Open
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
10 changes: 10 additions & 0 deletions mesmerize_core/algorithms/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import logging
from typing import Union

def setup_logging(log_level: Union[int, str] = logging.INFO):
if isinstance(log_level, str):
log_level = getattr(logging, log_level)
logging.basicConfig(
format="{asctime} - {levelname} - [{filename} {funcName}() {lineno}] - pid {process} - {message}",
filename=None, force=True,
level=log_level, style="{") # logging level can be DEBUG, INFO, WARNING, ERROR, CRITICAL
13 changes: 9 additions & 4 deletions mesmerize_core/algorithms/cnmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
if __name__ in ["__main__", "__mp_main__"]: # when running in subprocess
from mesmerize_core import set_parent_raw_data_path, load_batch
from mesmerize_core.utils import IS_WINDOWS
from mesmerize_core.algorithms._utils import setup_logging
else: # when running with local backend
from ..batch_utils import set_parent_raw_data_path, load_batch
from ..utils import IS_WINDOWS
from ._utils import setup_logging


def run_algo(batch_path, uuid, data_path: str = None):
def run_algo(batch_path, uuid, data_path: str = None, log_level=None):
if log_level is not None:
setup_logging(log_level)
algo_start = time.time()
set_parent_raw_data_path(data_path)

Expand Down Expand Up @@ -147,9 +151,10 @@ def run_algo(batch_path, uuid, data_path: str = None):
@click.command()
@click.option("--batch-path", type=str)
@click.option("--uuid", type=str)
@click.option("--data-path")
def main(batch_path, uuid, data_path: str = None):
run_algo(batch_path, uuid, data_path)
@click.option("--data-path", default=None)
@click.option("--log-level", type=int, default=None)
def main(batch_path, uuid, data_path, log_level):
run_algo(batch_path, uuid, data_path, log_level=log_level)


if __name__ == "__main__":
Expand Down
13 changes: 9 additions & 4 deletions mesmerize_core/algorithms/cnmfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
if __name__ in ["__main__", "__mp_main__"]: # when running in subprocess
from mesmerize_core import set_parent_raw_data_path, load_batch
from mesmerize_core.utils import IS_WINDOWS
from mesmerize_core.algorithms._utils import setup_logging
else: # when running with local backend
from ..batch_utils import set_parent_raw_data_path, load_batch
from ..utils import IS_WINDOWS
from ._utils import setup_logging


def run_algo(batch_path, uuid, data_path: str = None):
def run_algo(batch_path, uuid, data_path: str = None, log_level=None):
if log_level is not None:
setup_logging(log_level)
algo_start = time.time()
set_parent_raw_data_path(data_path)

Expand Down Expand Up @@ -128,9 +132,10 @@ def run_algo(batch_path, uuid, data_path: str = None):
@click.command()
@click.option("--batch-path", type=str)
@click.option("--uuid", type=str)
@click.option("--data-path")
def main(batch_path, uuid, data_path: str = None):
run_algo(batch_path, uuid, data_path)
@click.option("--data-path", default=None)
@click.option("--log-level", type=int, default=None)
def main(batch_path, uuid, data_path, log_level):
run_algo(batch_path, uuid, data_path, log_level=log_level)


if __name__ == "__main__":
Expand Down
13 changes: 9 additions & 4 deletions mesmerize_core/algorithms/mcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
# prevent circular import
if __name__ in ["__main__", "__mp_main__"]: # when running in subprocess
from mesmerize_core import set_parent_raw_data_path, load_batch
from mesmerize_core.algorithms._utils import setup_logging
else: # when running with local backend
from ..batch_utils import set_parent_raw_data_path, load_batch
from ._utils import setup_logging


def run_algo(batch_path, uuid, data_path: str = None):
def run_algo(batch_path, uuid, data_path: str = None, log_level=None):
if log_level is not None:
setup_logging(log_level)
algo_start = time.time()
set_parent_raw_data_path(data_path)

Expand Down Expand Up @@ -156,9 +160,10 @@ def run_algo(batch_path, uuid, data_path: str = None):
@click.command()
@click.option("--batch-path", type=str)
@click.option("--uuid", type=str)
@click.option("--data-path", type=str)
def main(batch_path, uuid, data_path: str = None):
run_algo(batch_path, uuid, data_path)
@click.option("--data-path", default=None)
@click.option("--log-level", type=int, default=None)
def main(batch_path, uuid, data_path, log_level):
run_algo(batch_path, uuid, data_path, log_level=log_level)


if __name__ == "__main__":
Expand Down
17 changes: 16 additions & 1 deletion mesmerize_core/caiman_extensions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from datetime import datetime
import time
from copy import deepcopy
import logging

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -536,10 +537,14 @@ def _run_local(
batch_path: Path,
uuid: UUID,
data_path: Union[Path, None],
log_level=None,
):
algo_module = getattr(algorithms, algo)
algo_module.run_algo(
batch_path=str(batch_path), uuid=str(uuid), data_path=str(data_path)
batch_path=str(batch_path),
uuid=str(uuid),
data_path=str(data_path),
log_level=log_level
)

return DummyProcess()
Expand Down Expand Up @@ -643,6 +648,7 @@ def run(self, backend: Optional[str] = None, wait: bool = True, **kwargs):
batch_path=batch_path,
uuid=self._series["uuid"],
data_path=get_parent_raw_data_path(),
log_level=kwargs.get("log_level")
)

# Create the runfile in the batch dir using this Series' UUID as the filename
Expand All @@ -660,6 +666,15 @@ def run(self, backend: Optional[str] = None, wait: bool = True, **kwargs):
if get_parent_raw_data_path() is not None:
args_str += f" --data-path {lex.quote(str(get_parent_raw_data_path()))}"

# set log level
if 'log_level' in kwargs:
level = kwargs['log_level']
if isinstance(level, str):
level = getattr(logging, level)
else:
level = logging.getLogger().getEffectiveLevel()
args_str += f" --log-level {level}"

# make the runfile
runfile_path = make_runfile(
module_path=os.path.abspath(
Expand Down
Loading