GithubHelp home page GithubHelp logo

beans's Introduction

BEANSp

Bayesian Estimation of Accreting Neutron Star parameters

Features

This software uses a Markov Chain Monte Carlo approach to match observations of an accreting neutron star in outburst with a simple ignition model to constrain parameters including the neutron star mass, radius, surface gravity, distance and system inclination, and accreted fuel composition.

The code is written in Python 3, except for settle which is a C++ code with a python wrapper. It makes use of Dan Foreman-Mackey's python implementation of MCMC, emcee, available at https://github.com/dfm/emcee.

Credits

Software written by Adelle Goodwin and Duncan Galloway; for a full description see Goodwin et al. (2019, https://doi.org/10.1093/mnras/stz2638 or preprint at https://arxiv.org/pdf/1907.00996).

The original algorithm is described in Galloway & Cumming (2006, https://iopscience.iop.org/article/10.1086/507598).

pySettle was forked from the original settle written by Andrew Cumming and available at https://github.com/andrewcumming/settle

Package installation and usage

BEANSp is on pyPI (https://pypi.org/project/beansp/) so installation is easy - either system-wide, or in virtual environment:

pip install beansp

You can then import the main Beans module as follows:

from beansp import Beans 

(Please refer to this simple test script as an example.)

Build and installation from this github repository

Please refer to build instructions.

beans's People

Contributors

adellej avatar lukewaterson avatar martincupak avatar outs1der avatar paulhancock avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

beans's Issues

Segmentation fault sometimes encountered at the end of run

  • beans version: <=2.80
  • Python version: 3.8.12
  • Operating System: macOS Ventura 13.3.1

Description

At the end of a run a Segmentation fault is sometimes encountered, following the autocorrelation plot step:

        .
        .
        .
Running analses with do_analysis...
** WARNING ** discarding burnin 2000 will leave too few steps (200 total), ignoring
The autocorrelation time for each parameter as calculated by emcee is: [ 95.98950977  97.67665904 100.4139989   94.46512299 109.10875376
 110.24860239 103.61368367 114.80621353]
  mean 103.3, min 94.5, max 114.8
plot_autocorr: saving figure as base17511_autocorrelationtimes.pdf
Segmentation fault
(beans) MU00153203X [1:24pm] [~/python/beans] > /Users/duncan/miniforge3/envs/beans/lib/python3.8/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 7 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

What I Did

This example was a restart, but not clear if that's what triggers the issue

>>> B.restart=True
>>> B.nsteps=800
>>> B.do_run()
** WARNING ** run will overwrite existing config file base17511.ini
              enter Y[RETURN] to continue: y

Times in example GTI file for 1808-369 not in MJD

  • beans version: unknown
  • Python version: 3.8.5
  • Operating System: Mac

Description

Trying to use the gti_checking option

What I Did

Called beans as recommended in the example, but set gti_checking to 1:

gti_checking=1, gtiname='/Users/duncan/python/beans/data/1808_gti.txt', 
  ...:           theta= (0.5, 0.015, 0.2, 2.1, 3.5, 0.108, 0.90, 0.5, 1.4, 11.2), 
  ...:           numburstssim=3, bc=1., threads = 4, restart=False)
Reading in observation data files ...
Observations found: 
 persistent fluxes = [2.437 2.524 2.501 2.536 2.541 2.298 2.084 1.946 1.913 1.853 1.826 1.695
 1.667 1.652 1.511 1.44  1.469 1.465 1.458 1.441 1.361 1.323 1.295 1.259
 1.247 1.184]
 You have chosen gti_checking = 1, so the gti data is st = [-52562.42413039 -52562.36069289 -52562.29476696 -52562.22902622
 -52562.16178085 -52562.09717437 -52562.029929   -52561.9655077
 -52561.37159567 -52561.30585493 -52561.24079706 -52561.17505631

examination of the example GTI file suggests those values are already relative to some reference time rather than MJD as expected in the code

comparison option in do_analysis fails for ensemble mode

  • beans version: 2.26.0
  • Python version: 3.8.12
  • Operating System: macOS Ventura 13.6.6

Description

After running the chains in ensemble mode, you should be able to plot the comparison of the data; but this is not currently implemented for that mode.

What I Did

from beansp import Beans,beans
B=Beans(config_file='canon.ini',corr=beans.corr_kepler)
B.do_run()
B.do_analysis(['comparison'],burnin=840)
Reading in and processing blobs, ignoring first 840...
...done
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/duncan/python/beans/beansp/beans.py", line 2356, in do_analysis
    
  File "/Users/duncan/python/beans/beansp/beans.py", line 2356, in <listcomp>
    
TypeError: 'int' object is not subscriptable

ValueError: max() arg is an empty sequence interrupting do_run

  • beans version: 2.25.0
  • Python version: 3.8.12
  • Operating System: MacOS Ventura 13.3.1

Description

Following a call to do_run''' the sampler will occasionally fail with a ValueError: max() arg is an empty sequence``` error.

Cause is unknown, but I believe it may be related to too few (or none) valid new points for the sampler on a single step.

Possible workaround includes increasing the number of walkers, but a more reliable solution is to reduce the stretch_a parameter (e.g. to stretch_a/2+1/2; this parameter is 2 by default and must be between 1 and 2) and then continue the run

What I Did

     .
     .
 76%|███████████████████████████████▉          | 76/100 [11:07<03:39,  9.16s/it] emcee: Exception while calling your likelihood function:                         
  params: [6.62444658e-01 5.14554382e-04 7.80165047e-03 9.97523810e+00           
 1.39801204e+00 1.84366942e+00]                                                  
  args: (None, array([0.38172, 0.52387, 0.59306, 0.736  , 0.605  , 0.708  , 0.71 2  ]), array([0.00694444, 0.00694444, 0.00694444, 0.031     , 0.026     ,        
       0.028     , 0.031     ]))                                                 
  kwargs: {}                                                                     
  exception:                                                                     
Traceback (most recent call last):                                               
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/emcee/en semble.py", line 624, in __call__                                                
    return self.f(x, *self.args, **self.kwargs)                                  
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/b eans.py", line 930, in lnprob                                                    
    like, model = self.lnlike(theta_in, x, y, yerr)                              
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/b eans.py", line 868, in lnlike                                                    
    model, valid, model2 = runmodel( theta_in, self)                             
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/r un_model.py", line 161, in runmodel                                              
    result = generate_burst_train( bean,  Q_b, X, Z, dist, xi_p, mass, radius, d ebug=debug)                                                                      
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/b urstrain.py", line 335, in generate_burst_train                                  
    mdot_max = max(smdot)                                                        
ValueError: max() arg is an empty sequence                                       

burst_table method fails for non-numeric alpha values in the input table

  • beans version: 2.25.0
  • Python version: 3.8.12
  • Operating System: MacOS Ventura 13.3.1

Description

burst_table method fails for non-numeric alpha values, as might be extracted from the MINBAR table which inserts '--' for missing data. Could make this more tolerant if there's a way to test for numeric entries

What I Did

B=Beans(config_file='test.ini',corr=beans.corr_goodwin19)
B.do_run(pos='test_69.p')
B.do_analysis(['comparison'],burnin=250)
B.burst_table(key=69)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/beans.py", line 1640, in burst_table
    bursts['alpha_obs'] = MaskedColumn(self.alpha, mask=self.alpha <=0., 
TypeError: '<=' not supported between instances of 'numpy.ndarray' and 'float'

intermittent divide by zeros from lnZprior

  • beans version: 2.2.1
  • Python version: 3.8.12
  • Operating System: macOS Ventura 13.3.1

Description

intermittent warnings during sampling following call to do_run, when using the lnZprior function (called in turn from the prior for SAX J1808.4-3658, prior_1808):

.../python3.8/site-packages/beansp/beans.py:71: RuntimeWarning: divide by zero encountered in log return np.log(

doesn't seem to affect operations otherwise

What I Did

from beansp import Beans, beans
B=Beans(prior=beans.prior_1808)
B.do_run()

call get_a_b on __init__ and store results with Beans object

  • beans version: ?
  • Python version: 3.8
  • Operating System: macOS

Description

generate_burst_train calls get_a_b, which determines the coefficients for the linear flux interpolation, each time it is run. This step needs to be done only once (e.g. when the Beans object is initialised and the flux measurements read in). The a, b coefficients could then be stored as object attributes and passed to the function

Test Suite Issue

  • beans version: beans 0.1.0
  • Python version: python 3.8.5
  • Operating System: Ubuntu 20.04.1 LTS

Description

Describe what you were trying to get done.
Tell us what happened, what went wrong, and what you expected to happen.

I was trying to run pytest, as per the installation instructions.

What I Did

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

$pytest

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_runmodel.py ____________________
ImportError while importing test module '/home/cedric/beans/tests/test_runmodel.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_runmodel.py:3: in
from beans.run_model import runmodel
beans/run_model.py:3: in
from burstrain import *
E ModuleNotFoundError: No module named 'burstrain'
=============================== warnings summary ===============================
/home/cedric/.local/lib/python3.8/site-packages/matplotlib/backends/backend_gtk3.py:40
/home/cedric/.local/lib/python3.8/site-packages/matplotlib/backends/backend_gtk3.py:40: DeprecationWarning: Gdk.Cursor.new is deprecated
cursors.MOVE: Gdk.Cursor.new(Gdk.CursorType.FLEUR),

beans/run_model.py:110
/home/cedric/beans/beans/run_model.py:110: SyntaxWarning: "is" with a literal. Did you mean "=="?
if gti_checking is 1:

-- Docs: https://docs.pytest.org/en/latest/warnings.html
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
===================== 2 warnings, 1 error in 4.59 seconds ======================

Restart feature does not work as intended

  • beans version: unknown
  • Python version: 3.8.5
  • Operating System: Linux (Ubuntu)

Description

Calling beans with restart=True begins the run from scratch instead of resuming the run from the .h5py file. In run_emcee.py, pos is currently defined in the exact same way for both restart=True and restart=False.

plot method fails if the model is not valid

  • beans version: 2.25
  • Python version: 3.8.12
  • Operating System: MacOS Ventura 13.3.1

Description

Like the description says. If the current theta parameters do not produce a valid model, the plot method throws an error.

A workaround is to set show_model=False which will prevent the model calculation, but this should be detected automatically and flagged so that it exits properly

What I Did

B=Beans(config_file='test.ini',corr=beans.corr_goodwin19)
B.theta=(0.58,0.013,0.4,3,1.6,1)
B.plot()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/beans.py", line 972, in plot
    test, valid, model = runmodel(self.theta, self, match=False,
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/run_model.py", line 161, in runmodel
    result = generate_burst_train( bean,  Q_b, X, Z, dist, xi_p, mass, radius, debug=debug)
  File "/Users/duncan/miniforge3/envs/beans/lib/python3.8/site-packages/beansp/burstrain.py", line 335, in generate_burst_train
    mdot_max = max(smdot)
ValueError: max() arg is an empty sequence

The 'for' loop in the settle mainer() function runs only once - return is inside the loop block

  • Operating System:

Description

The 'for' loop in the mainer() function runs only once - return is inside the loop block.
Is that intended behaviour?

Line numbers for reference, it is module setlle.cc

85  int mainer(double* flu, double* Z, double* X, double* mdo, int* docomp,
86         double* trec, double* alpha, double* fluen, double* radius, double*mass)

141  for (int ii=1; ii<=1; ii++) {

276  return 0;
277  } // loop through flux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.