File size: 1,621 Bytes
87034d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/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')