Skip to content

Commit

Permalink
Merge 0a76669 into d1907a1
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Mar 22, 2021
2 parents d1907a1 + 0a76669 commit 7b3b5ab
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 5 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci_cron_weekly.yml
@@ -0,0 +1,27 @@
# GitHub Actions workflow that runs on a cron schedule.

name: Cron Scheduled CI Tests

on:
schedule:
# run at 6am UTC on Mondays
- cron: '0 6 * * 1'

jobs:
# Testing links in documents is a good example of something to run on a schedule
# to catch links that stop working for some reason.
doc_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python to build docs with sphinx
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Check links in docs using tox
run: |
tox -e linkcheck
86 changes: 86 additions & 0 deletions .github/workflows/ci_tests.yml
@@ -0,0 +1,86 @@
# GitHub Actions workflow for testing and continuous integration.
#
# This file performs testing using tox and tox.ini to define and configure the test environments.

name: CI Tests

on:
push:
branches:
- master # GitHub now defaults to 'main' as the name of the primary branch. Change this as needed.
# tags: # run CI if specific tags are pushed
pull_request:
# branches: # only build on PRs against 'main' if you need to further limit when CI is run.
# - main

jobs:
# Github Actions supports ubuntu, windows, and macos virtual environments:
# https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
ci_tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- name: Code style checks
os: ubuntu-latest
python: 3.x
toxenv: codestyle

- name: Python 3.7 with minimal dependencies
os: ubuntu-latest
python: 3.7
toxenv: py37-test

- name: Python 3.8 with all optional dependencies and coverage checking
os: ubuntu-latest
python: 3.8
toxenv: py38-test-alldeps-cov

- name: OS X - Python 3.8 with all optional dependencies
os: macos-latest
python: 3.8
toxenv: py38-test-alldeps

- name: Windows - Python 3.8 with all optional dependencies
os: windows-latest
python: 3.8
toxenv: py38-test-alldeps

# - name: Python 3.7 with oldest supported version of all dependencies
# os: ubuntu-16.04
# python: 3.7
# toxenv: py37-test-oldestdeps

# - name: Python 3.8 with latest dev versions of key dependencies
# os: ubuntu-latest
# python: 3.8
# toxenv: py38-test-devdeps

- name: Test building of Sphinx docs
os: ubuntu-latest
python: 3.8
toxenv: build_docs

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up python ${{ matrix.python }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox coveralls
- name: Install graphviz dependency
if: "endsWith(matrix.toxenv, 'build_docs')"
run: sudo apt-get -y install graphviz
- name: Test with tox
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tox -e ${{ matrix.toxenv }}
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -35,6 +35,9 @@ docs/_build
.floo
.flooignore

# Visual Studio Code project files
.vscode

# Packages/installer info
*.egg
*.egg-info
Expand Down
5 changes: 4 additions & 1 deletion docs/changes.rst
Expand Up @@ -5,7 +5,10 @@ PyDL Changelog
1.0.0rc2 (unreleased)
---------------------

* No changes yet.
* Document behavior of :func:`pydl.rebin` for integer inputs; begin migration
to GitHub Actions for CI. (PR `#61`_)

.. _`#61`: https://github.com/weaverba137/pydl/pull/61

1.0.0rc1 (2020-04-28)
---------------------
Expand Down
18 changes: 16 additions & 2 deletions pydl/rebin.py
Expand Up @@ -35,6 +35,15 @@ def rebin(x, d, sample=False):
:exc:`ValueError`
If the new dimensions are incompatible with the algorithm.
Warnings
--------
This function may not be 100% compatible with the IDL version
*for integer inputs*. It is not possible at present to examine the details
of the IDL code to determine the exact type manipulation that are used.
For further discussion see Issue `#60`_.
.. _`#60`: https://github.com/weaverba137/pydl/issues/60
References
----------
http://www.harrisgeospatial.com/docs/rebin.html
Expand Down Expand Up @@ -72,8 +81,8 @@ def rebin(x, d, sample=False):
sliceobj0 = [slice(None)]*len(d0)
sliceobj1 = [slice(None)]*len(d0)
sliceobj = [slice(None)]*len(d)
f = d0[k]/d[k]
if d[k] > d0[k]:
f = d0[k]/d[k]
for i in range(d[k]):
p = f*i
fp = int(floor(p))
Expand All @@ -97,6 +106,7 @@ def rebin(x, d, sample=False):
sliceobj[k] = slice(i, i + 1)
r[tuple(sliceobj)] = xx[tuple(sliceobj0)]
else:
f = d0[k]//d[k]
for i in range(d[k]):
sliceobj[k] = slice(i, i + 1)
if sample:
Expand All @@ -106,6 +116,10 @@ def rebin(x, d, sample=False):
else:
sliceobj0[k] = slice(int(f*i), int(f*(i+1)))
rshape = r[tuple(sliceobj)].shape
r[tuple(sliceobj)] = xx[tuple(sliceobj0)].sum(k).reshape(rshape)/f
rr = xx[tuple(sliceobj0)].sum(k).reshape(rshape)
if xx.dtype.kind == 'u' or xx.dtype.kind == 'i':
r[tuple(sliceobj)] = rr//f
else:
r[tuple(sliceobj)] = rr/f
xx = r
return r
82 changes: 81 additions & 1 deletion pydl/tests/test_pydl.py
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Test the top-level pydl functions.
"""
# import pytest
import pytest
import numpy as np
try:
from astropy.tests.compat import assert_allclose
Expand Down Expand Up @@ -162,6 +162,86 @@ def test_rebin():
assert np.allclose(r, rexpect)


@pytest.mark.xfail
def test_rebin_int():
"""Test rebin on integers. Comparing to IDL code similar to this::
IDL> seed = 100
IDL> array = FIX(RANDOMN(seed, 10, 20) * 100, TYPE=1) ; UINT8
IDL> array_rebin = REBIN(array, 5, 10)
"""
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_rebin = np.array([[161, 70, 105, 107, 173],
[171, 104, 140, 49, 149],
[135, 94, 57, 140, 50],
[148, 84, 129, 204, 26],
[100, 117, 69, 204, 127],
[ 88, 185, 135, 159, 61],
[ 78, 165, 150, 85, 82],
[116, 140, 83, 89, 181],
[123, 148, 190, 157, 122],
[165, 105, 75, 105, 107]], dtype=np.uint8)

ar = rebin(array, (10, 5))
assert (array_rebin == ar).all()


def test_rebin_int_sample():
"""Similar to test_rebin_int(), but using the sample option.
"""
array = np.array([[188, 186, 25, 212, 34, 98, 3, 235, 155, 148],
[107, 166, 4, 41, 101, 190, 39, 154, 153, 239],
[135, 181, 92, 161, 213, 136, 35, 61, 80, 164],
[123, 248, 8, 157, 96, 118, 99, 1, 109, 246],
[226, 71, 183, 27, 46, 99, 8, 239, 66, 25],
[ 27, 219, 37, 130, 5, 81, 65, 250, 96, 14],
[ 71, 157, 156, 136, 47, 225, 247, 191, 49, 12],
[231, 133, 9, 38, 243, 2, 235, 145, 23, 22],
[146, 38, 49, 89, 42, 57, 220, 214, 135, 47],
[101, 116, 122, 209, 141, 37, 158, 224, 245, 82],
[ 15, 47, 51, 250, 207, 193, 209, 228, 110, 1],
[ 59, 232, 216, 224, 24, 118, 190, 10, 107, 27],
[ 84, 193, 112, 206, 113, 171, 138, 117, 244, 20],
[ 5, 31, 128, 214, 200, 119, 59, 27, 57, 10],
[226, 71, 177, 85, 0, 68, 54, 207, 141, 250],
[ 52, 119, 121, 177, 165, 99, 68, 29, 137, 200],
[172, 91, 181, 187, 87, 250, 45, 154, 58, 83],
[ 56, 175, 189, 35, 203, 223, 243, 187, 252, 97],
[186, 172, 207, 128, 61, 231, 89, 57, 131, 222],
[206, 96, 29, 60, 3, 8, 221, 55, 60, 17]], dtype=np.uint8)
array_sample = np.array([[188, 25, 34, 3, 155],
[135, 92, 213, 35, 80],
[226, 183, 46, 8, 66],
[ 71, 156, 47, 247, 49],
[146, 49, 42, 220, 135],
[ 15, 51, 207, 209, 110],
[ 84, 112, 113, 138, 244],
[226, 177, 0, 54, 141],
[172, 181, 87, 45, 58],
[186, 207, 61, 89, 131]], dtype=np.uint8)
ars = rebin(array, (10, 5), sample=True)
assert (array_sample == ars).all()


def test_smooth():
test_data_file = get_pkg_data_filename('t/smooth_data.txt')
noise = np.loadtxt(test_data_file, dtype='d')
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -65,6 +65,7 @@ text_file_format = rst
addopts = --doctest-rst

[coverage:run]
relative_files = True
omit =
pydl/_astropy_init*
pydl/conftest.py
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Expand Up @@ -23,7 +23,7 @@ isolated_build = true
pypi_filter = https://raw.githubusercontent.com/astropy/ci-helpers/master/pip_pinnings.txt

# Pass through the following environment variables which may be needed for the CI
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI TRAVIS
passenv = HOME WINDIR LC_ALL LC_CTYPE CC CI GITHUB_* COVERALLS_*

# Run the tests in a temporary directory to make sure that we don't import
# this package from the source tree
Expand Down Expand Up @@ -52,6 +52,7 @@ description =

# The following provides some specific pinnings for key packages
deps =
cov: coveralls

numpy116: numpy==1.16.*
numpy117: numpy==1.17.*
Expand All @@ -73,6 +74,7 @@ commands =
pip freeze
!cov: pytest --pyargs pydl {toxinidir}/docs {posargs}
cov: pytest --pyargs pydl {toxinidir}/docs --cov pydl --cov-config={toxinidir}/setup.cfg {posargs}
cov: coveralls

[testenv:astropy20]
description = run tests with astropy2.0.*
Expand Down

0 comments on commit 7b3b5ab

Please sign in to comment.