Commit cdb08a2e authored by Alessia Marcolini's avatar Alessia Marcolini
Browse files

Remove unused files

parent 0bd7b229
# IPython line magic to enable import and executions of `utils` in notebooks
#
# To enable this magic, please copy or link this file in your **startup** IPython folder
# Default Path: $HOME/.ipython/profile_default/startup
from IPython.core.magic import register_line_magic
from IPython.display import HTML as html_print
import os
import sys
@register_line_magic
def HN_env(line):
def set_path(path):
if not path:
path = '..'
curpath = os.path.abspath(os.path.curdir)
env = os.path.join(curpath, path)
sys.path += [env]
return f'<text style="color: green;">Success</text>'
return html_print(set_path(line))
preprocess.ipynb, Andrea, 10 Dec 2018
Errors:
['HN-CHUM-005', 'HN-HMR-017', 'HN-HMR-007']
Errors in SUV conversion
HN-CHUM-020
HN-CHUS-093
HN-HMR-001
\ No newline at end of file
%% Cell type:code id: tags:
``` python
#PATH = '/home/bizzego/UniTn/networks_dami'
PATH = '/media/damiana/DATA'
#PATH = '/media/damiana/Maxtor'
```
%% Cell type:code id: tags:
``` python
import os
import numpy as np
import SimpleITK as sitk
import pandas as pd
import dicom_utils.dicom_utils as du
import dicom_utils.dicom_utils.visualize as viz
import gc
def to_numpy(image):
return(sitk.GetArrayFromImage(image))
```
%% Cell type:code id: tags:
``` python
#%%
DATADIR = f'{PATH}/data/original' #Original data
OUTDIR = f'{PATH}/data/processed/bbox_fixed2/' #Destinatino of processed data (a folder for each patient will be created)
DIR_INFO_FILE = f'{PATH}/data/summary.csv' #where to find the info about the Original data folders to use
ROI_INFO_FILE = f'{PATH}/data/INFO_GTVcontours_HN.csv' # where to find the info about the name of the ROI
```
%% Cell type:code id: tags:
``` python
BOX_SIZE = 128 #mm == pixels for voxel size of 1mm3
VOXEL_SIZE = [1,1,1]
HALF_BOX = int(BOX_SIZE/2)
gaussian = sitk.SmoothingRecursiveGaussianImageFilter()
gaussian.SetSigma(2)
#%%
dir_info = pd.read_csv(DIR_INFO_FILE)
roi_info = pd.read_csv(ROI_INFO_FILE)
subjects = os.listdir(DATADIR)
errors = []
```
%% Cell type:code id: tags:
``` python
SUB = subjects[:4]
```
%% Cell type:code id: tags:
``` python
#%%
for SUB in subjects[:4]: #cambiare
#%%
print(SUB)
#%%
```
%% Output
HN-CHUM-001
%% Cell type:code id: tags:
``` python
subjects
```
%% Output
['HN-CHUM-001',
'HN-CHUM-002',
'HN-CHUM-003',
'HN-CHUM-004',
'HN-CHUM-005',
'HN-CHUM-006',
'HN-CHUM-007',
'HN-CHUM-008',
'HN-CHUM-009',
'HN-CHUM-010',
'HN-CHUM-011',
'HN-CHUM-012',
'HN-CHUM-013',
'HN-CHUM-014',
'HN-CHUM-015',
'HN-CHUM-016',
'HN-CHUM-017',
'HN-CHUM-018',
'HN-CHUM-019',
'HN-CHUM-021',
'HN-CHUM-022',
'HN-CHUM-023',
'HN-CHUM-024',
'HN-CHUM-025',
'HN-CHUM-026',
'HN-CHUM-027',
'HN-CHUM-028',
'HN-CHUM-029',
'HN-CHUM-030',
'HN-CHUM-031',
'HN-CHUM-032',
'HN-CHUM-033',
'HN-CHUM-034',
'HN-CHUM-035',
'HN-CHUM-036',
'HN-CHUM-037',
'HN-CHUM-038',
'HN-CHUM-039',
'HN-CHUM-041',
'HN-CHUM-042',
'HN-CHUM-043',
'HN-CHUM-044',
'HN-CHUM-045',
'HN-CHUM-046',
'HN-CHUM-047',
'HN-CHUM-048',
'HN-CHUM-049',
'HN-CHUM-050',
'HN-CHUM-051',
'HN-CHUM-052',
'HN-CHUM-053',
'HN-CHUM-054',
'HN-CHUM-055',
'HN-CHUM-056',
'HN-CHUM-057',
'HN-CHUM-058',
'HN-CHUM-059',
'HN-CHUM-061',
'HN-CHUM-062',
'HN-CHUM-063',
'HN-CHUM-064',
'HN-CHUM-065',
'HN-CHUS-001',
'HN-CHUS-002',
'HN-CHUS-003',
'HN-CHUS-004',
'HN-CHUS-005',
'HN-CHUS-006',
'HN-CHUS-007',
'HN-CHUS-008',
'HN-CHUS-009',
'HN-CHUS-010',
'HN-CHUS-011',
'HN-CHUS-012',
'HN-CHUS-013',
'HN-CHUS-014',
'HN-CHUM-020',
'HN-CHUM-040',
'HN-CHUM-060',
'HN-CHUS-015',
'HN-CHUS-016',
'HN-CHUS-017',
'HN-CHUS-018',
'HN-CHUS-019',
'HN-CHUS-020',
'HN-CHUS-021',
'HN-CHUS-022',
'HN-CHUS-023',
'HN-CHUS-024',
'HN-CHUS-025',
'HN-CHUS-026',
'HN-CHUS-027',
'HN-CHUS-028',
'HN-CHUS-029',
'HN-CHUS-030',
'HN-CHUS-031',
'HN-CHUS-032',
'HN-CHUS-033',
'HN-CHUS-034',
'HN-CHUS-035',
'HN-CHUS-036',
'HN-CHUS-037',
'HN-CHUS-038',
'HN-CHUS-039',
'HN-CHUS-040',
'HN-CHUS-041']
%% Cell type:code id: tags:
``` python
dir_info_sub = dir_info.query("subject == @SUB")
roi_name = roi_info.query('patient == @SUB')['roi_name'].values[0]
dir_CT = dir_info_sub.query("modality == 'CT'").dir.values[0]
dir_PT = dir_info_sub.query("modality == 'PT'").dir.values[0]
dir_RT = dir_info_sub.query("modality == 'RTSTRUCT'").dir.values[0]
scan_CT = du.load_series(os.path.join(DATADIR, dir_CT))
scan_PT = du.load_SUV(os.path.join(DATADIR, dir_PT))
#%%
if 'PETPET' in dir_RT:
segmentation = du.load_roi(os.path.join(DATADIR, dir_RT, '000000.dcm'), roi_name, scan_PT)
else:
segmentation = du.load_roi(os.path.join(DATADIR, dir_RT, '000000.dcm'), roi_name, scan_CT)
#%%
start_mm, stop_mm = du.get_bbox_vertices(segmentation)
center_mm = (np.array(stop_mm) + np.array(start_mm))/2
start_mm = center_mm - HALF_BOX - 5 #add margin to allow a better interpolation
stop_mm = center_mm + HALF_BOX + 5
scan_CT_box = du.extract_volume(scan_CT, start_mm, stop_mm)
#%%
#upsample and register
scan_CT_box = du.processing.resample(scan_CT_box, spacing=VOXEL_SIZE)
scan_PT_box = sitk.Resample(scan_PT, scan_CT_box)
#segmentation_box = sitk.Resample(segmentation, scan_CT_box)
#segmentation_box = gaussian.Execute(segmentation_box)
#out = segmentation_box>0.5
start_mm = start_mm + 5 #remove margin
stop_mm = stop_mm - 5 #remove margin
scan_CT_box = du.extract_volume(scan_CT_box, start_mm, stop_mm)
scan_PT_box = du.extract_volume(scan_PT_box, start_mm, stop_mm)
out = np.stack([to_numpy(scan_CT_box), to_numpy(scan_PT_box)], axis = 0)#, to_numpy(segmentation_box)], axis = 0)
#save
np.save(f'{OUTDIR}/{SUB}.npy', out)
del scan_CT_box, scan_PT_box, segmentation, out
gc.collect()
```
%% Output
0
%% Cell type:code id: tags:
``` python
errors.append(SUB)
print(f'Error processing sub: {SUB}')
#%%
print(errors)
```
%% Output
Error processing sub: HN-CHUM-001
['HN-CHUM-001', 'HN-CHUM-002', 'HN-CHUM-003', 'HN-CHUM-001', 'HN-CHUM-001']
%% Cell type:code id: tags:
``` python
```