Skip to content

Commit

Permalink
Merged in refactor/pre-commit (pull request #156)
Browse files Browse the repository at this point in the history
Pre-commit 🤯

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Feb 22, 2023
2 parents 462dcee + 65f20fc commit b059146
Show file tree
Hide file tree
Showing 94 changed files with 2,899 additions and 1,645 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
current_version = 3.8.0
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
serialize =
serialize =
{major}.{minor}.{patch}
commit = False
tag = False
Expand Down
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,3 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
6ad28467153aab333eba6fe65298904d836aa712
778533215c89743e041303e10a79166187d0408b
b21e47d612bc442204177ca492e444c31e923d75
8ac3292a50e1aa8373bc01d897209514d67bb835
b51cc243b0fb1ff301e4a24361b007ed54294800
2 changes: 1 addition & 1 deletion .github/workflows/pypi_upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: PYPI_Upload

# Controls when the action will run.
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Upload Python Package
on:
release:
types: [created]

workflow_dispatch:

jobs:
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ __pycache__/
*.py[cod]
*$py.class

# Pants tooling
/.pants.*
/dist/
/.pids

# C extensions
*.so

Expand Down Expand Up @@ -110,6 +115,7 @@ celerybeat.pid
.venv
env/
venv/
venv310/
ENV/
env.bak/
venv.bak/
Expand Down Expand Up @@ -236,4 +242,3 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-ast
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: no-commit-to-branch
args: [--branch, master, --branch, staging, --branch, production]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
stages:
- manual
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: docs\*
stages:
- manual
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
prune tests*
prune tests*
1 change: 0 additions & 1 deletion docs/source/calibration_docs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,3 @@ TRS-398 API Documentation
.. autoclass:: pylinac.calibration.trs398.TRS398Photon

.. autoclass:: pylinac.calibration.trs398.TRS398Electron

29 changes: 19 additions & 10 deletions docs/source/code_snippets/tg51_class.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
"""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)
CHAMBER = '30013' # PTW
CHAMBER = "30013" # PTW
P_ELEC = 1.000
ND_w = 5.443 # Gy/nC
MU = 200
CLINICAL_PDD = 66.5

tg51_6x = tg51.TG51Photon(
unit='TrueBeam1',
unit="TrueBeam1",
chamber=CHAMBER,
temp=TEMP, press=PRESS,
n_dw=ND_w, p_elec=P_ELEC,
measured_pdd10=66.4, lead_foil=None,
clinical_pdd10=66.5, energy=ENERGY,
voltage_reference=-300, voltage_reduced=-150,
temp=TEMP,
press=PRESS,
n_dw=ND_w,
p_elec=P_ELEC,
measured_pdd10=66.4,
lead_foil=None,
clinical_pdd10=66.5,
energy=ENERGY,
voltage_reference=-300,
voltage_reduced=-150,
m_reference=(25.65, 25.66, 25.65),
m_opposite=(25.64, 25.65, 25.65),
m_reduced=(25.64, 25.63, 25.63),
mu=MU, tissue_correction=1.0
mu=MU,
tissue_correction=1.0,
)

# Done!
Expand All @@ -39,4 +44,8 @@
print(tg51_6x.dose_mu_dmax_adjusted)

# generate a PDF for record-keeping
tg51_6x.publish_pdf('TB1 6MV TG-51.pdf', notes=['My notes', 'I used Pylinac to do this; so easy!'], open_file=False)
tg51_6x.publish_pdf(
"TB1 6MV TG-51.pdf",
notes=["My notes", "I used Pylinac to do this; so easy!"],
open_file=False,
)
18 changes: 12 additions & 6 deletions docs/source/code_snippets/tg51_function.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""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)
CHAMBER = '30013' # PTW
CHAMBER = "30013" # PTW
P_ELEC = 1.000
ND_w = 5.443 # Gy/nC
MU = 200
Expand All @@ -18,7 +17,7 @@
# Section 5 (kQ)
kq = tg51.kq_photon_pddx(chamber=CHAMBER, pddx=pdd10x)
# Alternatively, get kQ from TPR (way quicker to measure, without needing to measure TPR!)
tpr = tg51.tpr2010_from_pdd2010(pdd2010=(38.0/66.4))
tpr = tg51.tpr2010_from_pdd2010(pdd2010=(38.0 / 66.4))
kq = tg51.kq_photon_tpr(chamber=CHAMBER, tpr=tpr)

# Section 6 (Temp/Press)
Expand All @@ -31,13 +30,20 @@

# Section 8 (ionization)
m_reduced = (25.61, 25.62)
p_ion = tg51.p_ion(voltage_reference=300, voltage_reduced=150, m_reference=m_reference, m_reduced=m_reduced)
p_ion = tg51.p_ion(
voltage_reference=300,
voltage_reduced=150,
m_reference=m_reference,
m_reduced=m_reduced,
)

# Section 9 (M corrected)
m_corr = tg51.m_corrected(p_ion=p_ion, p_tp=p_tp, p_elec=P_ELEC, p_pol=p_pol, m_reference=m_reference)
m_corr = tg51.m_corrected(
p_ion=p_ion, p_tp=p_tp, p_elec=P_ELEC, p_pol=p_pol, m_reference=m_reference
)

# Section 10 (dose to water @ 10cm)
dose_10 = m_corr*kq*ND_w
dose_10 = m_corr * kq * ND_w
dose_10_per_mu = dose_10 / MU

# Section 11 (dose/MU to water @ dmax)
Expand Down
24 changes: 15 additions & 9 deletions docs/source/code_snippets/trs398_class.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
"""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)
CHAMBER = '30013' # PTW
CHAMBER = "30013" # PTW
K_ELEC = 1.000
ND_w = 5.443 # Gy/nC
MU = 200
CLINICAL_PDD = 66.5

trs398_6x = trs398.TRS398Photon(
unit='TrueBeam1',
setup='SSD',
unit="TrueBeam1",
setup="SSD",
chamber=CHAMBER,
temp=TEMP, press=PRESS,
temp=TEMP,
press=PRESS,
n_dw=ND_w,
clinical_pdd_zref=CLINICAL_PDD,
tpr2010=(38.2/66.6),
tpr2010=(38.2 / 66.6),
energy=ENERGY,
fff=False,
k_elec=K_ELEC,
voltage_reference=-300, voltage_reduced=-150,
voltage_reference=-300,
voltage_reduced=-150,
m_reference=(25.65, 25.66, 25.65),
m_opposite=(25.64, 25.65, 25.65),
m_reduced=(25.64, 25.63, 25.63),
mu=MU, tissue_correction=1.0
mu=MU,
tissue_correction=1.0,
)

# Done!
Expand All @@ -43,4 +45,8 @@
print(trs398_6x.dose_mu_zmax_adjusted)

# generate a PDF for record-keeping
trs398_6x.publish_pdf('TB1 6MV TRS-398.pdf', notes=['My notes', 'I used Pylinac to do this; so easy!'], open_file=False)
trs398_6x.publish_pdf(
"TB1 6MV TRS-398.pdf",
notes=["My notes", "I used Pylinac to do this; so easy!"],
open_file=False,
)
30 changes: 21 additions & 9 deletions docs/source/code_snippets/trs398_function.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
"""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
CHAMBER = "30013" # PTW
K_ELEC = 1.000
ND_w = 5.443 # Gy/nC
MU = 200


# Section 3 (dosimeter corrections)
k_tp = trs398.k_tp(temp=TEMP, press=PRESS)
k_pol = trs398.k_pol(m_reference=(25.66, 25.67, 25.66), m_opposite=(25.65, 25.66, 25.66))
k_s = trs398.k_s(voltage_reference=300, voltage_reduced=150,
m_reference=(25.66, 25.67, 25.66), m_reduced=(25.63, 25.65, 25.64))
m_corrected = trs398.m_corrected(m_reference=(25.66, 25.67, 25.66),
k_tp=k_tp, k_elec=K_ELEC, k_pol=k_pol, k_s=k_s) \
/ MU
k_pol = trs398.k_pol(
m_reference=(25.66, 25.67, 25.66), m_opposite=(25.65, 25.66, 25.66)
)
k_s = trs398.k_s(
voltage_reference=300,
voltage_reduced=150,
m_reference=(25.66, 25.67, 25.66),
m_reduced=(25.63, 25.65, 25.64),
)
m_corrected = (
trs398.m_corrected(
m_reference=(25.66, 25.67, 25.66),
k_tp=k_tp,
k_elec=K_ELEC,
k_pol=k_pol,
k_s=k_s,
)
/ MU
)

# Section 4 (kQ + dose at zref)
kq = trs398.kq_photon(chamber=CHAMBER, tpr=(39.2/68.1))
kq = trs398.kq_photon(chamber=CHAMBER, tpr=(39.2 / 68.1))
dose_mu_zref = m_corrected * ND_w * kq

# Section 5 (Dose at zmax)
Expand Down
Loading

0 comments on commit b059146

Please sign in to comment.