Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MPBA Radiomics
RADLER
Commits
3903899f
Commit
3903899f
authored
Mar 16, 2020
by
Alessia Marcolini
Browse files
Remove debug stuff
parent
2d97a800
Changes
1
Show whitespace changes
Inline
Side-by-side
02_radiomics_features_extraction/extract_features_radiomics.py
View file @
3903899f
...
@@ -26,7 +26,7 @@ PIXEL_SPACING = [1.0, 2.0, 3.0, 4.0, 5.0]
...
@@ -26,7 +26,7 @@ PIXEL_SPACING = [1.0, 2.0, 3.0, 4.0, 5.0]
#%%
#%%
DATADIR
=
Path
(
'data'
)
/
DATASET
/
'processed'
/
'bbox'
/
BBOX
DATADIR
=
Path
(
'data'
)
/
DATASET
/
'processed'
/
'bbox'
/
BBOX
OUTDIR
=
Path
(
'data'
)
/
DATASET
/
'processed'
OUTDIR
=
Path
(
'data'
)
/
DATASET
/
'processed'
OUTFILE
=
f
'radiomics_features_
{
BBOX
}
_radnew21
.csv'
# output file name
OUTFILE
=
f
'radiomics_features_
{
BBOX
}
.csv'
# output file name
clinical
=
pd
.
read_csv
(
Path
(
'data'
)
/
DATASET
/
'processed'
/
f
'clinical_
{
DATASET
}
.csv'
)
clinical
=
pd
.
read_csv
(
Path
(
'data'
)
/
DATASET
/
'processed'
/
f
'clinical_
{
DATASET
}
.csv'
)
...
@@ -40,7 +40,7 @@ extractor_intensity = RadiomicsFeatureExtractor(params_intensity)
...
@@ -40,7 +40,7 @@ extractor_intensity = RadiomicsFeatureExtractor(params_intensity)
params_texture
=
'02_radiomics_features_extraction/texture_new.yaml'
# param file to use to create the extractor
params_texture
=
'02_radiomics_features_extraction/texture_new.yaml'
# param file to use to create the extractor
extractor_texture
=
RadiomicsFeatureExtractor
(
params_texture
)
extractor_texture
=
RadiomicsFeatureExtractor
(
params_texture
)
filenames
=
[
f
for
f
in
os
.
listdir
(
DATADIR
)
if
f
.
endswith
(
'.npy'
)]
[:
2
]
filenames
=
[
f
for
f
in
os
.
listdir
(
DATADIR
)
if
f
.
endswith
(
'.npy'
)]
exclude_list
=
[]
exclude_list
=
[]
...
@@ -60,8 +60,6 @@ def process_file(filename):
...
@@ -60,8 +60,6 @@ def process_file(filename):
curr_modality
.
SetSpacing
(
VOXEL_SPACING
)
curr_modality
.
SetSpacing
(
VOXEL_SPACING
)
modalities
.
append
(
curr_modality
)
modalities
.
append
(
curr_modality
)
# print(data[-1, :, :, :] == data[1, :, :, :])
# print(np.max(data[-1, :, :, :]))
has_label
=
np
.
max
(
data
[
-
1
,
:,
:,
:])
>
0
has_label
=
np
.
max
(
data
[
-
1
,
:,
:,
:])
>
0
if
has_label
:
if
has_label
:
...
@@ -89,7 +87,7 @@ def process_file(filename):
...
@@ -89,7 +87,7 @@ def process_file(filename):
for
NB
in
N_BINS
:
for
NB
in
N_BINS
:
if
not
broken
:
if
not
broken
:
extractor_texture
.
settings
[
'binCount'
]
=
NB
extractor_texture
.
settings
[
'binCount'
]
=
NB
try
:
# uniform binning
# uniform binning
extractor_texture
.
settings
[
'binMode'
]
=
'uniform'
extractor_texture
.
settings
[
'binMode'
]
=
'uniform'
...
@@ -112,6 +110,9 @@ def process_file(filename):
...
@@ -112,6 +110,9 @@ def process_file(filename):
feature
[
feature
[
f
'
{
key
}
_
{
P
}
_
{
NB
}
_equalized_
{
name
}
'
f
'
{
key
}
_
{
P
}
_
{
NB
}
_equalized_
{
name
}
'
]
=
result
[
key
]
]
=
result
[
key
]
except
Exception
as
e
:
print
(
e
)
broken
=
True
if
not
broken
:
if
not
broken
:
feature
[
'filename'
]
=
filename
feature
[
'filename'
]
=
filename
...
@@ -126,18 +127,16 @@ def process_file(filename):
...
@@ -126,18 +127,16 @@ def process_file(filename):
#%% MULTIPROCESS
#%% MULTIPROCESS
result
=
[]
#
result = []
for
file
in
filenames
:
#
for file in filenames:
feat
=
process_file
(
file
)
#
feat = process_file(file)
result
.
append
(
feat
)
#
result.append(feat)
# %%
# %%
multiproc
=
ListMultiprocessing
(
process_file
,
N_JOBS
)
multiproc
.
execute
(
filenames
)
# multiproc = ListMultiprocessing(process_file, N_JOBS)
result
=
multiproc
.
get_result
()
# multiproc.execute(filenames)
# result = multiproc.get_result()
# print('done')
# print('done')
#%% Save features in a Pandas df
#%% Save features in a Pandas df
...
@@ -148,6 +147,4 @@ print('Number of files: ', features.shape[0])
...
@@ -148,6 +147,4 @@ print('Number of files: ', features.shape[0])
print
(
'Number of features: '
,
features
.
shape
[
1
]
-
1
)
print
(
'Number of features: '
,
features
.
shape
[
1
]
-
1
)
# %%
# %%
features
.
to_csv
(
OUTDIR
/
OUTFILE
)
features
.
to_csv
(
OUTDIR
/
OUTFILE
)
# %%
# %%
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment