Skip to content

Commit

Permalink
Renamed routines to use camel-case
Browse files Browse the repository at this point in the history
  • Loading branch information
adityaapte committed Jun 25, 2024
1 parent 04f89ad commit 0048cdd
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 81 deletions.
24 changes: 12 additions & 12 deletions cerr/dcm_export/iod_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from random import randint


def get_file_meta(dataType) -> FileMetaDataset:
def getFileMeta(dataType) -> FileMetaDataset:
file_meta = FileMetaDataset()
file_meta.FileMetaInformationGroupLength = 202
file_meta.FileMetaInformationVersion = b"\x00\x01"
Expand All @@ -42,7 +42,7 @@ def get_file_meta(dataType) -> FileMetaDataset:
return file_meta


def add_equipment_tags(ds: FileDataset, equipDict):
def addEquipmentTags(ds: FileDataset, equipDict):
dt = datetime.now()
ds.Manufacturer = "pyCERR"
ds.ManufacturerModelName = "pyCERR"
Expand All @@ -53,7 +53,7 @@ def add_equipment_tags(ds: FileDataset, equipDict):

return ds

def add_study_tags(ds: FileDataset, studyDict):
def addStudyTags(ds: FileDataset, studyDict):
dt = datetime.now()
ds.StudyDate = studyDict["StudyDate"]
ds.StudyTime = studyDict["StudyTime"]
Expand All @@ -63,7 +63,7 @@ def add_study_tags(ds: FileDataset, studyDict):

return ds

def add_series_tags(ds: FileDataset, seriesDict):
def addSeriesTags(ds: FileDataset, seriesDict):
dt = datetime.now()
ds.Modality = seriesDict['Modality']
ds.SeriesDate = dt.strftime("%Y%m%d")
Expand All @@ -74,7 +74,7 @@ def add_series_tags(ds: FileDataset, seriesDict):

return ds

def add_patient_tags(ds: FileDataset, patDict):
def addPatientTags(ds: FileDataset, patDict):
ds.PatientName = patDict["PatientName"]
ds.PatientID = patDict["PatientID"]
ds.PatientBirthDate = patDict["PatientBirthDate"]
Expand All @@ -84,7 +84,7 @@ def add_patient_tags(ds: FileDataset, patDict):
ds.PatientWeight = patDict["PatientWeight"]
return ds

def add_content_tags(ds: FileDataset, contentDict):
def addContentTags(ds: FileDataset, contentDict):
dt = datetime.now()
ds.ContentCreatorName = ''
ds.ContentDate = dt.strftime("%Y%m%d")
Expand All @@ -95,7 +95,7 @@ def add_content_tags(ds: FileDataset, contentDict):
return ds


def add_sop_common_tags(ds: FileDataset):
def addSOPCommonTags(ds: FileDataset):
dt = datetime.now()
ds.SpecificCharacterSet = "ISO_IR 192" # "ISO_IR 100"
ds.InstanceCreationDate = dt.strftime("%Y%m%d")
Expand All @@ -110,11 +110,11 @@ def add_sop_common_tags(ds: FileDataset):
return ds


def add_general_image_tags(ds: FileDataset):
def addGeneralImageTags(ds: FileDataset):
# ds.InstanceNumber # 0020,0013
pass

def add_image_plane_tags(ds: FileDataset):
def addImagePlaneTags(ds: FileDataset):
# ds.PixelSpacing # 0028,0030 (mm)
# ds.ImageOrientation
# ds.ImagePosition
Expand All @@ -123,17 +123,17 @@ def add_image_plane_tags(ds: FileDataset):
# ds.SliceThickness # optional, for scan
pass

def add_image_pixel_tags(ds: FileDataset):
def addImagePixelTags(ds: FileDataset):
pass


def add_ref_FOR_tags(ds_refFOR: Sequence):
def addRefFORTags(ds_refFOR: Sequence):
#ds_refFOR.FrameOfReference
#s_refFOR.RTReferencedStudySequence = Sequence()
pass


def add_structure_set_tags(ds: FileDataset, structureDict):
def addStructureSetTags(ds: FileDataset, structureDict):
# https://dicom.nema.org/dicom/2013/output/chtml/part03/sect_A.19.html
dt = datetime.now()
ds.StructureSetLabel = structureDict['StructureSetLabel'] # 3006,0002 Structure Set Label
Expand Down
36 changes: 18 additions & 18 deletions cerr/dcm_export/rtstruct_iod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

org_root = '1.3.6.1.4.1.9590.100.1.2.'

def get_dcm_tag_vals(structNumV, planC, seriesOpts = {}):
def getDcmTagVals(structNumV, planC, seriesOpts = {}):

assocScanNum = scn.getScanNumFromUID(planC.structure[structNumV[0]].assocScanUID,planC)
pat_tags = {"PatientName": planC.scan[assocScanNum].scanInfo[0].patientName,
Expand Down Expand Up @@ -69,7 +69,7 @@ def get_dcm_tag_vals(structNumV, planC, seriesOpts = {}):

return pat_tags, study_tags, series_tags, equiqmt_tags, content_tags, struct_set_tags

def get_ref_FOR_seq(structNumV, planC):
def getRefFORSeq(structNumV, planC):
# 3006,0010 Referenced Frame of Reference Sequence
# 0020,0052 Frame of Reference UID
# 3006,0012 RT Referenced Study Sequence
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_ref_FOR_seq(structNumV, planC):
return refFORSeq


def get_struct_set_roi_seq(structNumV, planC):
def getStructSetROISeq(structNumV, planC):
# 3006,0020 Structure Set ROI Sequence
# 3006,0022 ROI Number
# 3006,0024 Referenced Frame of Reference UID
Expand Down Expand Up @@ -132,7 +132,7 @@ def get_struct_set_roi_seq(structNumV, planC):
def convertCerrToDcmCoords(pointsM,planC):
return pointsM

def get_roi_contour_seq(structNumV, planC):
def getROIContourSeq(structNumV, planC):
# 3006, 0039 ROI Contour Sequence
#3006,0084 Referenced ROI Number
#3006,002A ROI Display Color
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_roi_contour_seq(structNumV, planC):

return roiContourSeq

def get_roi_observ_seq(structNumV, planC):
def getROIObservSeq(structNumV, planC):
#3006,0080 RT Observation Sequence
# 3006,0082 Observation Number
# 3006,0084 Referenced ROI Number
Expand Down Expand Up @@ -235,36 +235,36 @@ def create(structNumV, filePath, planC, seriesOpts = {}):

# Get related UIDs for structNumV
pat_tags, study_tags, series_tags, equiqmt_tags, content_tags, struct_set_tags = \
get_dcm_tag_vals(structNumV, planC, seriesOpts)
getDcmTagVals(structNumV, planC, seriesOpts)

# Initialize RTSTRUCT series
# ds = create_reg_dataset(base_series_data, filePath)
file_meta = iod_helper.get_file_meta('RTSTRUCT')
file_meta = iod_helper.getFileMeta('RTSTRUCT')
ds = FileDataset(filePath, {}, file_meta=file_meta, preamble=b"\0" * 128)

ds = iod_helper.add_sop_common_tags(ds)
ds = iod_helper.addSOPCommonTags(ds)

# Add Patient tags
ds = iod_helper.add_patient_tags(ds, pat_tags)
ds = iod_helper.addPatientTags(ds, pat_tags)

# Add Study tags
ds = iod_helper.add_study_tags(ds, study_tags)
ds = iod_helper.addStudyTags(ds, study_tags)

# Add Series tags
ds = iod_helper.add_series_tags(ds, series_tags)
ds = iod_helper.addSeriesTags(ds, series_tags)

# Add Equipment tags
ds = iod_helper.add_equipment_tags(ds, equiqmt_tags)
ds = iod_helper.addEquipmentTags(ds, equiqmt_tags)

# Add Content tags
ds = iod_helper.add_content_tags(ds, content_tags)
ds = iod_helper.addContentTags(ds, content_tags)

# Add Structure Set tags
ds = iod_helper.add_structure_set_tags(ds, struct_set_tags)
ds.ReferencedFrameOfReferenceSequence = get_ref_FOR_seq(structNumV, planC)
ds.StructureSetROISequence = get_struct_set_roi_seq(structNumV, planC)
ds.ROIContourSequence = get_roi_contour_seq(structNumV, planC)
ds.RTROIObservationsSequence = get_roi_observ_seq(structNumV, planC)
ds = iod_helper.addStructureSetTags(ds, struct_set_tags)
ds.ReferencedFrameOfReferenceSequence = getRefFORSeq(structNumV, planC)
ds.StructureSetROISequence = getStructSetROISeq(structNumV, planC)
ds.ROIContourSequence = getROIContourSeq(structNumV, planC)
ds.RTROIObservationsSequence = getROIObservSeq(structNumV, planC)

print("Writing RTSTRUCT file ...", filePath)
ds.save_as(filePath)
Expand Down
33 changes: 15 additions & 18 deletions cerr/plan_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def loadH5Strucutre(structGrp, planC):
return planC


def load_dcm_dir(dcm_dir, opts={}, initplanC=''):
def loadDcmDir(dcm_dir, opts={}, initplanC=''):
"""This routine imports metadata from DICOM directory and sub-directories into an instance of PlanC.
Args:
Expand All @@ -410,7 +410,7 @@ def load_dcm_dir(dcm_dir, opts={}, initplanC=''):
raise FileNotFoundError(dcm_dir + 'is not a valid directory path')
# pc.PlanC is the container to hold various dicom objects
# Parse dcm_dir an extract a map of CT, RTSTRUCT, RTDOSE etc files to pass to populate_planC_field routine
df_img = parse_dcm_dir(dcm_dir)
df_img = parseDcmHeader(dcm_dir)
#pt_groups = df_img.groupby(by=["PatientName","PatientID","Modality"])
# Ignore fileName column from grouping
if not isinstance(initplanC, PlanC):
Expand All @@ -431,19 +431,19 @@ def load_dcm_dir(dcm_dir, opts={}, initplanC=''):
modality = group_content.iloc[0,4]
if modality in ["CT","PT", "MR"]:
# populate scan attributes
scan_meta = populate_planC_field('scan', files, opts)
scan_meta = populatePlanCField('scan', files, opts)
planC.scan.extend(scan_meta)
elif modality in ["RTSTRUCT", "SEG"]:
# populate structure attributes
struct_meta = populate_planC_field('structure', files)
struct_meta = populatePlanCField('structure', files)
planC.structure.extend(struct_meta)
elif modality == "RTPLAN":
# populate beams attributes
beams_meta = populate_planC_field('beams', files)
beams_meta = populatePlanCField('beams', files)
planC.beams.extend(beams_meta)
elif modality == "RTDOSE":
# populate dose attributes
dose_meta = populate_planC_field('dose', files)
dose_meta = populatePlanCField('dose', files)
planC.dose.extend(dose_meta)
else:
print(d["Modality"][0]+ " not supported")
Expand All @@ -468,7 +468,7 @@ def load_dcm_dir(dcm_dir, opts={}, initplanC=''):
#with open(save_file, 'wb') as pickle_file:
# pickle.dump(planC, pickle_file)

def populate_planC_field(field_name, file_list, opts={}):
def populatePlanCField(field_name, file_list, opts={}):
if field_name == "scan":
scan_meta = []
scan_meta.append(scn.load_sorted_scan_info(file_list))
Expand All @@ -495,18 +495,15 @@ def populate_planC_field(field_name, file_list, opts={}):
beams_meta = bms.load_beams(file_list)
return beams_meta

def load_planC_from_pkl(file_name=""):
def loadPlanCFromPkl(file_name=""):
file_name = r"C:\Users\aptea\PycharmProjects\pycerr\src\pycerr\tcga-ba-4074.mat"
# Load planC from file
#planC = sio.loadmat(file_name)
with open(file_name, 'rb') as pickle_file:
planC = pickle.load(pickle_file)
return planC

def save_scan_to_nii(scan_num, nii_file_name, planC):
pass

def load_nii_scan(nii_file_name, imageType = "CT SCAN", direction='', initplanC=''):
def loadNiiScan(nii_file_name, imageType ="CT SCAN", direction='', initplanC=''):
if not isinstance(initplanC, PlanC):
planC = PlanC(header=headr.Header())
else:
Expand Down Expand Up @@ -605,7 +602,7 @@ def load_nii_scan(nii_file_name, imageType = "CT SCAN", direction='', initplanC=
return planC


def load_nii_structure(nii_file_name, assocScanNum, planC, labels_dict = {}):
def loadNiiStructure(nii_file_name, assocScanNum, planC, labels_dict = {}):
planC = structr.import_nii(nii_file_name,assocScanNum,planC,labels_dict)
# struct_meta = structr.import_nii(nii_file_name,assocScanNum,planC,labels_dict)
# numOrigStructs = len(planC.structure)
Expand All @@ -618,10 +615,10 @@ def load_nii_structure(nii_file_name, assocScanNum, planC, labels_dict = {}):
return planC


def load_nii_dose(nii_file_name, planC):
def loadNiiDose(nii_file_name, planC):
pass

def load_nii_vf(dvf_file, baseScanNum, planC):
def loadNiiVf(dvf_file, baseScanNum, planC):

# Get image direction of the baseScanNum
scanOrientV = planC.scan[baseScanNum].scanInfo[0].imageOrientationPatient
Expand Down Expand Up @@ -690,7 +687,7 @@ def load_nii_vf(dvf_file, baseScanNum, planC):
return planC


def import_scan_array(scan3M, xV, yV, zV, modality, assocScanNum, planC):
def importScanArray(scan3M, xV, yV, zV, modality, assocScanNum, planC):
org_root = '1.3.6.1.4.1.9590.100.1.2.' # to create seriesInstanceUID
seriesInstanceUID = generate_uid(prefix=org_root)
scan = scn.Scan()
Expand Down Expand Up @@ -749,12 +746,12 @@ def import_scan_array(scan3M, xV, yV, zV, modality, assocScanNum, planC):
planC.scan.append(scan)
return planC

def import_structure_mask(mask3M, assocScanNum, structName, structNum, planC):
def importStructureMask(mask3M, assocScanNum, structName, structNum, planC):
planC = structr.import_structure_mask(mask3M, assocScanNum, structName, structNum, planC)
return planC


def parse_dcm_dir(dcm_dir):
def parseDcmHeader(dcm_dir):
from pydicom.misc import is_dicom
from pydicom import dcmread
import os
Expand Down
4 changes: 2 additions & 2 deletions cerr/radiomics/ibsi1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from cerr.radiomics import first_order, gray_level_cooccurence, run_length,\
size_zone, neighbor_gray_level_dependence, neighbor_gray_tone
from cerr.utils.mask import compute_boundingbox
from cerr.utils.mask import computeBoundingBox
from cerr.radiomics import preprocess, texture_utils
import json

Expand Down Expand Up @@ -166,7 +166,7 @@ def computeScalarFeatures(scanNum, structNum, settingsFile, planC):
# Pre-process Image
(processedScan3M, processedMask3M, morphMask3M, gridS, radiomicsSettingS, diagS) = \
preprocess.preProcessForRadiomics(scanNum, structNum, radiomicsSettingS, planC)
minr,maxr,minc,maxc,mins,maxs,__ = compute_boundingbox(processedMask3M)
minr,maxr,minc,maxc,mins,maxs,__ = computeBoundingBox(processedMask3M)
voxSizeV = gridS["PixelSpacingV"]

############################################
Expand Down
4 changes: 2 additions & 2 deletions cerr/radiomics/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
import cerr.contour.rasterseg as rs
from cerr.utils.mask import compute_boundingbox
from cerr.utils.mask import computeBoundingBox
import SimpleITK as sitk

# from scipy.interpolate import interpn
Expand Down Expand Up @@ -313,7 +313,7 @@ def padScan(scan3M, mask3M, method, marginV, cropFlag=True):
mask3M = mask3M.copy()

if cropFlag:
minr, maxr, minc, maxc, mins, maxs, __ = compute_boundingbox(mask3M)
minr, maxr, minc, maxc, mins, maxs, __ = computeBoundingBox(mask3M)
croppedScan3M = scan3M[minr:maxr+1, minc:maxc+1, mins:maxs+1]
croppedMask3M = mask3M[minr:maxr+1, minc:maxc+1, mins:maxs+1]
minr = minr - marginV[0]
Expand Down
4 changes: 2 additions & 2 deletions cerr/radiomics/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from cerr.utils.mask import getSurfacePoints
from scipy.spatial import distance
from skimage import measure
from cerr.utils.mask import compute_boundingbox
from cerr.utils.mask import computeBoundingBox

def trimeshSurfaceArea(v,f):
"""Routine to calculate surface area from vertices and faces of triangular mesh
Expand Down Expand Up @@ -101,7 +101,7 @@ def calcShapeFeatures(mask3M, xValsV, yValsV, zValsV):
volume = voxel_volume * np.sum(maskForShape3M)

# Fill holes
rmin,rmax,cmin,cmax,smin,smax,_ = compute_boundingbox(maskForShape3M, 0, 1)
rmin,rmax,cmin,cmax,smin,smax,_ = computeBoundingBox(maskForShape3M, 0, 1)
#struct3D = np.ones((3,3,3))
#maskForShape3M = ndimage.binary_fill_holes(maskForShape3M[rmin:rmax+1,cmin:cmax+1,smin:smax+1])
maskForShape3M = maskForShape3M[rmin:rmax+1,cmin:cmax+1,smin:smax+1]
Expand Down
4 changes: 2 additions & 2 deletions cerr/radiomics/texture_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from scipy.signal import convolve
from scipy.ndimage import rotate
from cerr.radiomics.preprocess import padScan
from cerr.utils.mask import compute_boundingbox
from cerr.utils.mask import computeBoundingBox


def meanFilter(scan3M, kernelSize, absFlag=False):
Expand Down Expand Up @@ -710,7 +710,7 @@ def energyFilter(tex3M, mask3M, texPadFlag, texPadSizeV, texPadMethod,\
if not texPadFlag:
valOrigPadV = [0,0,0,0,0,0]
elif texPadMethod.lower=='expand':
minr, maxr, minc, maxc, mins, maxs, __ = compute_boundingbox(mask3M)
minr, maxr, minc, maxc, mins, maxs, __ = computeBoundingBox(mask3M)
valOrigPadV = [np.min(texPadSizeV[0], minr), np.min(texPadSizeV[0], origSizeV[0]-maxr),\
np.min(texPadSizeV[1], minc), np.min(texPadSizeV[1], origSizeV[1]-maxc),\
np.min(texPadSizeV[2], mins), np.min(texPadSizeV[2], origSizeV[2]-maxs)]
Expand Down
Loading

0 comments on commit 0048cdd

Please sign in to comment.