3
3
import numpy as np
4
4
import pytest
5
5
6
- from .. import ThermalModel , Node , HeatSink , SolarHeat , Pitch , Eclipse , __version__
6
+ from xija import ThermalModel , Node , HeatSink , SolarHeat , Pitch , Eclipse , __version__
7
7
from numpy import sin , cos , abs
8
8
9
9
print
10
10
print 'Version =' , __version__
11
11
12
- os .chdir (os .path .abspath (os .path .dirname (__file__ )))
12
+ CURRDIR = os .path .abspath (os .path .dirname (__file__ ))
13
+
14
+
15
+ def abs_path (spec ):
16
+ return os .path .join (CURRDIR , spec )
13
17
14
18
15
19
def test_dpa_real ():
16
20
mdl = ThermalModel ('dpa' , start = '2012:001' , stop = '2012:007' ,
17
- model_spec = 'dpa.json' )
21
+ model_spec = abs_path ( 'dpa.json' ) )
18
22
# Check that cmd_states database can be read. Skip if not, probably
19
23
# running test on a platform without access.
20
24
try :
@@ -26,7 +30,7 @@ def test_dpa_real():
26
30
mdl .make ()
27
31
mdl .calc ()
28
32
dpa = mdl .comp ['1dpamzt' ]
29
- reffile = 'dpa_real.npz'
33
+ reffile = abs_path ( 'dpa_real.npz' )
30
34
if not os .path .exists (reffile ):
31
35
print 'Writing reference file' , reffile
32
36
np .savez (reffile , times = mdl .times , dvals = dpa .dvals ,
@@ -45,7 +49,7 @@ def test_pitch_clip():
45
49
Make sure the model still runs with no interpolation error.
46
50
"""
47
51
mdl = ThermalModel ('dpa' , start = '2012:001' , stop = '2012:007' ,
48
- model_spec = 'dpa_clip.json' )
52
+ model_spec = abs_path ( 'dpa_clip.json' ) )
49
53
try :
50
54
mdl ._get_cmd_states ()
51
55
except :
@@ -58,7 +62,7 @@ def test_pitch_clip():
58
62
59
63
def test_dpa ():
60
64
mdl = ThermalModel ('dpa' , start = '2012:001' , stop = '2012:007' ,
61
- model_spec = 'dpa.json' )
65
+ model_spec = abs_path ( 'dpa.json' ) )
62
66
times = (mdl .times - mdl .times [0 ]) / 10000.0
63
67
mdl .comp ['1dpamzt' ].set_data (30.0 )
64
68
mdl .comp ['sim_z' ].set_data ((100000 * sin (times )).astype (int ))
@@ -77,20 +81,22 @@ def test_dpa():
77
81
mdl .make ()
78
82
mdl .calc ()
79
83
dpa = mdl .comp ['1dpamzt' ]
80
- if not os .path .exists ('dpa.npz' ):
84
+ reffile = abs_path ('dpa.npz' )
85
+ if not os .path .exists (reffile ):
81
86
print 'Writing reference file dpa.npz'
82
- np .savez ('dpa.npz' , times = mdl .times , dvals = dpa .dvals ,
87
+ np .savez (reffile , times = mdl .times , dvals = dpa .dvals ,
83
88
mvals = dpa .mvals )
84
89
85
- regr = np .load ('dpa.npz' )
90
+ regr = np .load (reffile )
86
91
assert np .allclose (mdl .times , regr ['times' ])
87
92
assert np .allclose (dpa .dvals , regr ['dvals' ])
88
93
assert np .allclose (dpa .mvals , regr ['mvals' ])
89
94
90
95
91
96
def test_data_types ():
92
97
for data_type in (int , float , np .float32 , np .float64 , np .int32 , np .int64 , np .complex64 ):
93
- mdl = ThermalModel ('dpa' , start = '2012:001' , stop = '2012:007' , model_spec = 'dpa.json' )
98
+ mdl = ThermalModel ('dpa' , start = '2012:001' , stop = '2012:007' ,
99
+ model_spec = abs_path ('dpa.json' ))
94
100
dpa = mdl .comp ['1dpamzt' ]
95
101
dpa .set_data (data_type (30.0 ))
96
102
if data_type is np .complex64 :
@@ -102,7 +108,7 @@ def test_data_types():
102
108
103
109
def test_minusz ():
104
110
mdl = ThermalModel ('minusz' , start = '2012:001' , stop = '2012:004' ,
105
- model_spec = 'minusz.json' )
111
+ model_spec = abs_path ( 'minusz.json' ) )
106
112
times = (mdl .times - mdl .times [0 ]) / 10000.0
107
113
msids = ('tephin' , 'tcylaft6' , 'tcylfmzm' , 'tmzp_my' , 'tfssbkt1' )
108
114
for msid in msids :
@@ -127,7 +133,7 @@ def test_minusz():
127
133
128
134
def test_pftank2t ():
129
135
mdl = ThermalModel ('pftank2t' , start = '2012:001' , stop = '2012:004' ,
130
- model_spec = 'pftank2t.json' )
136
+ model_spec = abs_path ( 'pftank2t.json' ) )
131
137
times = (mdl .times - mdl .times [0 ]) / 10000.0
132
138
msids = ('pftank2t' , 'pf0tank2t' )
133
139
for msid in msids :
@@ -138,7 +144,7 @@ def test_pftank2t():
138
144
mdl .make ()
139
145
mdl .calc ()
140
146
141
- regrfile = 'pftank2t.npz'
147
+ regrfile = abs_path ( 'pftank2t.npz' )
142
148
if not os .path .exists (regrfile ):
143
149
print 'Writing reference file' , regrfile
144
150
kwargs = {msid : mdl .comp [msid ].mvals for msid in msids }
0 commit comments