Skip to content

Commit

Permalink
Merge pull request #61 from aditiiyer/testing
Browse files Browse the repository at this point in the history
Added documentation
  • Loading branch information
aditiiyer authored Jun 13, 2024
2 parents 42633b9 + 10fd0ec commit 11e482f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
13 changes: 7 additions & 6 deletions cerr/radiomics/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,18 @@ def padScan(scan3M, mask3M, method, marginV, cropFlag=True):
'periodic' - Image is padded with periodic expansion.
'nearest' - Image is padded by using values from nearest neighbors.
'mirror' - Image is padded by mirrorig the boundary region as per the margin.
marginV:
cropFlag:
marginV: np.array (1D) specifying amount of padding to be applied
[nRows, nCols, nSlices] in voxels.
cropFlag: [optional, default:True] bool for flag to crop around mask bounding box
when set to True.
Returns:
np.ndarray(dtype=:
np.ndarray(dtype=:) outScan3M
outMask3M
outLimitsV
np.ndarray(dtype=int): , maskBoundingBox3M, morphmask3M, gridS, paramS, diagS
"""

if cropFlag is None:
cropFlag = True

if method.lower() == 'none':
marginV = [0, 0, 0]

Expand Down
42 changes: 31 additions & 11 deletions cerr/radiomics/textureUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
from cerr.utils.mask import compute_boundingbox

def loadSettingsFromFile(settingsFile, scanNum=None, planC=None):
""" Load filter parameters from user-input JSON file"""
"""
Function to load filter parameters from user-input JSON.
Args:
settingsFile: string from path to JSON file.
scanNum: [optional, default=None] Scan no. from which to extract additional
parameters like voxel size.
planC: [optional, default=None] pyCERR's plan container object.
Returns:
paramS: dictionary of radiomics parameters parsed from JSON file.
filterTypes: list of texture filters specified in JSON file.
"""

# Read settings
with open(settingsFile) as json_file:
Expand All @@ -29,12 +41,15 @@ def loadSettingsFromFile(settingsFile, scanNum=None, planC=None):

def processImage(filterType, scan3M, mask3M, paramS):
"""
Process scan using selected filter and parameters
Function to process scan using selected filter and parameters
Args:
filterType: String for name of supported filter.
scan3M: np.ndarray for 3D scan.
mask3M: np.ndarray(dtype=bool) for 3D binary mask.
paramS: dictionary of parameters (read from JSON).
Returns:
outS: dictionary containing response maps for each filter type.
filterType : Name of supported filter
scan3M : 3D scan array
mask3M : 3D mask
paramS : Dictionary of parameters (read from JSON)
"""

filterType = filterType.strip().lower()
Expand Down Expand Up @@ -156,11 +171,16 @@ def processImage(filterType, scan3M, mask3M, paramS):

def generateTextureMapFromPlanC(planC, scanNum, strNum, configFilePath):
"""
Filter image and add to planC
planC : Plan container
scanNum : Index of scan to be filtered
strNum : Index of ROI
configFilePath : Path to JSON config file with filter parameters
Function to filter scan and import result to planC.
Args:
planC: pyCERR's plan container object.
scanNum: int for index of scan to be filtered.
strNum: int for index of ROI.
configFilePath: string for path to JSON config file with filter parameters.
Returns:
planC: pyCERR's plan container object with texture map as pseudo-scan.
"""

# Extract scan and mask
Expand Down
8 changes: 7 additions & 1 deletion cerr/utils/statisticsUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import numpy as np

def quantile(x,q):
"""
Function to compute specified quantile from input array.
Returns:
qth quantile of values in input x.
"""
n = len(x)
y = np.sort(x)
return(np.interp(q, np.linspace(1/(2*n), (2*n-1)/(2*n), n), y))

def prctile(x,p):
"""Equivalent to Matlab's prctile"""
"""MATLAB prctile.m equivalent function to compute percentile"""
y = x[~np.isnan(x)]
return(quantile(y,np.array(p)/100))
11 changes: 11 additions & 0 deletions cerr/utils/uid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
from datetime import datetime

def createUID(modality):
"""
Function to create a unique identifier for various pyCERR dataclass objects.
Args:
modality: string for pyCERR object. May be 'SCAN', 'STRUCTURE', 'DOSE',
'BEAMS', 'STRUCTURESET', 'DVH', 'IVH', 'DEFORM', 'BEAM', 'CERR',
'TEXTURE', 'ANNOTATION', 'SEGLABEL', 'REGISTRATION', 'IM', 'FEATURESET'.
Returns:
Unique identifier for object of specified class, using current date and time.
"""
modality = modality.upper()
if modality == 'SCAN':
modality = 'CT'
Expand Down

0 comments on commit 11e482f

Please sign in to comment.