Skip to content

Commit

Permalink
fix requirements for plan2sobp (#783)
Browse files Browse the repository at this point in the history
* better reqs

* docs update

* defer package imports

* fix
  • Loading branch information
grzanka authored Jan 2, 2025
1 parent 964bc4b commit 353e06c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 2 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ In order to use all feautures (i.e. all available converters), use::

pip install "pymchelper[full]"

To install as well `plan2sobp` program type: ``pip install "pymchelper[dicom]"``


Python package (Debian based Linux)
-----------------------------------
Expand Down
38 changes: 25 additions & 13 deletions pymchelper/utils/radiotherapy/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import argparse
import pymchelper

import pydicom as dicom
import numpy as np
from pathlib import Path
from typing import Optional

from dataclasses import dataclass, field
from math import exp, log
from scipy.interpolate import interp1d

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -84,6 +82,13 @@ def __init__(self, fn: Path, nominal=True):

self.has_divergence = False

try:
from scipy.interpolate import interp1d
except ImportError:
logger.error("scipy is not installed, cannot interpolate beam model.")
logger.error("Please install pymchelper[dicom] or pymchelper[all] to us this feature.")
return

if cols in (6, 10):
self.f_en = interp1d(energy, data[:, 0], kind=k) # nominal energy [MeV]
self.f_e = interp1d(energy, data[:, 1], kind=k) # measured energy [MeV]
Expand Down Expand Up @@ -524,10 +529,16 @@ def load_PLD_IBA(file_pld: Path, scaling=1.0) -> Plan:

def load_DICOM_VARIAN(file_dcm: Path, scaling=1.0) -> Plan:
"""Load varian type dicom plans."""
p = Plan()
try:
import pydicom as dicom
except ImportError:
logger.error("pydicom is not installed, cannot read DICOM files.")
logger.error("Please install pymchelper[dicom] or pymchelper[all] to us this feature.")
return p
ds = dicom.dcmread(file_dcm)
# Total number of energy layers used to produce SOBP

p = Plan()
p.patient_id = ds['PatientID'].value
p.patient_name = ds['PatientName'].value
p.patient_initals = ""
Expand Down Expand Up @@ -617,16 +628,20 @@ def main(args=None) -> int:
help="optional input beam model in commasparated CSV format",
dest='fbm',
default=None)
parser.add_argument('-i', '--flip',
parser.add_argument('-i',
'--flip',
action='store_true',
help="flip XY axis of input (x -> y and y -> x)",
dest="flip_xy", default=False)
parser.add_argument('-x', '--xflip',
dest="flip_xy",
default=False)
parser.add_argument('-x',
'--xflip',
action='store_true',
help="flip x axis of input (x -> -x)",
dest="flip_x",
default=False)
parser.add_argument('-y', '--yflip',
parser.add_argument('-y',
'--yflip',
action='store_true',
help="flip y axis of input (y -> -y)",
dest="flip_y",
Expand All @@ -635,8 +650,8 @@ def main(args=None) -> int:
'--field',
type=int,
dest='field_nr',
help="select which field to export, for dicom files holding several fields. "
+ "'0' will produce multiple output files with a running number.",
help="select which field to export, for dicom files holding several fields. " +
"'0' will produce multiple output files with a running number.",
default=1)
parser.add_argument('-d',
'--diag',
Expand Down Expand Up @@ -672,10 +687,7 @@ def main(args=None) -> int:
else:
bm = None

pln = load(parsed_args.fin, bm, parsed_args.scale,
parsed_args.flip_xy,
parsed_args.flip_x,
parsed_args.flip_y)
pln = load(parsed_args.fin, bm, parsed_args.scale, parsed_args.flip_xy, parsed_args.flip_x, parsed_args.flip_y)

if parsed_args.diag:
pln.diagnose()
Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def write_version_py():
'image': ['matplotlib'],
'excel': ['xlwt'],
'hdf': ['h5py'],
'dicom': ["pydicom"],
'dicom': ["pydicom", "scipy"],
'pytrip': [
'scipy',
"pytrip98>=3.8.0,<3.9.0 ; platform_system == 'Darwin' and python_version >= '3.11'",
Expand Down Expand Up @@ -79,10 +79,8 @@ def write_version_py():
# |---------------------------------------------------|
# see https://www.python.org/dev/peps/pep-0508/ for language specification
install_requires = [
"numpy>=1.26 ; python_version == '3.12'",
"numpy>=1.23.3 ; python_version == '3.11'",
"numpy>=1.21 ; python_version == '3.10'",
"numpy>=1.20,<1.27.0 ; python_version == '3.9'"
"numpy>=1.26 ; python_version == '3.12'", "numpy>=1.23.3 ; python_version == '3.11'",
"numpy>=1.21 ; python_version == '3.10'", "numpy>=1.20,<1.27.0 ; python_version == '3.9'"
]

setuptools.setup(
Expand Down

0 comments on commit 353e06c

Please sign in to comment.