Skip to content

Commit

Permalink
Merge branch 'main' into bug_464
Browse files Browse the repository at this point in the history
  • Loading branch information
rrjbca committed Sep 8, 2021
2 parents 8693e59 + c2cb389 commit 0354771
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 52 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sphinx:
python:
version: 3.7
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
Expand Down
17 changes: 16 additions & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,19 @@
},
{
"orcid": "0000-0002-4437-0770",
"affiliation": "University of Manchester",
"affiliation": "University of Oxford, University of Manchester",
"name": "Ian Harrison"
},
{
"orcid": "0000-0002-5304-9372",
"affiliation": "University of Portsmouth",
"name": "Ian Harry"
},
{
"orcid": "0000-0001-9994-1115",
"affiliation": "University of Geneva",
"name": "William G. Hartley"
},
{
"orcid": "0000-0001-9233-2341",
"affiliation": "University of Portsmouth",
Expand Down Expand Up @@ -103,10 +108,20 @@
"affiliation": "Institute of Astronomy and Astrophysics Academia Sinica",
"name": "Keiichi Umetsu"
},
{
"orcid": "0000-0001-9841-943X",
"affiliation": "University of Portsmouth",
"name": "Arthur E. Tolley"
},
{
"orcid": "0000-0002-7627-8688",
"affiliation": "University of Portsmouth",
"name": "Andrew R. Williamson"
},
{
"orcid": "0000-0003-3334-3037",
"affiliation": "University of Manchester",
"name": "Laura Wolz"
}
],
"contributors": [
Expand Down
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SkyPy: A package for modelling the Universe
===========================================

|Read the Docs| |GitHub| |Codecov|
|Read the Docs| |GitHub| |Codecov| |Compatibility|

This package contains methods for modelling the Universe, galaxies and the
Milky Way. SkyPy simulates populations of astronomical objects, generating
Expand Down Expand Up @@ -68,7 +68,7 @@ You are welcome to talk about the SkyPy package and code using our
`Discussions Page`_. For any other questions about the project in general,
please get in touch with the `SkyPy Co-ordinators`_.

.. _Discussions Page: https://github.com/skypyproject/skypy/discussions
.. _Discussions Page: https://github.com/skypyproject/skypy/discussions
.. _SkyPy Co-ordinators: mailto:skypy-coordinators@googlegroups.com

Contributing
Expand All @@ -95,6 +95,9 @@ in the `Code of Conduct`_.
.. |GitHub| image:: https://github.com/skypyproject/skypy/workflows/Tests/badge.svg
:target: https://github.com/skypyproject/skypy/actions

.. |Compatibility| image:: https://github.com/skypyproject/skypy/actions/workflows/compatibility.yaml/badge.svg
:target: https://github.com/skypyproject/skypy/actions/workflows/compatibility.yaml

.. |Codecov| image:: https://codecov.io/gh/skypyproject/skypy/branch/main/graph/badge.svg
:target: https://codecov.io/gh/skypyproject/skypy

Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setuptools==58.0.0
10 changes: 5 additions & 5 deletions examples/galaxies/sdss_dered_10deg2.ecsv
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# - name: magnitude
# datatype: float32
# - name: dered_u
# datatype: int
# datatype: uint16
# - name: dered_g
# datatype: int
# datatype: uint16
# - name: dered_r
# datatype: int
# datatype: uint16
# - name: dered_i
# datatype: int
# datatype: uint16
# - name: dered_z
# datatype: int
# datatype: uint16
magnitude dered_u dered_g dered_r dered_i dered_z
15.0 5 6 5 9 9
15.1 4 5 11 8 17
Expand Down
5 changes: 5 additions & 0 deletions skypy/galaxies/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ def ryden04_ellipticity(mu_gamma, sigma_gamma, mu, sigma, size=None):
size : int or tuple of ints or None
Size of the sample. If `None` the size is inferred from the parameters.
Returns
-------
ellipticity: (size,) array_like
Ellipticities sampled from the Ryden 2004 model.
References
----------
.. [1] Ryden B. S., 2004, ApJ, 601, 214
Expand Down
22 changes: 6 additions & 16 deletions skypy/pipeline/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from astropy.utils.data import get_pkg_data_filename
import networkx
import numpy as np
import os
import pytest
from skypy.pipeline import Pipeline
from skypy.pipeline._items import Call, Ref
Expand All @@ -21,7 +20,7 @@
HAS_H5PY = True


def test_pipeline():
def test_pipeline(tmp_path):

# Evaluate and store the default astropy cosmology.
config = {'test_cosmology': Call(default_cosmology.get)}
Expand All @@ -44,7 +43,7 @@ def test_pipeline():

pipeline = Pipeline(config)
pipeline.execute()
output_filename = 'output.fits'
output_filename = str(tmp_path / 'output.fits')
pipeline.write(output_filename)
assert len(pipeline['test_table']) == size
assert np.all(pipeline['test_table.column1'] < pipeline['test_table.column2'])
Expand Down Expand Up @@ -251,7 +250,7 @@ def value_in_cm(q):


@pytest.mark.skipif(not HAS_H5PY, reason='Requires h5py')
def test_hdf5():
def test_hdf5(tmp_path):
size = 100
string = size*'a'
config = {'tables': {
Expand All @@ -264,8 +263,9 @@ def test_hdf5():

pipeline = Pipeline(config)
pipeline.execute()
pipeline.write('output.hdf5')
hdf_table = read_table_hdf5('output.hdf5', 'tables/test_table', character_as_bytes=False)
output_filename = str(tmp_path / 'output.hdf5')
pipeline.write(output_filename)
hdf_table = read_table_hdf5(output_filename, 'tables/test_table', character_as_bytes=False)
assert np.all(hdf_table == pipeline['test_table'])


Expand All @@ -289,13 +289,3 @@ def test_depends():
pipeline = Pipeline(config)
pipeline.execute()
assert np.all(pipeline['table_1'] == pipeline['table_2'])


def teardown_module(module):

# Remove fits file generated in test_pipeline
os.remove('output.fits')

# Remove hdf5 file generated in test_hdf5
if HAS_H5PY:
os.remove('output.hdf5')
42 changes: 18 additions & 24 deletions skypy/pipeline/tests/test_skypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from astropy.utils.data import get_pkg_data_filename
from contextlib import redirect_stdout
from io import StringIO
import os
import pytest
from skypy import __version__ as skypy_version
from skypy.pipeline import load_skypy_yaml
from skypy.pipeline._items import Call
from skypy.pipeline.scripts import skypy


def test_skypy():
def test_skypy(tmp_path):

# No arguments
with pytest.raises(SystemExit) as e:
Expand All @@ -36,36 +35,39 @@ def test_skypy():
assert e.value.code == 2

# Process empty config file
filename = get_pkg_data_filename('data/empty_config.yml')
assert skypy.main([filename, 'empty.fits']) == 0
config_filename = get_pkg_data_filename('data/empty_config.yml')
output_filename = str(tmp_path / 'empty.fits')
assert skypy.main([config_filename, output_filename]) == 0

# Process test config file
filename = get_pkg_data_filename('data/test_config.yml')
assert skypy.main([filename, 'test.fits']) == 0
config_filename = get_pkg_data_filename('data/test_config.yml')
output_filename = str(tmp_path / 'test.fits')
assert skypy.main([config_filename, output_filename]) == 0

# Invalid file format
output_filename = str(tmp_path / 'test.invalid')
with pytest.raises(SystemExit) as e:
skypy.main([filename, 'test.invalid'])
skypy.main([config_filename, output_filename])
assert e.value.code == 2


def test_logging(capsys):
def test_logging(capsys, tmp_path):

# Run skypy with default verbosity and check log is empty
filename = get_pkg_data_filename('data/test_config.yml')
output_file = 'logging.fits'
skypy.main([filename, output_file])
config_filename = get_pkg_data_filename('data/test_config.yml')
output_filename = str(tmp_path / 'logging.fits')
skypy.main([config_filename, output_filename])
out, err = capsys.readouterr()
assert(not err)

# Run again with increased verbosity and capture log. Force an exception by
# not using the "--overwrite" flag when the output file already exists.
with pytest.raises(SystemExit):
skypy.main([filename, output_file, '--verbose'])
skypy.main([config_filename, output_filename, '--verbose'])
out, err = capsys.readouterr()

# Determine all DAG jobs and function calls from config
config = load_skypy_yaml(filename)
config = load_skypy_yaml(config_filename)
cosmology = config.pop('cosmology', None)
tables = config.pop('tables', {})
config.update({k: v.pop('.init', Call(Table)) for k, v in tables.items()})
Expand All @@ -88,21 +90,13 @@ def test_logging(capsys):
assert("[INFO] skypy.pipeline: Setting cosmology" in err)

# Check writing output file is in the log
assert(f"[INFO] skypy: Writing {output_file}" in err)
assert(f"[INFO] skypy: Writing {output_filename}" in err)

# Check error for existing output file is in the log
assert(f"[ERROR] skypy: File '{output_file}' already exists." in err)
assert(f"[ERROR] skypy: File {output_filename!r} already exists." in err)

# Run again with decreased verbosity and check the log is empty
with pytest.raises(SystemExit):
skypy.main([filename, output_file, '-qq'])
skypy.main([config_filename, output_filename, '-qq'])
out, err = capsys.readouterr()
assert(not err)


def teardown_module(module):

# Remove fits file generated in test_skypy
os.remove('empty.fits')
os.remove('logging.fits')
os.remove('test.fits')
16 changes: 12 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist =
py{36,37,38,39}-test{,-all}{,-dev,-latest,-oldest}{,-cov}
py{36,37,38,39}-test-numpy{116,117,118,119,120}
py{36,37,38,39}-test-scipy{12,13,14,15,16}
py{36,37,38,39}-test-numpy{116,117,118,119,120,121}
py{36,37,38,39}-test-scipy{12,13,14,15,16,17}
py{36,37,38,39}-test-astropy{40,41,42}
build_docs
linkcheck
Expand Down Expand Up @@ -43,11 +43,13 @@ description =
numpy118: with numpy 1.18.*
numpy119: with numpy 1.19.*
numpy120: with numpy 1.20.*
numpy121: with numpy 1.21.*
scipy12: with scipy 1.2.*
scipy13: with scipy 1.3.*
scipy14: with scipy 1.4.*
scipy15: with scipy 1.5.*
scipy16: with scipy 1.6.*
scipy17: with scipy 1.7.*
astropy40: with astropy 4.0.*
astropy41: with astropy 4.1.*
astropy42: with astropy 4.2.*
Expand All @@ -60,12 +62,14 @@ deps =
numpy118: numpy==1.18.*
numpy119: numpy==1.19.*
numpy120: numpy==1.20.*
numpy121: numpy==1.21.*

scipy12: scipy==1.2.*
scipy13: scipy==1.3.*
scipy14: scipy==1.4.*
scipy15: scipy==1.5.*
scipy16: scipy==1.6.*
scipy17: scipy==1.7.*

astropy40: astropy==4.0.*
astropy41: astropy==4.1.*
Expand All @@ -76,8 +80,8 @@ deps =
dev: git+https://github.com/astropy/astropy.git#egg=astropy

latest: astropy==4.2.*
latest: numpy==1.20.*
latest: scipy==1.6.*
latest: numpy==1.21.*
latest: scipy==1.7.*

oldest: astropy==4.0.*
oldest: numpy==1.16.*
Expand All @@ -88,6 +92,10 @@ extras =
test
all: all

# Enable pip to install pre-releases in the dev environment
pip_pre =
dev: True

commands =
pip freeze
!cov: pytest --pyargs skypy {toxinidir}/docs {posargs}
Expand Down

0 comments on commit 0354771

Please sign in to comment.