Skip to content

Commit 47402a2

Browse files
committed
black -S xija
1 parent ab26929 commit 47402a2

23 files changed

+1331
-696
lines changed

pyproject.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[tool.black]
2+
include = '\.pyi?$'
3+
exclude = '''
4+
/(
5+
\.git
6+
| \.hg
7+
| \.mypy_cache
8+
| \.tox
9+
| \.venv
10+
| _build
11+
| buck-out
12+
| build
13+
| dist
14+
| docs
15+
)/
16+
'''
17+
18+
[tool.isort]
19+
profile = "black"

xija/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@
77

88
__version__ = ska_helpers.get_version(__package__)
99

10+
1011
def test(*args, **kwargs):
1112
"""Run py.test unit tests.
1213
1314
Parameters
1415
----------
1516
*args :
16-
17+
1718
**kwargs :
18-
19+
1920
2021
Returns
2122
-------
2223
2324
"""
2425
import testr
26+
2527
return testr.test(*args, **kwargs)

xija/clogging.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,25 @@ def emit(self, record):
99
pass
1010

1111

12-
def config_logger(name, format='%(message)s', datefmt=None,
13-
stream=sys.stdout, level=logging.INFO,
14-
filename=None, filemode='w', filelevel=None,
15-
propagate=False):
12+
def config_logger(
13+
name,
14+
format='%(message)s',
15+
datefmt=None,
16+
stream=sys.stdout,
17+
level=logging.INFO,
18+
filename=None,
19+
filemode='w',
20+
filelevel=None,
21+
propagate=False,
22+
):
1623
"""Do basic configuration for the logging system. Similar to
1724
logging.basicConfig but the logger ``name`` is configurable and both a file
1825
output and a stream output can be created. Returns a logger object.
19-
26+
2027
The default behaviour is to create a StreamHandler which writes to
2128
sys.stdout, set a formatter using the "%(message)s" format string, and
2229
add the handler to the ``name`` logger.
23-
30+
2431
A number of optional keyword arguments may be specified, which can alter
2532
the default behaviour.
2633

xija/component/base.py

+94-45
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class Param(dict):
2121
-------
2222
2323
"""
24-
def __init__(self, comp_name, name, val, min=-1e38, max=1e38,
25-
fmt="{:.4g}", frozen=False):
24+
25+
def __init__(
26+
self, comp_name, name, val, min=-1e38, max=1e38, fmt="{:.4g}", frozen=False
27+
):
2628
dict.__init__(self)
2729
self.comp_name = comp_name
2830
self.name = name
@@ -42,6 +44,7 @@ def __getattr__(self, attr):
4244

4345
class ModelComponent(object):
4446
"""Model component base class"""
47+
4548
def __init__(self, model):
4649
# This class overrides __setattr__ with a method that requires
4750
# the `pars` and `pars_dict` attrs to be visible. So do this
@@ -64,8 +67,7 @@ def model_plotdate(self):
6467
self._model_plotdate = cxctime2plotdate(self.model.times)
6568
return self._model_plotdate
6669

67-
def add_par(self, name, val=None, min=-1e38, max=1e38, fmt="{:.4g}",
68-
frozen=False):
70+
def add_par(self, name, val=None, min=-1e38, max=1e38, fmt="{:.4g}", frozen=False):
6971
param = Param(self.name, name, val, min=min, max=max, fmt=fmt, frozen=frozen)
7072
self.pars_dict[name] = param
7173
self.pars.append(param)
@@ -104,8 +106,7 @@ def get_par(self, name):
104106
if par.name == name:
105107
return par
106108
else:
107-
raise ValueError('No par named "{}" in {}',
108-
self.__class__.__name__)
109+
raise ValueError('No par named "{}" in {}', self.__class__.__name__)
109110

110111
@property
111112
def name(self):
@@ -136,28 +137,34 @@ def dvals(self):
136137
if self.data is None:
137138
dvals = self.get_dvals_tlm()
138139
elif isinstance(self.data, np.ndarray):
139-
dvals = self.model.interpolate_data(self.data, self.data_times,
140-
str(self))
141-
elif isinstance(self.data, (six.integer_types, float, np.integer, np.floating,
142-
bool, str)):
140+
dvals = self.model.interpolate_data(
141+
self.data, self.data_times, str(self)
142+
)
143+
elif isinstance(
144+
self.data,
145+
(six.integer_types, float, np.integer, np.floating, bool, str),
146+
):
143147
if isinstance(self.data, six.string_types):
144148
dtype = 'S{}'.format(len(self.data))
145149
else:
146150
dtype = type(self.data)
147151
dvals = np.empty(self.model.n_times, dtype=dtype)
148152
dvals[:] = self.data
149153
else:
150-
raise ValueError("Data value '{}' and type '{}' for '{}' component "
151-
"not allowed ".format(self.data, type(self.data).__name__, self))
154+
raise ValueError(
155+
"Data value '{}' and type '{}' for '{}' component "
156+
"not allowed ".format(self.data, type(self.data).__name__, self)
157+
)
152158
self._dvals = dvals
153159
return self._dvals
154160

155161

156162
class TelemData(ModelComponent):
157163
times = property(lambda self: self.model.times)
158164

159-
def __init__(self, model, msid, mval=True, data=None,
160-
fetch_attr='vals', units=None):
165+
def __init__(
166+
self, model, msid, mval=True, data=None, fetch_attr='vals', units=None
167+
):
161168
super(TelemData, self).__init__(model)
162169
self.msid = msid
163170
self.n_mvals = 1 if mval else 0
@@ -173,8 +180,9 @@ def get_dvals_tlm(self):
173180
def plot_data__time(self, fig, ax):
174181
lines = ax.get_lines()
175182
if not lines:
176-
plot_cxctime(self.model.times, self.dvals, ls='-', color='#386cb0',
177-
fig=fig, ax=ax)
183+
plot_cxctime(
184+
self.model.times, self.dvals, ls='-', color='#386cb0', fig=fig, ax=ax
185+
)
178186
ax.grid()
179187
ax.set_title('{}: data'.format(self.name))
180188
ylabel = '%s' % self.name
@@ -226,11 +234,23 @@ class Node(TelemData):
226234
-------
227235
228236
"""
229-
def __init__(self, model, msid, sigma=-10, quant=None,
230-
predict=True, mask=None, name=None, data=None,
231-
fetch_attr='vals', units='degC'):
232-
TelemData.__init__(self, model, msid, data=data,
233-
fetch_attr=fetch_attr, units=units)
237+
238+
def __init__(
239+
self,
240+
model,
241+
msid,
242+
sigma=-10,
243+
quant=None,
244+
predict=True,
245+
mask=None,
246+
name=None,
247+
data=None,
248+
fetch_attr='vals',
249+
units='degC',
250+
):
251+
TelemData.__init__(
252+
self, model, msid, data=data, fetch_attr=fetch_attr, units=units
253+
)
234254
self._sigma = sigma
235255
self.quant = quant
236256
self.predict = predict
@@ -254,8 +274,9 @@ def randx(self):
254274
"""
255275
if not hasattr(self, '_randx'):
256276
dx = self.quant or 1.0
257-
self._randx = np.random.uniform(low=-dx / 2.0, high=dx / 2.0,
258-
size=self.model.n_times)
277+
self._randx = np.random.uniform(
278+
low=-dx / 2.0, high=dx / 2.0, size=self.model.n_times
279+
)
259280
return self._randx
260281

261282
@property
@@ -278,17 +299,28 @@ def calc_stat(self):
278299
resids = self.resids
279300
if self.mask is not None:
280301
resids = resids[self.mask.mask]
281-
return np.sum(resids ** 2 / self.sigma ** 2)
302+
return np.sum(resids**2 / self.sigma**2)
282303

283304
def plot_data__time(self, fig, ax):
284305
lines = ax.get_lines()
285306
if not lines:
286-
plot_cxctime(self.model.times, self.mvals, ls='-', color='#d92121', fig=fig, ax=ax)
287-
plot_cxctime(self.model.times, self.dvals, ls='-', color='#386cb0', fig=fig, ax=ax)
307+
plot_cxctime(
308+
self.model.times, self.mvals, ls='-', color='#d92121', fig=fig, ax=ax
309+
)
310+
plot_cxctime(
311+
self.model.times, self.dvals, ls='-', color='#386cb0', fig=fig, ax=ax
312+
)
288313
# Overplot bad time regions in cyan
289314
for i0, i1 in self.model.bad_times_indices:
290-
plot_cxctime(self.model.times[i0:i1], self.dvals[i0:i1], '-c',
291-
fig=fig, ax=ax, linewidth=5, alpha=0.5)
315+
plot_cxctime(
316+
self.model.times[i0:i1],
317+
self.dvals[i0:i1],
318+
'-c',
319+
fig=fig,
320+
ax=ax,
321+
linewidth=5,
322+
alpha=0.5,
323+
)
292324
ax.grid()
293325
ax.set_title('{}: model (red) and data (blue)'.format(self.name))
294326
ax.set_ylabel('Temperature (%s)' % self.units)
@@ -304,11 +336,20 @@ def plot_resid__time(self, fig, ax):
304336
resids[i0:i1] = np.nan
305337

306338
if not lines:
307-
plot_cxctime(self.model.times, resids, ls='-', color='#386cb0', fig=fig, ax=ax)
339+
plot_cxctime(
340+
self.model.times, resids, ls='-', color='#386cb0', fig=fig, ax=ax
341+
)
308342
# Overplot bad time regions in cyan
309343
for i0, i1 in self.model.bad_times_indices:
310-
plot_cxctime(self.model.times[i0:i1], resids[i0:i1], '-c',
311-
fig=fig, ax=ax, linewidth=5, alpha=0.5)
344+
plot_cxctime(
345+
self.model.times[i0:i1],
346+
resids[i0:i1],
347+
'-c',
348+
fig=fig,
349+
ax=ax,
350+
linewidth=5,
351+
alpha=0.5,
352+
)
312353
ax.grid()
313354
ax.set_title('{}: residuals (data - model)'.format(self.name))
314355
ax.set_ylabel('Temperature (%s)' % self.units)
@@ -326,8 +367,14 @@ def plot_resid__data(self, fig, ax):
326367
resids[i0:i1] = np.nan
327368

328369
if not lines:
329-
ax.plot(self.dvals + self.randx, resids, 'o',
330-
markersize=0.25, color='#386cb0', markeredgecolor='#386cb0')
370+
ax.plot(
371+
self.dvals + self.randx,
372+
resids,
373+
'o',
374+
markersize=0.25,
375+
color='#386cb0',
376+
markeredgecolor='#386cb0',
377+
)
331378
ax.grid()
332379
ax.set_title('{}: residuals (data - model) vs data'.format(self.name))
333380
ax.set_ylabel('Residuals (%s)' % self.units)
@@ -352,17 +399,19 @@ class Coupling(ModelComponent):
352399
-------
353400
354401
"""
402+
355403
def __init__(self, model, node1, node2, tau):
356404
ModelComponent.__init__(self, model)
357405
self.node1 = self.model.get_comp(node1)
358406
self.node2 = self.model.get_comp(node2)
359407
self.add_par('tau', tau, min=2.0, max=200.0)
360408

361409
def update(self):
362-
self.tmal_ints = (tmal.OPCODES['coupling'],
363-
self.node1.mvals_i, # y1 index
364-
self.node2.mvals_i # y2 index
365-
)
410+
self.tmal_ints = (
411+
tmal.OPCODES['coupling'],
412+
self.node1.mvals_i, # y1 index
413+
self.node2.mvals_i, # y2 index
414+
)
366415
self.tmal_floats = (self.tau,)
367416

368417
def __str__(self):
@@ -377,6 +426,7 @@ class Delay(ModelComponent):
377426
``delay`` ksec. Conversely for a negative delay the values at the end will
378427
be constant for ``delay`` ksec.
379428
"""
429+
380430
def __init__(self, model, node, delay=0):
381431
super().__init__(model)
382432
self.node = self.model.get_comp(node)
@@ -388,17 +438,16 @@ def __str__(self):
388438

389439
class HeatSink(ModelComponent):
390440
"""Fixed temperature external heat bath"""
441+
391442
def __init__(self, model, node, T=0.0, tau=20.0):
392443
ModelComponent.__init__(self, model)
393444
self.node = self.model.get_comp(node)
394445
self.add_par('T', T, min=-100.0, max=100.0)
395446
self.add_par('tau', tau, min=2.0, max=200.0)
396447

397448
def update(self):
398-
self.tmal_ints = (tmal.OPCODES['heatsink'],
399-
self.node.mvals_i) # dy1/dt index
400-
self.tmal_floats = (self.T,
401-
self.tau)
449+
self.tmal_ints = (tmal.OPCODES['heatsink'], self.node.mvals_i) # dy1/dt index
450+
self.tmal_floats = (self.T, self.tau)
402451

403452
def __str__(self):
404453
return 'heatsink__{0}'.format(self.node)
@@ -425,6 +474,7 @@ class HeatSinkRef(ModelComponent):
425474
-------
426475
427476
"""
477+
428478
def __init__(self, model, node, T=0.0, tau=20.0, T_ref=20.0):
429479
ModelComponent.__init__(self, model)
430480
self.node = self.model.get_comp(node)
@@ -433,10 +483,8 @@ def __init__(self, model, node, T=0.0, tau=20.0, T_ref=20.0):
433483
self.add_par('T_ref', T_ref, min=-100, max=100)
434484

435485
def update(self):
436-
self.tmal_ints = (tmal.OPCODES['heatsink'],
437-
self.node.mvals_i) # dy1/dt index
438-
self.tmal_floats = (self.P * self.tau + self.T_ref,
439-
self.tau)
486+
self.tmal_ints = (tmal.OPCODES['heatsink'], self.node.mvals_i) # dy1/dt index
487+
self.tmal_floats = (self.P * self.tau + self.T_ref, self.tau)
440488

441489
def __str__(self):
442490
return 'heatsink__{0}'.format(self.node)
@@ -473,6 +521,7 @@ class AcisFPtemp(Node):
473521
-------
474522
475523
"""
524+
476525
def __init__(self, model, mask=None):
477526
Node.__init__(self, model, 'fptemp_11', mask=mask)
478527

0 commit comments

Comments
 (0)