Skip to content

Commit

Permalink
isort
Browse files Browse the repository at this point in the history
  • Loading branch information
jrkerns committed Feb 22, 2023
1 parent 2d14ae5 commit b51cc24
Show file tree
Hide file tree
Showing 51 changed files with 337 additions and 366 deletions.
1 change: 0 additions & 1 deletion docs/source/code_snippets/tg51_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A script to calculate TG-51 dose using pylinac classes and following the TG-51 photon form"""
from pylinac.calibration import tg51


ENERGY = 6
TEMP = 22.1
PRESS = tg51.mmHg2kPa(755.0)
Expand Down
1 change: 0 additions & 1 deletion docs/source/code_snippets/tg51_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A script to calculate TG-51 dose using pylinac functions and following the TG-51 photon form"""
from pylinac.calibration import tg51


ENERGY = 6
TEMP = 22.1
PRESS = tg51.mmHg2kPa(755.0)
Expand Down
1 change: 0 additions & 1 deletion docs/source/code_snippets/trs398_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A script to calculate TRS-398 dose using pylinac classes and following the TRS-398 photon form"""
from pylinac.calibration import trs398


ENERGY = 6
TEMP = 22.1
PRESS = trs398.mmHg2kPa(755.0)
Expand Down
1 change: 0 additions & 1 deletion docs/source/code_snippets/trs398_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A script to calculate TRS-398 dose using pylinac functions and following the TRS-398 photon form"""
from pylinac.calibration import trs398


TEMP = 22.1
PRESS = trs398.mmHg2kPa(755.0)
CHAMBER = "30013" # PTW
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# pylinac documentation build configuration file, created by
# sphinx-quickstart on Thu Sep 10 11:56:25 2015.
Expand Down
50 changes: 25 additions & 25 deletions pylinac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@
"Pylinac is only supported on Python 3.7+. Please update your environment."
)

# alphabetized modules
from .acr import ACRCT, ACRMRILarge
from .calibration import tg51, trs398

# import shortcuts
# core first
from .core import decorators, geometry, image, io, mask, profile, roi, utilities

# alphabetized modules
from .acr import ACRCT, ACRMRILarge
from .ct import CatPhan504, CatPhan600, CatPhan503, CatPhan604
from .quart import QuartDVT
from .core.utilities import clear_data_files, assign2machine
from .core.utilities import assign2machine, clear_data_files
from .ct import CatPhan503, CatPhan504, CatPhan600, CatPhan604
from .field_analysis import (
FieldAnalysis,
DeviceFieldAnalysis,
Protocol,
Centering,
Device,
DeviceFieldAnalysis,
Edge,
FieldAnalysis,
Interpolation,
Normalization,
Centering,
Protocol,
)
from .log_analyzer import Dynalog, MachineLogs, TrajectoryLog, load_log
from .picketfence import PicketFence # must be after log analyzer
from .planar_imaging import (
LeedsTOR,
StandardImagingQC3,
LasVegas,
DoselabMC2kV,
DoselabMC2MV,
StandardImagingQCkV,
PTWEPIDQC,
SNCMV,
SNCkV,
StandardImagingFC2,
IMTLRad,
SNCFSQA,
LeedsTORBlue,
SNCMV,
SNCMV12510,
DoselabMC2kV,
DoselabMC2MV,
IBAPrimusA,
IMTLRad,
LasVegas,
LeedsTOR,
LeedsTORBlue,
SNCkV,
StandardImagingFC2,
StandardImagingQC3,
StandardImagingQCkV,
)
from .log_analyzer import load_log, Dynalog, TrajectoryLog, MachineLogs
from .picketfence import PicketFence # must be after log analyzer
from .quart import QuartDVT
from .starshot import Starshot
from .vmat import DRMLC, DRGS
from .vmat import DRGS, DRMLC
from .winston_lutz import WinstonLutz, WinstonLutzMultiTargetMultiField
from .calibration import tg51, trs398
6 changes: 3 additions & 3 deletions pylinac/acr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from io import BytesIO
from pathlib import Path
from typing import Union, List, Dict, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union

import numpy as np
from matplotlib import pyplot as plt
Expand All @@ -15,10 +15,10 @@
from .core import pdf
from .core.geometry import Line, Point
from .core.mtf import MTF
from .core.profile import SingleProfile, Interpolation
from .core.profile import Interpolation, SingleProfile
from .core.roi import HighContrastDiskROI, RectangleROI
from .core.utilities import ResultBase
from .ct import CatPhanBase, CatPhanModule, ThicknessROI, Slice, get_regions
from .ct import CatPhanBase, CatPhanModule, Slice, ThicknessROI, get_regions

# CT
CT_UNIFORMITY_MODULE_OFFSET_MM = 70
Expand Down
30 changes: 15 additions & 15 deletions pylinac/calibration/trs398.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import webbrowser
from abc import ABC
from datetime import datetime
from typing import Union, Optional
from typing import Optional, Union

import argue
import numpy as np

from ..core.pdf import PylinacCanvas
from ..core.typing import NumberOrArray
from ..core.utilities import Structure, is_close
from . import tg51 as _tg51
from .tg51 import MAX_PPOL # make available to module
from .tg51 import (
mmHg2kPa,
mbar2kPa,
fahrenheit2celsius,
tpr2010_from_pdd2010,
MIN_PTP,
MAX_PELEC,
MAX_PION,
MAX_PTP,
MIN_PELEC,
MAX_PELEC,
MIN_PPOL,
MAX_PPOL,
MIN_PION,
MAX_PION,
) # make available to module
from ..core.pdf import PylinacCanvas
from ..core.typing import NumberOrArray
from ..core.utilities import is_close, Structure
MIN_PPOL,
MIN_PTP,
fahrenheit2celsius,
mbar2kPa,
mmHg2kPa,
tpr2010_from_pdd2010,
)

V1_V2_FITS = {
2.0: {"a0": 2.337, "a1": -3.636, "a2": 2.299},
Expand Down Expand Up @@ -1137,7 +1137,7 @@ def publish_pdf(
metadata is at the top of every page while notes is at the bottom of the report.
"""
was_adjusted = "Yes" if self.output_was_adjusted else "No"
title = "TRS-398 Electron Report - {} MV".format(self.energy)
title = f"TRS-398 Electron Report - {self.energy} MV"

canvas = PylinacCanvas(filename, page_title=title, metadata=metadata)
text = [
Expand Down
43 changes: 21 additions & 22 deletions pylinac/core/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import math
from itertools import zip_longest
from typing import Union, Optional, List, Iterable, Tuple
from typing import Iterable, List, Optional, Tuple, Union

import argue
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Circle as mpl_Circle, Rectangle as mpl_Rectangle
from matplotlib.patches import Circle as mpl_Circle
from matplotlib.patches import Rectangle as mpl_Rectangle

from .utilities import is_iterable

Expand Down Expand Up @@ -39,16 +40,16 @@ class Point:
z: float
y: float
x: float
_attr_list: List[str] = ["x", "y", "z", "idx", "value"]
_coord_list: List[str] = ["x", "y", "z"]
_attr_list: list[str] = ["x", "y", "z", "idx", "value"]
_coord_list: list[str] = ["x", "y", "z"]

def __init__(
self,
x: Union[float, tuple, Point] = 0,
x: float | tuple | Point = 0,
y: float = 0,
z: float = 0,
idx: Optional[int] = None,
value: Optional[float] = None,
idx: int | None = None,
value: float | None = None,
as_int: bool = False,
):
"""
Expand Down Expand Up @@ -85,7 +86,7 @@ def __init__(
self.y = int(round(self.y))
self.z = int(round(self.z))

def distance_to(self, thing: Union["Point", "Circle"]) -> float:
def distance_to(self, thing: Point | Circle) -> float:
"""Calculate the distance to the given point.
Parameters
Expand Down Expand Up @@ -116,7 +117,7 @@ def as_array(self, only_coords: bool = True) -> np.array:
]
)

def as_vector(self) -> "Vector":
def as_vector(self) -> Vector:
return Vector(x=self.x, y=self.y, z=self.z)

def __repr__(self):
Expand Down Expand Up @@ -160,9 +161,7 @@ class Circle:
center: Point
radius: float

def __init__(
self, center_point: Union[Point, Iterable] = (0, 0), radius: float = 0
):
def __init__(self, center_point: Point | Iterable = (0, 0), radius: float = 0):
"""
Parameters
----------
Expand Down Expand Up @@ -229,7 +228,7 @@ def as_scalar(self) -> float:
"""Return the scalar equivalent of the vector."""
return math.sqrt(self.x**2 + self.y**2 + self.z**2)

def distance_to(self, thing: Union[Circle, Point]) -> float:
def distance_to(self, thing: Circle | Point) -> float:
"""Calculate the distance to the given point.
Parameters
Expand All @@ -248,19 +247,19 @@ def distance_to(self, thing: Union[Circle, Point]) -> float:
(self.x - p.x) ** 2 + (self.y - p.y) ** 2 + (self.z - p.z) ** 2
)

def __sub__(self, other: "Vector") -> "Vector":
def __sub__(self, other: Vector) -> Vector:
new_x = self.x - other.x
new_y = self.y - other.y
new_z = self.z - other.z
return Vector(x=new_x, y=new_y, z=new_z)

def __add__(self, other: "Vector") -> "Vector":
def __add__(self, other: Vector) -> Vector:
new_x = self.x + other.x
new_y = self.y + other.y
new_z = self.z + other.z
return Vector(x=new_x, y=new_y, z=new_z)

def __truediv__(self, other: float) -> "Vector":
def __truediv__(self, other: float) -> Vector:
for attr in ("x", "y", "z"):
val = getattr(self, attr)
setattr(self, attr, val / other)
Expand Down Expand Up @@ -297,8 +296,8 @@ class Line:

def __init__(
self,
point1: Union[Point, Tuple[float, float]],
point2: Union[Point, Tuple[float, float]],
point1: Point | tuple[float, float],
point2: Point | tuple[float, float],
):
"""
Parameters
Expand Down Expand Up @@ -355,7 +354,7 @@ def length(self) -> float:
"""Return length of the line, if finite."""
return self.point1.distance_to(self.point2)

def distance_to(self, point: "Point") -> float:
def distance_to(self, point: Point) -> float:
"""Calculate the minimum distance from the line to a point.
Equations are from here: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html #14
Expand Down Expand Up @@ -397,16 +396,16 @@ def plot2axes(
class Rectangle:
"""A rectangle with width, height, center Point, top-left corner Point, and bottom-left corner Point."""

width: Union[int, float]
height: Union[int, float]
width: int | float
height: int | float
_as_int: bool
center: Point

def __init__(
self,
width: float,
height: float,
center: Union[Point, Tuple],
center: Point | tuple,
as_int: bool = False,
):
"""
Expand Down
18 changes: 8 additions & 10 deletions pylinac/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import typing
from collections import Counter
from datetime import datetime
from io import BytesIO, BufferedReader
from io import BufferedReader, BytesIO
from pathlib import Path
from typing import Union, Sequence, List, Any, Tuple, Optional, BinaryIO
from typing import Any, BinaryIO, List, Optional, Sequence, Tuple, Union

import argue
import matplotlib.pyplot as plt
Expand All @@ -24,17 +24,17 @@
from scipy import ndimage
from skimage.draw import disk

from ..settings import PATH_TRUNCATION_LENGTH, get_dicom_cmap
from .geometry import Point
from .io import (
get_url,
TemporaryZipDirectory,
retrieve_filenames,
get_url,
is_dicom_image,
retrieve_dicom_file,
retrieve_filenames,
)
from .profile import stretch as stretcharray
from .utilities import is_close, decode_binary
from ..settings import get_dicom_cmap, PATH_TRUNCATION_LENGTH
from .utilities import decode_binary, is_close

ARRAY = "Array"
DICOM = "DICOM"
Expand Down Expand Up @@ -129,7 +129,7 @@ def retrieve_image_files(path: str) -> List[str]:
def load(
path: Union[str, Path, ImageLike, np.ndarray, BinaryIO], **kwargs
) -> ImageLike:
"""Load a DICOM image, JPG/TIF/BMP image, or numpy 2D array.
r"""Load a DICOM image, JPG/TIF/BMP image, or numpy 2D array.
Parameters
----------
Expand Down Expand Up @@ -1169,9 +1169,7 @@ def _get_axis_value(self, axis_str: str, axis_dcm_attr: str) -> float:
axis_found = True
# if it is, then make sure it follows the naming convention of <axis###>
else:
match = re.search(
r"(?<={})\d+".format(axis_str.lower()), filename.lower()
)
match = re.search(rf"(?<={axis_str.lower()})\d+", filename.lower())
if match is None:
raise ValueError(
f"The filename contains '{axis_str}' but could not read a number following it. Use the format '...{axis_str}<#>...'"
Expand Down
Loading

0 comments on commit b51cc24

Please sign in to comment.