Skip to content

Commit

Permalink
fix: some fixes to errors raised (#94)
Browse files Browse the repository at this point in the history
* 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.

* fix: tests that raise a different error now

* docs: update readme badges

* test: add tests of error corner cases

* docs: better python badge
  • Loading branch information
steven-murray authored Jan 18, 2024
1 parent acfd76b commit 3987d01
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 23 deletions.
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
85 changes: 85 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -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"
66 changes: 66 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/steven-murray/21cmSense/issues/new?template=bug_report.md>`
* `Request a Feature <https://github.com/steven-murray/21cmSense/issues/new?template=feature_request.md>`
* `Ask a Question <https://github.com/steven-murray/21cmSense/issues/new?template=question.md>`
* `Report a bug <https://github.com/rasg-affiliates/21cmSense/issues/new?template=bug_report.md>`
* `Request a Feature <https://github.com/rasg-affiliates/21cmSense/issues/new?template=feature_request.md>`
* `Ask a Question <https://github.com/rasg-affiliates/21cmSense/issues/new?template=question.md>`

When doing any of these, please try to be as succinct, but detailed, as possible, and use
a "Minimum Working Example" whenever applicable.
Expand All @@ -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 <https://github.com/steven-murray/21cmSense>`_
1. First fork `21cmSense <https://github.com/rasg-affiliates/21cmSense>`_
(look for the "Fork" button), then clone the fork locally::

git clone [email protected]:your_name_here/21cmSense.git
Expand Down
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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/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
: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
: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.
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/cli_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/steven-murray/21cmSense/tree/main/docs/tutorials/data>`_.
`here <https://github.com/rasg-affiliates/21cmSense/tree/main/docs/tutorials/data>`_.

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 <https://github.com/steven-murray/21cmSense/blob/master/example_configs/observatory_hera.yml>`_).
`observatory config <https://github.com/rasg-affiliates/21cmSense/blob/master/example_configs/observatory_hera.yml>`_).
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
Expand Down
5 changes: 4 additions & 1 deletion py21cmsense/antpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions py21cmsense/observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions tests/test_antpos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
11 changes: 10 additions & 1 deletion tests/test_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,9 +29,17 @@ 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)

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)
Expand Down

0 comments on commit 3987d01

Please sign in to comment.