[ENH]: Consistency of logging #239
80 changed files with 284 additions and 100 deletions
1
docs/changes/newsfragments/239.enh
Normal file
1
docs/changes/newsfragments/239.enh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Improve logging consistency of components by `Synchon Mandal`_
|
||||
|
|
@ -23,6 +23,7 @@ DataGrabbers, Preprocessors, Markers, etc., following the *junifer* way.
|
|||
:caption: Contents:
|
||||
|
||||
extension
|
||||
logging
|
||||
datagrabber
|
||||
marker
|
||||
preprocessor
|
||||
|
|
|
|||
38
docs/extending/logging.rst
Normal file
38
docs/extending/logging.rst
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
.. include:: ../links.inc
|
||||
|
||||
.. _logging_in_extension:
|
||||
|
||||
Logging in a ``junifer`` extension
|
||||
==================================
|
||||
|
||||
It is important to have proper logging in your code and ``junifer`` makes it trivial to do so for your extensions.
|
||||
|
||||
For DataGrabber:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from junifer.datagrabber import logger
|
||||
|
||||
|
||||
For Preprocessor:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from junifer.preprocess import logger
|
||||
|
||||
|
||||
For Marker:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from junifer.marker import logger
|
||||
|
||||
|
||||
For Storage:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from junifer.storage import logger
|
||||
|
||||
|
||||
Importing the correct logger will give you a properly set up logger which will fit right in with the rest of ``junifer``\'s log output.
|
||||
|
|
@ -10,6 +10,8 @@ import os
|
|||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import structlog
|
||||
|
||||
from ..api.queue_context import GnuParallelLocalAdapter, HTCondorAdapter
|
||||
from ..datagrabber import BaseDataGrabber
|
||||
from ..markers import BaseMarker
|
||||
|
|
@ -27,11 +29,14 @@ from ..typing import (
|
|||
PreprocessorLike,
|
||||
StorageLike,
|
||||
)
|
||||
from ..utils import logger, raise_error, warn_with_log, yaml
|
||||
from ..utils import raise_error, warn_with_log, yaml
|
||||
|
||||
|
||||
__all__ = ["collect", "list_elements", "queue", "reset", "run"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="api")
|
||||
|
||||
|
||||
def _get_datagrabber(datagrabber_config: dict) -> DataGrabberLike:
|
||||
"""Get DataGrabber.
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ from pathlib import Path
|
|||
from typing import Any
|
||||
|
||||
from ...typing import Elements
|
||||
from ...utils import logger, make_executable, raise_error, run_ext_cmd
|
||||
from ...utils import make_executable, raise_error, run_ext_cmd
|
||||
from .queue_context_adapter import (
|
||||
EnvKind,
|
||||
EnvShell,
|
||||
QueueContextAdapter,
|
||||
QueueContextEnv,
|
||||
logger,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,12 +10,13 @@ from pathlib import Path
|
|||
from typing import Any
|
||||
|
||||
from ...typing import Elements
|
||||
from ...utils import logger, make_executable, raise_error, run_ext_cmd
|
||||
from ...utils import make_executable, raise_error, run_ext_cmd
|
||||
from .queue_context_adapter import (
|
||||
EnvKind,
|
||||
EnvShell,
|
||||
QueueContextAdapter,
|
||||
QueueContextEnv,
|
||||
logger,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ else:
|
|||
from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
|
||||
import structlog
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
from ...utils import raise_error
|
||||
|
|
@ -26,6 +27,9 @@ from ...utils import raise_error
|
|||
|
||||
__all__ = ["EnvKind", "EnvShell", "QueueContextAdapter", "QueueContextEnv"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="api")
|
||||
|
||||
|
||||
class EnvKind(str, Enum):
|
||||
"""Accepted Python environment kind."""
|
||||
|
|
|
|||
|
|
@ -10,13 +10,17 @@ import sys
|
|||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
import structlog
|
||||
|
||||
from ..typing import Elements
|
||||
from ..utils import logger, raise_error, warn_with_log, yaml
|
||||
from ..utils import raise_error, warn_with_log, yaml
|
||||
|
||||
|
||||
__all__ = ["parse_elements", "parse_yaml"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="cli")
|
||||
|
||||
|
||||
def parse_yaml(filepath: str | Path) -> dict: # noqa: C901
|
||||
"""Parse YAML.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import numpy as np
|
|||
from numpy.typing import ArrayLike
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, run_ext_cmd
|
||||
from ...utils import run_ext_cmd
|
||||
|
||||
|
||||
__all__ = ["ANTsCoordinatesWarper"]
|
||||
|
|
@ -46,6 +46,9 @@ class ANTsCoordinatesWarper:
|
|||
The transformed coordinates.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._coordinates import logger
|
||||
|
||||
logger.debug("Using ANTs for coordinates transformation")
|
||||
|
||||
# Create element-specific tempdir for storing post-warping assets
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ from typing import Any
|
|||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import structlog
|
||||
from junifer_data import get
|
||||
from numpy.typing import ArrayLike
|
||||
|
||||
from ...utils import logger, raise_error
|
||||
from ...utils import raise_error
|
||||
from ..pipeline_data_registry_base import BasePipelineDataRegistry
|
||||
from ..utils import JUNIFER_DATA_PARAMS, get_dataset_path, get_native_warper
|
||||
from ._ants_coordinates_warper import ANTsCoordinatesWarper
|
||||
|
|
@ -21,6 +22,9 @@ from ._fsl_coordinates_warper import FSLCoordinatesWarper
|
|||
|
||||
__all__ = ["CoordinatesRegistry"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="data")
|
||||
|
||||
|
||||
class CoordinatesRegistry(BasePipelineDataRegistry):
|
||||
"""Class for coordinates data registry.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import numpy as np
|
|||
from numpy.typing import ArrayLike
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, run_ext_cmd
|
||||
from ...utils import run_ext_cmd
|
||||
|
||||
|
||||
__all__ = ["FSLCoordinatesWarper"]
|
||||
|
|
@ -46,6 +46,9 @@ class FSLCoordinatesWarper:
|
|||
The transformed coordinates.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._coordinates import logger
|
||||
|
||||
logger.debug("Using FSL for coordinates transformation")
|
||||
|
||||
# Create element-specific tempdir for storing post-warping assets
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any
|
|||
import nibabel as nib
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, raise_error, run_ext_cmd
|
||||
from ...utils import raise_error, run_ext_cmd
|
||||
from ..template_spaces import get_template, get_xfm
|
||||
|
||||
|
||||
|
|
@ -71,6 +71,9 @@ class ANTsMapsWarper:
|
|||
If ``warp_data`` is None when ``dst="T1w"``.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._maps import logger
|
||||
|
||||
# Create element-scoped tempdir so that warped maps is
|
||||
# available later as nibabel stores file path reference for
|
||||
# loading on computation
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any
|
|||
import nibabel as nib
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, run_ext_cmd
|
||||
from ...utils import run_ext_cmd
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -53,6 +53,9 @@ class FSLMapsWarper:
|
|||
The transformed maps image.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._maps import logger
|
||||
|
||||
logger.debug("Using FSL for maps transformation")
|
||||
|
||||
# Create element-scoped tempdir so that warped maps is
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ from typing import TYPE_CHECKING, Any, Optional
|
|||
import nibabel as nib
|
||||
import nilearn.image as nimg
|
||||
import numpy as np
|
||||
import structlog
|
||||
from junifer_data import get
|
||||
|
||||
from ...utils import logger, raise_error
|
||||
from ...utils import raise_error
|
||||
from ..pipeline_data_registry_base import BasePipelineDataRegistry
|
||||
from ..utils import (
|
||||
JUNIFER_DATA_PARAMS,
|
||||
|
|
@ -29,6 +30,9 @@ if TYPE_CHECKING:
|
|||
|
||||
__all__ = ["MapsRegistry"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="data")
|
||||
|
||||
|
||||
class MapsRegistry(BasePipelineDataRegistry):
|
||||
"""Class for maps data registry.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import nibabel as nib
|
|||
import numpy as np
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, raise_error, run_ext_cmd
|
||||
from ...utils import raise_error, run_ext_cmd
|
||||
from ..template_spaces import get_template, get_xfm
|
||||
|
||||
|
||||
|
|
@ -92,6 +92,9 @@ class ANTsMaskWarper:
|
|||
If ``warp_data`` is None when ``dst="T1w"``.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._masks import logger
|
||||
|
||||
# Create element-scoped tempdir so that warped mask is
|
||||
# available later as nibabel stores file path reference for
|
||||
# loading on computation
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import nibabel as nib
|
|||
import numpy as np
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, run_ext_cmd
|
||||
from ...utils import run_ext_cmd
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -74,6 +74,9 @@ class FSLMaskWarper:
|
|||
The transformed mask image.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._masks import logger
|
||||
|
||||
logger.debug("Using FSL for mask transformation")
|
||||
|
||||
# Create element-scoped tempdir so that warped mask is
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from typing import (
|
|||
import nibabel as nib
|
||||
import nilearn.image as nimg
|
||||
import numpy as np
|
||||
import structlog
|
||||
from junifer_data import get
|
||||
from nilearn.masking import (
|
||||
compute_background_mask,
|
||||
|
|
@ -22,7 +23,7 @@ from nilearn.masking import (
|
|||
intersect_masks,
|
||||
)
|
||||
|
||||
from ...utils import logger, raise_error
|
||||
from ...utils import raise_error
|
||||
from ..pipeline_data_registry_base import BasePipelineDataRegistry
|
||||
from ..template_spaces import get_template
|
||||
from ..utils import (
|
||||
|
|
@ -41,6 +42,9 @@ if TYPE_CHECKING:
|
|||
|
||||
__all__ = ["MaskRegistry", "compute_brain_mask"]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="data")
|
||||
|
||||
|
||||
def compute_brain_mask(
|
||||
target_data: dict[str, Any],
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any
|
|||
import nibabel as nib
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, raise_error, run_ext_cmd
|
||||
from ...utils import raise_error, run_ext_cmd
|
||||
from ..template_spaces import get_template, get_xfm
|
||||
|
||||
|
||||
|
|
@ -71,6 +71,9 @@ class ANTsParcellationWarper:
|
|||
If ``warp_data`` is None when ``dst="T1w"``.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._parcellations import logger
|
||||
|
||||
# Create element-scoped tempdir so that warped parcellation is
|
||||
# available later as nibabel stores file path reference for
|
||||
# loading on computation
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Any
|
|||
import nibabel as nib
|
||||
|
||||
from ...pipeline import WorkDirManager
|
||||
from ...utils import logger, run_ext_cmd
|
||||
from ...utils import run_ext_cmd
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
@ -53,6 +53,9 @@ class FSLParcellationWarper:
|
|||
The transformed parcellation image.
|
||||
|
||||
"""
|
||||
# Imported here to avoid circular import
|
||||
from ._parcellations import logger
|
||||
|
||||
logger.debug("Using FSL for parcellation transformation")
|
||||
|
||||
# Create element-scoped tempdir so that warped parcellation is
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@ import nibabel as nib
|
|||
import nilearn.image as nimg
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import structlog
|
||||
from junifer_data import get
|
||||
|
||||
from ...utils import logger, raise_error, warn_with_log
|
||||
from ...utils import raise_error, warn_with_log
|
||||
from ..pipeline_data_registry_base import BasePipelineDataRegistry
|
||||
from ..utils import (
|
||||
JUNIFER_DATA_PARAMS,
|
||||
|
|
@ -36,6 +37,9 @@ __all__ = [
|
|||
"merge_parcellations",
|
||||
]
|
||||
|
||||
_log = structlog.get_logger("junifer")
|
||||
logger = _log.bind(pkg="data")
|
||||
|
||||
|
||||
class ParcellationRegistry(BasePipelineDataRegistry):
|
||||
"""Class for parcellation data registry.
|
||||
|
|
@ -58,8 +62,12 @@ class ParcellationRegistry(BasePipelineDataRegistry):
|
|||
# The built-in parcellations are files that are shipped with the
|
||||
# junifer-data dataset.
|
||||
# Make built-in and external dictionaries for validation later
|
||||
self._builtin = {}
|
||||
self._external = {}
|
||||
self._builtin: dict[
|
||||
str, dict[str, str | int | Path | list[str] | list[int]]
|
||||
] = {}
|
||||
self._external: dict[
|
||||
str, dict[str, str | int | Path | list[str] | list[int]]
|
||||
] = {}
|
||||
|
||||
# Add SUIT
|
||||
self._builtin.update(
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue