Skip to content

Commit a4ee7bd

Browse files
authored
Merge pull request #551 from PIC-IRIS/i550-fix-ph5toms-trace-start-before-cut
Make sure the beginning of the cut trace is at or after the cut time
2 parents 34cc9cb + 588e4ec commit a4ee7bd

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

ph5/core/ph5api.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,10 @@ def cut(self, das, start_fepoch, stop_fepoch, chan=1,
11961196
else:
11971197
# Cut start is somewhere in window
11981198
cut_start_fepoch = start_fepoch
1199-
cut_start_sample = round(
1200-
(cut_start_fepoch - window_start_fepoch) * sr)
1199+
# round up to make sure it will start at or after
1200+
# window_start_fepoch
1201+
cut_start_sample = int(math.ceil(
1202+
(cut_start_fepoch - window_start_fepoch) * sr))
12011203
# Requested stop is after end of window so we need rest of window
12021204
if stop_fepoch > window_stop_fepoch:
12031205
cut_stop_fepoch = window_stop_fepoch

ph5/core/tests/test_ph5api.py

+35
Original file line numberDiff line numberDiff line change
@@ -1298,5 +1298,40 @@ def test_cut(self):
12981298
self.assertEqual(traces[1].nsamples, 236)
12991299

13001300

1301+
class TestPH5APICutTimeStartInMiddleOfSample(LogTestCase):
1302+
"""
1303+
This test to make sure the traces return will be at or after the cut
1304+
"""
1305+
def setUp(self):
1306+
super(TestPH5APICutTimeStartInMiddleOfSample, self).setUp()
1307+
self.home = os.getcwd()
1308+
self.ph5API_object = ph5api.PH5(
1309+
path=os.path.join(
1310+
self.home, 'ph5/test_data/ph5_cut_start_in_middle_of_sample'),
1311+
nickname='master.ph5')
1312+
1313+
def tearDown(self):
1314+
self.ph5API_object.close()
1315+
super(TestPH5APICutTimeStartInMiddleOfSample, self).tearDown()
1316+
1317+
def test_cut(self):
1318+
cut_start_epoch = 1508630400.0
1319+
cut_end_epoch = 1508716799.0
1320+
das = self.ph5API_object.query_das_t(
1321+
das='A123', chan=1, sample_rate=100, sample_rate_multiplier=1,
1322+
start_epoch=cut_start_epoch, stop_epoch=cut_end_epoch
1323+
)
1324+
das = [x for x in das]
1325+
traces = self.ph5API_object.cut(
1326+
das='A123', chan=1, sample_rate=100, das_t=das,
1327+
start_fepoch=cut_start_epoch, stop_fepoch=cut_end_epoch,
1328+
apply_time_correction=True
1329+
)
1330+
1331+
trace_start_epoch = traces[0].start_time.epoch(fepoch=True)
1332+
# make sure trace start at or after cut start
1333+
self.assertGreaterEqual(trace_start_epoch, cut_start_epoch)
1334+
1335+
13011336
if __name__ == "__main__":
13021337
unittest.main()
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)