8000 Black formatting & pre-commit hooks by loli · Pull Request #119 · loli/medpy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Black formatting & pre-commit hooks #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 15, 2023
Merged
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
39 changes: 15 additions & 24 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
TODO.txt

# Images #
##########
# Images
*.nii
*.mhd
*.raw

# DOC dirs #
############
# Local virtual envs
.venv/

# DOC dirs
doc/build/
doc/generated/
doc/source/generated/

# Notebooks dirs #
##################
# Notebooks dirs
.ipynb_checkpoints

# BUILD dirs #
##############
# BUILD dirs
build/
dist/
MedPy.egg-info/

# Only locally used, temporary .py scripts. #
#############################################
# Only locally used, temporary .py scripts.
_*.py
!__init__.py

# Backup files #
################
# Backup files
*.bak

# Compiled source #
###################
# Compiled source
*.com
*.class
*.dll
Expand All @@ -42,8 +38,7 @@ _*.py
*.pyc
*.pyo

# Packages #
############
# Packages
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
Expand All @@ -55,29 +50,25 @@ _*.py
*.tar
*.zip

# Logs and databases #
######################
# Logs and databases
*.log
*.sql
*.sqlite

# OS generated files #
######################
# OS generated files
.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
*~

# Eclipse and PyDev project files #
###################################
# Eclipse and PyDev project files
.project
.pydevproject
.settings/
.metadata/

# Suggestions by GitHub for Python projects #
#############################################
# Suggestions by GitHub for Python projects
# Packages
*.egg
*.egg-info
Expand Down
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: debug-statements

- repo: https://github.com/pycqa/isort
rev: "5.13.2"
hooks:
- id: isort
args: ["--profile", "black", "--line-length=88"]

- repo: https://github.com/psf/black
rev: 23.12.0
hooks:
- id: black

- repo: https://github.com/hadialqattan/pycln
rev: "v2.4.0"
hooks:
- id: pycln
args: ["--all"]

- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
- id: detect-secrets
args: ["--exclude-files", ".*\\.ipynb"]
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ MedPy is an image processing library and collection of scripts targeted towards
- Download (development version): https://github.com/loli/medpy
- HTML documentation and installation instruction (development version): create this from doc/ folder following instructions in contained README file

## Contribute

- Clone `master` branch from [github](https://github.com/loli/medpy)
- Install [pre-commit] hooks
- Submit your change as a PR request

## Python 2 version

Python 2 is no longer supported. But you can still use the older releases `<=0.3.0`.
Expand Down
2 changes: 1 addition & 1 deletion README_PYPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The supported image file formats should include at least the following. Note tha
* Analyze (plain, SPM99, SPM2) (.hdr/.img, .img.gz)
* Digital Imaging and Communications in Medicine (DICOM) (.dcm, .dicom)
* Digital Imaging and Communications in Medicine (DICOM) series (<directory>/)
* Nearly Raw Raster Data (Nrrd) (.nrrd, .nhdr)
* Nearly Raw Raster Data (Nrrd) (.nrrd, .nhdr)
* Medical Imaging NetCDF (MINC) (.mnc, .MNC)
* Guys Image Processing Lab (GIPL) (.gipl, .gipl.gz)

Expand Down
104 changes: 75 additions & 29 deletions bin/medpy_anisotropic_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import logging
import os

from medpy.core import Logger
from medpy.filter.smoothing import anisotropic_diffusion

# own modules
from medpy.io import get_pixel_spacing, load, save

# third-party modules

# path changes

# own modules
from medpy.io import load, save, get_pixel_spacing
from medpy.core import Logger
from medpy.filter.smoothing import anisotropic_diffusion


# information
__author__ = "Oskar Maier"
Expand All @@ -42,61 +43,106 @@
__description__ = """
Executes gradient anisotropic diffusion filter over an image.
This smoothing algorithm is edges preserving.

Note that the images voxel-spacing will be taken into account.

Copyright (C) 2013 Oskar Maier
This program comes with ABSOLUTELY NO WARRANTY; This is free software,
and you are welcome to redistribute it under certain conditions; see
the LICENSE file or <http://www.gnu.org/licenses/> for details.
the LICENSE file or <http://www.gnu.org/licenses/> for details.
"""


# code
def main():
# parse cmd arguments
parser = getParser()
parser.parse_args()
args = getArguments(parser)

# prepare logger
logger = Logger.getInstance()
if args.debug: logger.setLevel(logging.DEBUG)
elif args.verbose: logger.setLevel(logging.INFO)

if args.debug:
logger.setLevel(logging.DEBUG)
elif args.verbose:
logger.setLevel(logging.INFO)

# check if output image exists (will also be performed before saving, but as the smoothing might be very time intensity, a initial check can save frustration)
if not args.force:
if os.path.exists(args.output):
raise parser.error('The output image {} already exists.'.format(args.output))

raise parser.error(
"The output image {} already exists.".format(args.output)
)

# loading image
data_input, header_input = load(args.input)

# apply the watershed
logger.info('Applying anisotropic diffusion with settings: niter={} / kappa={} / gamma={}...'.format(args.iterations, args.kappa, args.gamma))
data_output = anisotropic_diffusion(data_input, args.iterations, args.kappa, args.gamma, get_pixel_spacing(header_input))
logger.info(
"Applying anisotropic diffusion with settings: niter={} / kappa={} / gamma={}...".format(
args.iterations, args.kappa, args.gamma
)
)
data_output = anisotropic_diffusion(
data_input,
args.iterations,
args.kappa,
args.gamma,
get_pixel_spacing(header_input),
)

# save file
save(data_output, args.output, header_input, args.force)

logger.info('Successfully terminated.')

logger.info("Successfully terminated.")


def getArguments(parser):
"Provides additional validation of the arguments collected by argparse."
return parser.parse_args()


def getParser():
"Creates and returns the argparse parser object."
parser = argparse.ArgumentParser(description=__description__)
parser.add_argument('input', help='Source volume.')
parser.add_argument('output', help='Target volume.')
parser.add_argument('-i', '--iterations', type=int, default=1, help='The number of smoothing iterations. Strong parameter.')
parser.add_argument('-k', '--kappa', type=int, default=50, help='The algorithms kappa parameter. The higher the more edges are smoothed over.')
parser.add_argument('-g', '--gamma', type=float, default=0.1, help='The algorithms gamma parameter. The higher, the stronger the plateaus between edges are smeared.')
parser.add_argument('-v', dest='verbose', action='store_true', help='Display more information.')
parser.add_argument('-d', dest='debug', action='store_true', help='Display debug information.')
parser.add_argument('-f', dest='force', action='store_true', help='Silently override existing output images.')

parser.add_argument("input", help="Source volume.")
parser.add_argument("output", help="Target volume.")
parser.add_argument(
"-i",
"--iterations",
type=int,
default=1,
help="The number of smoothing iterations. Strong parameter.",
)
parser.add_argument(
"-k",
"--kappa",
type=int,
default=50,
help="The algorithms kappa parameter. The higher the more edges are smoothed over.",
)
parser.add_argument(
"-g",
"--gamma",
type=float,
default=0.1,
help="The algorithms gamma parameter. The higher, the stronger the plateaus between edges are smeared.",
)
parser.add_argument(
"-v", dest="verbose", action="store_true", help="Display more information."
)
parser.add_argument(
"-d", dest="debug", action="store_true", help="Display debug information."
)
parser.add_argument(
"-f",
dest="force",
action="store_true",
help="Silently override existing output images.",
)

return parser



if __name__ == "__main__":
main()
Loading
0