From 3a0560b67a4dbd9d6a870a73f081d2cf4f4de305 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Thu, 18 Jan 2024 11:19:35 +0100 Subject: [PATCH 1/5] fix: some fixes to errors raised Emits nicer ValueErrors in a couple of instances, instead of mere assertions. Also adds some .github YAML configurations for upcoming changes to CD. --- .github/dependabot.yml | 21 ++++++++ .github/labels.yml | 85 +++++++++++++++++++++++++++++++++ .github/release-drafter.yml | 66 +++++++++++++++++++++++++ CONTRIBUTING.rst | 8 ++-- README.rst | 10 ++-- docs/conf.py | 4 +- docs/tutorials/cli_tutorial.rst | 4 +- py21cmsense/antpos.py | 5 +- py21cmsense/observatory.py | 11 +++-- setup.cfg | 2 +- 10 files changed, 199 insertions(+), 17 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/labels.yml create mode 100644 .github/release-drafter.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..592b5b2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: monthly + - package-ecosystem: pip + directory: "/.github/workflows" + schedule: + interval: monthly + - package-ecosystem: pip + directory: "/docs" + schedule: + interval: monthly + - package-ecosystem: pip + directory: "/" + schedule: + interval: monthly + versioning-strategy: lockfile-only + allow: + - dependency-type: "all" diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..11bf924 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,85 @@ +--- +# Labels names are important as they are used by Release Drafter to decide +# regarding where to record them in changelog or if to skip them. +# +# The repository labels will be automatically configured using this file and +# the GitHub Action https://github.com/marketplace/actions/github-labeler. +- name: "API breaking" + description: Breaking Changes + color: e305fc +- name: "good first issue" + description: Good for newcomers + color: 7057ff + +- name: "status: duplicate" + description: This issue or pull request already exists + color: d93f0b +- name: "status: invalid" + description: Invalid issue or pull request + color: d93f0b +- name: "status: requires discussion" + description: Issue requires further discussion before implementation + color: f71bd2 +- name: "status: requires research" + description: Issue requires further research before implementation + color: "d93f0b" +- name: "status: wontfix" + description: Valid issue, but out of scope for future fixes + color: "d93f0b" + +- name: "type: maint: dependencies" + description: Pull requests that update a dependency file + color: "0366d6" +- name: "type: maint: documentation" + description: Improvements or additions to documentation + color: "0075ca" +- name: "type: maint: refactoring" + description: Refactoring + color: ef67c4 +- name: "type: maint: removal" + description: Removals and Deprecations + color: 9ae7ea +- name: "type: maint: style" + description: Style + color: c120e5 +- name: "type: maint: build" + description: Build System and Dependencies + color: bfdadc + +- name: "type: accuracy" + description: "Enhancement that improves accuracy" + color: "bfd4f2" +- name: "type: bug" + description: Something isn't working + color: d73a4a +- name: "type: feature: ui" + description: New feature that adds functionality for the user + color: "0e8a16" +- name: "type: feature: physical" + description: New feature that adds new analysis/physical model + color: "0e8a16" +- name: "type: testing" + description: Testing improvements + color: b1fc6f +- name: "type: performance: memory" + description: Performance improvements that reduce memory usage + color: "016175" +- name: "type: performance: cpu" + description: Performance improvements that reduce walltime + color: "016175" +- name: "type: ci" + description: Updates to CI (GH actions, RTD, etc.) + color: "000000" +- name: "type: question" + description: A question about the code or documentation + color: d876e3 + +- name: "priority: low" + description: Low priority + color: "BFD4F2" +- name: "priority: medium" + description: Medium priority + color: "E99695" +- name: "priority: high" + description: High priority + color: "B60205" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..6a94a5b --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,66 @@ +# See https://github.com/marketplace/actions/release-drafter for configuration +categories: + - title: ":boom: Breaking Changes" + label: "breaking" + - title: ":rocket: Features" + label: "enhancement" + - title: ":fire: Removals and Deprecations" + label: "removal" + - title: ":beetle: Fixes" + label: "bug" + - title: ":racehorse: Performance" + label: "performance" + - title: ":rotating_light: Testing" + label: "testing" + - title: ":construction_worker: Continuous Integration" + label: "ci" + - title: ":books: Documentation" + label: "documentation" + - title: ":hammer: Refactoring" + label: "refactoring" + - title: ":lipstick: Style" + label: "style" + - title: ":package: Dependencies" + labels: + - "dependencies" + - "build" +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +autolabeler: + - label: 'documentation' + files: + - '*.md' + branch: + - '/.*docs{0,1}.*/' + - label: 'bug' + branch: + - '/fix.*/' + title: + - '/fix/i' + - label: 'enhancement' + branch: + - '/feature.*|add-.+/' + title: + - '/feat:.+|feature:.+/i' + - label: "removal" + title: + - "/remove .*/i" + - label: "performance" + title: + - "/.* performance .*/i" + - label: "ci" + files: + - '.github/*' + - '.pre-commit-config.yaml' + - '.coveragrc' + - label: "style" + files: + - ".flake8" + - label: "refactoring" + title: + - "/.* refactor.*/i" + +template: | + ## Changes + + $CHANGES diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 86f391f..03e758c 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -10,9 +10,9 @@ Bug reports/Feature Requests/Feedback/Questions It is incredibly helpful to us when users report bugs, unexpected behaviour, or request features. You can do the following: - * `Report a bug ` - * `Request a Feature ` - * `Ask a Question ` + * `Report a bug ` + * `Request a Feature ` + * `Ask a Question ` When doing any of these, please try to be as succinct, but detailed, as possible, and use a "Minimum Working Example" whenever applicable. @@ -32,7 +32,7 @@ pre-commit hooks will run that enforce the ``black`` coding style. If you do not install these requirements, you must manually run black before committing your changes, otherwise your changes will likely fail continuous integration. -1. First fork `21cmSense `_ +1. First fork `21cmSense `_ (look for the "Fork" button), then clone the fork locally:: git clone git@github.com:your_name_here/21cmSense.git diff --git a/README.rst b/README.rst index 5afb62d..9236b6a 100644 --- a/README.rst +++ b/README.rst @@ -2,15 +2,17 @@ 21cmSense ========= -.. image:: https://travis-ci.org/steven-murray/21cmSense.svg?branch=master - :target: https://travis-ci.org/steven-murray/21cmSense -.. image:: https://codecov.io/gh/steven-murray/21cmSense/branch/master/graph/badge.svg - :target: https://codecov.io/gh/steven-murray/21cmSense +.. image:: https://img.shields.io/badge/Python-3.9-3776AB.svg?style=flat&logo=python&logoColor=white + :target: https://www.python.org +.. image:: https://codecov.io/gh/rasg-affiliates/21cmSense/branch/master/graph/badge.svg + :target: https://codecov.io/gh/rasg-affiliates/21cmSense .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black .. image:: https://readthedocs.org/projects/21cmsense/badge/?version=latest :target: https://21cmsense.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status +.. image:: https://img.shields.io/github/license/Ileriayo/markdown-badges?style=for-the-badge + :target: ./LICENSE.rst A python package for calculating the expected sensitivities of 21cm experiments to the Epoch of Reionization and/or Cosmic Dawn power spectrum. diff --git a/docs/conf.py b/docs/conf.py index a70eacb..6b22837 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -43,8 +43,8 @@ pygments_style = "trac" extlinks = { - "issue": ("https://github.com/steven-murray/21cmSense/issues/%s", "#"), - "pr": ("https://github.com/steven-murray/21cmSense/pull/%s", "PR #"), + "issue": ("https://github.com/rasg-affiliates/21cmSense/issues/%s", "#"), + "pr": ("https://github.com/rasg-affiliates/21cmSense/pull/%s", "PR #"), } html_theme = "furo" diff --git a/docs/tutorials/cli_tutorial.rst b/docs/tutorials/cli_tutorial.rst index 1a7e867..58912e3 100644 --- a/docs/tutorials/cli_tutorial.rst +++ b/docs/tutorials/cli_tutorial.rst @@ -13,13 +13,13 @@ files:: These are all the configuration and data files we will need to perform the sensitivity estimate. You can obtain them -`here `_. +`here `_. Antenna Positions ~~~~~~~~~~~~~~~~~ In general you do not need a file of antenna positions -- you could alternatively specify a function to generate them (eg. see the default example -`observatory config `_). +`observatory config `_). Typically, however, you will have a given list of positions. These can be in the format of a ``.npy`` array, a pickle file, or a simple ASCII file. In any case, the array must be of shape ``(Nant, 3)``, where the three columns are East, North and Elevation, all diff --git a/py21cmsense/antpos.py b/py21cmsense/antpos.py index 6886b6b..968d5b5 100644 --- a/py21cmsense/antpos.py +++ b/py21cmsense/antpos.py @@ -16,7 +16,7 @@ @yaml.yaml_func() def hera( - hex_num, + hex_num: int, separation: tp.Length = 14 * un.m, split_core: bool = False, outriggers: bool = False, @@ -46,6 +46,9 @@ def hera( antpos A 2D array of antenna positions, shape ``(Nants, 3)``. """ + if hex_num <= 1: + raise ValueError("hex_num must be greater than 1") + sep = separation.to_value("m") if row_separation is None: diff --git a/py21cmsense/observatory.py b/py21cmsense/observatory.py index 2bf0f9a..93fdafa 100644 --- a/py21cmsense/observatory.py +++ b/py21cmsense/observatory.py @@ -80,9 +80,14 @@ class Observatory: @_antpos.validator def _antpos_validator(self, att, val): tp.vld_physical_type("length")(self, att, val) - assert val.ndim == 2 - assert val.shape[-1] == 3 - assert val.shape[0] > 1 + if val.ndim != 2: + raise ValueError("antpos must be a 2D array.") + + if val.shape[-1] != 3: + raise ValueError("antpos must have shape (Nants, 3).") + + if val.shape[0] <= 1: + raise ValueError("antpos must have at least two antennas.") @cached_property def antpos(self) -> np.ndarray: diff --git a/setup.cfg b/setup.cfg index e6875dc..8ac5c2b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,7 +5,7 @@ author = Jonathan Pober license = mit long_description = file: README.rst long_description_content_type = text/x-rst; charset=UTF-8 -url = https://github.com/steven-murray/21cmSense +url = https://github.com/rasg-affiliates/21cmSense # Change if running only on Windows, Mac or Linux (comma-separated) platforms = any # Add here all kinds of additional classifiers as defined under From 63c4e2004c60c6c17c8f00648623d78512a4fd96 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Thu, 18 Jan 2024 11:27:02 +0100 Subject: [PATCH 2/5] fix: tests that raise a different error now --- tests/test_antpos.py | 4 ++-- tests/test_observatory.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_antpos.py b/tests/test_antpos.py index 0382aaf..5a7b31f 100644 --- a/tests/test_antpos.py +++ b/tests/test_antpos.py @@ -6,7 +6,7 @@ from py21cmsense.antpos import hera -@pytest.mark.parametrize("n", [3, 5, 8, 1]) +@pytest.mark.parametrize("n", [3, 5, 8]) def test_hera_split_core(n): # https://en.wikipedia.org/wiki/Centered_hexagonal_number # 3*n^2 - 3n + 1 @@ -16,7 +16,7 @@ def test_hera_split_core(n): assert len(antpos2) == len(antpos1) - n -@pytest.mark.parametrize("n", [3, 5, 8, 1]) +@pytest.mark.parametrize("n", [3, 5, 8]) def test_hera_outriggers(n): # https://en.wikipedia.org/wiki/Centered_hexagonal_number # 3*n^2 - 3n + 1 diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 7688da2..107e889 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -28,7 +28,7 @@ def test_antpos(bm): Observatory(antpos=np.zeros((10, 3)) * units.s, beam=bm) # Need more than one antenna - with pytest.raises(AssertionError): + with pytest.raises(ValueError, match="antpos must have at least two antennas"): Observatory(antpos=np.zeros((1, 3)) * units.m, beam=bm) From 4dd712f5d76b04d93816ba4d472402ac8adef9e0 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Thu, 18 Jan 2024 11:30:01 +0100 Subject: [PATCH 3/5] docs: update readme badges --- README.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 9236b6a..6013c32 100644 --- a/README.rst +++ b/README.rst @@ -4,15 +4,15 @@ .. image:: https://img.shields.io/badge/Python-3.9-3776AB.svg?style=flat&logo=python&logoColor=white :target: https://www.python.org -.. image:: https://codecov.io/gh/rasg-affiliates/21cmSense/branch/master/graph/badge.svg - :target: https://codecov.io/gh/rasg-affiliates/21cmSense +.. image:: https://codecov.io/gh/rasg-affiliates/21cmSense/branch/main/graph/badge.svg + :target: https://codecov.io/gh/rasg-affiliates/21cmSense .. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black + :target: https://github.com/psf/black .. image:: https://readthedocs.org/projects/21cmsense/badge/?version=latest - :target: https://21cmsense.readthedocs.io/en/latest/?badge=latest - :alt: Documentation Status -.. image:: https://img.shields.io/github/license/Ileriayo/markdown-badges?style=for-the-badge - :target: ./LICENSE.rst + :target: https://21cmsense.readthedocs.io/en/latest/?badge=latest + :alt: Documentation Status +.. image:: https://img.shields.io/github/license/Ileriayo/markdown-badges?style=flat + :target: ./LICENSE.rst A python package for calculating the expected sensitivities of 21cm experiments to the Epoch of Reionization and/or Cosmic Dawn power spectrum. From 2443fda497966fcb69f06a9bd8d6515ad76279c4 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Thu, 18 Jan 2024 11:37:04 +0100 Subject: [PATCH 4/5] test: add tests of error corner cases --- tests/test_antpos.py | 5 +++++ tests/test_observatory.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/test_antpos.py b/tests/test_antpos.py index 5a7b31f..8defa57 100644 --- a/tests/test_antpos.py +++ b/tests/test_antpos.py @@ -34,3 +34,8 @@ def test_hera_set_row_sep(): antpos3 = hera(4, row_separation=12.12 * un.m) assert not np.allclose(antpos1, antpos3) + + +def test_bad_hex_num(): + with pytest.raises(ValueError): + hera(1) diff --git a/tests/test_observatory.py b/tests/test_observatory.py index 107e889..a19001f 100644 --- a/tests/test_observatory.py +++ b/tests/test_observatory.py @@ -2,6 +2,7 @@ import numpy as np import pyuvdata +import re from astropy import units from astropy.coordinates import EarthLocation from pathlib import Path @@ -31,6 +32,14 @@ def test_antpos(bm): with pytest.raises(ValueError, match="antpos must have at least two antennas"): Observatory(antpos=np.zeros((1, 3)) * units.m, beam=bm) + with pytest.raises(ValueError, match="antpos must be a 2D array"): + Observatory(antpos=np.zeros(10) * units.m, beam=bm) + + with pytest.raises( + ValueError, match=re.escape("antpos must have shape (Nants, 3)") + ): + Observatory(antpos=np.zeros((10, 2)) * units.m, beam=bm) + def test_observatory_class(bm): a = Observatory(antpos=np.zeros((3, 3)) * units.m, beam=bm) From 969459d4824b85e112beea87b996ec4089226c24 Mon Sep 17 00:00:00 2001 From: Steven Murray Date: Thu, 18 Jan 2024 16:42:10 +0100 Subject: [PATCH 5/5] docs: better python badge --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 6013c32..ffe08fd 100644 --- a/README.rst +++ b/README.rst @@ -2,8 +2,8 @@ 21cmSense ========= -.. image:: https://img.shields.io/badge/Python-3.9-3776AB.svg?style=flat&logo=python&logoColor=white - :target: https://www.python.org +.. image:: https://img.shields.io/pypi/pyversions/21cmSense + :alt: PyPI - Python Version .. image:: https://codecov.io/gh/rasg-affiliates/21cmSense/branch/main/graph/badge.svg :target: https://codecov.io/gh/rasg-affiliates/21cmSense .. image:: https://img.shields.io/badge/code%20style-black-000000.svg