• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JohannesBuchner / PyMultiNest / 11677775296

20 Sep 2024 08:24AM UTC coverage: 56.327% (+0.2%) from 56.173%
11677775296

push

github

web-flow
Merge pull request #258 from sahiljhawar/mac-ci

Fixes gfortran issue on MacOS

365 of 648 relevant lines covered (56.33%)

2.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.41
/pymultinest/watch.py
1
from __future__ import absolute_import, unicode_literals, print_function
5✔
2
import threading
5✔
3

4
class ProgressWatcher(threading.Thread):
5✔
5
        """
6
                Abstract class for watching the progress of MultiNest.
7
        """
8
        def __init__(self, n_params, interval_ms = 200, outputfiles_basename = "chains/1-"):
5✔
9
                threading.Thread.__init__(self)
×
10
                self.n_params = n_params
×
11
                self.outputfiles_basename = outputfiles_basename
×
12
                self.interval_ms = interval_ms
×
13
                """
14
                This file contains the current set of live points. It has nPar+2 
15
                columns. The first nPar columns are the ndim
16
                parameter values along with the (nPar-ndim)  additional 
17
                parameters that are being passed by the likelihood
18
                routine for MultiNest to save along with the ndim parameters. 
19
                The nPar+1 column is the log-likelihood value &
20
                the last column is the node no. (used for clustering).
21
                """
22
                self.live = "%s%s" % (self.outputfiles_basename , "phys_live.points")
×
23
                """
24
                This file contains the set of rejected points. It has nPar+3 
25
                columns. The first nPar columns are the ndim
26
                parameter values along with the (nPar-ndim)  additional 
27
                parameters that are being passed by the likelihood
28
                routine for MultiNest to save along with the ndim parameters. 
29
                The nPar+1 column is the log-likelihood value,
30
                nPar+2 column is the log(prior mass) & the last column  is the 
31
                node no. (used for clustering).
32
                """                
33
                self.rejected = "%s%s" % (self.outputfiles_basename , "ev.dat")
×
34
                self.running = True
×
35
        
36
        def stop(self):
5✔
37
                self.running = False
×
38

39
class ProgressPrinter(ProgressWatcher):
5✔
40
        """
41
                Continuously writes out the number of live and rejected points. 
42
        """
43
        def run(self):
5✔
44
                import time
×
45
                while self.running:
×
46
                        time.sleep(self.interval_ms / 1000.)
×
47
                        if not self.running:
×
48
                                break
×
49
                        try:
×
50
                                print(('rejected points: ', len(open(self.rejected, 'r').readlines())))
×
51
                                print(('alive points: ', len(open(self.live, 'r').readlines())))
×
52
                        except Exception as e:
×
53
                                print(e)
×
54

55
class ProgressPlotter(ProgressWatcher):
5✔
56
        """
57
                Continuously creates plots (pdfs) of the live points. 
58
        """
59
        
60
        def run(self):
5✔
61
                import time
×
62
                while self.running:
×
63
                        time.sleep(self.interval_ms / 1000.)
×
64
                        if not self.running:
×
65
                                break
×
66
                        try:
×
67
                                self._plot_live()
×
68
                        except Exception as e:
×
69
                                print(e)
×
70
        
71
        def _plot_live(self):
5✔
72
                import matplotlib.pyplot as plt
×
73
                import numpy
×
74
                import shutil, os
×
75
                x = numpy.loadtxt(self.live, ndmin=2)
×
76
                for i in range(self.n_params):
×
77
                        plt.subplot(self.n_params, 1, 1+i)
×
78
                        plt.plot(x[:,i], x[:,self.n_params], '.')
×
79
                f = "%s.pdf" % self.live
×
80
                # using a temporary file because the writing 
81
                # takes some time, during which the user should still be able
82
                # to look at the previous version
83
                ftmp = "%s.next.pdf" % self.live
×
84
                plt.savefig(ftmp)
×
85
                shutil.copyfile(ftmp, f)
×
86
                os.remove(ftmp)
×
87

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc