Skip to content

Commit

Permalink
added segment number to labels (#356)
Browse files Browse the repository at this point in the history
* added segment number to labels

* added test for segment labels
  • Loading branch information
CommonClimate authored Mar 3, 2023
1 parent e33f68f commit 4a03bae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pyleoclim/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2369,9 +2369,13 @@ def segment(self, factor=10):
if len(seg_y)>1:
s_list=[]
for idx,s in enumerate(seg_y):
if self.label is not None:
s_lbl = self.label + ' segment ' + str(idx+1)
else:
s_lbl = 'segment ' + str(idx+1)
s_tmp=Series(time=seg_t[idx],value=s,time_name=self.time_name,
time_unit=self.time_unit, value_name=self.value_name,
value_unit=self.value_unit,label=self.label)
value_unit=self.value_unit,label=s_lbl)
s_list.append(s_tmp)
res=MultipleSeries(series_list=s_list)
elif len(seg_y)==1:
Expand All @@ -2380,6 +2384,7 @@ def segment(self, factor=10):
raise ValueError('No timeseries detected')
return res


def sel(self, value=None, time=None, tolerance=0):
"""
Slice Series based on 'value' or 'time'.
Expand Down
11 changes: 11 additions & 0 deletions pyleoclim/tests/test_core_Series.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def test_segment_t1(self):
ts_seg = ts.segment()

assert type(ts_seg) == type(ts)

def test_segment_t2(self):
'''Test that in the case of segmentation, segment returns a Multiple Series object'''
t = (1,2,3000)
v = (1,2,3)

ts = pyleo.Series(time = t, value = v, label = 'series')

ts_seg = ts.segment()

assert ts_seg.series_list[0].label == 'series segment 1'

class TestUiSeriesSlice:
'''Test for Series.slice()
Expand Down

0 comments on commit 4a03bae

Please sign in to comment.