Skip to content

Commit aecb0d1

Browse files
Merge pull request #3 from supathdhitalGEO/main
update the metrics calculation
2 parents 876c94b + 4f2cf00 commit aecb0d1

File tree

9 files changed

+357
-600
lines changed

9 files changed

+357
-600
lines changed
33.6 KB
Binary file not shown.

dist/fimeval-0.1.44.tar.gz

34.4 KB
Binary file not shown.
33.6 KB
Binary file not shown.

dist/fimeval-0.1.45.tar.gz

34.4 KB
Binary file not shown.

poetry.lock

Lines changed: 334 additions & 571 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fimeval"
3-
version = "0.1.43"
3+
version = "0.1.45"
44
description = "A Framework for Automatic Evaluation of Flood Inundation Mapping Predictions Evaluation"
55
authors = [
66
"Surface Dynamics Modeling Lab",

src/fimeval/ContingencyMap/evaluationFIM.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def evaluateFIM(
4040
Merged = []
4141
Unique = []
4242
FAR_values = []
43-
Dice_values = []
4443

4544
# Dynamically call the specified method
4645
method = globals().get(method)
@@ -226,7 +225,7 @@ def resize_image(
226225
extract_c = np.where(mask2, out_image2, 0)
227226
extract_c = np.where(extract_c > 0, 1, 0)
228227
idx_pwc = np.where(extract_c == 1)
229-
out_image2[idx_pwc] = -1
228+
out_image2[idx_pwc] = 5
230229
out_image2_resized = resize_image(
231230
out_image2,
232231
out_transform2,
@@ -255,7 +254,6 @@ def resize_image(
255254
FPR,
256255
merged,
257256
FAR,
258-
Dice,
259257
) = evaluationmetrics(out_image1, out_image2_resized)
260258

261259
# Append values to the lists
@@ -275,7 +273,6 @@ def resize_image(
275273
Merged.append(merged)
276274
Unique.append(unique_values)
277275
FAR_values.append(FAR)
278-
Dice_values.append(Dice)
279276

280277
results = {
281278
"CSI_values": csi_values,
@@ -294,7 +291,6 @@ def resize_image(
294291
# 'Merged': Merged,
295292
# 'Unique': Unique
296293
"FAR_values": FAR_values,
297-
"Dice_values": Dice_values,
298294
}
299295
for candidate_idx, candidate_path in enumerate(candidate_paths):
300296
candidate_BASENAME = os.path.splitext(os.path.basename(candidate_path))[0]

src/fimeval/ContingencyMap/metrics.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ def evaluationmetrics(out_image1, out_image2):
77
unique_values, counts = np.unique(merged, return_counts=True)
88
class_pixel_counts = dict(zip(unique_values, counts))
99
class_pixel_counts
10-
TN = class_pixel_counts[1]
11-
FP = class_pixel_counts[2]
12-
FN = class_pixel_counts[3]
13-
TP = class_pixel_counts[4]
14-
TPR = TP / (TP + FN)
15-
FNR = FN / (TP + FN)
16-
Acc = (TP + TN) / (TP + TN + FP + FN)
17-
Prec = TP / (TP + FP)
18-
sen = TP / (TP + FN)
19-
F1_score = 2 * (Prec * sen) / (Prec + sen)
20-
CSI = TP / (TP + FN + FP)
21-
POD = TP / (TP + FN)
22-
FPR = FP / (FP + TN)
23-
FAR = FP / (TP + FP)
24-
Dice = 2 * TP / (2 * TP + FP + FN)
10+
TN = class_pixel_counts.get(1,0)
11+
FP = class_pixel_counts.get(2,0)
12+
FN = class_pixel_counts.get(3,0)
13+
TP = class_pixel_counts.get(4,0)
14+
epsilon = 1e-8
15+
TPR = TP / (TP + FN+epsilon)
16+
FNR = FN / (TP + FN+epsilon)
17+
Acc = (TP + TN) / (TP + TN + FP + FN+epsilon)
18+
Prec = TP / (TP + FP+epsilon)
19+
sen = TP / (TP + FN+epsilon)
20+
F1_score = 2 * (Prec * sen) / (Prec + sen+epsilon)
21+
CSI = TP / (TP + FN + FP+epsilon)
22+
POD = TP / (TP + FN+epsilon)
23+
FPR = FP / (FP + TN+epsilon)
24+
FAR = FP / (TP + FP+epsilon)
2525

2626
return (
2727
unique_values,
@@ -40,5 +40,4 @@ def evaluationmetrics(out_image1, out_image2):
4040
FPR,
4141
merged,
4242
FAR,
43-
Dice,
4443
)

src/fimeval/ContingencyMap/printcontingency.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def getContingencyMap(raster_path, method_path):
1818
combined_flood = np.full_like(band1, fill_value=1, dtype=int)
1919

2020
# Map pixel values to colors
21-
combined_flood[band1 == -1] = 0
21+
combined_flood[band1 == 5] = 0
2222
combined_flood[band1 == 0] = 1
2323
combined_flood[band1 == 1] = 2
2424
combined_flood[band1 == 2] = 3
@@ -60,12 +60,11 @@ def getContingencyMap(raster_path, method_path):
6060

6161
# Create legend patches
6262
value_labels = {
63-
0: "Permanent Water",
64-
1: "No Data",
65-
2: "True Negative",
66-
3: "False Positive",
67-
4: "False Negative",
68-
5: "True Positive",
63+
1: "True negative",
64+
2: "False positive",
65+
3: "False negative",
66+
4: "True positive",
67+
5: "Permanent water bodies"
6968
}
7069
legend_patches = [
7170
Patch(

0 commit comments

Comments
 (0)