Skip to content

Commit 3a8a617

Browse files
committed
added function contents
1 parent 6c8d7f0 commit 3a8a617

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

diffpy/snmf/subroutines.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,21 @@ def reconstruct_signal(components, signal_idx):
187187
components: tuple of ComponentSignal objects
188188
The tuple containing the ComponentSignal objects
189189
signal_idx: int
190-
The index of the specific signal to be reconstructed
190+
The index of the specific signal in the input data to be reconstructed
191191
192192
Returns
193193
-------
194194
1d array like
195195
The reconstruction of a signal from calculated weights, stretching factors, and iq values.
196196
197197
"""
198-
pass
198+
signal_length = len(components[0].grid)
199+
reconstruction = np.zeros(signal_length)
200+
for component in components:
201+
stretched = component.apply_stretch(signal_idx)[0]
202+
stretched_and_weighted = component.apply_weight(signal_idx, stretched)
203+
reconstruction += stretched_and_weighted
204+
return reconstruction
199205

200206

201207
def initialize_arrays(number_of_components, number_of_moments, signal_length):

diffpy/snmf/tests/test_subroutines.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,17 @@ def test_construct_weight_matrix(tcwm):
252252
def test_update_weights(tuw):
253253
actual = update_weights(tuw[0], tuw[1], tuw[2])
254254
assert np.shape(actual) == (len(tuw[0]), len(tuw[0][0].weights))
255-
trs = []
255+
256+
trs = [([ComponentSignal([0, .25, .5, .75, 1], 2, 0), ComponentSignal([0, .25, .5, .75, 1], 2, 1),
257+
ComponentSignal([0, .25, .5, .75, 1], 2, 2)], 1),
258+
([ComponentSignal([0, .25, .5, .75, 1], 2, 0), ComponentSignal([0, .25, .5, .75, 1], 2, 1),
259+
ComponentSignal([0, .25, .5, .75, 1], 2, 2)], 0),
260+
([ComponentSignal([0, .25, .5, .75, 1], 3, 0), ComponentSignal([0, .25, .5, .75, 1], 3, 1),
261+
ComponentSignal([0, .25, .5, .75, 1], 3, 2)], 2),
262+
# ([ComponentSignal([0, .25, .5, .75, 1], 2, 0), ComponentSignal([0, .25, .5, .75, 1], 2, 1),
263+
# ComponentSignal([0, .25, .5, .75, 1], 2, 2)], -1),
264+
]
256265
@pytest.mark.parametrize('trs',trs)
257266
def test_reconstruct_signal(trs):
258-
assert False
267+
actual = reconstruct_signal(trs[0], trs[1])
268+
assert len(actual) == len(trs[0][0].grid)

0 commit comments

Comments
 (0)