Skip to main content

ifree

Python package PyPI PyPI - Python Version License

ifree is a small python package for making you free.

  • Radiomics Feature Extraction
  • Feature Pre-Processing and Selecting,
  • Dicom Processing
  • Crop CT/MR according to RT Structure
  • Calculate dose volume histogram (DVH)

One of the main benefits of ifree is that it handles data easily (see example below).

Installation

ifree can be installed with pip:

pip install ifree

For the bleeding edge version, install directly from github (consider adding --force-reinstall):

pip install git+git://github.com/linzhenyuyuchen/ifree.git

or by cloning the repo:

git clone https://github.com/linzhenyuyuchen/ifree.git
cd ifree
python setup.py install

Example

Feature Processing

Radiomics Feature Extractor

radiomics.yaml

# https://github.com/Radiomics/pyradiomics/blob/master/examples/exampleSettings/exampleMR_NoResampling.yaml
# https://github.com/Radiomics/pyradiomics/blob/master/examples/exampleSettings/MR_2D_extraction.yaml
imageType:
  Original: {}
  LoG:
   # If the in-plane spacing is large (> 2mm), consider removing sigma value 1.
   sigma: [ 1.0, 3.0, 5.0 ]
  Wavelet: {}

setting:
  label: 1 # 255
#  interpolator: 'sitkBSpline'
#  resampledPixelSpacing: [2, 2, 2]

#  normalize: true
#  normalizeScale: 100  # This allows you to use more or less the same bin width.

featureClass:
  firstorder:
  shape:
  glcm:
  glrlm:
  glszm:
  gldm:
  ngtdm:
from ifree import processing

idx = list()
imagePaths = list()
maskPaths = list()
paramPath = "./radiomics.yaml"
outputPath = "./features.csv"

helper = processing.FeatureExtractor(idx, imagePaths, maskPaths, paramPath, outputPath)
helper.extract(force=True)

Feature Pre-Processing

df_train = pd.DataFrame()
df_test = pd.DataFrame()
helper = processing.FeatureProcess(df_train, df_test)
# preprocessing methods
helper.simpleImpute(strategy='mean') # mean, median, most_frequent, constant
helper.standardScale()
helper.normalizer()
helper.minMaxScaler()
helper.pca(n_components=10)
array_train = helper.X_train
array_test = helper.X_test

Feature Selector

x_array = np.array()
y_list = list()
featureNames = list()
selector = processing.FeatureSelector(x_array, y_list, featureNames)
# selection methods
x_array_new, y_array_new = selector.univarSelector(top_k=600, method_name="f_classif", inplace=True)
print(x_array_new.shape)
x_array_new, y_array_new = selector.ttestSelector(inplace=True)
print(x_array_new.shape)
x_array_new, y_array_new = selector.mannSelector(inplace=True)
print(x_array_new.shape)
x_array_new, y_array_new = selector.modelSelector(inplace=True)
print(x_array_new.shape)
# name of selected features 
print(selector.featureNames)

Dicom Processing

Crop CT/MR according to RT

from ifree import dicom

# get paths for CT, MR, DOSE and RT
fileDir = "./p/"
ctfiles, rtfile, mrfiles, dosefile, patientID, patientName = dicom.GetFilePath(fileDir)

# get MRs or CTs related to RT and copy them to new dir
patientNames, patientIDs, id2mrs, id2rt, id2dose = dicom.archiveFiles(old_Dir, new_Dir, copyed=True)

# crop ROI-MASK and its CT or MR
roiName = "ctv"
newDir = "./p/"
newSize = [100, 100, 100] # leave None to get origin size
idx_done_list = dicom.cropROI(id2mrs, id2rt, roiName, newDir, newSize)

idx_done_list = dicom.cropDose(id2dose, id2rt, roiName, newDir, newSize)

Get Dose-Volume Histogram (DVH)

# Get Dose-Volume Histogram (DVH)
rtssfile = "./RT.dicom"
rtdosefile = "./RS.dicom"
# percents is the space between 0-100
roiname = "Body"
data, percents = dicom.get_dvh_of_key(rtssfile, rtdosefile)
dose_list, max_value, min_value, mean_value = data[roiname]

# saved to dataframe
dose_features = {}
roiname = "Body"
for i, (pid, rtssfile) in enumerate(id2rt.item()):
    rtdosefile = id2dose[pid]
    # percents is the space between 0-100
    data, percents = dicom.get_dvh_of_key(rtssfile, rtdosefile)
    dose_list, max_value, min_value, mean_value = data[roiname]
    tmp = {"pid": pid, "dose_max": max_value, "dose_min": min_value, "dose_mean": mean_value,}
    for i, pc in enumerate(percents):
        tmp[f"dose_{pc}"] = dose_list[i]
    dose_features[i] = tmp
df_dose_features = pd.DataFrame.from_dict(dose_features, orient='index')
df_dose_features.head()

For more examples, see the examples folder.

Metadata

Release files for ifree 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ifree 1.1.1
File Size Uploaded Provenance Actions
ifree-1.1.1.tar.gz 16.9 kB Without provenance Details for ifree-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ifree 1.1.1
File Interpreter ABI Platform Actions
ifree-1.1.1-py3-none-any.whl Python 3 none any Details for ifree-1.1.1-py3-none-any.whl

Total release size: 33.7 kB

Release files / ifree-1.1.1.tar.gz

Download URL ifree-1.1.1.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9552fe2f194d1a21664351717d484311180ad7b4f07ac482583263bce1425e97
BLAKE2b-256 checksum
How to use checksums
27da323548ab4d622932ccbc8bffeb2289da13bc80198e591d12fd9233811f90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.6

Release files / ifree-1.1.1-py3-none-any.whl

Download URL ifree-1.1.1-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85d74eb36830f21c5a11c8d30df5318caf3ccb23ca36f8bcd89ed949d0032cdb
BLAKE2b-256 checksum
How to use checksums
ad5a1f189507ea408f834e55d49d86db06388eff23ab7d209f612e7f3be55b46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.6

Security for ifree 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page