cf / app_prep
Yeefei's picture
Upload 230 files
87034d1 verified
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 17 19:47:32 2024
@author: yanwe
"""
import pandas as pd
import shutil
import os
test = pd.read_csv('/mnt/de1dcd1c-9be8-42ed-aa06-bb73570121ac/MIMIC_CXR/60k/meta/test.csv', nrows=500)
test['path_preproc'] = None
for n in range(500):
test.loc[n,'path_preproc'] = f'{n}.jpg'
source_file = '/mnt/de1dcd1c-9be8-42ed-aa06-bb73570121ac/MIMIC_CXR/60k/data'
target_directory = '/mnt/de1dcd1c-9be8-42ed-aa06-bb73570121ac/cf_app/data/mimic_subset'
for n in range(500):
file_name = os.path.join(source_file, test.loc[n,'dicom_id'] + '.jpg')
new_name = os.path.join(target_directory, test.loc[n,'path_preproc'])
shutil.copy(file_name, new_name)
def label_to_name(data):
if data['disease_label'] == 0:
return "No Finding"
elif data['disease_label'] == 1:
return "Pleural Effusion"
elif data['disease_label'] == 2:
return "Pneumonia"
else:
return "No Finding"
def label_to_sex(data):
if data['sex_label'] == 0:
return "Female"
elif data['sex_label'] == 1:
return "Male"
else:
return "Female"
def label_to_race(data):
if data['race_label'] == 0:
return "White"
elif data['race_label'] == 1:
return "Black"
elif data['race_label'] == 2:
return "Asian"
test['disease'] = test.apply(label_to_name, axis=1)
test['sex'] = test.apply(label_to_sex, axis=1)
test['race'] = test.apply(label_to_race, axis=1)
test.to_csv('/mnt/de1dcd1c-9be8-42ed-aa06-bb73570121ac/cf_app/data/mimic_subset/mimic.sample.test.csv')