diff --git a/.ci-helpers/update_credits.py b/.ci-helpers/update_credits.py new file mode 100644 index 00000000000..847df1e2eee --- /dev/null +++ b/.ci-helpers/update_credits.py @@ -0,0 +1,77 @@ +"""Script for updating `credits.rst` and `README.rst` between releases, +requires the `rst-include` package""" + +import pathlib +import re +import textwrap +import warnings + +import requests +from rst_include import rst_include + + +def generate_zenodo(): + """Generates `zenodo.rst` file with BibTeX citation + Adapted from: https://astrodata.nyc/posts/2021-04-23-zenodo-sphinx/""" + + CONCEPT_DOI = "592480" # See: https://help.zenodo.org/#versioning + zenodo_path = pathlib.Path("docs/resources/zenodo.rst") + + try: + headers = {"accept": "application/x-bibtex"} + response = requests.get( + f"https://zenodo.org/api/records/{CONCEPT_DOI}", headers=headers + ) + response.encoding = "utf-8" + citation = re.findall("@software{(.*)\,", response.text) + zenodo_record = ( + f".. |ZENODO| replace:: {citation[0]}\n\n" + ".. code-block:: bibtex\n\n" + + textwrap.indent(response.text, " " * 4) + ) + + except Exception as e: + warnings.warn( + "Failed to retrieve Zenodo record for TARDIS: " f"{str(e)}" + ) + + not_found_msg = """ + Couldn"t retrieve the TARDIS software citation from Zenodo. Get it + directly from `this link `_ . + """ + + zenodo_record = ( + ".. |ZENODO| replace:: \n\n" + ".. warning:: \n\n" + textwrap.indent(not_found_msg, " " * 4) + ) + + with open(zenodo_path, "w") as f: + f.write(zenodo_record) + + print(zenodo_record) + + +def main(): + generate_zenodo() + + rst_include.include( + source="docs/resources/credits_template.rst", + target="docs/resources/credits.rst", + quiet=False, + inplace=False, + source_encoding="utf-8", + target_encoding="utf-8", + ) + + rst_include.include( + source="README_TEMPLATE.rst", + target="README.rst", + quiet=False, + inplace=False, + source_encoding="utf-8", + target_encoding="utf-8", + ) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 9cb4945dc32..00000000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,30 +0,0 @@ -# For more information on how to use this template please refer to: -# http://tardis-sn.github.io/tardis/development/continuous_integration.html - -name: black - -on: - push: - branches: - - '*' - - pull_request: - branches: - - '*' - -jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.x - - - name: Install Black - run: pip install black==22.3 - - - name: Run Black - run: black --check tardis diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml new file mode 100644 index 00000000000..2c6aff6a596 --- /dev/null +++ b/.github/workflows/codestyle.yml @@ -0,0 +1,48 @@ +# For more information about TARDIS pipelines, please refer to: +# +# https://tardis-sn.github.io/tardis/development/continuous_integration.html + +name: codestyle + +on: + push: + branches: + - '*' + + pull_request: + branches: + - '*' + +jobs: + black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install Black + run: pip install black==22.3 + + - name: Run Black + run: black --check tardis + + flake8: + if: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.x + + - name: Install Flake8 + run: pip install flake8==4.0.1 pep8-naming==0.12.1 + + - name: Run Flake8 + run: flake8 tardis diff --git a/.github/workflows/payload.yml b/.github/workflows/payload.yml new file mode 100644 index 00000000000..5321f6a1504 --- /dev/null +++ b/.github/workflows/payload.yml @@ -0,0 +1,13 @@ +name: payload + +on: + push: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: echo $PAYLOAD + env: + PAYLOAD: ${{ github.event }} diff --git a/.github/workflows/post-release.yml b/.github/workflows/post-release.yml index c566836db8b..27fa47b495d 100644 --- a/.github/workflows/post-release.yml +++ b/.github/workflows/post-release.yml @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v2 - name: Wait for Zenodo webhook - run: sleep 120 + run: sleep 180 - name: Setup Python uses: actions/setup-python@v3 @@ -57,6 +57,32 @@ jobs: name: citation path: CITATION.cff + credits: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Wait for Zenodo webhook + run: sleep 180 + + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: '3.x' + + - name: Install rst-include + run: pip install rst-include requests + + - name: Update README.rst + run: python .ci-helpers/update_credits.py + + - uses: actions/upload-artifact@v3 + with: + name: credits + path: | + README.rst + docs/resources/credits.rst + pull_request: needs: [changelog, citation] runs-on: ubuntu-latest @@ -71,6 +97,7 @@ jobs: run: | cp /tmp/changelog/CHANGELOG.md . cp /tmp/citation/CITATION.cff . + cp -r /tmp/credits/* . - name: Get current date run: echo "DATE=$(date +'%Y.%m.%d')" >> $GITHUB_ENV diff --git a/.gitignore b/.gitignore index 95b55b93422..6dd3f261c4a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ MANIFEST # Sphinx docs/api docs/_build -docs/resources/ZENODO.rst docs/tutorials.rst docs/io/configuration/components/models/converters/density_parse.csv docs/io/configuration/components/models/converters/abund_parse.csv diff --git a/.mailmap b/.mailmap index d6954330037..ac704b1f904 100644 --- a/.mailmap +++ b/.mailmap @@ -172,10 +172,11 @@ Stuart Sim ssim Stuart Sim Stuart Sim Stuart Sim Stuart Sim -tardis-bot -tardis-bot tardis-bot -tardis-bot tardis-bot -tardis-bot tardis-bot <60989672+tardis-bot@users.noreply.github.com> +TARDIS Bot +TARDIS Bot tardis-bot +TARDIS Bot TARDIS Bot +TARDIS Bot TARDIS Bot <60989672+tardis-bot@users.noreply.github.com> +TARDIS Bot Azure Pipelines Tomas Bylund Tomas Bylund Tobychev diff --git a/README_TEMPLATE.rst b/README_TEMPLATE.rst new file mode 100644 index 00000000000..2310b633728 --- /dev/null +++ b/README_TEMPLATE.rst @@ -0,0 +1,56 @@ +====== +TARDIS +====== + +.. image:: https://img.shields.io/badge/Donate-to%20TARDIS-brightgreen.svg + :target: https://numfocus.salsalabs.org/donate-to-tardis/index.html + +.. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A + :target: http://numfocus.org + +.. image:: https://badges.gitter.im/Join%20Chat.svg + :target: https://gitter.im/tardis-sn/tardis + +.. image:: https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc + :target: https://open.vscode.dev/tardis-sn/tardis +| + +TARDIS is a tool that creates synthetic observations (*spectra*) for exploding +stars (*supernovae*). + +.. image:: https://codecov.io/gh/tardis-sn/tardis/branch/master/graph/badge.svg + :target: https://codecov.io/gh/tardis-sn/tardis + +.. image:: https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/tardis/badges/docstr-cov + :target: https://github.com/tardis-sn/tardis/actions/workflows/docstr-cov.yml?query=branch%3Amaster + +.. image:: https://github.com/tardis-sn/tardis/actions/workflows/tests.yml/badge.svg + :target: https://github.com/tardis-sn/tardis/actions/workflows/tests.yml + +.. image:: https://github.com/tardis-sn/tardis/actions/workflows/build-docs.yml/badge.svg + :target: https://tardis-sn.github.io/tardis/index.html + +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black +| + + +.. include:: docs/resources/credits.rst + + +******* +License +******* + +.. image:: https://img.shields.io/conda/l/conda-forge/tardis-sn + :target: https://github.com/tardis-sn/tardis/blob/master/licenses/LICENSE.rst + +.. image:: http://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat + :target: http://www.astropy.org +| + +This project is Copyright (c) TARDIS Collaboration and licensed under +the terms of the BSD 3-Clause license. This package is based upon +the `Astropy package template `_ +which is licensed under the BSD 3-clause license. See the licenses folder for +more information. diff --git a/docs/conf.py b/docs/conf.py index 39c5183c6c7..48d98edf89b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -63,6 +63,7 @@ # directories to ignore when looking for source files. exclude_patterns.append("_templates") exclude_patterns.append("_build") +exclude_patterns.append("**_template.rst") exclude_patterns.append("**.ipynb_checkpoints") exclude_patterns.append("resources/research_done_using_TARDIS/ads.ipynb") @@ -334,54 +335,8 @@ # -- Sphinx hook-ins --------------------------------------------------------- -import re -import pathlib -import requests -import textwrap -import warnings from shutil import copyfile - -def generate_ZENODO(app): - """Creating ZENODO.rst - Adapted from: https://astrodata.nyc/posts/2021-04-23-zenodo-sphinx/""" - CONCEPT_DOI = "592480" # See: https://help.zenodo.org/#versioning - zenodo_path = pathlib.Path("resources/ZENODO.rst") - - try: - headers = {"accept": "application/x-bibtex"} - response = requests.get( - f"https://zenodo.org/api/records/{CONCEPT_DOI}", headers=headers - ) - response.encoding = "utf-8" - citation = re.findall("@software{(.*)\,", response.text) - zenodo_record = ( - f".. |ZENODO| replace:: {citation[0]}\n\n" - ".. code-block:: bibtex\n\n" - + textwrap.indent(response.text, " " * 4) - ) - - except Exception as e: - warnings.warn( - "Failed to retrieve Zenodo record for TARDIS: " f"{str(e)}" - ) - - not_found_msg = """ - Couldn"t retrieve the TARDIS software citation from Zenodo. Get it - directly from `this link `_ . - """ - - zenodo_record = ( - ".. |ZENODO| replace:: \n\n" - ".. warning:: \n\n" + textwrap.indent(not_found_msg, " " * 4) - ) - - with open(zenodo_path, "w") as f: - f.write(zenodo_record) - - print(zenodo_record) - - def generate_tutorials_page(app): """Create tutorials.rst""" notebooks = "" @@ -434,7 +389,6 @@ def create_redirect_files(app, docname): def setup(app): - app.connect("builder-inited", generate_ZENODO) app.connect("builder-inited", generate_tutorials_page) app.connect("autodoc-skip-member", autodoc_skip_member) app.connect("build-finished", create_redirect_files) diff --git a/docs/resources/credits.rst b/docs/resources/credits_template.rst similarity index 99% rename from docs/resources/credits.rst rename to docs/resources/credits_template.rst index c57155d375c..493261e08f9 100644 --- a/docs/resources/credits.rst +++ b/docs/resources/credits_template.rst @@ -72,4 +72,4 @@ The following BibTeX entries are needed for the references: adsnote = {Provided by the SAO/NASA Astrophysics Data System} } -.. include:: ZENODO.rst +.. include:: zenodo.rst diff --git a/tardis/io/schemas/montecarlo.yml b/tardis/io/schemas/montecarlo.yml index 4a31f5228c5..d3811194e07 100644 --- a/tardis/io/schemas/montecarlo.yml +++ b/tardis/io/schemas/montecarlo.yml @@ -64,6 +64,10 @@ properties: default: false description: Enables a more complete treatment of relativitic effects. This includes angle aberration as well as use of the fully general Doppler formula. + enable_nonhomologous_expansion: + type: boolean + default: false + description: Enables nonhomologous expansion. Treats shells as piece-wise homologous areas for velocity-radius dependence. tracking: type: object default: {} diff --git a/tardis/montecarlo/base.py b/tardis/montecarlo/base.py index ce3664ead89..b5f9d502440 100644 --- a/tardis/montecarlo/base.py +++ b/tardis/montecarlo/base.py @@ -202,6 +202,7 @@ def _initialize_geometry_arrays(self, model): self.r_inner_cgs = model.r_inner.to("cm").value self.r_outer_cgs = model.r_outer.to("cm").value self.v_inner_cgs = model.v_inner.to("cm/s").value + self.v_outer_cgs = model.v_outer.to("cm/s").value def _initialize_packets(self, T, no_of_packets, iteration, radius): # the iteration is added each time to preserve randomness diff --git a/tardis/montecarlo/montecarlo_numba/base.py b/tardis/montecarlo/montecarlo_numba/base.py index 79763b1fb85..a2686f43e42 100644 --- a/tardis/montecarlo/montecarlo_numba/base.py +++ b/tardis/montecarlo/montecarlo_numba/base.py @@ -53,6 +53,8 @@ def montecarlo_radial1d( numba_model = NumbaModel( runner.r_inner_cgs, runner.r_outer_cgs, + runner.v_inner_cgs, + runner.v_outer_cgs, model.time_explosion.to("s").value, ) numba_plasma = numba_plasma_initialize(plasma, runner.line_interaction_type) diff --git a/tardis/montecarlo/montecarlo_numba/formal_integral.py b/tardis/montecarlo/montecarlo_numba/formal_integral.py index 9d664c62805..a0561ac725d 100644 --- a/tardis/montecarlo/montecarlo_numba/formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/formal_integral.py @@ -293,6 +293,8 @@ def generate_numba_objects(self): self.numba_model = NumbaModel( self.runner.r_inner_i, self.runner.r_outer_i, + self.runner.r_inner_i / self.model.time_explosion.to("s").value, + self.runner.r_outer_i / self.model.time_explosion.to("s").value, self.model.time_explosion.to("s").value, ) self.numba_plasma = numba_plasma_initialize( diff --git a/tardis/montecarlo/montecarlo_numba/numba_interface.py b/tardis/montecarlo/montecarlo_numba/numba_interface.py index b3c32b5f693..a78a9537317 100644 --- a/tardis/montecarlo/montecarlo_numba/numba_interface.py +++ b/tardis/montecarlo/montecarlo_numba/numba_interface.py @@ -17,12 +17,14 @@ ("r_inner", float64[:]), ("r_outer", float64[:]), ("time_explosion", float64), + ("v_inner", float64[:]), + ("v_outer", float64[:]), ] @jitclass(numba_model_spec) class NumbaModel(object): - def __init__(self, r_inner, r_outer, time_explosion): + def __init__(self, r_inner, r_outer, v_inner, v_outer, time_explosion): """ Model for the Numba mode @@ -30,10 +32,14 @@ def __init__(self, r_inner, r_outer, time_explosion): ---------- r_inner : numpy.ndarray r_outer : numpy.ndarray + v_inner : numpy.ndarray + v_outer : numpy.ndarray time_explosion : float """ self.r_inner = r_inner self.r_outer = r_outer + self.v_inner = v_inner + self.v_outer = v_outer self.time_explosion = time_explosion diff --git a/tardis/montecarlo/montecarlo_numba/tests/conftest.py b/tardis/montecarlo/montecarlo_numba/tests/conftest.py index 6b9be84d2ba..91d1ae63cfd 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/conftest.py +++ b/tardis/montecarlo/montecarlo_numba/tests/conftest.py @@ -52,6 +52,8 @@ def verysimple_numba_model(nb_simulation_verysimple): return NumbaModel( runner.r_inner_cgs, runner.r_outer_cgs, + runner.v_inner_cgs, + runner.v_outer_cgs, model.time_explosion.to("s").value, ) diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py b/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py index 90a36010d91..9eaa077c22b 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_cuda_formal_integral.py @@ -117,7 +117,13 @@ def formal_integral_model(request): This gets the Numba model to be used in later tests """ r = request.param["r"] - model = NumbaModel(r[:-1], r[1:], 1 / c.c.cgs.value) + model = NumbaModel( + r[:-1], + r[1:], + r[:-1] * c.c.cgs.value, + r[1:] * c.c.cgs.value, + 1 / c.c.cgs.value, + ) return model diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py b/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py index b019c787620..2a83aa0e550 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_numba_formal_integral.py @@ -57,7 +57,13 @@ def calculate_z(r, p): @pytest.fixture(scope="function", params=TESTDATA) def formal_integral_model(request): r = request.param["r"] - model = NumbaModel(r[:-1], r[1:], 1 / c.c.cgs.value) + model = NumbaModel( + r[:-1], + r[1:], + r[:-1] * c.c.cgs.value, + r[1:] * c.c.cgs.value, + 1 / c.c.cgs.value, + ) return model diff --git a/tardis/montecarlo/montecarlo_numba/tests/test_packet.py b/tardis/montecarlo/montecarlo_numba/tests/test_packet.py index c227a87feff..0ad3c0e2e4a 100644 --- a/tardis/montecarlo/montecarlo_numba/tests/test_packet.py +++ b/tardis/montecarlo/montecarlo_numba/tests/test_packet.py @@ -6,9 +6,7 @@ import tardis.montecarlo.montecarlo_numba.frame_transformations as frame_transformations import tardis.montecarlo.montecarlo_numba.opacities as opacities import tardis.montecarlo.montecarlo_numba.r_packet_transport as r_packet_transport -from tardis.montecarlo.montecarlo_numba.estimators import ( - update_line_estimators, -) +from tardis.montecarlo.montecarlo_numba.estimators import update_line_estimators import tardis.montecarlo.montecarlo_numba.utils as utils import tardis.montecarlo.montecarlo_numba.numba_interface as numba_interface @@ -31,6 +29,8 @@ def model(): return numba_interface.NumbaModel( r_inner=np.array([6.912e14, 8.64e14], dtype=np.float64), r_outer=np.array([8.64e14, 1.0368e15], dtype=np.float64), + v_inner=np.array([-1, -1], dtype=np.float64), + v_outer=np.array([-1, -1], dtype=np.float64), time_explosion=5.2e7, )