-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_postprocessing.py
More file actions
executable file
·140 lines (121 loc) · 4.82 KB
/
test_postprocessing.py
File metadata and controls
executable file
·140 lines (121 loc) · 4.82 KB
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
import tempfile
import numpy as np
import pandas as pd
from pathlib import Path as path
from openalea.adel import postprocessing as pp
DATA_DIRPATH = path(__file__).parent.resolve() / path("data/test_postprocessing")
INPUTS_DIRPATH = DATA_DIRPATH / "inputs"
OUTPUTS_DIRPATH = DATA_DIRPATH / "outputs"
ADEL_OUTPUT_FILENAME = "adel_output.csv"
RELATIVE_TOLERANCE = 10e-3
ABSOLUTE_TOLERANCE = 10e-3
# TO DO restore full test by validating new expectations
def test_aggregate_adel_output():
adel_output_df = pd.read_csv(INPUTS_DIRPATH / ADEL_OUTPUT_FILENAME)
adel_output_df["species"] = "0"
adel_output_aggregated_df = pp.aggregate_adel_output(
adel_output_df, by=["TT", "species", "plant", "axe_id"]
)
adel_output_df.drop(["species"], axis=1, inplace=True)
adel_output_aggregated_df.to_csv(
OUTPUTS_DIRPATH / "actual_adel_aggregated_output.csv", index=False, na_rep="NA"
)
desired_adel_output_aggregated_df = pd.read_csv(
OUTPUTS_DIRPATH / "desired_adel_aggregated_output.csv"
)
adel_output_aggregated_df = adel_output_aggregated_df.select_dtypes(
include=[np.number]
)
desired_adel_output_aggregated_df = desired_adel_output_aggregated_df.select_dtypes(
include=[np.number]
)
np.testing.assert_allclose(
adel_output_aggregated_df.values,
desired_adel_output_aggregated_df.values,
RELATIVE_TOLERANCE,
ABSOLUTE_TOLERANCE,
)
def test_phenology():
adel_output_df = pd.read_csv(INPUTS_DIRPATH / ADEL_OUTPUT_FILENAME)
adel_output_df["species"] = "0"
phenology_df = pp.phenology(adel_output_df)
phenology_df.drop(["species"], axis=1, inplace=True)
phenology_df.to_csv(
OUTPUTS_DIRPATH / "actual_phenology.csv", index=False, na_rep="NA"
)
desired_phenology_df = pd.read_csv(OUTPUTS_DIRPATH / "desired_phenology.csv")
desired_phenology_df.drop(["has_ear"], axis=1, inplace=True)
phenology_df = phenology_df.select_dtypes(include=[np.number])
desired_phenology_df = desired_phenology_df.select_dtypes(include=[np.number])
np.testing.assert_allclose(
phenology_df.values,
desired_phenology_df.values,
RELATIVE_TOLERANCE,
ABSOLUTE_TOLERANCE,
)
def test_axis_statistics():
adel_output_df = pd.read_csv(INPUTS_DIRPATH / ADEL_OUTPUT_FILENAME)
adel_output_df["species"] = "0"
axis_statistics_df, intermediate_df = pp.axis_statistics(
adel_output_df, domain_area=1
)
axis_statistics_df.drop(["species"], axis=1, inplace=True)
intermediate_df.drop(["species"], axis=1, inplace=True)
axis_statistics_df.to_csv(
OUTPUTS_DIRPATH / "actual_axis_statistics.csv", index=False, na_rep="NA"
)
intermediate_df.to_csv(
OUTPUTS_DIRPATH / "actual_intermediate.csv", index=False, na_rep="NA"
)
desired_axis_statistics_df = pd.read_csv(
OUTPUTS_DIRPATH / "desired_axis_statistics.csv"
)
desired_axis_statistics_df.drop(["has_ear"], axis=1, inplace=True)
axis_statistics_df = axis_statistics_df.select_dtypes(include=[np.number])
desired_axis_statistics_df = desired_axis_statistics_df.select_dtypes(
include=[np.number]
)
np.testing.assert_allclose(
axis_statistics_df.values,
desired_axis_statistics_df.values,
RELATIVE_TOLERANCE,
ABSOLUTE_TOLERANCE,
)
desired_intermediate_df = pd.read_csv(OUTPUTS_DIRPATH / "desired_intermediate.csv")
desired_intermediate_df.drop(["has_ear"], axis=1, inplace=True)
intermediate_df = intermediate_df.select_dtypes(include=[np.number])
desired_intermediate_df = desired_intermediate_df.select_dtypes(include=[np.number])
np.testing.assert_allclose(
intermediate_df.values,
desired_intermediate_df.values,
RELATIVE_TOLERANCE,
ABSOLUTE_TOLERANCE,
)
def test_plot_statistics():
axis_statistics_df = pd.read_csv(INPUTS_DIRPATH / "axis_statistics.csv")
axis_statistics_df["species"] = "0"
plot_statistics_df = pp.plot_statistics(
axis_statistics_df, plant_number=9, domain_area=1
)
plot_statistics_df.drop(["species"], axis=1, inplace=True)
plot_statistics_df.to_csv(
OUTPUTS_DIRPATH / "actual_plot_statistics.csv", index=False, na_rep="NA"
)
desired_plot_statistics_df = pd.read_csv(
OUTPUTS_DIRPATH / "desired_plot_statistics.csv"
)
plot_statistics_df = plot_statistics_df.select_dtypes(include=[np.number])
desired_plot_statistics_df = desired_plot_statistics_df.select_dtypes(
include=[np.number]
)
np.testing.assert_allclose(
plot_statistics_df.values,
desired_plot_statistics_df.values,
RELATIVE_TOLERANCE,
ABSOLUTE_TOLERANCE,
)
# if __name__ == '__main__':
# test_aggregate_adel_output()
# test_phenology()
# test_axis_statistics()
# test_plot_statistics()