Skip to content

Commit

Permalink
gui chain load statusbar
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbant committed May 26, 2021
1 parent 590febe commit b109b99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
11 changes: 7 additions & 4 deletions getdist/chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class ParamError(WeightedSampleError):
"""


def print_load_line(message):
if print_load_details:
print(message)


def last_modified(files):
"""
Returns the the latest "last modified" time for the given list of files. Ignores files that do not exist.
Expand Down Expand Up @@ -1341,13 +1346,11 @@ def loadChains(self, root, files_or_samples: Sequence, weights=None, loglikes=No
files_or_samples = [files_or_samples]
self.name_tag = self.name_tag or os.path.basename(root)
for fname in files_or_samples:
if print_load_details:
print(fname)
print_load_line(fname)
try:
self.chains.append(WeightedSamples(fname, **WSkwargs))
except WeightedSampleError:
if print_load_details:
print('Ignored file %s (likely empty)' % fname)
print_load_line('Ignored file %s (likely empty)' % fname)
nchains = len(self.chains)
if not nchains:
raise WeightedSampleError('loadChains - no chains found for ' + root)
Expand Down
16 changes: 12 additions & 4 deletions getdist/gui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
matplotlib.use('Qt5Agg')

import getdist
from getdist import plots, IniFile
from getdist import plots, IniFile, chains
from getdist.chain_grid import ChainDirGrid, file_root_to_root, get_chain_root_files, load_supported_grid
from getdist.mcsamples import SettingError, ParamError

Expand Down Expand Up @@ -77,13 +77,13 @@ class GuiSelectionError(Exception):


class QStatusLogger(logging.Handler):
def __init__(self, parent):
super().__init__(level=logging.WARNING)
def __init__(self, parent, level=logging.WARNING):
super().__init__(level=level)
self.widget = parent

def emit(self, record):
msg = self.format(record)
self.widget.showMessage(msg, color='red')
self.widget.showMessage(msg, color='red' if self.level == logging.WARNING else None)

def write(self, m):
pass
Expand Down Expand Up @@ -170,6 +170,7 @@ def __init__(self, app, ini=None, base_dir=None):

self.log_handler = QStatusLogger(self)
logging.getLogger().addHandler(self.log_handler)

self._last_color = None

dirs = self.getSettings().value('directoryList')
Expand Down Expand Up @@ -2248,6 +2249,13 @@ def run_gui():
app = QApplication(sys.argv) # noqa
app.setApplicationName("GetDist GUI")
mainWin = MainWindow(app, ini=args.ini)

def load_info(message):
print(message)
mainWin.showMessage(message)

chains.print_load_line = load_info

mainWin.show()
mainWin.raise_()
sys.exit(app.exec_())
Expand Down
6 changes: 2 additions & 4 deletions getdist/mcsamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,9 @@ def readChains(self, files_or_samples, weights=None, loglikes=None):
if self.ignore_frac and (not self.jobItem or not hasattr(self.jobItem, "isImportanceJob")
or (not self.jobItem.isImportanceJob and not self.jobItem.isBurnRemoved())):
self.removeBurnFraction(self.ignore_frac)
if chains.print_load_details:
print('Removed %s as burn in' % self.ignore_frac)
chains.print_load_line('Removed %s as burn in' % self.ignore_frac)
elif not int(self.ignore_rows):
if chains.print_load_details:
print('Removed no burn in')
chains.print_load_line('Removed no burn in')

self.deleteFixedParams()

Expand Down

0 comments on commit b109b99

Please sign in to comment.