-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
146 lines (124 loc) · 7.46 KB
/
conftest.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# ================================================================================================ #
# Project : Deep Learning for Breast Cancer Detection #
# Version : 0.1.0 #
# Python : 3.10.12 #
# Filename : /conftest.py #
# ------------------------------------------------------------------------------------------------ #
# Author : John James #
# Email : [email protected] #
# URL : https://github.com/john-james-ai/BreastCancerDetection #
# ------------------------------------------------------------------------------------------------ #
# Created : Friday September 22nd 2023 06:54:46 am #
# Modified : Monday February 12th 2024 12:08:17 pm #
# ------------------------------------------------------------------------------------------------ #
# License : MIT License #
# Copyright : (c) 2023 John James #
# ================================================================================================ #
import cv2
import pandas as pd
import pytest
from bcd.dal.image import ImageIO
from bcd.utils.image import grayscale
# ------------------------------------------------------------------------------------------------ #
collect_ignore_glob = [
"data/**/*.*",
"bcd/preprocess/**/*.*",
"tests/test_data/**/*.*",
"tests/test_explore/**/*.*",
]
# ------------------------------------------------------------------------------------------------ #
CASE_FP = "data/meta/2_clean/cases.csv"
IMAGE_FP = "data/meta/2_clean/dicom.csv"
EVALUATION_FP = "tests/data/3_denoise/results.csv"
# ------------------------------------------------------------------------------------------------ #
# pylint: disable=redefined-outer-name, no-member
# ------------------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------------------ #
# URLS #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="session", autouse=False)
def urls():
urls = [
"https://wiki.cancerimagingarchive.net/download/attachments/22516629/CBIS-DDSM-All-doiJNLP-zzWs5zfZ.tcia?version=1&modificationDate=1534787024127&api=v2",
"https://wiki.cancerimagingarchive.net/download/attachments/22516629/mass_case_description_train_set.csv?version=1&modificationDate=1506796355038&api=v2",
"https://wiki.cancerimagingarchive.net/download/attachments/22516629/calc_case_description_train_set.csv?version=1&modificationDate=1506796349666&api=v2",
"https://wiki.cancerimagingarchive.net/download/attachments/22516629/mass_case_description_test_set.csv?version=1&modificationDate=1506796343175&api=v2",
"https://wiki.cancerimagingarchive.net/download/attachments/22516629/calc_case_description_test_set.csv?version=1&modificationDate=1506796343686&api=v2",
]
return urls
# ------------------------------------------------------------------------------------------------ #
# CASE IDS #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="module", autouse=False)
def mmg_ids():
"""Creates a list of case ids."""
df = pd.read_csv(IMAGE_FP)
df = df.loc[df["series_description"] == "full mammogram images"]
df = df.sample(n=10)
return list(df["mmg_id"])
# ------------------------------------------------------------------------------------------------ #
# EVALS #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="module", autouse=False)
def evals():
return pd.read_csv(EVALUATION_FP)
# ------------------------------------------------------------------------------------------------ #
# IMAGES #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="module", autouse=False)
def images():
img1 = "data/image/1_dev/converted/train/benign/347c2455-cb62-40f8-a173-9e4eb9a21902.png"
img2 = "data/image/1_dev/converted/train/benign/4ed91643-1e06-4b2c-8efb-bc60dd9e0313.png"
img3 = "data/image/1_dev/converted/train/malignant/7dcc12fd-88f0-4048-a6ab-5dd0bd836f08.png"
img4 = "data/image/1_dev/converted/train/malignant/596ef5db-9610-4f13-9c1a-4c411b1d957c.png"
img1 = cv2.imread(img1, cv2.IMREAD_GRAYSCALE)
img2 = cv2.imread(img2, cv2.IMREAD_GRAYSCALE)
img3 = cv2.imread(img3, cv2.IMREAD_GRAYSCALE)
img4 = cv2.imread(img4, cv2.IMREAD_GRAYSCALE)
return [img1, img2, img3, img4]
# ------------------------------------------------------------------------------------------------ #
# IMAGE META #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="module", autouse=False)
def image_meta():
"""Returns a dictionary containing a randomly selected case from the DICOM metadata dataset."""
df = pd.read_csv(IMAGE_FP)
s = df.sample(n=1)
s = s.squeeze()
return s.to_dict()
# ------------------------------------------------------------------------------------------------ #
# IMAGE #
# ------------------------------------------------------------------------------------------------ #
@pytest.fixture(scope="session", autouse=False)
def image():
"""Serves up a random image for each function."""
df = pd.read_csv(IMAGE_FP)
meta = df.sample(n=1)
fp = meta["filepath"]
img = ImageIO.read(filepath=fp)
return grayscale(img)
@pytest.fixture(scope="session", autouse=False)
def image_mlo():
"""Serves up a random MLO image for each function."""
df = pd.read_csv(IMAGE_FP)
meta = df.loc[df["image_view"] == "MLO"].sample(n=1)
fp = meta["filepath"]
img = ImageIO.read(filepath=fp)
return grayscale(img)
@pytest.fixture(scope="session", autouse=False)
def image_cc():
"""Serves up a random CC image for each function."""
df = pd.read_csv(IMAGE_FP)
meta = df.loc[df["image_view"] == "CC"].sample(n=1)
fp = meta["filepath"]
img = ImageIO.read(filepath=fp)
return grayscale(img)
@pytest.fixture(scope="session", autouse=False)
def image_dicom():
"""Serves up a random image for each function."""
df = pd.read_csv(IMAGE_FP)
meta = df.sample(n=1)
fp = meta["filepath"]
return ImageIO.read(filepath=fp)