1
- # -*- coding: utf-8 -*-
2
1
"""Testing observations in fmu-ensemble."""
3
2
4
3
import os
@@ -66,24 +65,26 @@ def test_real_mismatch():
66
65
)
67
66
realmis = obs .mismatch (real )
68
67
69
- # Check layout of returned data
70
- assert isinstance (realmis , pd .DataFrame )
71
- assert len (realmis ) == 1
68
+ pd .testing .assert_frame_equal (
69
+ realmis ,
70
+ pd .DataFrame (
71
+ [
72
+ {
73
+ "OBSTYPE" : "txt" ,
74
+ "OBSKEY" : "parameters.txt/FWL" ,
75
+ "MISMATCH" : - 2.0 ,
76
+ "L1" : 2.0 ,
77
+ "L2" : 4.0 ,
78
+ "SIMVALUE" : 1700 ,
79
+ "OBSVALUE" : 1702 ,
80
+ "MEASERROR" : 1 ,
81
+ "SIGN" : - 1 ,
82
+ }
83
+ ]
84
+ ),
85
+ )
72
86
assert "REAL" not in realmis .columns # should only be there for ensembles.
73
- assert "OBSTYPE" in realmis .columns
74
- assert "OBSKEY" in realmis .columns
75
87
assert "DATE" not in realmis .columns # date is not relevant
76
- assert "MISMATCH" in realmis .columns
77
- assert "L1" in realmis .columns
78
- assert "L2" in realmis .columns
79
-
80
- # Check actually computed values, there should only be one row with data:
81
- assert realmis .loc [0 , "OBSTYPE" ] == "txt"
82
- assert realmis .loc [0 , "OBSKEY" ] == "parameters.txt/FWL"
83
- assert realmis .loc [0 , "MISMATCH" ] == - 2
84
- assert realmis .loc [0 , "SIGN" ] == - 1
85
- assert realmis .loc [0 , "L1" ] == 2
86
- assert realmis .loc [0 , "L2" ] == 4
87
88
88
89
# Another observation set:
89
90
obs2 = Observations (
@@ -96,12 +97,46 @@ def test_real_mismatch():
96
97
}
97
98
)
98
99
realmis2 = obs2 .mismatch (real )
99
- assert len (realmis2 ) == 3
100
- assert "parameters.txt/RMS_SEED" in realmis2 ["OBSKEY" ].values
101
- assert "outputs.txt/top_structure" in realmis2 ["OBSKEY" ].values
102
- assert "npv.txt" in realmis2 ["OBSKEY" ].values
103
-
104
- # assert much more!
100
+ pd .testing .assert_frame_equal (
101
+ realmis2 ,
102
+ pd .DataFrame (
103
+ [
104
+ {
105
+ "OBSTYPE" : "txt" ,
106
+ "OBSKEY" : "parameters.txt/RMS_SEED" ,
107
+ "MISMATCH" : - 177148215.0 ,
108
+ "L1" : 177148215.0 ,
109
+ "L2" : 3.1381490077686224e16 ,
110
+ "SIMVALUE" : 422851785 ,
111
+ "OBSVALUE" : 600000000 ,
112
+ "MEASERROR" : 1 ,
113
+ "SIGN" : - 1 ,
114
+ },
115
+ {
116
+ "OBSTYPE" : "txt" ,
117
+ "OBSKEY" : "outputs.txt/top_structure" ,
118
+ "MISMATCH" : 24.0 ,
119
+ "L1" : 24.0 ,
120
+ "L2" : 576.0 ,
121
+ "SIMVALUE" : 3224 ,
122
+ "OBSVALUE" : 3200 ,
123
+ "MEASERROR" : 1 ,
124
+ "SIGN" : 1 ,
125
+ },
126
+ {
127
+ "OBSTYPE" : "scalar" ,
128
+ "OBSKEY" : "npv.txt" ,
129
+ "MISMATCH" : 44.0 ,
130
+ "L1" : 44.0 ,
131
+ "L2" : 1936.0 ,
132
+ "SIMVALUE" : 3444 ,
133
+ "OBSVALUE" : 3400 ,
134
+ "MEASERROR" : 1 ,
135
+ "SIGN" : 1 ,
136
+ },
137
+ ]
138
+ ),
139
+ )
105
140
106
141
# Test that we can write the observations to yaml
107
142
# and verify that the exported yaml can be reimported
@@ -215,6 +250,26 @@ def test_smry():
215
250
# loaded realization.
216
251
mismatch = obs .mismatch (real )
217
252
253
+ # Assert the first row exactly:
254
+ pd .testing .assert_frame_equal (
255
+ mismatch .head (1 ),
256
+ pd .DataFrame (
257
+ [
258
+ {
259
+ "OBSTYPE" : "smry" ,
260
+ "OBSKEY" : "WBP4:OP_1" ,
261
+ "DATE" : datetime .date (2001 , 1 , 1 ),
262
+ "MEASERROR" : 4.0 ,
263
+ "MISMATCH" : - 2.159454345703125 ,
264
+ "OBSVALUE" : 251.0 ,
265
+ "SIMVALUE" : 248.84054565429688 ,
266
+ "L1" : 2.159454345703125 ,
267
+ "L2" : 4.663243071176112 ,
268
+ "SIGN" : - 1 ,
269
+ }
270
+ ]
271
+ ),
272
+ )
218
273
assert len (mismatch ) == 21 # later: implement counting in the obs object
219
274
assert mismatch .L1 .sum () > 0
220
275
assert mismatch .L2 .sum () > 0
@@ -537,7 +592,6 @@ def test_ensset_mismatch():
537
592
== mismatch [mismatch .ENSEMBLE == "iter-1" ].L1 .sum ()
538
593
)
539
594
540
- # This is quite hard to input in dict-format. Better via YAML..
541
595
obs_pr = Observations (
542
596
{
543
597
"smry" : [
0 commit comments