Skip to content

Commit

Permalink
answer Sam comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbore committed Jun 27, 2024
1 parent 83ede5a commit d103f68
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FROM debian:stable AS runtime
COPY --from=build /venv /venv

# Point to conda executables
ENV PATH /venv/bin:$PATH
ENV PATH="/venv/bin:$PATH"

# Set FSL variables
ENV FSLDIR="/venv"
Expand Down Expand Up @@ -54,4 +54,4 @@ RUN pip install -e .

RUN pip install pydeface

ENTRYPOINT [""]
ENTRYPOINT ["dcm2bids"]
11 changes: 4 additions & 7 deletions dcm2bids/dcm2bids_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,17 @@ def run(self):

if self.bids_validate:
try:
self.logger.info(f"BIDS VALIDATION")
self.logger.info("BIDS VALIDATION")
bids_version = run_shell_command(['bids-validator', '-v'], False)
self.logger.info(f"Use bids-validator version: {bids_version.decode()[:-1]}")
bids_report = run_shell_command(['bids-validator', self.bids_dir])
self.logger.info("Report from bids-validator")
self.logger.info(bids_report.decode())
except Exception:
self.logger.error("\033[91m"
"The bids-validator does not seem to work properly. "
self.logger.error("The bids-validator does not seem to work properly. "
"The bids-validator may not be installed on your "
"computer. Please check: "
"https://github.com/bids-standard/bids-validator."
"\033[0m")
"https://github.com/bids-standard/bids-validator.")

def move(self, acq, idList, post_op):
"""Move an acquisition to BIDS format"""
Expand Down Expand Up @@ -198,11 +196,10 @@ def move(self, acq, idList, post_op):
continue
except Exception:
self.logger.error(
"\033[91m"
f"The command post_op: \"{cmd}\" "
"does not seem to work properly. "
"Check if it is installed on your "
"computer.\033[0m\n")
"computer.\n")

if ".json" in ext:
data = acq.dstSidecarData(idList)
Expand Down
5 changes: 4 additions & 1 deletion dcm2bids/dcm2niix_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ def execute(self):

if "Warning" in output or "Error" in output:
self.logger.info("Log from dcm2niix execution")
self.logger.info(f"\033[93m{output}\033[0m")
if "Warning" in output:
self.logger.warning(f"{output}")
else:
self.logger.error(f"{output}")
else:
self.logger.debug(f"\n{output}")
self.logger.info("Check log file for dcm2niix output\n")
Expand Down
29 changes: 28 additions & 1 deletion dcm2bids/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup_logging(log_level, log_file=None):

sh = logging.StreamHandler(sys.stdout)
sh.setLevel(log_level)
sh_fmt = logging.Formatter(fmt="%(levelname)-8s| %(message)s")
sh_fmt = CustomFormatter(fmt="%(levelname)-8s| %(message)s")
sh.setFormatter(sh_fmt)

# default formatting is kept for the log file"
Expand All @@ -30,3 +30,30 @@ def setup_logging(log_level, log_file=None):
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[fh, sh]
)


class CustomFormatter(logging.Formatter):
"""Logging colored formatter, adapted from https://stackoverflow.com/a/56944256/3638629"""

grey = '\x1b[38;21m'
blue = '\x1b[38;5;39m'
yellow = '\x1b[38;5;226m'
red = '\x1b[38;5;196m'
bold_red = '\x1b[31;1m'
reset = '\x1b[0m'

def __init__(self, fmt):
super().__init__()
self.fmt = fmt
self.FORMATS = {
logging.DEBUG: self.grey + self.fmt + self.reset,
logging.INFO: self.blue + self.fmt + self.reset,
logging.WARNING: self.yellow + self.fmt + self.reset,
logging.ERROR: self.red + self.fmt + self.reset,
logging.CRITICAL: self.bold_red + self.fmt + self.reset
}

def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: fsl
channels:
- https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/
- conda-forge
- HCC
dependencies:
- fsl-bet2
- fsl-flirt

0 comments on commit d103f68

Please sign in to comment.