From aad52bbfd1e852ae2a34ed630b97fdc06d803507 Mon Sep 17 00:00:00 2001 From: Rick Nitsche Date: Fri, 4 Dec 2020 15:51:37 -0800 Subject: [PATCH 1/4] feat(sensitivity): print percentage of rfi mask Closes #101 --- bondia/plot/sensitivity.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bondia/plot/sensitivity.py b/bondia/plot/sensitivity.py index d565553..7c7d3f7 100644 --- a/bondia/plot/sensitivity.py +++ b/bondia/plot/sensitivity.py @@ -152,6 +152,10 @@ def view(self): f"Error: {str(err)}. Please report this problem." ) rfi = np.squeeze(rfi_container.mask[:]) + + # calculate percentage masked to print later + rfi_percentage = round(np.count_nonzero(rfi) / rfi.size * 100) + sens *= np.where(rfi, np.nan, 1) if self.divide_by_estimate: @@ -180,6 +184,9 @@ def view(self): "colorbar": True, "xticks": [0, 60, 120, 180, 240, 300, 360], } + if self.mask_rfi: + image_opts["title"] = f"RFI mask: {rfi_percentage}%" + overlay_opts = { "xlim": xlim, "ylim": ylim, From 5cc89f3b14570945064f737cc6bb5eefc1771c1b Mon Sep 17 00:00:00 2001 From: Rick Nitsche Date: Wed, 16 Dec 2020 10:01:08 -0800 Subject: [PATCH 2/4] feat(gui): add option: sort days by number of opinions --- bondia/gui.py | 45 ++++++++++++++++++++++------------ bondia/opinion.py | 37 ++++++++++++++++++++++++++++ bondia/templates/material.html | 1 + bondia/templates/mdl.html | 1 + bondia/templates/mdl_tabs.html | 1 + bondia/templates/mwc.html | 1 + 6 files changed, 71 insertions(+), 15 deletions(-) diff --git a/bondia/gui.py b/bondia/gui.py index 30112fd..07ba738 100644 --- a/bondia/gui.py +++ b/bondia/gui.py @@ -21,6 +21,7 @@ class BondiaGui(param.Parameterized): lsd = param.ObjectSelector(label="Select Sidereal Day") revision = param.ObjectSelector(label="Select Data Revision") filter_lsd = param.Boolean(default=False, label="Hide days I have voted for") + sort_lsds = param.Boolean(default=False, label="Sort by number of opinions") def __init__( self, @@ -65,20 +66,31 @@ def __init__( self.param["lsd"].objects = list(self._data.days(self.revision)) self.lsd = self._choose_lsd() - @param.depends("revision", "filter_lsd", watch=True) + @param.depends("revision", "filter_lsd", "sort_lsds", watch=True) def update_days(self): """Update days depending on selected revision.""" + if self.filter_lsd and self.current_user is not None: - self.param["lsd"].objects = opinion.get_days_without_opinion( + days = opinion.get_days_without_opinion( list(self._data.days(self.revision)), self.revision, self.current_user, ) else: - self.param["lsd"].objects = list(self._data.days(self.revision)) + days = list(self._data.days(self.revision)) + + if self.sort_lsds: + days = opinion.sort_by_num_opinions(self.revision, days) + + self.param["lsd"].objects = days if self.param["lsd"].objects: - self.lsd = self._choose_lsd() + l = self._choose_lsd() + if getattr(self, "lsd", -1) == l: + self.lsd = l + self.param.trigger("lsd") + else: + self.lsd = l @param.depends("lsd") def data_description(self): @@ -99,20 +111,19 @@ def update_data_description_day(self): plot.revision = self.revision def _choose_lsd(self): - selected_day = getattr(self, "lsd", None) + if self.sort_lsds: + day = self.param["lsd"].objects[0] + else: + selected_day = getattr(self, "lsd", None) - days = self._data.days(self.revision) - if self.current_user is None: - return days[-1] - day = opinion.get_day_without_opinion( - selected_day, days, self.revision, self.current_user - ) + days = self._data.days(self.revision) + if self.current_user is None: + return days[-1] + day = opinion.get_day_without_opinion( + selected_day, days, self.revision, self.current_user + ) logger.debug(f"Chose new LSD to display: {day}.") - # If day doesn't change, the opinion UI is not updated. So we do it here... - if hasattr(self, "lsd") and day == selected_day: - self.param.trigger("lsd") - return day def _update_opinion_warning(self): @@ -194,6 +205,8 @@ def populate_template(self, template): # Checkbox to show only days w/o opinion template.add_panel("day_filter_opinion_checkbox", self.param["filter_lsd"]) + # Checkbox to sort days by number of opinions + template.add_panel("day_sort_checkbox", self.param["sort_lsds"]) # Fill the template with components template.add_panel("data_description", self.data_description) @@ -321,6 +334,8 @@ def _click_opinion(self, event, decision): else: self._opinion_warning.alert_type = "success" self._opinion_warning.object = f"Opinion added for LSD {lsd.lsd}" + if self.sort_lsds or self.filter_lsd: + self.update_days() self.lsd = self._choose_lsd() @property diff --git a/bondia/opinion.py b/bondia/opinion.py index 1ae9746..86eed49 100644 --- a/bondia/opinion.py +++ b/bondia/opinion.py @@ -2,6 +2,8 @@ from time import time +from peewee import fn + from chimedb.dataflag import DataFlagOpinion, DataFlagOpinionType, DataRevision from chimedb.core.mediawiki import MediaWikiUser @@ -102,6 +104,39 @@ def get_days_with_opinion(revision, user): return [d.lsd for d in days_with_opinion] +def sort_by_num_opinions(revision, lsds): + results = ( + DataFlagOpinion.select( + DataFlagOpinion.lsd, fn.COUNT(DataFlagOpinion.id).alias("count") + ) + .join(DataRevision) + .where( + DataRevision.name == revision, DataFlagOpinion.lsd << [d.lsd for d in lsds] + ) + .group_by(DataFlagOpinion.lsd) + .order_by(fn.COUNT(DataFlagOpinion.id)) + ).execute() + + lsds = {day.lsd: day for day in lsds} + sort_keys = [(r.count, r.lsd) for r in results] + _, lsd_keys = zip(*sort_keys) + + # add the days witout opinions + for lsd in lsds.keys(): + if lsd not in lsd_keys: + lsd_keys.append(lsd) + sort_keys.append((lsd, 0)) + + sort_keys.sort() + + # reuse old day objects + sorted_lsds = [] + for keys in sort_keys: + sorted_lsds.append(lsds[keys[1]]) + + return sorted_lsds + + def get_days_without_opinion(days, revision, user): user = user.capitalize() days_with_opinion = get_days_with_opinion(revision, user) @@ -215,6 +250,8 @@ def get_notes_for_day(day): Dict[string, Tuple[string, string]] Decisions ("good", "bad" or "unsure") and notes with user names as keys """ + if day is None: + return {} try: entries = DataFlagOpinion.select( DataFlagOpinion.notes, DataFlagOpinion.decision, DataFlagOpinion.user_id diff --git a/bondia/templates/material.html b/bondia/templates/material.html index 6011ae9..3218c04 100644 --- a/bondia/templates/material.html +++ b/bondia/templates/material.html @@ -33,6 +33,7 @@

Select Day

{{ embed(roots.day_selector) | indent(8) }}
{{ embed(roots.day_filter_opinion_checkbox) }} + {{ embed(roots.day_sort_checkbox) }}
{{ embed(roots.plot_selector) | indent(8) }}

diff --git a/bondia/templates/mdl.html b/bondia/templates/mdl.html index 6dbe2bb..573b333 100644 --- a/bondia/templates/mdl.html +++ b/bondia/templates/mdl.html @@ -35,6 +35,7 @@ {{ embed(roots.rev_selector) }} {{ embed(roots.day_selector) }} {{ embed(roots.day_filter_opinion_checkbox) }} + {{ embed(roots.day_sort_checkbox) }}

Select Plots

{{ embed(roots.toggle_delay_spectrum) }}
diff --git a/bondia/templates/mdl_tabs.html b/bondia/templates/mdl_tabs.html index a3c0db6..1ec8b23 100644 --- a/bondia/templates/mdl_tabs.html +++ b/bondia/templates/mdl_tabs.html @@ -36,6 +36,7 @@ {{ embed(roots.rev_selector) }} {{ embed(roots.day_selector) }} {{ embed(roots.day_filter_opinion_checkbox) }} + {{ embed(roots.day_sort_checkbox) }}

Select Plots

{{ embed(roots.toggle_delay_spectrum) }}
diff --git a/bondia/templates/mwc.html b/bondia/templates/mwc.html index f02f480..ce952bb 100644 --- a/bondia/templates/mwc.html +++ b/bondia/templates/mwc.html @@ -57,6 +57,7 @@ {{ embed(roots.rev_selector) }} {{ embed(roots.day_selector) }} {{ embed(roots.day_filter_opinion_checkbox) }} + {{ embed(roots.day_sort_checkbox) }}

Select Plots

{{ embed(roots.toggle_delay_spectrum) }}
From 99f4ad433b7a0a4c8d1d0b9fb41ae1867d44ffc1 Mon Sep 17 00:00:00 2001 From: Rick Nitsche Date: Wed, 16 Dec 2020 10:37:34 -0800 Subject: [PATCH 3/4] ci(github): use pip legacy resolver --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3e4840..cdab3b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -103,7 +103,7 @@ jobs: - name: Install python packages from private repos run: | - pip install ./ch_util ./chimedb ./chimedb_di ./chimedb_dataflag ./chimedb_config ./ch_pipeline + pip install --use-deprecated=legacy-resolver ./ch_util ./chimedb ./chimedb_di ./chimedb_dataflag ./chimedb_config ./ch_pipeline - name: Remove cloned repositories run: | @@ -115,12 +115,12 @@ jobs: - name: Install bondia dependencies run: | - pip install -r requirements.txt + pip install --use-deprecated=legacy-resolver -r requirements.txt pip install pytest - name: Install bondia run: | - pip install . + pip install --use-deprecated=legacy-resolver . - name: Run tests run: pytest . From c4a5ae1435c603209c3de9d43342eb44eff58889 Mon Sep 17 00:00:00 2001 From: Rick Nitsche Date: Wed, 16 Dec 2020 22:10:25 -0800 Subject: [PATCH 4/4] chore(changelog): version 0.5.0 --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7c34b1..a2c771f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# [0.5.0](https://github.com/chime-experiment/bondia/compare/v0.4.1...v0.5.0) (2020-12-17) + + +### Features + +* **gui:** add option: sort days by number of opinions ([5cc89f3](https://github.com/chime-experiment/bondia/commit/5cc89f3b14570945064f737cc6bb5eefc1771c1b)) +* **sensitivity:** print percentage of rfi mask ([aad52bb](https://github.com/chime-experiment/bondia/commit/aad52bbfd1e852ae2a34ed630b97fdc06d803507)), closes [#101](https://github.com/chime-experiment/bondia/issues/101) + + + # [0.4.1](https://github.com/chime-experiment/bondia/compare/v0.4.0...v0.4.1) (2020-12-05)