GithubHelp home page GithubHelp logo

xuanxu / starmatrix Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 1.28 MB

Modelling nucleosynthesis of galactic chemical elements

Home Page: https://starmatrix.readthedocs.io

License: MIT License

Python 95.26% TeX 4.74%
astrophysics galaxies

starmatrix's Introduction

✨Starmatrix

Build status Documentation Status Coverage status MIT License starmatrix in PyPi Paper

Starmatrix is a Q-Matrices generator.

Based on explicit values for solar abundances, Z and IMF, Starmatrix calculates matrices Q(i,j) of masses of elements i ejected to the galactic medium as element j, for a complete range of stellar masses, accounting for supernovae of types Ia and II. You can read more about the Matrices Q formalism in Ferrini et al. 1992.

Starmatrix computes the contribution matrix of 15 elements:

H D He3 He4 C C13 N O n.r. Ne Mg Si S Ca Fe

Starmatrix is a tool for astronomers working with galactic chemical evolution models needing detailed datasets to use as input, wanting to compare the validity of different yield sets or assessing different nucleosynthesis modeling assumptions.

Installation

The easiest way to install the package is using pip:

$ pip install starmatrix

This will install the most recent release version and also some dependencies if they are not found in the system: numpy, scipy and pyyaml

A previous installation can be upgraded to the latest version with:

$ pip install --upgrade starmatrix

Edge

If you want to play with the latest code present in this repository even if it has not been released yet, you can do it by cloning the repo locally and instructing pip to install it:

$ git clone https://github.com/xuanxu/starmatrix.git
$ cd starmatrix
$ pip install -e .

Python >= 3.7 is required.

Test installation

To test installation worked you can just run Starmatrix with default values running:

$ starmatrix --generate-config
$ starmatrix --config config-example.yml

The first command will generate a basic configuration file (named config-example.yml) and the second command will run Starmatrix using that configuration. A folder named results should be created with the output files.

Test suite

Starmatrix includes a test suite located in the /src/starmatrix/tests directory. The current state of the build is publicly tracked by GitHub CI. You can run the latest tests locally and get information on code coverage if you clone the code to your local machine, install its development dependencies and use pytest:

$ git clone https://github.com/xuanxu/starmatrix.git
$ cd starmatrix
$ pip install -e ".[dev]"
$ pytest

Usage

Use starmatrix running:

$ starmatrix --config FILENAME

where FILENAME is the path to the config yaml file.

Running starmatrix will produce a directory with three output files:

  • mass_intervals: all the mass intervals used to integrate for all the mass range
  • imf_supernova_rates: the initial mass functions for the supernova rates for each mass interval
  • qm-matrices: the Q(m) matrices for every mass interval defined in the mass_intervals file, expressed as stellar mass fractions.

You can find the complete documentation at ReadTheDocs' Starmatrix page.

Input params

Starmatrix reads a config file where several options can be set in yaml format:

z: 0.0200               # metallicity
sol_ab: as09            # solar abundances
imf: kroupa2002         # initial mass function (IMF)
imf_m_low: 0.15         # lower mass limit for the IMF
imf_m_up: 100           # upper mass limit for the IMF
total_time_steps: 300   # number of time steps (will result in a Q Matrix per step)
m_min: 0.98             # min value for stellar mass
m_max: 40               # max value for stellar mass
binary_fraction: 0.15   # rate of binary stars
snia_m_max              # Upper mass limit for binaries with SN Ia. Default value: 16 Msun
dtd_sn: rlp             # delay time distribution for supernovae
sn_yields: iwa1998      # Dataset for Supernovae yields
output_dir: results     # Name of the directory where results are written.
integration_step: logt  # The integration step can be constant in t, constant in log(t), or custom.
expelled_elements_filename: ejecta.txt  # Filename of ejected data.

Starmatrix will use its internal default values for all params for which no values are provided.

If you want to use an existent configuration file as template for your own, you can run:

$ starmatrix --generate-config

That command will create a config-example.yml file in the current dir containing the default values.

Starmatrix uses solar mass (M*) as the reference unit for all quantities, so internally the upper and lower limits for IMF are expressed in solar masses, Delay Time Distributions are expressed as [Supernovae per Year per M*] and the expelled elements file is expected to express data as expelled mass per solar mass, same as the supernova yields.

Initial mass function

The imf param in the config file can be set to use any of the predefined IMFs from different papers/authors:

salpeter

Salpeter 1955

starburst

Starburst 1999 (a Salpeter with mass limits in [1, 120])

miller_scalo

Miller & Scalo 1979

ferrini

Ferrini, Palla & Penco 1998

kroupa2001

Kroupa 2001

kroupa2002

Kroupa 2002

chabrier

Chabrier 2003

maschberger

Maschberger 2012

The default value is kroupa2002. If you want to use your own IMF you can do so subclassing the IMF class.

The IMF will be normalized integrating in the [imf_m_low, imf_m_up] mass interval (default: [0.15, 100], except Starburst: [1, 120]).

Solar abundances

The sol_ab param in the config file can be set to use any of the available abundances datasets from different papers/authors:

ag89

Anders & Grevesse 1989

gs98

Grevesse & Sauval 1998

as05

Asplund et al. 2005

as09

Asplund et al. 2009

he10

Heger 2010

lo19

Lodders et al. 2019

The default value is as09. If you want to use your own abundances data you can do so subclassing the Abundances class.

Delay Time Distributions

The dtd_sn param in the config file can be set to use any of the available Delay Time Distributions for supernova rates from different papers/authors:

rlp

Supernova rates from Ruiz-Lapuente et al. (2000)

maoz

DTD of Type Ia supernovae from Maoz & Graur (2017)

castrillo

DTD of Type Ia supernovae from Castrillo et al. (2021)

greggio

DTD of Type Ia supernovae from Greggio, L. (2005)

chen

DTD of Type Ia supernovae from Chen et al. (2021)

greggio-CDD04

DTD from model Close DD 0.4 Gyrs from Greggio, L. (2005)

greggio-CDD1

DTD from model Close DD 1 Gyr from Greggio, L. (2005)

greggio-WDD04

DTD from model Wide DD 0.4 Gyrs from Greggio, L. (2005)

greggio-WDD1

DTD from model Wide DD 1 Gyr from Greggio, L. (2005)

greggio-SDCH

DTD from model SD Chandra from Greggio, L. (2005)

greggio-SDSCH

DTD from model SD sub-Chandra from Greggio, L. (2005)

strolger-fit1

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (10, 600, 220)

strolger-fit2

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (110, 1000, 2)

strolger-fit3

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (350, 1200, 20)

strolger-fit4

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (6000, 6000, -2)

strolger-fit5

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (-650, 2200, 1100)

strolger-optimized

Phi function from Strolger et al. (2020) with (ξ, ω, 𝛼) = (-1518, 51, 50)

Supernovae yields

The sn_yields param in the config file can be set to use any of the available supernova yields datasets from different papers/authors:

iwa1998

Data from Iwamoto, K. et al., 1999

sei2013

Data from Seitenzahl et al. 2013

ln2018-1

Data from Leung & Nomoto 2018, Tables 6/7

ln2018-2

Data from Leung & Nomoto 2018, Tables 8/9

ln2018-3

Data from Leung & Nomoto 2018, Tables 10/11

ln2020

Data from Leung & Nomoto 2020

br2019-1

Data from Bravo, E. et al., Table 3

br2019-2

Data from Bravo, E. et al., Table 4

gro2021-1

Data from Gronow, S. et al., Tables 3/A10 He+Core detonations

gro2021-2

Data from Gronow, S. et al., Tables 4/A8 He+Core detonations

mor2018-1

Data from Mori, K. et al., W7

mor2018-2

Data from Mori, K. et al., WDD2

Contributions

If you find a bug or have a question, please [open an issue in the project's repo](https://github.com/xuanxu/starmatrix/issues).

Contributions are welcome, please read our contributing guidelines.

Citation

If you find Starmatrix helpful, please consider citing:

@article{Bazan2022,
   doi = {10.21105/joss.04461},
   url = {https://doi.org/10.21105/joss.04461},
   year = {2022},
   publisher = {The Open Journal},
   volume = {7},
   number = {75},
   pages = {4461},
   author = {Juanjo Bazán and Mercedes Mollá},
   title = {Starmatrix: Modelling nucleosynthesis of galactic chemical elements},
   journal = {Journal of Open Source Software}
}

License

Copyright © 2022 Juanjo Bazán, released under the MIT license.

Credits

Starmatrix is built upon a long list of previous works from different authors/papers:

  • Ferrini et al., 1992, ApJ, 387, 138
  • Ferrini & Poggiantti, 1993, ApJ, 410, 44F
  • Portinari, Chiosi & Bressan, 1998,AA,334,505P
  • Talbot & Arnett, 1973, ApJ, 186, 51-67
  • Galli et al., 1995, ApJ, 443, 536G
  • Mollá et al., 2015, MNRAS, 451, 3693-3708
  • Iwamoto et al., 1999, ApJS, 125, 439
  • Seitenzahl et al., 2013, MNRAS, Volume 429, Issue 2, 1156–1172
  • Matteucci & Greggio, 1986, A&A, 154, 279M
  • Mollá et al., 2017, MNRAS, 468, 305-318
  • Gavilan, Mollá & Buell, 2006, A&A, 450, 509
  • Raiteri C.M., Villata M. & Navarro J.F., 1996, A&A 315, 105-115
  • Ruiz-Lapuente, P., Canal, R., 2000, astro.ph..9312R
  • Maoz, D. & Graur, O., 2017, ApJ, 848, 25M
  • Castrillo, A. et al., 2021, MNRAS V501, 3, 3122–3136
  • Greggio, L., 2005, A&A 441, 1055–1078
  • Leung & Nomoto, 2018, ApJ, Vol 861, Issue 2, Id 143
  • Leung & Nomoto, 2020, ApJ, Vol 888, Issue 2, Id 80
  • Bravo, E. et al., 2019, MNRAS, 482, Issue 4, 4346–4363
  • Gronow, S. et al., 2021, A&A 656, A94
  • Mori, K. et al., 2018, ApJ, 863:176
  • Chen, X., Hu, L. & Wang, L., 2021, ApJ, 922, 15
  • Strolger et al, 2020, ApJ, Vol 890, 2. doi: 10.3847/1538-4357/ab6a97

starmatrix's People

Contributors

danielskatz avatar xuanxu avatar ygrange avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

ygrange

starmatrix's Issues

[JOSS Review]: Tests

Testing as per README.md instructions after fresh install (into conda env)

Fresh install

$> git pull --rebase
$> pip install -e ".[dev]" 
...
Successfully installed attrs-21.4.0 coverage-6.4.2 iniconfig-1.1.1 packaging-21.3 pluggy-1.0.0 py-1.11.0 pyparsing-3.0.9 pytest-7.1.2 pytest-cov-3.0.0 pytest-mock-3.8.2 starmatrix-1.7.1 tomli-2.0.1

Also noted that --cov=starmatrix on the CL is redundant since already present in the setup.cfg/[tool:pytest line 66

$> pytest -v --cov=starmatrix                                                                                                                                                         [main] 
==================================================================================== test session starts =====================================================================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0 -- /opt/anaconda3/envs/starmatrix_review/bin/python
cachedir: .pytest_cache
rootdir: /home/XXX/Repositories/JOSSReviews/starmatrix, configfile: setup.cfg, testpaths: src/starmatrix/tests
plugins: cov-3.0.0, mock-3.8.2
collected 97 items                                                                                                                                                                           

src/starmatrix/tests/test_abundances.py::test_select_abundances PASSED                                                                                                                 [  1%]
src/starmatrix/tests/test_abundances.py::test_abundances_classes_presence PASSED                                                                                                       [  2%]
src/starmatrix/tests/test_abundances.py::test_description_presence PASSED                                                                                                              [  3%]
src/starmatrix/tests/test_abundances.py::test_feh_with_z_zero PASSED                                                                                                                   [  4%]
src/starmatrix/tests/test_abundances.py::test_feh_with_z_non_zero PASSED                                                                                                               [  5%]
src/starmatrix/tests/test_abundances.py::test_h_he4_values PASSED                                                                                                                      [  6%]
src/starmatrix/tests/test_abundances.py::test_elements_value_presence PASSED                                                                                                           [  7%]
src/starmatrix/tests/test_abundances.py::test_abundance_values_presence PASSED                                                                                                         [  8%]
src/starmatrix/tests/test_abundances.py::test_cri_lim_exception PASSED                                                                                                                 [  9%]
src/starmatrix/tests/test_cli.py::test_option_generate_config PASSED                                                                                                                   [ 10%]
src/starmatrix/tests/test_cli.py::test_option_config PASSED                                                                                                                            [ 11%]
src/starmatrix/tests/test_cli.py::test_model_is_configured_properly PASSED                                                                                                             [ 12%]
src/starmatrix/tests/test_cli.py::test_model_is_run PASSED                                                                                                                             [ 13%]
src/starmatrix/tests/test_cli.py::test_creation_of_output_directory FAILED                                                                                                             [ 14%]
src/starmatrix/tests/test_cli.py::test_existent_output_directory PASSED                                                                                                                [ 15%]
src/starmatrix/tests/test_dtds.py::test_dtds_presence PASSED                                                                                                                           [ 16%]
src/starmatrix/tests/test_dtds.py::test_select_dtd PASSED                                                                                                                              [ 17%]
src/starmatrix/tests/test_dtds.py::test_no_negative_time_values PASSED                                                                                                                 [ 18%]
src/starmatrix/tests/test_dtds.py::test_dtd_correction_factor PASSED                                                                                                                   [ 19%]
src/starmatrix/tests/test_elements.py::test_read_file_on_init PASSED                                                                                                                   [ 20%]
src/starmatrix/tests/test_elements.py::test_interpolation_for_mass_data PASSED                                                                                                         [ 21%]
src/starmatrix/tests/test_elements.py::test_extrapolation_for_mass_data PASSED                                                                                                         [ 22%]
src/starmatrix/tests/test_elements.py::test_for_mass_with_no_yield_corrections PASSED                                                                                                  [ 23%]
src/starmatrix/tests/test_elements.py::test_for_mass_with_yield_corrections PASSED                                                                                                     [ 24%]
src/starmatrix/tests/test_elements.py::test_cri_lim_exception PASSED                                                                                                                   [ 25%]
src/starmatrix/tests/test_functions.py::test_value_in_interval PASSED                                                                                                                  [ 26%]
src/starmatrix/tests/test_functions.py::test_secondary_mass_fraction PASSED                                                                                                            [ 27%]
src/starmatrix/tests/test_functions.py::test_mean_lifetime_stellar_mass_relation PASSED                                                                                                [ 28%]
src/starmatrix/tests/test_functions.py::test_total_energy_no_negative_time_values PASSED                                                                                               [ 29%]
src/starmatrix/tests/test_functions.py::test_imf_zero PASSED                                                                                                                           [ 30%]
src/starmatrix/tests/test_functions.py::test_imf_binaries_are_zero_for_non_valid_masses PASSED                                                                                         [ 31%]
src/starmatrix/tests/test_functions.py::test_imf_binary_primary_integrates_phi_primary PASSED                                                                                          [ 32%]
src/starmatrix/tests/test_functions.py::test_imf_binary_secondary_integrates_phi_secondary PASSED                                                                                      [ 34%]
src/starmatrix/tests/test_functions.py::test_global_imf PASSED                                                                                                                         [ 35%]
src/starmatrix/tests/test_functions.py::test_imf_supernovae_II_non_zero_for_SNII_masses PASSED                                                                                         [ 36%]
src/starmatrix/tests/test_functions.py::test_imf_supernovae_II_is_zero_for_lower_masses PASSED                                                                                         [ 37%]
src/starmatrix/tests/test_functions.py::test_imf_supernovae_II_includes_binary_primaries PASSED                                                                                        [ 38%]
src/starmatrix/tests/test_functions.py::test_return_fractions PASSED                                                                                                                   [ 39%]
src/starmatrix/tests/test_imfs.py::test_select_imf PASSED                                                                                                                              [ 40%]
src/starmatrix/tests/test_imfs.py::test_valid_values_presence PASSED                                                                                                                   [ 41%]
src/starmatrix/tests/test_imfs.py::test_description_presence PASSED                                                                                                                    [ 42%]
src/starmatrix/tests/test_imfs.py::test_salpeter_alpha PASSED                                                                                                                          [ 43%]
src/starmatrix/tests/test_imfs.py::test_imf_is_zero_if_no_positive_mass PASSED                                                                                                         [ 44%]
src/starmatrix/tests/test_imfs.py::test_minimum_mass_value_for_kroupa_imfs PASSED                                                                                                      [ 45%]
src/starmatrix/tests/test_imfs.py::test_for_mass_is_normalized PASSED                                                                                                                  [ 46%]
src/starmatrix/tests/test_imfs.py::test_normalization_factor PASSED                                                                                                                    [ 47%]
src/starmatrix/tests/test_imfs.py::test_phi_m_phi_relation PASSED                                                                                                                      [ 48%]
src/starmatrix/tests/test_imfs.py::test_stars_per_mass_unit PASSED                                                                                                                     [ 49%]
src/starmatrix/tests/test_matrix.py::test_q_index PASSED                                                                                                                               [ 50%]
src/starmatrix/tests/test_matrix.py::test_empty_q_matrix PASSED                                                                                                                        [ 51%]
src/starmatrix/tests/test_matrix.py::test_matrices_are_empty_if_not_enough_mass PASSED                                                                                                 [ 52%]
src/starmatrix/tests/test_matrix.py::test_q_sn_size PASSED                                                                                                                             [ 53%]
src/starmatrix/tests/test_matrix.py::test_q_size PASSED                                                                                                                                [ 54%]
src/starmatrix/tests/test_matrix.py::test_q_applies_yield_corrections PASSED                                                                                                           [ 55%]
src/starmatrix/tests/test_matrix.py::test_q_with_no_yield_corrections PASSED                                                                                                           [ 56%]
src/starmatrix/tests/test_matrix.py::test_cri_lim_exception PASSED                                                                                                                     [ 57%]
src/starmatrix/tests/test_model.py::test_model_initialization PASSED                                                                                                                   [ 58%]
src/starmatrix/tests/test_model.py::test_model_run PASSED                                                                                                                              [ 59%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_with_logt_step PASSED                                                                                               [ 60%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_with_t_step PASSED                                                                                                  [ 61%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_with_two_steps_t PASSED                                                                                             [ 62%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_with_fixed_n_steps PASSED                                                                                           [ 63%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_with_invalid_step PASSED                                                                                            [ 64%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_step_t PASSED                                                                                                       [ 65%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_step_logt PASSED                                                                                                    [ 67%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_two_steps_t PASSED                                                                                                  [ 68%]
src/starmatrix/tests/test_model.py::test_explosive_nucleosynthesis_fixed_n_steps PASSED                                                                                                [ 69%]
src/starmatrix/tests/test_model.py::test_create_q_matrices PASSED                                                                                                                      [ 70%]
src/starmatrix/tests/test_model.py::test_create_q_matrices_all_zeros_files_if_wrong_data PASSED                                                                                        [ 71%]
src/starmatrix/tests/test_model.py::test_matrix_header PASSED                                                                                                                          [ 72%]
src/starmatrix/tests/test_model.py::test_return_fractions PASSED                                                                                                                       [ 73%]
src/starmatrix/tests/test_settings.py::test_defaults PASSED                                                                                                                            [ 74%]
src/starmatrix/tests/test_settings.py::test_default_settings_with_no_params PASSED                                                                                                     [ 75%]
src/starmatrix/tests/test_settings.py::test_default_settings_adds_extra_params PASSED                                                                                                  [ 76%]
src/starmatrix/tests/test_settings.py::test_default_settings_adds_extra_params_only_if_needed PASSED                                                                                   [ 77%]
src/starmatrix/tests/test_settings.py::test_validate_with_valid_values PASSED                                                                                                          [ 78%]
src/starmatrix/tests/test_settings.py::test_validate_with_invalid_values PASSED                                                                                                        [ 79%]
src/starmatrix/tests/test_settings.py::test_validate_max_mass_with_valid_values PASSED                                                                                                 [ 80%]
src/starmatrix/tests/test_settings.py::test_validate_max_mass_with_invalid_values PASSED                                                                                               [ 81%]
src/starmatrix/tests/test_settings.py::test_validate_mass_limits_for_starburst_imf PASSED                                                                                              [ 82%]
src/starmatrix/tests/test_settings.py::test_validate_with_invalid_settings PASSED                                                                                                      [ 83%]
src/starmatrix/tests/test_settings.py::test_validate_with_yield_corrections PASSED                                                                                                     [ 84%]
src/starmatrix/tests/test_settings.py::test_validate_yield_corrections_with_invalid_input PASSED                                                                                       [ 85%]
src/starmatrix/tests/test_settings.py::test_validate_yield_corrections PASSED                                                                                                          [ 86%]
src/starmatrix/tests/test_settings.py::test_deprecation_warnings PASSED                                                                                                                [ 87%]
src/starmatrix/tests/test_supernovae.py::test_empty_yields_set_is_all_zeroes PASSED                                                                                                    [ 88%]
src/starmatrix/tests/test_supernovae.py::test_yields_structure PASSED                                                                                                                  [ 89%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_iwamoto PASSED                                                                                                               [ 90%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_seitenzahl PASSED                                                                                                            [ 91%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_leung_nomoto_2018 PASSED                                                                                                     [ 92%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_leung_nomoto_2020 PASSED                                                                                                     [ 93%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_bravo_2019 PASSED                                                                                                            [ 94%]
src/starmatrix/tests/test_supernovae.py::test_yields_from_gronow_2021 PASSED                                                                                                           [ 95%]
src/starmatrix/tests/dtds/test_strolger.py::test_parameters_initialization PASSED                                                                                                      [ 96%]
src/starmatrix/tests/dtds/test_strolger.py::test_has_description PASSED                                                                                                                [ 97%]
src/starmatrix/tests/dtds/test_strolger.py::test_is_normalized PASSED                                                                                                                  [ 98%]
src/starmatrix/tests/dtds/test_strolger.py::test_normalization_rate_uses_hubble_efficiency PASSED                                                                                      [100%]

========================================================================================== FAILURES ==========================================================================================
_____________________________________________________________________________ test_creation_of_output_directory ______________________________________________________________________________

__wrapped_mock_method__ = <function NonCallableMock.assert_called_once_with at 0x7f7b614db490>, args = (<MagicMock name='makedirs' id='140163821917936'>, 'results'), kwargs = {}
__tracebackhide__ = True, msg = "Expected 'makedirs' to be called once. Called 0 times.", __mock_self = <MagicMock name='makedirs' id='140163821917936'>

    def assert_wrapper(
        __wrapped_mock_method__: Callable[..., Any], *args: Any, **kwargs: Any
    ) -> None:
        __tracebackhide__ = True
        try:
>           __wrapped_mock_method__(*args, **kwargs)

/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/pytest_mock/plugin.py:432: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <MagicMock name='makedirs' id='140163821917936'>, args = ('results',), kwargs = {}, msg = "Expected 'makedirs' to be called once. Called 0 times."

    def assert_called_once_with(self, /, *args, **kwargs):
        """assert that the mock was called exactly once and that that call was
        with the specified arguments."""
        if not self.call_count == 1:
            msg = ("Expected '%s' to be called once. Called %s times.%s"
                   % (self._mock_name or 'mock',
                      self.call_count,
                      self._calls_repr()))
>           raise AssertionError(msg)
E           AssertionError: Expected 'makedirs' to be called once. Called 0 times.

/opt/anaconda3/envs/starmatrix_review/lib/python3.10/unittest/mock.py:930: AssertionError

During handling of the above exception, another exception occurred:

mocker = <pytest_mock.plugin.MockerFixture object at 0x7f7a6ecaed10>, deactivate_os_actions = None, mock_config_file = {'m_max': 33.0, 'total_time_steps': 123}

    def test_creation_of_output_directory(mocker, deactivate_os_actions, mock_config_file):
        mocker.spy(cli, "create_output_directory")
        cli.main()
        cli.create_output_directory.assert_called_once_with('results')
>       os.makedirs.assert_called_once_with('results')
E       AssertionError: Expected 'makedirs' to be called once. Called 0 times.

src/starmatrix/tests/test_cli.py:77: AssertionError
------------------------------------------------------------------------------------ Captured stdout call ------------------------------------------------------------------------------------

Running model with settings:

   z = 0.02
   sol_ab = as09
   imf = kroupa2002
   imf_alpha = 2.35
   imf_m_low = 0.15
   imf_m_up = 100
   m_min = 0.98
   m_max = 40.0
   binary_fraction = 0.15
   dtd_sn = rlp
   dtd_correction_factor = 1.0
   sn_yields = iwa1998
   output_dir = results
   matrix_headers = True
   return_fractions = False
   integration_step = logt
   deprecation_warnings = True
   expelled_elements_filename = /home/XXX/Repositories/JOSSReviews/starmatrix/src/starmatrix/sample_input/expelled_elements
   total_time_steps = 300

Done. Output files ready in 'results' directory.

---------- coverage: platform linux, python 3.10.4-final-0 -----------
Name                           Stmts   Miss Branch BrPart  Cover
----------------------------------------------------------------
src/starmatrix/__init__.py         1      0      0      0   100%
src/starmatrix/abundances.py      85      0     18      0   100%
src/starmatrix/cli.py             39      1     10      1    96%
src/starmatrix/constants.py        9      0      0      0   100%
src/starmatrix/dtds.py           165      0     82      7    97%
src/starmatrix/elements.py        38      0     16      0   100%
src/starmatrix/functions.py       86      0     32      1    99%
src/starmatrix/imfs.py           114      0     42      0   100%
src/starmatrix/matrix.py         123      0     52      1    99%
src/starmatrix/model.py          171      0     52      0   100%
src/starmatrix/settings.py        74      0     40      0   100%
src/starmatrix/supernovae.py     125      0    104      9    96%
----------------------------------------------------------------
TOTAL                           1030      1    448     19    99%

================================================================================== short test summary info ===================================================================================
FAILED src/starmatrix/tests/test_cli.py::test_creation_of_output_directory - AssertionError: Expected 'makedirs' to be called once. Called 0 times.
================================================================================ 1 failed, 96 passed in 1.76s ================================================================================

[JOSS Review] API documentation

I find the API documentation provided at https://starmatrix.readthedocs.io a bit rudimentary. I'd suggest to document classes and methods (along with signature and return type) and standalone functions. You're already using docstrings, if you add

:param <parameter_name>: <description>
:type   <parameter_name>: <type>

to class methods and then add the sphinx autodoc extension, to the list of extensions in docs/conf.py, you'll have it. This would also activate online documentation in ipython or jupyter interactive environments.

[JOSS Review] Interactive usage

I'm following the "Advanced" example at https://starmatrix.readthedocs.io/en/latest/usage.html#examples.

Now I'm at the step to define my custom parameters. I could set it all up one by one but what would really be helpful is to be able
to get a handle to the default variables and only customize the ones I want to vary. That's possible via settings.default_settings() but that is not mentioned in the tutorial. I suggest adding a corresponding line o the docs.

The rest of the example works just fine.

Add Strolger's phi

In Strolger et al, ApJ, 2020, 890, 2 there is a Phi function used to fit Delay Time Distributions by parameter optimization.
Strolger

Task: Add Phi with different parameter options to Starmatrix: the 4 fits for binary population synthesis analyses for SD scenarios, and the optimized solution.
fits
params

[JOSS review] paper comments

I read it with interest, some comments, mostly textual advice:

Line 10: "This yields varies" -> "These yields vary"

Line 11-13: I have a few comments about this part.

  • What do you mean by a "simple" stellar population? (Also I wonder if the word "sample" may not be better here)
  • "at each time step" -> I am not sure where the time steps came from. Maybe reword it as "This process is repeated several times, where for each iteration the time is advanced by a fixed value/3Myr/whatever is appropriate here.
  • You have not defined GCE before (educated guess: Galactic Chemical Element), it would be nice if this is written out at least once somewhere.

Line 17: At the rist of just not knowing the jargon (Google does not really help me here); "neutron rich elements", is that in essence "all heavier elements"? Also I think rewording it as "and one number representing all heavier/neutron-rich (pick what you prefer) elements"

Line 21/22: I wanted to make sure I parsed the Q correctly, so I went to the Ferrini paper out of curiosity. Ferrini states "we use the restitution matrices Qij(m) defined as the fraction of the mass of an element j initially present in a star of mass m that is transformed in element i and ejected", you state "Starmatrix calculates matrices Qij of masses of elements i ejected to the galactic medium as element j". I think those two definitions are eachothers inverse. Is this intentional?

Line 34: "as a open source" -> "as an open source"

Figure 1: "Oxigen" -> "Oxygen"

What I think I would like to read in the paper is something I also mentioned w.r.t. the README: It would be nice to mention what the default configuration values are (I think in the paper you can mention that there are default values and that those are typical values for an XYZ-type situation.

Also one thing I wonder after reading the paper, but before playing around is: Could I add my own data set (say, I develop my own IMF or supernova yield model; would it be hard to try it out in Starmatrix)? The README claims this is possible, then I would certainly mention it in the paper because I see it as an extra strenth of the tool.

[JOSS Review] Installation

Here's my first review item for openjournals/joss-reviews#4461

Installation via pip install starmatrix

  • no problem with the installation (in conda env).
  • then run
starmatrix --generate-config                                                                                                                                                       
Created file: config-example.yml

=> OK

  • Testing the installation as per README.md:
$> starmatrix --config config-example.yml                                                                                                                                             

Running model with settings:

   z = 0.02
   sol_ab = as09
   imf = kroupa2002
   imf_alpha = 2.35
   imf_m_low = 0.15
   imf_m_up = 100
   m_min = 0.98
   m_max = 40.0
   binary_fraction = 0.15
   dtd_sn = rlp
   dtd_correction_factor = 1.0
   sn_yields = iwa1998
   output_dir = results
   matrix_headers = True
   return_fractions = False
   integration_step = logt
   deprecation_warnings = True
   expelled_elements_filename = ejections.dat
   total_time_steps = 300

Traceback (most recent call last):
  File "/opt/anaconda3/envs/starmatrix_review/bin/starmatrix", line 8, in <module>
    sys.exit(main())
  File "/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/starmatrix/cli.py", line 41, in main
    model.Model(context).run()
  File "/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/starmatrix/model.py", line 16, in __init__
    self.init_variables()
  File "/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/starmatrix/model.py", line 21, in init_variables
    self.context["expelled"] = elements.Expelled(expelled_elements_filename=self.context["expelled_elements_filename"])
  File "/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/starmatrix/elements.py", line 16, in __init__
    self.read_expelled_elements_file(expelled_elements_filename)
  File "/opt/anaconda3/envs/starmatrix_review/lib/python3.10/site-packages/starmatrix/elements.py", line 36, in read_expelled_elements_file
    expelled_data = open(filename, "r")
FileNotFoundError: [Errno 2] No such file or directory: 'ejections.dat'

Installation from source

cd starmatrix
pip install -e .
  • Generate config
$> starmatrix --generate-config          
Created file: config-example.yml
  • Test
$> starmatrix --config config-example.yml

Running model with settings:

   z = 0.02
   sol_ab = as09
   imf = kroupa2002
   imf_alpha = 2.35
   imf_m_low = 0.15
   imf_m_up = 100
   m_min = 0.8
   m_max = 100.0
   binary_fraction = 0.15
   dtd_sn = rlp
   dtd_correction_factor = 1.0
   sn_yields = iwa1998
   output_dir = results
   matrix_headers = True
   return_fractions = False
   integration_step = logt
   deprecation_warnings = True
   expelled_elements_filename = /home/grotec/Repositories/JOSSReviews/starmatrix/src/starmatrix/sample_input/expelled_elements
   total_time_steps = 300

Done. Output files ready in 'results' directory.

Have to remove the config-example.yml from the previous run though.

Conclusion:

Installation from pip and installation from source result in different config-example.yml causing IO error in the former case.

[JOSS Review]: Units

I assume that all quantities are expressed in solar mass units and other domain specific unit systems. It should be mentioned clearly in
the code, README and paper.

I could imagine that this code be used as a pre or postprocessor to other codes that may employ a different system of units, so unit conversion would have to be considered. To ease such a use case, I would suggest to employ a physical units library such as pint. I understand this is a huge change to the codebase, therefore I leave this as recommendation for future work.

Document the CRI-LIM exception

There is a different treatment of the abundances if the yield data comes from Cristallo et al. 2011 (for low mass stars) + Limongi & Chieffi 2012 (for massive stars) because abundances needs to be corrected for non solar metalicities as they don't follow solar scale.

This info need to be added to the documentation somewhere.

[JOSS Review] Documentation

Since I've got a few comments on the documentation, I decided to put the comments in here so that we can have a topical discussion on that too.

I mentioned this in the README as well, but if I install starmatrix clean, and run it without a config file I get an answer. I think that means you have some set of sane default values.

It would be great, especially for newcomers to the field, to document those. I did notice that the default config file that is generated actually has defaults so it may just be as simple as copy-pasting from there. If it makes sense you could even add some extra sentence describing the standard set (think of something like "default values represent the most popular IMF, with solar environment type metallicity, "etc.

readthedocs

https://starmatrix.readthedocs.io/en/latest/usage.html
custom_params = { ... } I assume this is a dict containing the same parameters as are documented in the configuration page: https://starmatrix.readthedocs.io/en/latest/configuration.html . May be nice to explicitly say this and add a link.

About the starmatrix utility functions:
You mention those but as far as I can see there is no API documentation on readthedocs. What may be useful is to give high-level API documentation in the readthedocs (e.g. make a list of the package contents and tell what is what, so basically this list with one sentence per item:

    abundances
    cli
    constants
    dtds
    elements
    functions
    imfs
    matrix
    model
    settings
    supernovae
    tests (package)

And then refer to the python help for documentation of the functions/objects underneath.

Also: It is mentioned here and there that one can add their own models by subclassing something, but I would expect the docs to actually tell me what to subclass with a small example.

Python docstrings

I noticed the docstrings do not all explain each of the parameters explicitly, in some cases it is not really clear to me what the parameter is supposed to mean. If I look at for instance the function class (which I assume is going to be the one most people will want to develop against, most of the functions take the same set of parameters so this should not be a huge effort.

For example

    imf_binary_primary(m, imf, binary_fraction=0.15)
        Initial mass function for primary stars of binary systems
        Integrated between  m' and m'' using Newton-Cotes
        Returns 0 unless m is in (1.5, 16)

I guess imf is an imf object type, or a string representing an imported one? And m is a mass, but then you take the first and second derivative? So maybe m is a function defining the mass distribution?

I would propose a format like (just guessing here):

imf_binary_primary(m, imf, binary_fraction=0.15)
Initial mass function for primary stars of binary systems Integrated between  m' and m'' using Newton-Cotes. 
arguments: 
m: int, mass in solar masses for which to define the number of stars
imf: staramtrix.imfs, imf to compute the mass for
returns: the number of stars between m' and m'', or 0 if m is not in (1.5, 16)

(you could use an existing docstring standard as well of course)

[JOSS Review]: matrix datastructure

I suggest to return the Q matrix not as a plain array but as an xarray with appropriately labeled axes and dimensions. Otherwise every user will have to code up a index-to-element mapping which is a potential source of error that could easily be avoided. Getting the raw array out of an xarray is trivial.

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.