Skip to content

Commit 8ff5a0b

Browse files
committed
ref: change behavior for empty pipeline.get_features and update screenshots
1 parent 614cfdf commit 8ff5a0b

File tree

10 files changed

+63
-27
lines changed

10 files changed

+63
-27
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
learning features)
44
- fix: modify the GUI to enable box filtering for ml_score_???
55
features
6+
- ref: pipeline.get_features now only returns features that are
7+
available (previously all features were returned when no
8+
datasets were in the pipeline)
69
2.1.6
710
- fix: export file names were allowed to have invalid characters
811
- fix: Quick View showed filtered events that were not plotted

docs/scrots/make_scrots.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# Run all scrots
4+
FILES=make_scrots_*.py
5+
for f in $FILES
6+
do
7+
echo "Running $f..."
8+
# take action on each file. $f store current file name
9+
python $f
10+
done

docs/scrots/ui_ana_plot.png

948 Bytes
Loading

docs/scrots/ui_qv_event.png

2.2 KB
Loading

docs/scrots/ui_qv_poly.png

1.09 KB
Loading

docs/scrots/ui_qv_settings.png

-772 Bytes
Loading

shapeout2/gui/analysis/ana_filter.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,7 @@ def _populate_box_filters(self):
100100
times, additional features that were not there before
101101
(e.g. `ml_score_???`) are added.
102102
"""
103-
if self.pipeline is not None:
104-
# Do not sort here, because we will have to sort anyway
105-
# if there is no pipeline.
106-
feats, labs = self.pipeline.get_features(scalar=True,
107-
ret_labels=True)
108-
else:
109-
# This does not include the `ml_score_???` features.
110-
feats = dclab.dfn.scalar_feature_names
111-
labs = [dclab.dfn.feature_name2label[f] for f in feats]
103+
feats, labs = self.get_features_labels()
112104

113105
self.verticalLayout_box.setAlignment(QtCore.Qt.AlignTop)
114106

@@ -172,6 +164,22 @@ def filter_names(self):
172164
def pipeline(self):
173165
return self._pipeline
174166

167+
def get_features_labels(self):
168+
"""Wrapper around pipeline with default features if empty"""
169+
if self.pipeline is not None and self.pipeline.num_slots != 0:
170+
feats, labs = self.pipeline.get_features(scalar=True,
171+
label_sort=True,
172+
ret_labels=True,
173+
union=True)
174+
else:
175+
# fallback (nothing in the pipeline or no pipeline)
176+
features = dclab.dfn.scalar_feature_names
177+
labs = [dclab.dfn.get_feature_label(f) for f in features]
178+
lf = sorted(zip(labs, features))
179+
feats = [it[1] for it in lf]
180+
labs = [it[0] for it in lf]
181+
return feats, labs
182+
175183
def on_duplicate_filter(self):
176184
# determine the new filter state
177185
filt_state = self.__getstate__()
@@ -196,9 +204,7 @@ def on_moreless(self):
196204
"""User wants to choose box filters"""
197205
if not self._box_edit_view:
198206
# get available features to show
199-
features = self.pipeline.get_features(scalar=True,
200-
label_sort=True,
201-
union=True)
207+
features, _ = self.get_features_labels()
202208
# create missing range controls if applicable (e.g. ml_score_???)
203209
self._populate_box_filters()
204210
# Show all filters shared by all datasets to the user

shapeout2/gui/analysis/ana_plot.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def __init__(self, *args, **kwargs):
5757
self.widget_range_y.range_changed.connect(self.on_range_changed)
5858

5959
def __getstate__(self):
60-
feats_srt = self.pipeline.get_features(
61-
scalar=True, label_sort=True, plot_id=self.current_plot.identifier)
60+
feats_srt = self.get_features()
6261

6362
rx = self.widget_range_x.__getstate__()
6463
ry = self.widget_range_y.__getstate__()
@@ -130,8 +129,7 @@ def __getstate__(self):
130129
def __setstate__(self, state):
131130
if self.current_plot.identifier != state["identifier"]:
132131
raise ValueError("Plot identifier mismatch!")
133-
feats_srt = self.pipeline.get_features(
134-
scalar=True, label_sort=True, plot_id=self.current_plot.identifier)
132+
feats_srt = self.get_features()
135133
toblock = [
136134
self.comboBox_axis_x,
137135
self.comboBox_axis_y,
@@ -397,6 +395,18 @@ def plot_names(self):
397395
ids = []
398396
return ids
399397

398+
def get_features(self):
399+
"""Wrapper around pipeline with default features if empty"""
400+
feats_srt = self.pipeline.get_features(
401+
scalar=True, label_sort=True, plot_id=self.current_plot.identifier)
402+
if len(feats_srt) == 0:
403+
# fallback (nothing in the pipeline)
404+
features = dclab.dfn.scalar_feature_names
405+
labs = [dclab.dfn.get_feature_label(f) for f in features]
406+
lf = sorted(zip(labs, features))
407+
feats_srt = [it[1] for it in lf]
408+
return feats_srt
409+
400410
def on_axis_changed(self):
401411
gen = self.__getstate__()["general"]
402412
if self.sender() == self.comboBox_axis_x:
@@ -518,10 +528,7 @@ def update_content(self, event=None, plot_index=None):
518528
curfeat = None
519529
# repopulate
520530
cb.clear()
521-
feats_srt = self.pipeline.get_features(
522-
scalar=True,
523-
label_sort=True,
524-
plot_id=self.current_plot.identifier)
531+
feats_srt = self.get_features()
525532
for feat in feats_srt:
526533
cb.addItem(dclab.dfn.get_feature_label(feat), feat)
527534
if curfeat is not None:

shapeout2/gui/compute/comp_stats.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ def update_feature_list(self, use_pipeline=True):
185185
union=True,
186186
label_sort=True)
187187
else:
188-
# This is just a cheap way of getting a label-sorted list
189-
# of all scalar features.
190-
empty_pipeline = Pipeline()
191-
self.features = empty_pipeline.get_features(scalar=True,
192-
label_sort=True)
188+
# We want to compute statistics from a folder
189+
# TODO:
190+
# - Add ml_score_??? features
191+
192+
# label-sorted features
193+
features = dclab.dfn.scalar_feature_names
194+
labs = [dclab.dfn.get_feature_label(f) for f in features]
195+
lf = sorted(zip(labs, features))
196+
self.features = [it[1] for it in lf]
193197

194198
self.listWidget_features.clear()
195199
for feat in self.features:

shapeout2/pipeline/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ def get_features(self, scalar=False, label_sort=False, union=False,
303303
are used.
304304
ret_labels: bool
305305
If True, return the labels as well
306+
307+
Notes
308+
-----
309+
This function returns an empty list if there are no features
310+
available.
306311
"""
307312
if union:
308313
features = set()
@@ -325,8 +330,9 @@ def get_features(self, scalar=False, label_sort=False, union=False,
325330
features = ds_features
326331
else:
327332
features &= ds_features
328-
else:
329-
features = dclab.dfn.scalar_feature_names
333+
if features is None:
334+
# This means that the pipeline is empty
335+
features = []
330336
labs = [dclab.dfn.get_feature_label(f) for f in features]
331337
if label_sort:
332338
lf = sorted(zip(labs, features))

0 commit comments

Comments
 (0)