Skip to content

Commit

Permalink
Fix issue #11, enable integer redshift inputs to preprocess (#12)
Browse files Browse the repository at this point in the history
* Version increment
* Added test demonstrating Issue #11 
* Fix for Issue #11, Globalemu's astrophysics-free background preprocessing failed for uint inputs. Added explicit casting to floats to circumvent this problem
* Added testing for Python 3.10 and deprecated 3.6
* py.test to pytest
  • Loading branch information
ThomasGesseyJones authored Apr 13, 2023
1 parent 32ca401 commit 28ec19d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand All @@ -36,7 +36,7 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
coverage run --source=globalemu -m py.test
coverage run --source=globalemu -m pytest
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Introduction

:globalemu: Robust Global 21-cm Signal Emulation
:Author: Harry Thomas Jones Bevins
:Version: 1.5.1
:Version: 1.5.2
:Homepage: https://github.com/htjb/globalemu
:Documentation: https://globalemu.readthedocs.io/

Expand Down
7 changes: 5 additions & 2 deletions globalemu/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ def __init__(self, num, z, **kwargs):
if self.num != 'full':
raise TypeError("'num' must be an integer or 'full'.")

self.z = z
if type(self.z) not in set([np.ndarray, list]):
if type(z) not in set([np.ndarray, list]):
raise TypeError("'z' should be a numpy array or list.")

# Convert to numpy array, and cast to float to avoid NaN errors in AFB later
z = np.array(z, dtype=float)
self.z = z

self.base_dir = kwargs.pop('base_dir', 'model_dir/')
self.data_location = kwargs.pop('data_location', 'data/')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def readme(short=False):

setup(
name='globalemu',
version='1.5.1',
version='1.5.2',
description='globalemu: Robust and Fast Global 21-cm Signal Emulation',
long_description=readme(),
author='Harry T. J. Bevins',
Expand Down
6 changes: 6 additions & 0 deletions tests/test_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
import shutil


def test_preprocess_integer_redshift():
z = np.arange(5, 5 + 451, dtype=np.uint16)
process(10, z, data_location='21cmGEM_data/')
assert not np.any(np.isnan(np.loadtxt('model_dir/AFB.txt')))


def test_preprocess():
z = np.arange(5, 50.1, 0.1)

Expand Down

0 comments on commit 28ec19d

Please sign in to comment.